From 8aec47ec68518a817980457888f3068913aa2a42 Mon Sep 17 00:00:00 2001 From: Melanie Brown Date: Mon, 6 May 2024 16:19:16 -0400 Subject: [PATCH] fix and test single @ as operator --- Text/Shakespeare/Base.hs | 6 ++---- test/Text/Shakespeare/BaseSpec.hs | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Text/Shakespeare/Base.hs b/Text/Shakespeare/Base.hs index cbe3262..726d9b6 100644 --- a/Text/Shakespeare/Base.hs +++ b/Text/Shakespeare/Base.hs @@ -106,9 +106,7 @@ parseDeref = do derefInfix x = try $ do _ <- delim xs <- many $ try $ derefSingle >>= \x' -> delim >> return x' - op <- - (try $ liftA2 (:) (satisfy isOperatorChar) (many (satisfy isOperatorChar <|> char '@')) - <|> liftA2 (:) (char '@') (many1 (satisfy isOperatorChar <|> char '@'))) "operator" + op <- (many1 (satisfy isOperatorChar) <* lookAhead (oneOf " \t")) "operator" -- special handling for $, which we don't deal with when (op == "$") $ fail "don't handle $" let op' = DerefIdent $ Ident op @@ -121,7 +119,7 @@ parseDeref = do pure $ foldl DerefGetField x fields tyNameOrVar = liftA2 (:) (alphaNum <|> char '\'') (many (alphaNum <|> char '_' <|> char '\'')) derefType = try $ do - _ <- char '@' + _ <- char '@' >> notFollowedBy (oneOf " \t") x <- try tyNameOrVar <|> try (string "()") diff --git a/test/Text/Shakespeare/BaseSpec.hs b/test/Text/Shakespeare/BaseSpec.hs index 1a8b05f..7be4d2b 100644 --- a/test/Text/Shakespeare/BaseSpec.hs +++ b/test/Text/Shakespeare/BaseSpec.hs @@ -51,6 +51,12 @@ spec = do (DerefBranch (DerefIdent (Ident "x")) (DerefType "Maybe String")) + it "parseDeref parse single @ as operator" $ do + runParser parseDeref () "" "x @ y" `shouldBe` + Right + (DerefBranch + (DerefBranch (DerefIdent (Ident "@")) (DerefIdent (Ident "x"))) + (DerefIdent (Ident "y"))) it "parseDeref parse expressions with record dot" $ do runParser parseDeref () "" "x.y" `shouldBe`