commit 1c8457733e219a8b657b2f4fdf634458ae05fe23
parent 57f7389c4dccb18f18d95f3cdfd2861e2829cb68
Author: James Eversole <james@eversole.co>
Date: Wed, 1 Jan 2025 18:05:21 -0600
Fixes identifier lexing; support REPL file loading
Diffstat:
5 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1,10 +1,7 @@
bin/
-data/Purr.sqlite
-data/encryptionKey
/result
/config.dhall
/Dockerfile
-/docker-stack.yml
.stack-work/
*.swp
dist*
diff --git a/src/FileEval.hs b/src/FileEval.hs
@@ -17,3 +17,9 @@ evaluateFile filePath = do
case Map.lookup "__result" finalEnv of
Just finalResult -> return finalResult
Nothing -> error "No result found in final environment"
+
+evaluateFileEnv :: FilePath -> IO Env
+evaluateFileEnv filePath = do
+ contents <- readFile filePath
+ let asts = parseTricu contents
+ pure $ evalTricu library asts
diff --git a/src/Lexer.hs b/src/Lexer.hs
@@ -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
diff --git a/src/Main.hs b/src/Main.hs
@@ -38,10 +38,10 @@ evaluateMode = Evaluate
&= name "o"
, form = FSL &= typ "FORM"
&= help "Optional output form: (fsl|tree|ast|ternary|ascii).\n \
- \ Defaults to fsl."
+ \ Defaults to fsl \"Fork Stem Leaf\" form."
&= name "t"
}
- &= help "Evaluate a file and return the result of the expression in the final line"
+ &= help "Evaluate tricu and return the result of the expression in the final line"
&= explicit
&= name "eval"
diff --git a/src/REPL.hs b/src/REPL.hs
@@ -1,6 +1,7 @@
module REPL where
import Eval
+import FileEval
import Lexer
import Parser
import Research
@@ -21,6 +22,15 @@ repl env = runInputT defaultSettings (loop env)
case minput of
Nothing -> outputStrLn "Goodbye!"
Just ":_exit" -> outputStrLn "Goodbye!"
+ Just ":_load" -> do
+ path <- getInputLine "File path to load < "
+ case path of
+ Nothing -> do
+ outputStrLn "No input received; stopping import."
+ loop env
+ Just path -> do
+ loadedEnv <- liftIO $ evaluateFileEnv path
+ loop $ Map.union loadedEnv env
Just "" -> do
outputStrLn ""
loop env