-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lexer.x
38 lines (33 loc) · 948 Bytes
/
Lexer.x
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
{
module Lexer (Token(..), alexScanTokens) where
}
%wrapper "basic"
$alphanum = [A-Za-z0-9_]
@comment = "#"[^\n]*
@label = ":"[a-zA-Z0-9]+
@string = \" [^\"\n]+ \"
@number = [0-9]+
@literal = $alphanum+
tokens :-
";" { \yytext -> SEMICOLON }
"," { \yytext -> COMMA }
"{" { \yytext -> LBRACE }
"}" { \yytext -> RBRACE }
"/" { \yytext -> FSLASH }
"p" { \yytext -> CMD_p }
"P" { \yytext -> CMD_P }
"s" { \yytext -> CMD_s }
@comment ;
$white ;
@label { \yytext -> LABEL yytext }
@string { \yytext -> STRING yytext }
@number { \yytext -> NUMBER (read yytext) }
@literal { \yytext -> LIT yytext }
. { \yytext -> error ("Unexpected character '" ++ yytext ++ "'") }
{
data Token =
COLON | LBRACE | RBRACE | COMMA | SEMICOLON | FSLASH
| LABEL String | STRING String | NUMBER Int | LIT String
| CMD_p | CMD_P | CMD_s
deriving (Show)
}