We can coalesce constraints for parsing, just not decorate loops.
Chris Pressey
1 year, 7 months ago
82 | 82 |
parseAlt _st [] = Failure
|
83 | 83 |
-- we ignore the constraint here because it will be found and applied when we descend into e
|
84 | 84 |
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
|
87 | 88 |
|
88 | |
parse g state (Loop l _) = parseLoop state l where
|
|
89 |
parse g state (Loop l []) = parseLoop state l where
|
89 | 90 |
parseLoop st e =
|
90 | 91 |
case parse g st e of
|
91 | 92 |
Failure -> st
|
92 | 93 |
st' -> parseLoop st' e
|
|
94 |
|
|
95 |
parse _g _state (Loop l (_:_)) = error ("Parsing can't handle decorated Loops: " ++ depictExpr l)
|
93 | 96 |
|
94 | 97 |
parse _g state (Terminal c) = expectTerminal c state
|
95 | 98 |
|
14 | 14 |
preprocessGrammarForParsing :: Grammar -> Grammar
|
15 | 15 |
preprocessGrammarForParsing (Grammar productions) = Grammar $ map (preprocessProduction) productions where
|
16 | 16 |
preprocessProduction p@Production{ constituents=c } = p { constituents=preprocessExpr c }
|
17 | |
preprocessExpr = eliminateSingleAlts
|
|
17 |
preprocessExpr = eliminateSingleAlts . coalesceConstraints
|
18 | 18 |
|
19 | 19 |
|
20 | 20 |
--
|