I was wondering how do you parse comments (say, a la Haskell), in pegjs.
The goal:
{-
This is a comment and should parse.
Comments start with {- and end with -}.
If you've noticed, I still included {- and -} in the comment.
This means that comments should also nest
{- even {- to -} arbitrary -} levels
But they should be balanced
-}
For example, the following should not parse:
{- I am an unbalanced -} comment -}
But you should also have an escape mechanism:
{- I can escape comment \{- characters like this \-} -}
This sorta seems like parsing s-expressions, but with s-expressions, it's easy:
sExpression = "(" [^)]* ")"
Because the close parens is just one character and I can "not" it with the carrot. As an aside, I'm wondering how one can "not" something that is longer than a single character in pegjs.
Thanks for your help.