1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Move the Alt rule down to reflect constructor order.

This commit is contained in:
Rob Rix 2017-04-26 13:37:48 -04:00
parent 89b30a5124
commit d2da6e1ad7

View File

@ -98,8 +98,6 @@ runAssignment :: forall grammar a. (Symbol grammar, Enum grammar, Eq grammar, Sh
runAssignment = iterFreer run . fmap (\ a state -> Result (state, a))
where run :: AssignmentF (Node grammar) x -> (x -> AssignmentState grammar -> Result (AssignmentState grammar, a)) -> AssignmentState grammar -> Result (AssignmentState grammar, a)
run assignment yield initialState = case (assignment, stateNodes) of
-- Nullability: some rules, e.g. 'pure a' and 'many a', should match at the end of input. Either side of an alternation may be nullable, ergo Alt can match at the end of input.
(Alt a b, _) -> yield a state <|> yield b state
(Location, Rose (_ :. location) _ : _) -> yield location state
(Location, []) -> yield (Info.Range stateOffset stateOffset :. Info.SourceSpan statePos statePos :. Nil) state
(Source, Rose (_ :. range :. _) _ : _) -> yield (Source.sourceText (Source.slice (offsetRange range (negate stateOffset)) stateSource)) (advanceState state)
@ -112,6 +110,8 @@ runAssignment = iterFreer run . fmap (\ a state -> Result (state, a))
Just a -> yield a state
Nothing -> Error ["Expected one of " <> showChoices choices <> " but got " <> show symbol]
(Choose choices, []) -> Error [ "Expected one of " <> showChoices choices <> " but got end of input." ]
-- Nullability: some rules, e.g. 'pure a' and 'many a', should match at the end of input. Either side of an alternation may be nullable, ergo Alt can match at the end of input.
(Alt a b, _) -> yield a state <|> yield b state
(assignment, subtree : _) -> case assignment of
_ -> Error ["No rule to match " <> show subtree]
_ -> Error ["No rule to match at end of input."]