
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: a = 1 + 2 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: myFunc 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 as whiteSpace = skipMany space This didn't work either.

On Mon, Nov 05, 2007 at 01:18:02PM +0200, Anakreon Mendis wrote:
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 as whiteSpace = skipMany space
This didn't work either.
If you're using the lexing functionality found in Parsec.Token then keep in mind that those combinators will drop whitespace automatically. Shadowing the `space' function doesn't affect any other modules. If you want whitespace sensitivity then you'll have to write or use a separate scanner, as described in the manual. -- -- Matthew Danish -- user: mrd domain: cmu.edu -- OpenPGP public key: C24B6010 on keyring.debian.org

Matthew Danish
On Mon, Nov 05, 2007 at 01:18:02PM +0200, Anakreon Mendis wrote:
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 as whiteSpace = skipMany space
This didn't work either.
If you're using the lexing functionality found in Parsec.Token then keep in mind that those combinators will drop whitespace automatically. Shadowing the `space' function doesn't affect any other modules. If you want whitespace sensitivity then you'll have to write or use a separate scanner, as described in the manual. It's a pity. I do not want to implement a scanner when Parsec does the job well (except for newline treatment).
I wander if parsec could be extended in two issues. 1:Accept in LanguageDef a parser for line comments instead of a char. In basic comments start either with "'" or "REM". 2:Allow to configure in LanguageDef the treatment of newline and whitespace in general. As a workaround, before the input is delivered to the parser, the newline is changed into $\n and it works.
participants (2)
-
Anakreon Mendis
-
Matthew Danish