[wiki:Commentary < Commentary]
= Parser =
The parser has two main goals; to build an AST for the compiler and to give good syntax errors for the compiler user.
== Avoid using the try combinator ==
To generate good parser error messages, the use of Parsec.try should be avoided. Parsec.try is problematic because:
- The process of starting at the try, parsing forward, failing and then backtracking is slower than parsing with only a single token lookahead.
- Using try means that any failure will backtrack to the inner most try which is not really where the parse failed. This means that Parsec will not be able to produce good parser error messages. For instance, if the parser uses Parsec.try to parse a faulty list comprehension like this:
{{{
x = [ x + 2, y | x -- \ case { ALT .. }
-- overlaps with the nexta lambda form
(Parsec.try $ do
tok -- \ PAT .. -> EXP
do tok1 do tok Parser (Exp SP)
pBackslashExp startPos =
do pTok K.Case
alts do pats