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