/[james]/factorcss/Tokeniser.x
ViewVC logotype

Contents of /factorcss/Tokeniser.x

Parent Directory Parent Directory | Revision Log Revision Log


Revision 65 - (show annotations) (download)
Tue Dec 28 14:23:12 2004 UTC (19 years, 11 months ago) by james
File size: 3375 byte(s)
Output line and column number with parse errors.

1 --
2 -- This file is part of FactorCSS
3 -- Licensed under the MIT License,
4 -- http://www.opensource.org/licenses/mit-license
5 -- Copyright 2004 James Bursa <james@semichrome.net>
6 --
7
8 -- Tokeniser for CSS 2.1
9 -- See CSS 2.1 G.2
10
11 {
12 module Tokeniser where
13 }
14
15 %wrapper "posn"
16
17 $h = [0-9a-f]
18 $nonascii = [\x80-\xff]
19 @unicode = \\$h{1,6}(\r\n|[\ \t\r\n\f])?
20 @escape = @unicode|\\[\x20-\x7e\x80-\xff]
21 @nmstart = [_a-zA-Z]|$nonascii|@escape
22 @nmchar = [\-_a-zA-Z0-9]|$nonascii|@escape
23 @nl = \n|\r\n|\r|\f
24 @string1 = \"([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\'|$nonascii|@escape|\.)*\"
25 @string2 = \'([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\"|$nonascii|@escape|\.)*\'
26 @ident = @nmstart@nmchar*
27 @name = @nmchar+
28 @num = [\-\053]?[0-9]+|[0-9]*"."[0-9]+
29 @string = @string1|@string2
30 @url = ([\!\#\x24\x25&\x2a-\x7e]|$nonascii|@escape)*
31 $s = [\ \t\r\n\f]
32 @w = $s*
33 @range = \?{1,6}|$h(\?{0,5}|$h(\?{0,4}|$h(\?{0,3}|$h(\?{0,2}|$h(\??|$h)))))
34 $all = \x00-\xff
35 @comment = \/\*$all#\x2a*\*+($all#[\/\x2a]$all#\x2a*\*+)*\/
36
37 tokens :-
38
39 $s+ ;
40 @comment ;
41
42 "<!--" ;
43 "-->" ;
44 "~=" { \p s -> (INCLUDES, p) }
45 "|=" { \p s -> (DASHMATCH, p) }
46
47 @w"{" { \p s -> (LBRACE, p) }
48 @w"+" { \p s -> (PLUS, p) }
49 @w">" { \p s -> (GREATER, p) }
50 @w"," { \p s -> (COMMA, p) }
51
52 @string { \p s -> (STRING s, p) }
53
54 @ident { \p s -> (IDENT s, p) }
55
56 "#"@name { \p s -> (HASH s, p) }
57
58 "@import" { \p s -> (IMPORT_SYM, p) }
59 "@page" { \p s -> (PAGE_SYM, p) }
60 "@media" { \p s -> (MEDIA_SYM, p) }
61 "@charset" { \p s -> (CHARSET_SYM, p) }
62
63 "!"@w"important" { \p s -> (IMPORTANT_SYM, p) }
64
65 @num em { \p s -> (EMS (read ('0':(take (length s - 2) s))), p) }
66 @num ex { \p s -> (EXS (read ('0':(take (length s - 2) s))), p) }
67 @num px { \p s -> (LENGTH s, p) }
68 @num cm { \p s -> (LENGTH s, p) }
69 @num mm { \p s -> (LENGTH s, p) }
70 @num in { \p s -> (LENGTH s, p) }
71 @num pt { \p s -> (LENGTH s, p) }
72 @num pc { \p s -> (LENGTH s, p) }
73 @num deg { \p s -> (ANGLE s, p) }
74 @num rad { \p s -> (ANGLE s, p) }
75 @num grad { \p s -> (ANGLE s, p) }
76 @num ms { \p s -> (TIME s, p) }
77 @num s { \p s -> (TIME s, p) }
78 @num Hz { \p s -> (FREQ s, p) }
79 @num kHz { \p s -> (FREQ s, p) }
80 @num @ident { \p s -> (DIMEN s, p) }
81 @num "%" { \p s -> (PERCENTAGE (read ('0':(take (length s - 1) s))), p) }
82 @num { \p s -> (NUMBER (read ('0':s)), p) }
83
84 "url("@w@string@w")" { \p s -> (URI s, p) }
85 "url("@w@url@w")" { \p s -> (URI s, p) }
86 @ident"\050" { \p s -> (FUNCTION s, p) }
87
88 ";" { \p s -> (SEMI, p) }
89 "}" { \p s -> (RBRACE, p) }
90 ":" { \p s -> (COLON, p) }
91 "/" { \p s -> (SLASH, p) }
92 "-" { \p s -> (MINUS, p) }
93 "." { \p s -> (DOT, p) }
94 "*" { \p s -> (ASTERISK, p) }
95 "[" { \p s -> (LBRAC, p) }
96 "]" { \p s -> (RBRAC, p) }
97 "=" { \p s -> (EQUALS, p) }
98 ")" { \p s -> (RPAREN, p) }
99 . { \p s -> (DELIM (head s), p) }
100
101
102 {
103 type TokenPosn = (Token, AlexPosn)
104
105 data Token =
106 INCLUDES |
107 DASHMATCH |
108 LBRACE |
109 PLUS |
110 GREATER |
111 COMMA |
112 STRING String |
113 IDENT String |
114 HASH String |
115 IMPORT_SYM |
116 PAGE_SYM |
117 MEDIA_SYM |
118 CHARSET_SYM |
119 IMPORTANT_SYM |
120 EMS Float |
121 EXS Float |
122 LENGTH String |
123 ANGLE String |
124 TIME String |
125 FREQ String |
126 DIMEN String |
127 PERCENTAGE Float |
128 NUMBER Float |
129 URI String |
130 FUNCTION String |
131 SEMI |
132 RBRACE |
133 COLON |
134 SLASH |
135 MINUS |
136 DOT |
137 ASTERISK |
138 LBRAC |
139 RBRAC |
140 EQUALS |
141 RPAREN |
142 DELIM Char
143 deriving (Eq, Show)
144 }

  ViewVC Help
Powered by ViewVC 1.1.26