Skip to content

Commit

Permalink
Merge pull request #138 from EpitechPromo2027/135-example_fn-is-an-in…
Browse files Browse the repository at this point in the history
…valid-symbol-name
  • Loading branch information
Jabolol authored Jan 10, 2025
2 parents ea41a21 + dfc7221 commit 92fa191
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Ast/Parser/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ triedChoice ps =

-- | An identifier in our language syntax
identifier :: Parser String
identifier = lexeme ((:) <$> (MC.letterChar M.<|> M.oneOf "$") <*> M.many (MC.alphaNumChar M.<|> M.oneOf "$"))
identifier = lexeme ((:) <$> (MC.letterChar M.<|> M.oneOf "$_") <*> M.many (MC.alphaNumChar M.<|> M.oneOf "$_"))

-- | Gets the SrcLoc
parseSrcLoc :: Parser AT.SrcLoc
Expand Down
24 changes: 24 additions & 0 deletions test/Ast/Parser/ExprSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ spec = do
let expected = Right (AT.Var normalizeLoc "x" (AT.TInt 32))
result `shouldBe` expected

it "parses a snake case definition" $
do
let input = "x"
let env = PS.insertVar "x" (AT.TInt 32) initialEnv
let result = normalizeExpr <$> fst (S.runState (M.runParserT PE.parseExpr "" input) env)
let expected = Right (AT.Var normalizeLoc "x" (AT.TInt 32))
result `shouldBe` expected

it "fails for an undefined variable" $ do
let input = "y"
let result = parseWithEnv input
Expand Down Expand Up @@ -62,6 +70,22 @@ spec = do
}
result `shouldBe` expected

it "parses a variable declaration snake case" $
do
let input = "a_variable: int"
let result = normalizeExpr <$> parseWithEnv input
let expected =
Right $
AT.Declaration
normalizeLoc
"a_variable"
( AT.TInt
32
)
Nothing

result `shouldBe` expected

it "parses an assignment expression" $ do
let input = "x = 42"
let env = PS.insertVar "x" (AT.TInt 0) initialEnv
Expand Down

0 comments on commit 92fa191

Please # to comment.