1
1
mirror of https://github.com/github/semantic.git synced 2024-12-21 13:51:44 +03:00

Merge pull request #1302 from github/eof-drops-anonymous-nodes

Eof drops anonymous nodes
This commit is contained in:
Josh Vera 2017-08-16 10:22:50 -04:00 committed by GitHub
commit 6d87b858fe
2 changed files with 8 additions and 2 deletions

View File

@ -245,8 +245,7 @@ runAssignment toNode source = \ assignment state -> go assignment state >>= requ
_ -> anywhere (Just node)
anywhere node = case assignment of
End | Nothing <- node -> yield () state
| otherwise -> Left (makeError node)
End -> requireExhaustive ((), state) >>= uncurry yield
Location -> yield (Info.Range stateOffset stateOffset :. Info.Span statePos statePos :. Nil) state
Many rule -> fix (\ recur state -> (go rule state >>= \ (a, state') -> first (a:) <$> if state == state' then pure ([], state') else recur state') `catchError` const (pure ([], state))) state >>= uncurry yield
Alt as -> sconcat (flip yield state <$> as)

View File

@ -140,6 +140,13 @@ spec = do
`shouldBe`
Left (Error (Span (Pos 1 1) (Pos 1 1)) [Right Red] Nothing)
describe "eof" $ do
it "matches at the end of branches" $
fst <$> runAssignment headF "" eof (makeState [] :: State (AST Grammar)) `shouldBe` Right ()
it "matches before anonymous nodes at the end of branches" $
fst <$> runAssignment headF "magenta" eof (makeState [ node Magenta 0 7 [] ] :: State (AST Grammar)) `shouldBe` Right ()
describe "catchError" $ do
it "handler that always matches" $
fst <$> runAssignment headF "A"