parse (many (char '.') >> eof) "...">

Parsec - many and error messages

When I try to parse many p, I do not receive the message "Waiting for p":

> parse (many (char '.') >> eof) "" "a"
Left (line 1, column 1):
unexpected 'a'
expecting end of input

Compare with

> parse (sepBy (char '.') (char ',') >> eof) "" "a"
Left (line 1, column 1):
unexpected 'a'
expecting "." or end of input

which reports ".". as i expected. many1 p <|> return []also works.

All of these functions accept empty input , so why manynot letting them know what it expects? Is this a bug or a function?

+3
source share
4 answers

, many , sepBy many. "..." , , ; many , .

, , , Parsec. Parsec, , . , , . , uu-parsinglib.

+3

manyTill:

> parse (manyTill (char '.') eof) "" "a"
Left (line 1, column 1):
unexpected 'a'
expecting end of input or "."

- , >>. , . many , eof . eof , eof.

manyTill ( -), , ( , <|> ).

, , <?>:

> parse (many (char '.') >> eof <?> "lots of dots") "" "a"
Left (line 1, column 1):
unexpected 'a'
expecting lots of dots
+7

haddock

p p zero . p.

, - many.

[]

. expecting a or b , <|> ( ). many <|>, sepBy .

+1

This is a bug introduced in parsec-3.1. If you check previous versions, you will receive an error message that resembles the following:

> parse (many (char '.') >> eof) "" "a"
Left (line 1, column 1):
unexpected 'a'
expecting "." or end of input

At least this is what I get after fixing the error :-)

0
source

Source: https://habr.com/ru/post/1775291/


All Articles