diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-08-12 22:53:06 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-08-12 22:53:06 +0100 |
commit | 279f04cb63e45ceb9a9df82540d5362565b8b37b (patch) | |
tree | bf71e8d7829e6ccf29320dacaf7c4742423683c5 /src/Lexer.hs | |
download | micro-lang-hs-279f04cb63e45ceb9a9df82540d5362565b8b37b.tar.gz micro-lang-hs-279f04cb63e45ceb9a9df82540d5362565b8b37b.zip |
Initial import
Diffstat (limited to 'src/Lexer.hs')
-rw-r--r-- | src/Lexer.hs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/Lexer.hs b/src/Lexer.hs new file mode 100644 index 0000000..4938cfe --- /dev/null +++ b/src/Lexer.hs @@ -0,0 +1,49 @@ +module Lexer where + +import Text.Parsec +import Text.Parsec.Language (emptyDef) +import Text.Parsec.String (Parser) +import qualified Text.Parsec.Token as T + +scanner :: T.TokenParser () +scanner = T.makeTokenParser style + where + ops = ["+", "*", "-", ";"] + names = ["module", "private", "def", "return", "->"] + style = + emptyDef + { T.commentLine = "//", + T.reservedOpNames = ops, + T.reservedNames = names + } + +integer :: Parser Integer +integer = T.integer scanner + +parens :: Parser a -> Parser a +parens = T.parens scanner + +braces :: Parser a -> Parser a +braces = T.braces scanner + +commaSep :: Parser a -> Parser [a] +commaSep = T.commaSep scanner + +colonSep :: Parser String +colonSep = T.colon scanner + +identifier :: Parser String +identifier = T.identifier scanner + +reserved :: String -> Parser () +reserved = T.reserved scanner + +reservedOp :: String -> Parser () +reservedOp = T.reservedOp scanner + +scan :: Parser a -> Parser a +scan p = do + T.whiteSpace scanner + r <- p + eof + return r |