diff options
author | Marvin Borner | 2022-06-17 21:10:06 +0200 |
---|---|---|
committer | Marvin Borner | 2022-06-17 21:10:06 +0200 |
commit | 3a8e9afd461cf648fc6904df64eb76a3a95eeb99 (patch) | |
tree | 71ced441ef9c19d3de7d5c178a923eb668745a0d /src/Parser.hs | |
parent | bfc12aff90252dbcd9c40a1d095052ed771d4e56 (diff) |
Some binary magic
Diffstat (limited to 'src/Parser.hs')
-rw-r--r-- | src/Parser.hs | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index 33b3c44..6df479d 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -35,6 +35,9 @@ almostAnything :: Parser String almostAnything = many1 $ oneOf ".`#~@$%^&*_+-=|;',/?[]<>(){} " <|> letter <|> digit +importPath :: Parser String +importPath = many1 $ oneOf "./_+-" <|> letter <|> digit + parseAbstraction :: Parser Expression parseAbstraction = do reservedOp "[" @@ -57,7 +60,7 @@ parseNumeral :: Parser Expression parseNumeral = do num <- number spaces - pure $ decimalToTernary num + pure $ decimalToBinary num where sign = (char '-' >> return negate) <|> (char '+' >> return id) nat = read <$> many1 digit @@ -104,8 +107,21 @@ parseReplDefine = do parseComment :: Parser Instruction parseComment = string "#" >> Comment <$> almostAnything -parseLoad :: Parser Instruction -parseLoad = string ":load " >> Load <$> almostAnything +parseImport :: Parser Instruction +parseImport = do + string ":import " + spaces + path <- importPath + spaces + pure $ Import $ path ++ ".bruijn" + +parsePrint :: Parser Instruction +parsePrint = do + string ":print " + spaces + exp <- parseExpression + spaces + pure $ Evaluate exp parseTest :: Parser Instruction parseTest = do @@ -118,12 +134,17 @@ parseTest = do pure $ Test exp1 exp2 parseLine :: Parser Instruction -parseLine = try parseDefine <|> try parseComment <|> try parseTest +parseLine = + try parseDefine + <|> try parseComment + <|> try parsePrint + <|> try parseImport + <|> try parseTest parseReplLine :: Parser Instruction parseReplLine = try parseReplDefine <|> try parseComment <|> try parseEvaluate - <|> try parseLoad + <|> try parseImport <|> try parseTest |