-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTigerLexer.hs
More file actions
79 lines (74 loc) · 2.31 KB
/
TigerLexer.hs
File metadata and controls
79 lines (74 loc) · 2.31 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
module TigerLexer where
import TigerAbs
import qualified Data.Text as T
import Text.Parsec
import qualified Text.Parsec.Token as Tok
-- import Text.Parsec.Char
import qualified Text.Parsec.Text as PT
-- import Data.Functor.Identity
lexer :: Tok.TokenParser ()
lexer = Tok.makeTokenParser Tok.LanguageDef
{ Tok.commentStart = "/*"
, Tok.commentEnd = "*/"
, Tok.commentLine = []
, Tok.nestedComments = True
, Tok.identStart = letter
, Tok.identLetter = alphaNum <|> char '_'
, Tok.opStart = oneOf ":,;=&|<=>+-*/."
, Tok.opLetter = char '='
, Tok.reservedNames = [ "var"
, "let"
, "end"
, "in"
, "function"
, "type"
, "array"
, "of"
, "if"
, "then"
, "else"
, "while"
, "do"
, "for"
, "to"
, "break"
, "nil"
, "()"
]
, Tok.reservedOpNames = [ "="
, "&"
, "|"
, "<"
, "<="
, ">"
, ">="
, "<>"
, "+"
, "-"
, "*"
, "/"
, "\""
]
, Tok.caseSensitive = False
}
reservedOp = Tok.reservedOp lexer
reserved = Tok.reserved lexer
toInt :: Integer -> Int
toInt = fromInteger
-- number :: PT.Parser Integer
number = do
n <- Tok.natural lexer
return (toInt n)
parens = Tok.parens lexer
commaSep = Tok.commaSep lexer
commaSep1 = Tok.commaSep1 lexer
semiSep = Tok.semiSep lexer
semiSep1 = Tok.semiSep1 lexer
identifier = Tok.identifier lexer
dot = Tok.dot lexer
colon = Tok.colon lexer
brackets = Tok.brackets lexer
braces = Tok.braces lexer
symbol = Tok.symbol lexer
stringLiteral = Tok.stringLiteral lexer
whiteSpace = Tok.whiteSpace lexer