Fixes identifier lexing; support REPL file loading

This commit is contained in:
2025-01-01 18:05:21 -06:00
committed by James Eversole
parent 57f7389c4d
commit 1c8457733e
5 changed files with 23 additions and 11 deletions

View File

@ -17,7 +17,9 @@ keywordT = string "t" *> notFollowedBy alphaNumChar *> pure LKeywordT
identifier :: Lexer LToken
identifier = do
name <- some (letterChar <|> char '_' <|> char '-')
first <- letterChar <|> char '_'
rest <- many (letterChar <|> char '_' <|> char '-' <|> digitChar)
let name = first : rest
if (name == "t" || name == "__result")
then fail "Keywords (`t`, `__result`) cannot be used as an identifier"
else return (LIdentifier name)
@ -31,11 +33,8 @@ stringLiteral :: Lexer LToken
stringLiteral = do
char '"'
content <- many (noneOf ['"'])
if null content
then fail "Empty string literals are not allowed"
else do
char '"' --"
return (LStringLiteral content)
char '"' --"
return (LStringLiteral content)
assign :: Lexer LToken
assign = char '=' *> pure LAssign