1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Avoid revisiting anonymous nodes.

This commit is contained in:
Rob Rix 2017-04-26 11:47:53 -04:00
parent e89ea96739
commit ffbca016db

View File

@ -99,7 +99,7 @@ runAssignment :: forall grammar a. (Symbol grammar, Enum grammar, Eq grammar, Sh
runAssignment = iterFreer (\ assignment yield state -> case (assignment, dropAnonymous state) of runAssignment = iterFreer (\ assignment yield state -> case (assignment, dropAnonymous state) 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. -- 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, state) -> yield a state <|> yield b state (Alt a b, state) -> yield a state <|> yield b state
(assignment, AssignmentState offset _ source (subtree@(Rose (symbol :. range :. span :. Nil) children) : _)) -> case assignment of (assignment, state@(AssignmentState offset _ source (subtree@(Rose (symbol :. range :. span :. Nil) children) : _))) -> case assignment of
Symbol s -> if s == symbol then Symbol s -> if s == symbol then
yield () state yield () state
else else
@ -114,7 +114,7 @@ runAssignment = iterFreer (\ assignment yield state -> case (assignment, dropAno
Nothing -> Error ["Expected " <> showChoices choices <> " but got " <> show subtree] Nothing -> Error ["Expected " <> showChoices choices <> " but got " <> show subtree]
_ -> Error ["No rule to match " <> show subtree] _ -> Error ["No rule to match " <> show subtree]
(Symbol s, AssignmentState{}) -> Error [ "Expected " <> show s <> " but got end of input." ] (Symbol s, AssignmentState{}) -> Error [ "Expected " <> show s <> " but got end of input." ]
(Location, AssignmentState{..}) -> yield (Info.Range stateOffset stateOffset :. Info.SourceSpan statePos statePos :. Nil) state (Location, state@AssignmentState{..}) -> yield (Info.Range stateOffset stateOffset :. Info.SourceSpan statePos statePos :. Nil) state
(Source, AssignmentState{}) -> Error [ "Expected leaf node but got end of input." ] (Source, AssignmentState{}) -> Error [ "Expected leaf node but got end of input." ]
(Children _, AssignmentState{}) -> Error [ "Expected branch node but got end of input." ] (Children _, AssignmentState{}) -> Error [ "Expected branch node but got end of input." ]
(Choose choices, AssignmentState{}) -> Error [ "Expected " <> showChoices choices <> " but got end of input." ] (Choose choices, AssignmentState{}) -> Error [ "Expected " <> showChoices choices <> " but got end of input." ]