mirror of
https://github.com/github/semantic.git
synced 2024-12-30 02:14:20 +03:00
Define a combinator requiring exhaustiveness.
This commit is contained in:
parent
15b7735874
commit
07b132e631
@ -308,6 +308,13 @@ runAssignment source toNode = go
|
||||
| otherwise -> ([a], state')
|
||||
{-# INLINE runMany #-}
|
||||
|
||||
requireExhaustive :: (Symbol grammar, Recursive ast) => (forall x. Base ast x -> Node grammar) -> (a, AssignmentState ast grammar) -> Either (Error grammar) (a, AssignmentState ast grammar)
|
||||
requireExhaustive toNode (a, state) = case stateNodes (dropAnonymous toNode state) of
|
||||
[] -> Right (a, state)
|
||||
node : _ | Node nodeSymbol _ (Info.Span spanStart _) <- toNode (F.project node) ->
|
||||
Left $ fromMaybe (Error spanStart (UnexpectedSymbol [] nodeSymbol)) (stateError state)
|
||||
|
||||
|
||||
dropAnonymous :: (Symbol grammar, Recursive ast) => (forall x. Base ast x -> Node grammar) -> AssignmentState ast grammar -> AssignmentState ast grammar
|
||||
dropAnonymous toNode state = state { stateNodes = dropWhile ((/= Regular) . symbolType . nodeSymbol . toNode . F.project) (stateNodes state) }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user