-
Notifications
You must be signed in to change notification settings - Fork 2
/
Lexer.hs
35 lines (26 loc) · 875 Bytes
/
Lexer.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Lexer where
import Text.Parsec.String (Parser)
import Text.Parsec.Language (emptyDef)
import qualified Text.Parsec.Token as Tok
opNames :: [String]
opNames = ["+", "*", "-", "/", "==", ">=", "<=", "::", ">", "<", ".", "->"]
lexer :: Tok.TokenParser ()
lexer = Tok.makeTokenParser style
where
style = emptyDef {
Tok.commentLine = "#",
Tok.reservedOpNames = opNames,
Tok.reservedNames = ["let", "in", "fn", "fun", "=", "if", "else", "then", "=>", "{", "}", ","]
}
integer :: Parser Integer
integer = Tok.integer lexer
parens :: Parser a -> Parser a
parens = Tok.parens lexer
identifier :: Parser String
identifier = Tok.identifier lexer
reserved :: String -> Parser ()
reserved = Tok.reserved lexer
reservedOp :: String -> Parser ()
reservedOp = Tok.reservedOp lexer
whiteSpace :: Parser ()
whiteSpace = Tok.whiteSpace lexer