我想知道您如何在 pegjs 中解析评论(例如,la Haskell)。
目标:
{-
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
-}
例如,以下内容不应解析:
{- I am an unbalanced -} comment -}
但是你也应该有一个逃生机制:
{- I can escape comment \{- characters like this \-} -}
这种排序看起来像是解析 s-expressions,但使用 s-expressions 很容易:
sExpression = "(" [^)]* ")"
因为关闭括号只是一个字符,我不能用胡萝卜“不”它。顺便说一句,我想知道如何“不”比 pegjs 中的单个字符长的东西。
谢谢你的帮助。