1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Preserve backtracking errors via a setter.

This commit is contained in:
Rob Rix 2017-07-22 14:34:04 -04:00
parent 9bac600596
commit e8afa8817e

View File

@ -265,7 +265,7 @@ runAssignment toNode source assignment state = go assignment state >>= requireEx
(Choose choices, node : _) | Node symbol _ _ <- toNode (F.project node), Just a <- IntMap.lookup (fromEnum symbol) choices -> yield a state
(Many rule, _) -> uncurry yield (runMany rule state)
-- 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, _) -> either (\ err -> yield b state { stateError = Just err }) Right (yield a state)
(Alt a b, _) -> either (yield b . setStateError state . Just) Right (yield a state)
(Throw e, _) -> Left e
(Catch during handler, _) -> either (flip yield state . handler) Right (yield during state)
(_, []) -> Left (Error (statePos state) (UnexpectedEndOfInput expectedSymbols))
@ -311,6 +311,9 @@ data AssignmentState ast grammar = AssignmentState
makeState :: [ast] -> AssignmentState ast grammar
makeState = AssignmentState 0 (Info.Pos 1 1) Nothing 0
setStateError :: AssignmentState ast grammar -> Maybe (Error grammar) -> AssignmentState ast grammar
setStateError state error = state { stateError = error }
-- Instances