-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.y
142 lines (118 loc) · 2.17 KB
/
parser.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
class Parselly::Parser
expect 0
error_on_expect_mismatch
token COMMA PLUS GREATER TILDE SPACE HASH DOT LBRACKET RBRACKET COLON COLONCOLON IDENT STRING NUM NOT FUNCTION PIPE STAR EQUAL INCLUDES DASHMATCH PREFIXMATCH SUFFIXMATCH SUBSTRINGMATCH LPAREN RPAREN DASH
precedence left COMMA
precedence left PLUS GREATER TILDE SPACE
precedence left HASH DOT LBRACKET COLON COLONCOLON
rule
selectors_group
: selector
| selectors_group COMMA selector
;
selector
: simple_selector_sequence
| selector combinator simple_selector_sequence
;
combinator
: PLUS
| GREATER
| TILDE
| SPACE
;
simple_selector_sequence
: type_or_universal optional_modifiers
| required_modifiers
;
type_or_universal
: type_selector
| universal
;
optional_modifiers
: /* empty */
| optional_modifiers modifier
;
required_modifiers
: modifier
| required_modifiers modifier
;
modifier
: HASH
| class
| attrib
| pseudo
| negation
;
type_selector
: IDENT PIPE IDENT
| STAR PIPE IDENT
| IDENT
;
universal
: IDENT PIPE STAR
| STAR PIPE STAR
| STAR
;
class
: DOT IDENT
;
attrib
: LBRACKET IDENT attrib_operator attrib_value RBRACKET
| LBRACKET IDENT RBRACKET
| LBRACKET IDENT PIPE IDENT attrib_operator attrib_value RBRACKET
| LBRACKET STAR PIPE IDENT RBRACKET
;
attrib_operator
: EQUAL
| INCLUDES
| DASHMATCH
| PREFIXMATCH
| SUFFIXMATCH
| SUBSTRINGMATCH
;
attrib_value
: IDENT
| STRING
;
pseudo
: COLON COLON IDENT
| COLON IDENT
| COLON functional_pseudo
;
functional_pseudo
: FUNCTION expression RPAREN
;
expression
: term
| expression SPACE term
;
term
: PLUS
| DASH
| NUM
| NUM IDENT
| STRING
| IDENT
;
negation
: NOT negation_arg RPAREN
;
negation_arg
: type_selector
| universal
| HASH
| class
| attrib
| pseudo
;
end
---- inner
def parse
@lexer = Parselly::Lexer.new(@grammar_file)
@ast = Parselly::AST.new
do_parse
@ast
end
def next_token
@lexer.next_token
end