Space handling with Parsec

Anakreon Mendis anakreon at
Mon Nov 5 06:18:02 EST 2007

I hope this is the correct mailing list do address parsec
related questions.

There is a question about parsec which I hope you
could help.

According to the documentation space parser recognizes '\n'
as a space character.
I am implementing a Basic parser where newline is important.

For example, now the parser accepts the expression:
as equivalent to "a= 1 + 2" when it shouldn't.

If this was the only problem, it wouldn't be a big deal.

However, in basic, a function call is not required to enclose
the arguments with parenthesis. Thus, the expressions:
anOtherFunc arg1, arg2
are valid.

Since the newline is skipped, when the parser tries to match
the optional arguments of myFunc, it will search them in the
line below. The parser will consume characters and will fail.

What I tried to do is:
imported the Parsec module, hiding the `space`.
Reimplemented the space parser as
space = oneOf [' ', '\t']

The parser behaved the same.

Afterwords, I implemented the whiteSpace parser
whiteSpace = skipMany space

This didn't work either.

More information about the Libraries mailing list