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

Annotation of /factorcss/Tokeniser.x

Parent Directory Parent Directory | Revision Log Revision Log


Revision 64 - (hide annotations) (download)
Mon Dec 27 22:24:45 2004 UTC (20 years ago) by james
File size: 2984 byte(s)
Fix some character ranges.

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

  ViewVC Help
Powered by ViewVC 1.1.26