diff options
author | Marvin Borner | 2022-07-18 01:44:38 +0200 |
---|---|---|
committer | Marvin Borner | 2022-07-18 01:44:38 +0200 |
commit | 745147f88f400cced478dd588a2dfd7a7c2140a8 (patch) | |
tree | 3c8e963275ef111b21315a662fd601286f4e123b /src/Parser.hs | |
parent | 313e883f5e2146a2005ae0ed6a36af835cbbc961 (diff) |
Moved/improved standard library
and other things
Diffstat (limited to 'src/Parser.hs')
-rw-r--r-- | src/Parser.hs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index dc6951a..f4afb69 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -22,9 +22,21 @@ lexeme = L.lexeme sc symbol :: String -> Parser String symbol = L.symbol sc +-- def identifier disallows the import prefix dots +defIdentifier :: Parser String +defIdentifier = lexeme + ((:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> oneOf "?!'_-")) + +-- TODO: write as extension to defIdentifier identifier :: Parser String identifier = lexeme - ((:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> oneOf "?!'_-")) + ((:) <$> (letterChar <|> char '_') <*> many (alphaNumChar <|> oneOf "?!'_-.")) + +namespace :: Parser String +namespace = + lexeme ((:) <$> upperChar <*> many letterChar) + <|> string "." + <|> (space >> return "") parens :: Parser a -> Parser a parens = between (symbol "(") (symbol ")") @@ -93,13 +105,13 @@ parseEvaluate = Evaluate <$> parseExpression parseDefine :: Parser Instruction parseDefine = do - var <- identifier + var <- defIdentifier space Define var <$> parseExpression parseReplDefine :: Parser Instruction parseReplDefine = do - var <- identifier + var <- defIdentifier space symbol "=" space @@ -114,7 +126,9 @@ parseImport = do space path <- importPath space - pure $ Import $ path ++ ".bruijn" + ns <- namespace + space + pure $ Import (path ++ ".bruijn") ns parsePrint :: Parser Instruction parsePrint = do |