1 |
james |
61 |
-- Parser for CSS 2.1 |
2 |
|
|
-- See CSS 2.1 G.2 |
3 |
|
|
|
4 |
|
|
{ |
5 |
|
|
module Parser where |
6 |
|
|
import Tokeniser |
7 |
|
|
import CSS |
8 |
|
|
} |
9 |
|
|
|
10 |
|
|
%name parser |
11 |
|
|
%tokentype { Token } |
12 |
|
|
%token |
13 |
|
|
INCLUDES { INCLUDES } |
14 |
|
|
DASHMATCH { DASHMATCH } |
15 |
|
|
LBRACE { LBRACE } |
16 |
|
|
PLUS { PLUS } |
17 |
|
|
GREATER { GREATER } |
18 |
|
|
COMMA { COMMA } |
19 |
|
|
STRING { STRING $$ } |
20 |
|
|
IDENT { IDENT $$ } |
21 |
|
|
HASH { HASH $$ } |
22 |
|
|
IMPORT_SYM { IMPORT_SYM } |
23 |
|
|
PAGE_SYM { PAGE_SYM } |
24 |
|
|
MEDIA_SYM { MEDIA_SYM } |
25 |
|
|
CHARSET_SYM { CHARSET_SYM } |
26 |
|
|
IMPORTANT_SYM { IMPORTANT_SYM } |
27 |
|
|
EMS { EMS $$ } |
28 |
|
|
EXS { EXS $$ } |
29 |
|
|
LENGTH { LENGTH $$ } |
30 |
|
|
ANGLE { ANGLE $$ } |
31 |
|
|
TIME { TIME $$ } |
32 |
|
|
FREQ { FREQ $$ } |
33 |
|
|
DIMEN { DIMEN $$ } |
34 |
|
|
PERCENTAGE { PERCENTAGE $$ } |
35 |
|
|
NUMBER { NUMBER $$ } |
36 |
|
|
URI { URI $$ } |
37 |
|
|
FUNCTION { FUNCTION $$ } |
38 |
|
|
DELIM { DELIM $$ } |
39 |
|
|
SEMI { SEMI } |
40 |
|
|
RBRACE { RBRACE } |
41 |
|
|
COLON { COLON } |
42 |
|
|
SLASH { SLASH } |
43 |
|
|
MINUS { MINUS } |
44 |
|
|
DOT { DOT } |
45 |
|
|
LBRAC { LBRAC } |
46 |
|
|
RBRAC { RBRAC } |
47 |
|
|
ASTERISK { ASTERISK } |
48 |
|
|
EQUALS { EQUALS } |
49 |
|
|
RPAREN { RPAREN } |
50 |
|
|
|
51 |
|
|
%% |
52 |
|
|
|
53 |
|
|
stylesheet :: { Stylesheet } |
54 |
|
|
: charset import_list statement_list { Stylesheet $1 $2 $3 } |
55 |
|
|
|
56 |
|
|
charset :: { Maybe String } |
57 |
|
|
: { Nothing } |
58 |
|
|
| CHARSET_SYM STRING SEMI { Just $2 } |
59 |
|
|
|
60 |
|
|
import_list :: { [(String, [String])] } |
61 |
|
|
: { [] } |
62 |
|
|
| import_list import { $2 : $1 } |
63 |
|
|
|
64 |
|
|
import :: { (String, [String]) } |
65 |
|
|
: IMPORT_SYM STRING medium_list SEMI { ($2, $3) } |
66 |
|
|
| IMPORT_SYM URI medium_list SEMI { ($2, $3) } |
67 |
|
|
|
68 |
|
|
statement_list :: { [Statement] } |
69 |
|
|
: { [] } |
70 |
|
|
| statement_list statement { $2 : $1 } |
71 |
|
|
|
72 |
|
|
statement :: { Statement } |
73 |
|
|
: ruleset { $1 } |
74 |
|
|
| media { $1 } |
75 |
|
|
| page { $1 } |
76 |
|
|
|
77 |
|
|
medium_list :: { [String] } |
78 |
|
|
: { [] } |
79 |
|
|
| medium_list_1 { $1 } |
80 |
|
|
|
81 |
|
|
medium_list_1 :: { [String] } |
82 |
|
|
: medium { [$1] } |
83 |
|
|
| medium_list_1 COMMA medium { $3 : $1 } |
84 |
|
|
|
85 |
|
|
media :: { Statement } |
86 |
|
|
: MEDIA_SYM medium_list_1 LBRACE ruleset_list RBRACE |
87 |
|
|
{ Media $2 $4 } |
88 |
|
|
|
89 |
|
|
medium :: { String } |
90 |
|
|
: IDENT { $1 } |
91 |
|
|
|
92 |
|
|
ruleset_list :: { [Statement] } |
93 |
|
|
: { [] } |
94 |
|
|
| ruleset_list ruleset { $2 : $1 } |
95 |
|
|
|
96 |
|
|
page :: { Statement } |
97 |
|
|
: PAGE_SYM LBRACE declaration_list_1 RBRACE |
98 |
|
|
{ Page Nothing $3 } |
99 |
|
|
| PAGE_SYM pseudo_page LBRACE declaration_list_1 RBRACE |
100 |
|
|
{ Page (Just $2) $4 } |
101 |
|
|
|
102 |
|
|
declaration_list_1 :: { [Declaration] } |
103 |
|
|
: { [] } |
104 |
|
|
| declaration { [$1] } |
105 |
|
|
| declaration_list_1 SEMI { $1 } |
106 |
|
|
| declaration_list_1 SEMI declaration { $3 : $1 } |
107 |
|
|
|
108 |
|
|
pseudo_page :: { String } |
109 |
|
|
: COLON IDENT { $2 } |
110 |
|
|
|
111 |
|
|
ruleset :: { Statement } |
112 |
|
|
: selector_list_1 LBRACE declaration_list_1 RBRACE |
113 |
|
|
{ Ruleset $1 $3 } |
114 |
|
|
|
115 |
|
|
selector_list_1 :: { [Selector] } |
116 |
|
|
: selector { [$1] } |
117 |
|
|
| selector_list_1 COMMA selector { $3 : $1 } |
118 |
|
|
|
119 |
|
|
selector :: { Selector } |
120 |
|
|
: simple_selector { [($1, NoMore)] } |
121 |
|
|
| simple_selector combinator selector { ($1, $2) : $3 } |
122 |
|
|
|
123 |
|
|
combinator :: { Combinator } |
124 |
|
|
: { Ancestor } |
125 |
|
|
| PLUS { Preceded } |
126 |
|
|
| GREATER { Parent } |
127 |
|
|
|
128 |
|
|
simple_selector :: { SimpleSelector } |
129 |
|
|
: element_name detail_list_1 { ($1, $2) } |
130 |
|
|
| element_name { ($1, []) } |
131 |
|
|
| detail_list_1 { (Nothing, $1) } |
132 |
|
|
|
133 |
|
|
element_name :: { Maybe String } |
134 |
|
|
: IDENT { Just $1 } |
135 |
|
|
| ASTERISK { Nothing } |
136 |
|
|
|
137 |
|
|
detail_list_1 :: { [Detail] } |
138 |
|
|
: HASH { [Id $1] } |
139 |
|
|
| class { [$1] } |
140 |
|
|
| attrib { [$1] } |
141 |
|
|
| pseudo { [$1] } |
142 |
|
|
| detail_list_1 HASH { Id $2 : $1 } |
143 |
|
|
| detail_list_1 class { $2 : $1 } |
144 |
|
|
| detail_list_1 attrib { $2 : $1 } |
145 |
|
|
| detail_list_1 pseudo { $2 : $1 } |
146 |
|
|
|
147 |
|
|
class :: { Detail } |
148 |
|
|
: DOT IDENT { Class $2 } |
149 |
|
|
|
150 |
|
|
attrib :: { Detail } |
151 |
|
|
: LBRAC IDENT RBRAC { Attrib $2 } |
152 |
|
|
| LBRAC IDENT EQUALS IDENT RBRAC { AttribEq $2 $4 } |
153 |
|
|
| LBRAC IDENT EQUALS STRING RBRAC { AttribEq $2 $4 } |
154 |
|
|
| LBRAC IDENT INCLUDES IDENT RBRAC { AttribInc $2 $4 } |
155 |
|
|
| LBRAC IDENT INCLUDES STRING RBRAC { AttribInc $2 $4 } |
156 |
|
|
| LBRAC IDENT DASHMATCH IDENT RBRAC { AttribDM $2 $4 } |
157 |
|
|
| LBRAC IDENT DASHMATCH STRING RBRAC { AttribDM $2 $4 } |
158 |
|
|
|
159 |
|
|
pseudo :: { Detail } |
160 |
|
|
: COLON IDENT { Pseudo $2 } |
161 |
|
|
| COLON FUNCTION RPAREN { PseudoFunc $2 "" } |
162 |
|
|
| COLON FUNCTION IDENT RPAREN { PseudoFunc $2 $3 } |
163 |
|
|
|
164 |
|
|
declaration :: { Declaration } |
165 |
|
|
: property COLON value_list_1 { ($1, $3, False) } |
166 |
|
|
| property COLON value_list_1 prio { ($1, $3, True) } |
167 |
|
|
|
168 |
|
|
property :: { String } |
169 |
|
|
: IDENT { $1 } |
170 |
|
|
|
171 |
|
|
prio :: { Bool } |
172 |
|
|
: IMPORTANT_SYM { True } |
173 |
|
|
|
174 |
|
|
value_list :: { [Value] } |
175 |
|
|
: { [] } |
176 |
|
|
| value value_list { $1 : $2 } |
177 |
|
|
|
178 |
|
|
value_list_1 :: { [Value] } |
179 |
|
|
: value { [$1] } |
180 |
|
|
| value value_list_1 { $1 : $2 } |
181 |
|
|
|
182 |
|
|
value :: { Value } |
183 |
|
|
: NUMBER { Number $1 } |
184 |
|
|
| PERCENTAGE { Percentage $1 } |
185 |
|
|
| LENGTH { Length $1 } |
186 |
|
|
| EMS { Ems $1 } |
187 |
|
|
| EXS { Exs $1 } |
188 |
|
|
| ANGLE { Angle $1 } |
189 |
|
|
| TIME { Time $1 } |
190 |
|
|
| FREQ { Freq $1 } |
191 |
|
|
| STRING { StringV $1 } |
192 |
|
|
| IDENT { Ident $1 } |
193 |
|
|
| URI { Uri $1 } |
194 |
|
|
| HASH { HexColour $1 } |
195 |
|
|
| SLASH { Slash } |
196 |
|
|
| COMMA { Comma } |
197 |
|
|
| FUNCTION value_list RPAREN { Function $1 $2 } |
198 |
|
|
|
199 |
|
|
{ |
200 |
|
|
happyError :: [Token] -> a |
201 |
|
|
happyError _ = error "Parse error" |
202 |
|
|
} |