Today I've rewritten PArrow's primitive combinators to support proper backtracking and non-greedy matching, as well as subrule support. This now works correctly:
miniLang :: Grammar
miniLang = grammar
[ "literal" ~:~ "nil | true | false"
, "call" ~:~ "\\. <method>"
, "method" ~:~ "\\w+"
, "expr" ~:~ "<literal> <call>*"
]
ghci> "nil.foo.bar" ~~ miniLang .<> "expr"
Right (MatchObj
{ matchString = "nil.foo.bar"
, matchSubPos = fromList []
, matchSubNam =
{ "call" := MatchSeq (fromList
[ MatchStr "."
, MatchNam "method" (MatchStr "bar")
])
, "literal" := MatchStr "nil"
}
})
Both named and positional captures are supported, as well as negated and noncapturing variants (<!name> and <?name> respectively). This seems sufficient for porting the surface language parser of PILN and PIL2 from Parsec; tewk already volunteered to give it a try.
If it turns out that we need more features (e.g. lookaround, integration with OpTable, callbacks and backreferences), I'll definitely hack them in. :-)
Recent Comments