git @ Cat's Eye Technologies Fountain / 2fb5d97
We can coalesce constraints for parsing, just not decorate loops. Chris Pressey 1 year, 7 months ago
2 changed file(s) with 7 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
8282 parseAlt _st [] = Failure
8383 -- we ignore the constraint here because it will be found and applied when we descend into e
8484 parseAlt st [(_, e)] = parse g st e
85 parseAlt _st other =
86 error ("Multiple pre-conditions are satisfied in Alt: " ++ (depictExprs (map (snd) other)))
85 parseAlt (Parsing _str store) other =
86 error ("Multiple pre-conditions are satisfied in Alt: " ++ (depictExprs (map (snd) other)) ++ ", with state: " ++ show store)
87 parseAlt _ _ = Failure
8788
88 parse g state (Loop l _) = parseLoop state l where
89 parse g state (Loop l []) = parseLoop state l where
8990 parseLoop st e =
9091 case parse g st e of
9192 Failure -> st
9293 st' -> parseLoop st' e
94
95 parse _g _state (Loop l (_:_)) = error ("Parsing can't handle decorated Loops: " ++ depictExpr l)
9396
9497 parse _g state (Terminal c) = expectTerminal c state
9598
1414 preprocessGrammarForParsing :: Grammar -> Grammar
1515 preprocessGrammarForParsing (Grammar productions) = Grammar $ map (preprocessProduction) productions where
1616 preprocessProduction p@Production{ constituents=c } = p { constituents=preprocessExpr c }
17 preprocessExpr = eliminateSingleAlts
17 preprocessExpr = eliminateSingleAlts . coalesceConstraints
1818
1919
2020 --