attpoarsec and recursive parsing

PICCA Frederic-Emmanuel <[email protected]>
Newsgroups gmane.comp.lang.haskell.cafe
Message-ID <590626674.46873257.1729260822553.JavaMail.zimbra@synchrotron-soleil.fr>
Hello

I have this type

data MaskLocation = MaskLocation Text
                  | MaskLocation'Tmpl Text
                  | MaskLocation'Or MaskLocation MaskLocation
	deriving (Eq, Generic, Show)
	deriving anyclass (FromJSON, ToJSON)

instance FieldEmitter MaskLocation where
  fieldEmitter (MaskLocation t) = t
  fieldEmitter (MaskLocation'Tmpl t) = t
  fieldEmitter (MaskLocation'Or l r) = fieldEmitter l <> " | " <> fieldEmitter r

I just added the MaskLocation'Or constructor in order to  allow writing

"mymask.npy | mymask2.npy | ..."

So my question how should I write the new parser

here the parser for the MaskLocation without the MaskLocation'Or


instance FieldParsable MaskLocation where
  fieldParser =	do
    t ← takeText
    pure $ if "{scannumber:" `Data.Text.isInfixOf` t
           then MaskLocation'Tmpl t
           else MaskLocation t

It seems to me that I need to consume all text until I find a '|', call the parser on the collected text and start again the process.
But I do not have a  clear idea of how to collect all the values once the process is over.

If someone could help me design this parser, It would be great.

thanks a lot

Frederic
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.