2 |
-- This file is part of FactorCSS |
-- This file is part of FactorCSS |
3 |
-- Licensed under the MIT License, |
-- Licensed under the MIT License, |
4 |
-- http://www.opensource.org/licenses/mit-license |
-- http://www.opensource.org/licenses/mit-license |
5 |
-- Copyright 2004 James Bursa <james@semichrome.net> |
-- Copyright 2005 James Bursa <james@semichrome.net> |
6 |
-- |
-- |
7 |
|
|
8 |
-- Tokeniser for CSS 2.1 |
-- Tokeniser for CSS 2.1 |
25 |
@string2 = \'([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\"|$nonascii|@escape|\.)*\' |
@string2 = \'([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\"|$nonascii|@escape|\.)*\' |
26 |
@ident = @nmstart@nmchar* |
@ident = @nmstart@nmchar* |
27 |
@name = @nmchar+ |
@name = @nmchar+ |
28 |
@num = [\-\053]?[0-9]+|[0-9]*"."[0-9]+ |
@num = [\-\053]?([0-9]+|[0-9]*"."[0-9]+) |
29 |
@string = @string1|@string2 |
@string = @string1|@string2 |
30 |
@url = ([\!\#\x24\x25&\x2a-\x7e]|$nonascii|@escape)* |
@url = ([\!\#\x24\x25&\x2a-\x7e]|$nonascii|@escape)* |
31 |
$s = [\ \t\r\n\f] |
$s = [\ \t\r\n\f] |
36 |
|
|
37 |
tokens :- |
tokens :- |
38 |
|
|
39 |
$s+ ; |
$s+ { \p s -> (S, p) } |
40 |
@comment ; |
@comment ; |
41 |
|
|
42 |
"<!--" ; |
"<!--" ; |
45 |
"|=" { \p s -> (DASHMATCH, p) } |
"|=" { \p s -> (DASHMATCH, p) } |
46 |
|
|
47 |
@w"{" { \p s -> (LBRACE, p) } |
@w"{" { \p s -> (LBRACE, p) } |
48 |
|
@w"}" { \p s -> (RBRACE, p) } |
49 |
@w"+" { \p s -> (PLUS, p) } |
@w"+" { \p s -> (PLUS, p) } |
50 |
@w">" { \p s -> (GREATER, p) } |
@w">" { \p s -> (GREATER, p) } |
51 |
@w"," { \p s -> (COMMA, p) } |
@w"," { \p s -> (COMMA, p) } |
63 |
|
|
64 |
"!"@w"important" { \p s -> (IMPORTANT_SYM, p) } |
"!"@w"important" { \p s -> (IMPORTANT_SYM, p) } |
65 |
|
|
66 |
@num em { \p s -> (EMS (read ('0':(take (length s - 2) s))), p) } |
@num em { \p s -> (EMS (readz (take (length s - 2) s) p), p) } |
67 |
@num ex { \p s -> (EXS (read ('0':(take (length s - 2) s))), p) } |
@num ex { \p s -> (EXS (readz (take (length s - 2) s) p), p) } |
68 |
@num px { \p s -> (LENGTH s, p) } |
@num px { \p s -> (LENGTH s, p) } |
69 |
@num cm { \p s -> (LENGTH s, p) } |
@num cm { \p s -> (LENGTH s, p) } |
70 |
@num mm { \p s -> (LENGTH s, p) } |
@num mm { \p s -> (LENGTH s, p) } |
79 |
@num Hz { \p s -> (FREQ s, p) } |
@num Hz { \p s -> (FREQ s, p) } |
80 |
@num kHz { \p s -> (FREQ s, p) } |
@num kHz { \p s -> (FREQ s, p) } |
81 |
@num @ident { \p s -> (DIMEN s, p) } |
@num @ident { \p s -> (DIMEN s, p) } |
82 |
@num "%" { \p s -> (PERCENTAGE (read ('0':(take (length s - 1) s))), p) } |
@num "%" { \p s -> (PERCENTAGE (readz (take (length s - 1) s) p), p) } |
83 |
@num { \p s -> (NUMBER (read ('0':s)), p) } |
@num { \p s -> (NUMBER (readz s p), p) } |
84 |
|
|
85 |
"url("@w@string@w")" { \p s -> (URI s, p) } |
"url("@w@string@w")" { \p s -> (URI s, p) } |
86 |
"url("@w@url@w")" { \p s -> (URI s, p) } |
"url("@w@url@w")" { \p s -> (URI s, p) } |
87 |
@ident"\050" { \p s -> (FUNCTION s, p) } |
@ident"(" { \p s -> (FUNCTION s, p) } |
88 |
|
|
89 |
";" { \p s -> (SEMI, p) } |
";" { \p s -> (SEMI, p) } |
|
"}" { \p s -> (RBRACE, p) } |
|
90 |
":" { \p s -> (COLON, p) } |
":" { \p s -> (COLON, p) } |
91 |
"/" { \p s -> (SLASH, p) } |
"/" { \p s -> (SLASH, p) } |
92 |
"-" { \p s -> (MINUS, p) } |
"-" { \p s -> (MINUS, p) } |
103 |
type TokenPosn = (Token, AlexPosn) |
type TokenPosn = (Token, AlexPosn) |
104 |
|
|
105 |
data Token = |
data Token = |
106 |
|
S | |
107 |
INCLUDES | |
INCLUDES | |
108 |
DASHMATCH | |
DASHMATCH | |
109 |
LBRACE | |
LBRACE | |
142 |
RPAREN | |
RPAREN | |
143 |
DELIM Char |
DELIM Char |
144 |
deriving (Eq, Show) |
deriving (Eq, Show) |
145 |
|
|
146 |
|
readz :: Read a => String -> AlexPosn -> a |
147 |
|
readz s (AlexPn _ l c) = |
148 |
|
if (null xs) || not (null (snd (head xs))) |
149 |
|
then error ("Parse error at " ++ "line " ++ show l ++ |
150 |
|
", column " ++ show c ++ |
151 |
|
" (when parsing \"" ++ s ++ "\")") |
152 |
|
else fst (head xs) |
153 |
|
where xs = reads s |
154 |
|
|
155 |
} |
} |