-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLexer.lhs
More file actions
45 lines (39 loc) · 1.12 KB
/
Lexer.lhs
File metadata and controls
45 lines (39 loc) · 1.12 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
\begin{code}
module Lexer where
import qualified Text.Parsec.Token as P
import Text.Parsec.Token (GenLanguageDef(..))
import Text.Parsec.String (Parser)
import Text.Parsec.Char (oneOf, letter, alphaNum)
opChar :: Parser Char
opChar = oneOf ",:;!#$%&*+./<=>?@\\^|-~="
language = LanguageDef {
commentStart = "",
commentEnd = "",
commentLine = "#",
nestedComments = False,
identStart = letter,
identLetter = alphaNum,
opStart = opChar,
opLetter = opChar,
reservedNames = ["if", "else", "true", "false"],
reservedOpNames =
["+", "-", "*", "/", "++", "--",
"<", ">", "<=", ">=", "==", "!=", "=",
"&&", "||", "!"],
caseSensitive = True
}
lexer :: P.TokenParser ()
lexer = P.makeTokenParser language
whiteSpace = P.whiteSpace lexer
parens = P.parens lexer
braces = P.braces lexer
semi = P.semi lexer
identifier = P.identifier lexer
symbol = P.symbol lexer
integer = P.natural lexer
float = P.float lexer
naturalOrFloat = P.naturalOrFloat lexer
reserved = P.reserved lexer
reservedOp = P.reservedOp lexer
stringLiteral = P.stringLiteral lexer
\end{code}