mirror of
https://github.com/github/semantic.git
synced 2024-12-19 04:41:47 +03:00
Merge pull request #1302 from github/eof-drops-anonymous-nodes
Eof drops anonymous nodes
This commit is contained in:
commit
6d87b858fe
@ -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)
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user