From 59e6fd621ce42b25111b94a5e97b83593a7fbd8c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Sun, 6 Aug 2017 09:22:43 -0400 Subject: [PATCH] :fire: stateErrorCounter. --- src/Data/Syntax/Assignment.hs | 7 +++---- test/Data/Syntax/Assignment/Spec.hs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Data/Syntax/Assignment.hs b/src/Data/Syntax/Assignment.hs index 4a93779f6..9dd61f924 100644 --- a/src/Data/Syntax/Assignment.hs +++ b/src/Data/Syntax/Assignment.hs @@ -286,7 +286,7 @@ runAssignment toNode source = (\ assignment state -> go assignment state >>= req (a, state') <- go child state { stateNodes = toList node } >>= requireExhaustive yield a (advance state' { stateNodes = stateNodes }) Choose _ choices | symbol <- nodeSymbol (toNode node), inRange (bounds choices) symbol, Just choice <- choices ! symbol -> yield choice state - Catch during handler -> go during state `catchError` (flip go state { stateErrorCounter = succ stateErrorCounter } . handler . fst) >>= uncurry yield + Catch during handler -> go during state `catchError` (flip go state . handler . fst) >>= uncurry yield _ -> anywhere (Just node) anywhere node = case assignment of @@ -315,20 +315,19 @@ runAssignment toNode source = (\ assignment state -> go assignment state >>= req -- Advances the state past the current (head) node (if any), dropping it off stateNodes, and updating stateOffset & statePos to its end; or else returns the state unchanged. advance state@State{..} | node : rest <- stateNodes - , Node{..} <- toNode (F.project node) = State (Info.end nodeByteRange) (Info.spanEnd nodeSpan) stateErrorCounter rest + , Node{..} <- toNode (F.project node) = State (Info.end nodeByteRange) (Info.spanEnd nodeSpan) rest | otherwise = state -- | State kept while running 'Assignment's. data State ast = State { stateOffset :: {-# UNPACK #-} !Int -- ^ The offset into the Source thus far reached, measured in bytes. , statePos :: {-# UNPACK #-} !Info.Pos -- ^ The (1-indexed) line/column position in the Source thus far reached. - , stateErrorCounter :: {-# UNPACK #-} !Int -- ^ Monotonic counter tracking the number of error handlers invoked. , stateNodes :: ![ast] -- ^ The remaining nodes to assign. Note that 'children' rules recur into subterms, and thus this does not necessarily reflect all of the terms remaining to be assigned in the overall algorithm, only those “in scope.” } deriving (Eq, Show) makeState :: [ast] -> State ast -makeState = State 0 (Info.Pos 1 1) 0 +makeState = State 0 (Info.Pos 1 1) -- Instances diff --git a/test/Data/Syntax/Assignment/Spec.hs b/test/Data/Syntax/Assignment/Spec.hs index 41f634b6f..b6026be8c 100644 --- a/test/Data/Syntax/Assignment/Spec.hs +++ b/test/Data/Syntax/Assignment/Spec.hs @@ -217,13 +217,13 @@ spec = do it "advances past the current node" $ snd <$> runAssignment headF "hi" source (makeState [ node Red 0 2 [] ]) `shouldBe` - Right (State 2 (Info.Pos 1 3) 0 []) + Right (State 2 (Info.Pos 1 3) []) describe "children" $ do it "advances past the current node" $ snd <$> runAssignment headF "a" (children (pure (Out ""))) (makeState [node Red 0 1 []]) `shouldBe` - Right (State 1 (Info.Pos 1 2) 0 []) + Right (State 1 (Info.Pos 1 2) []) it "matches if its subrule matches" $ () <$ runAssignment headF "a" (children red) (makeState [node Blue 0 1 [node Red 0 1 []]])