diff --git a/src/Data/Syntax/Assignment.hs b/src/Data/Syntax/Assignment.hs index 8377ca7c1..26589ff93 100644 --- a/src/Data/Syntax/Assignment.hs +++ b/src/Data/Syntax/Assignment.hs @@ -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."]