[Haskell-cafe] Re: Parsec question (new user): unexpected end of input
Am 29.09.2010 05:35, schrieb Peter Schmitz: [...] Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1): unexpected end of input expecting The input was: [...] -- Parsers: taggedContent = do optionalWhiteSpace aTag many tagOrContent aTag many tagOrContent will consume all tags, so that no tag for the following aTag will be left. Cheers Christian eof return Parse complete. tagOrContent = aTag | someContent ? tagOrContent aTag = do tagBegin xs - many (noneOf [tagEndChar]) tagEnd optionalWhiteSpace return () someContent = do manyTill anyChar tagBegin return () optionalWhiteSpace = spaces -- i.e., any of \v\f\t\r\n tagBegin = char tagBeginChar tagEnd = char tagEndChar -- Etc: tagBeginChar = '' tagEndChar = '' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Parsec question (new user): unexpected end of input
Am 29.09.2010 09:54, schrieb Christian Maeder: Am 29.09.2010 05:35, schrieb Peter Schmitz: [...] Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1): unexpected end of input expecting The input was: [...] -- Parsers: taggedContent = do optionalWhiteSpace aTag many tagOrContent aTag many tagOrContent will consume all tags, so that no tag for the following aTag will be left. if you want to match a final tag, you could try: manyTill tagOrContent (try (aTag eof)) Cheers Christian eof return Parse complete. tagOrContent = aTag | someContent ? tagOrContent aTag = do tagBegin xs - many (noneOf [tagEndChar]) this also looks like manyTill anyChar tagEnd C. tagEnd optionalWhiteSpace return () someContent = do manyTill anyChar tagBegin return () optionalWhiteSpace = spaces -- i.e., any of \v\f\t\r\n tagBegin = char tagBeginChar tagEnd = char tagEndChar -- Etc: tagBeginChar = '' tagEndChar = '' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Parsec question (new user): unexpected end of input
Am 29.09.2010 11:55, schrieb Christian Maeder: Am 29.09.2010 09:54, schrieb Christian Maeder: Am 29.09.2010 05:35, schrieb Peter Schmitz: [...] Error parsing file: ...\sampleTaggedContent.txt (line 4, column 1): unexpected end of input expecting The input was: [...] -- Parsers: taggedContent = do optionalWhiteSpace aTag many tagOrContent aTag many tagOrContent will consume all tags, so that no tag for the following aTag will be left. if you want to match a final tag, you could try: manyTill tagOrContent (try (aTag eof)) better yet, avoiding backtracking, return different things for aTag and someContents and check if the last entry is a tag. tagOrContent = fmap Left aTag | fmap Right someContent taggedContent = do spaces aTag l - many tagOrContent eof case reverse l of Left _ : _ - return () _ - fail expected final tag before EOF C. Cheers Christian eof return Parse complete. tagOrContent = aTag | someContent ? tagOrContent aTag = do tagBegin xs - many (noneOf [tagEndChar]) this also looks like manyTill anyChar tagEnd C. tagEnd optionalWhiteSpace return () someContent = do manyTill anyChar tagBegin return () optionalWhiteSpace = spaces -- i.e., any of \v\f\t\r\n tagBegin = char tagBeginChar tagEnd = char tagEndChar -- Etc: tagBeginChar = '' tagEndChar = '' ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Parsec question (new user): unexpected end of input
Antoine and Christian: Many thanks for your help on this thread. (I am still digesting it; much appreciated; will post when I get it working.) -- Peter ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe