Skip to content

Commit

Permalink
fix and test single @ as operator
Browse files Browse the repository at this point in the history
  • Loading branch information
mixphix committed May 7, 2024
1 parent 5197f7e commit 8aec47e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Text/Shakespeare/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 "()")
Expand Down
6 changes: 6 additions & 0 deletions test/Text/Shakespeare/BaseSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 8aec47e

Please sign in to comment.