12 |
module Tokeniser where |
module Tokeniser where |
13 |
} |
} |
14 |
|
|
15 |
%wrapper "basic" |
%wrapper "posn" |
16 |
|
|
17 |
$h = [0-9a-f] |
$h = [0-9a-f] |
18 |
$nonascii = [\x80-\xff] |
$nonascii = [\x80-\xff] |
19 |
@unicode = \\$h{1,6}(\r\n|[\ \t\r\n\f])? |
@unicode = \\$h{1,6}(\r\n|[\ \t\r\n\f])? |
20 |
@escape = @unicode|\\[\x20-\x7e\x80-\xff] |
@escape = @unicode|\\[\x20-\x7e\x80-\xff] |
21 |
@nmstart = [_a-z]|$nonascii|@escape |
@nmstart = [_a-zA-Z]|$nonascii|@escape |
22 |
@nmchar = [\-_a-zA-Z0-9]|$nonascii|@escape |
@nmchar = [\-_a-zA-Z0-9]|$nonascii|@escape |
23 |
@nl = \n|\r\n|\r|\f |
@nl = \n|\r\n|\r|\f |
24 |
@string1 = \"([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\'|$nonascii|@escape|\.)*\" |
@string1 = \"([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\'|$nonascii|@escape|\.)*\" |
36 |
|
|
37 |
tokens :- |
tokens :- |
38 |
|
|
39 |
$s+ ; |
$s+ { \p s -> (S, p) } |
40 |
@comment ; |
@comment ; |
41 |
|
|
42 |
"<!--" ; |
"<!--" ; |
43 |
"-->" ; |
"-->" ; |
44 |
"~=" { \s -> INCLUDES } |
"~=" { \p s -> (INCLUDES, p) } |
45 |
"|=" { \s -> DASHMATCH } |
"|=" { \p s -> (DASHMATCH, p) } |
46 |
|
|
47 |
@w"{" { \s -> LBRACE } |
@w"{" { \p s -> (LBRACE, p) } |
48 |
@w"+" { \s -> PLUS } |
@w"+" { \p s -> (PLUS, p) } |
49 |
@w">" { \s -> GREATER } |
@w">" { \p s -> (GREATER, p) } |
50 |
@w"," { \s -> COMMA } |
@w"," { \p s -> (COMMA, p) } |
51 |
|
|
52 |
@string { \s -> STRING s } |
@string { \p s -> (STRING s, p) } |
53 |
|
|
54 |
@ident { \s -> IDENT s } |
@ident { \p s -> (IDENT s, p) } |
55 |
|
|
56 |
"#"@name { \s -> HASH s } |
"#"@name { \p s -> (HASH s, p) } |
57 |
|
|
58 |
"@import" { \s -> IMPORT_SYM } |
"@import" { \p s -> (IMPORT_SYM, p) } |
59 |
"@page" { \s -> PAGE_SYM } |
"@page" { \p s -> (PAGE_SYM, p) } |
60 |
"@media" { \s -> MEDIA_SYM } |
"@media" { \p s -> (MEDIA_SYM, p) } |
61 |
"@charset" { \s -> CHARSET_SYM } |
"@charset" { \p s -> (CHARSET_SYM, p) } |
62 |
|
|
63 |
"!"@w"important" { \s -> IMPORTANT_SYM } |
"!"@w"important" { \p s -> (IMPORTANT_SYM, p) } |
64 |
|
|
65 |
@num em { \s -> EMS (read (take (length s - 2) s)) } |
@num em { \p s -> (EMS (read ('0':(take (length s - 2) s))), p) } |
66 |
@num ex { \s -> EXS (read (take (length s - 2) s)) } |
@num ex { \p s -> (EXS (read ('0':(take (length s - 2) s))), p) } |
67 |
@num px { \s -> LENGTH s } |
@num px { \p s -> (LENGTH s, p) } |
68 |
@num cm { \s -> LENGTH s } |
@num cm { \p s -> (LENGTH s, p) } |
69 |
@num mm { \s -> LENGTH s } |
@num mm { \p s -> (LENGTH s, p) } |
70 |
@num in { \s -> LENGTH s } |
@num in { \p s -> (LENGTH s, p) } |
71 |
@num pt { \s -> LENGTH s } |
@num pt { \p s -> (LENGTH s, p) } |
72 |
@num pc { \s -> LENGTH s } |
@num pc { \p s -> (LENGTH s, p) } |
73 |
@num deg { \s -> ANGLE s } |
@num deg { \p s -> (ANGLE s, p) } |
74 |
@num rad { \s -> ANGLE s } |
@num rad { \p s -> (ANGLE s, p) } |
75 |
@num grad { \s -> ANGLE s } |
@num grad { \p s -> (ANGLE s, p) } |
76 |
@num ms { \s -> TIME s } |
@num ms { \p s -> (TIME s, p) } |
77 |
@num s { \s -> TIME s } |
@num s { \p s -> (TIME s, p) } |
78 |
@num Hz { \s -> FREQ s } |
@num Hz { \p s -> (FREQ s, p) } |
79 |
@num kHz { \s -> FREQ s } |
@num kHz { \p s -> (FREQ s, p) } |
80 |
@num @ident { \s -> DIMEN s } |
@num @ident { \p s -> (DIMEN s, p) } |
81 |
@num "%" { \s -> PERCENTAGE (read (take (length s - 1) s)) } |
@num "%" { \p s -> (PERCENTAGE (read ('0':(take (length s - 1) s))), p) } |
82 |
@num { \s -> NUMBER (read s) } |
@num { \p s -> (NUMBER (read ('0':s)), p) } |
83 |
|
|
84 |
"url("@w@string@w")" { \s -> URI s } |
"url("@w@string@w")" { \p s -> (URI s, p) } |
85 |
"url("@w@url@w")" { \s -> URI s } |
"url("@w@url@w")" { \p s -> (URI s, p) } |
86 |
@ident"\050" { \s -> FUNCTION s } |
@ident"\050" { \p s -> (FUNCTION s, p) } |
87 |
|
|
88 |
";" { \s -> SEMI } |
";" { \p s -> (SEMI, p) } |
89 |
"}" { \s -> RBRACE } |
"}" { \p s -> (RBRACE, p) } |
90 |
":" { \s -> COLON } |
":" { \p s -> (COLON, p) } |
91 |
"/" { \s -> SLASH } |
"/" { \p s -> (SLASH, p) } |
92 |
"-" { \s -> MINUS } |
"-" { \p s -> (MINUS, p) } |
93 |
"." { \s -> DOT } |
"." { \p s -> (DOT, p) } |
94 |
"*" { \s -> ASTERISK } |
"*" { \p s -> (ASTERISK, p) } |
95 |
"[" { \s -> LBRAC } |
"[" { \p s -> (LBRAC, p) } |
96 |
"]" { \s -> RBRAC } |
"]" { \p s -> (RBRAC, p) } |
97 |
"=" { \s -> EQUALS } |
"=" { \p s -> (EQUALS, p) } |
98 |
")" { \s -> RPAREN } |
")" { \p s -> (RPAREN, p) } |
99 |
. { \s -> DELIM (head s) } |
. { \p s -> (DELIM (head s), p) } |
100 |
|
|
101 |
|
|
102 |
{ |
{ |
103 |
|
type TokenPosn = (Token, AlexPosn) |
104 |
|
|
105 |
data Token = |
data Token = |
106 |
|
S | |
107 |
INCLUDES | |
INCLUDES | |
108 |
DASHMATCH | |
DASHMATCH | |
109 |
LBRACE | |
LBRACE | |