From 8265390933703eb4f76232f8e7fb2e49a13edd26 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 16 Aug 2017 08:52:29 -0400 Subject: [PATCH 1/3] Test that eof matches at the end of branches. --- test/Data/Syntax/Assignment/Spec.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/Data/Syntax/Assignment/Spec.hs b/test/Data/Syntax/Assignment/Spec.hs index 516cbb4e8..b5685c168 100644 --- a/test/Data/Syntax/Assignment/Spec.hs +++ b/test/Data/Syntax/Assignment/Spec.hs @@ -140,6 +140,10 @@ 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 () + describe "catchError" $ do it "handler that always matches" $ fst <$> runAssignment headF "A" From 3c7f4716078eca6f163e7e626b0de605ce1c04d2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 16 Aug 2017 08:55:26 -0400 Subject: [PATCH 2/3] Test that eof matches before anonymous nodes at the end of branches. Currently failed. --- test/Data/Syntax/Assignment/Spec.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/Data/Syntax/Assignment/Spec.hs b/test/Data/Syntax/Assignment/Spec.hs index b5685c168..5bf08a654 100644 --- a/test/Data/Syntax/Assignment/Spec.hs +++ b/test/Data/Syntax/Assignment/Spec.hs @@ -144,6 +144,9 @@ spec = 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" From bc4f6004f19c321c062e6dbf409793bac950f939 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 16 Aug 2017 08:56:43 -0400 Subject: [PATCH 3/3] Drop tokens before the end of branches. --- src/Data/Syntax/Assignment.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Data/Syntax/Assignment.hs b/src/Data/Syntax/Assignment.hs index a700eb8ba..59784a459 100644 --- a/src/Data/Syntax/Assignment.hs +++ b/src/Data/Syntax/Assignment.hs @@ -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)