From 8be255dfd730d979cb7c1fccd3563eb06ca63535 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sat, 22 Jul 2017 14:24:43 -0400 Subject: [PATCH] Define dropAnonymous closed over the projection. --- src/Data/Syntax/Assignment.hs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Data/Syntax/Assignment.hs b/src/Data/Syntax/Assignment.hs index c2d069ac8..ae8c59785 100644 --- a/src/Data/Syntax/Assignment.hs +++ b/src/Data/Syntax/Assignment.hs @@ -270,7 +270,7 @@ runAssignment toNode source assignment state = go assignment state >>= requireEx (Catch during handler, _) -> either (flip yield state . handler) Right (yield during state) (_, []) -> Left (Error (statePos state) (UnexpectedEndOfInput expectedSymbols)) (_, ast:_) -> let Node symbol _ (Info.Span spanStart _) = toNode (F.project ast) in Left (Error spanStart (UnexpectedSymbol expectedSymbols symbol)) - where state | any ((/= Regular) . symbolType) expectedSymbols = dropAnonymous toNode initialState + where state | any ((/= Regular) . symbolType) expectedSymbols = dropAnonymous initialState | otherwise = initialState expectedSymbols | Choose choices <- assignment = choiceSymbols choices | otherwise = [] @@ -285,14 +285,12 @@ runAssignment toNode source assignment state = go assignment state >>= requireEx | otherwise -> ([a], state') {-# INLINE runMany #-} requireExhaustive :: forall a. (a, AssignmentState ast grammar) -> Either (Error grammar) (a, AssignmentState ast grammar) - requireExhaustive (a, state) = case stateNodes (dropAnonymous toNode state) of + requireExhaustive (a, state) = case stateNodes (dropAnonymous 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) } + dropAnonymous state = state { stateNodes = dropWhile ((/= Regular) . symbolType . nodeSymbol . toNode . F.project) (stateNodes state) } -- | Advances the state past the current (head) node (if any), dropping it off -- stateNodes & its corresponding bytes off of source, and updating stateOffset &