Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Last active August 29, 2015 14:07
Show Gist options
  • Save yorickpeterse/0e4ad7a6848062011d92 to your computer and use it in GitHub Desktop.
Save yorickpeterse/0e4ad7a6848062011d92 to your computer and use it in GitHub Desktop.
state 10 contains 3 shift/reduce conflicts
state 11 contains 3 shift/reduce conflicts
state 12 contains 1 shift/reduce conflicts
state 27 contains 3 shift/reduce conflicts
state 28 contains 3 shift/reduce conflicts
state 39 contains 3 shift/reduce conflicts
-------- Grammar --------
rule 1 css: selectors
rule 2 css:
rule 3 selectors: selector
rule 4 selectors: selector selector
rule 5 selector: descendant_or_self
rule 6 selector: axis_selector
rule 7 descendant_or_self: node_test
rule 8 axis_selector: T_CHILD selector
rule 9 axis_selector: T_FOLLOWING selector
rule 10 axis_selector: T_FOLLOWING_DIRECT selector
rule 11 node_test: node_name
rule 12 node_test: predicates
rule 13 node_test: node_name predicates
rule 14 node_test: node_name attribute_predicate
rule 15 node_test: node_name attribute_predicate predicates
rule 16 node_name: T_IDENT
rule 17 node_name: T_IDENT T_PIPE T_IDENT
rule 18 node_name: T_PIPE T_IDENT
rule 19 predicates: predicates predicate
rule 20 predicates: predicate
rule 21 predicate: class
rule 22 predicate: id
rule 23 predicate: pseudo_class
rule 24 attribute_predicate: T_LBRACK attribute_predicate_members T_RBRACK
rule 25 attribute_predicate_members: attribute
rule 26 attribute_predicate_members: operator
rule 27 attribute: node_name
rule 28 operator: attribute T_EQ string
rule 29 class: T_DOT T_IDENT
rule 30 id: T_HASH T_IDENT
rule 31 pseudo_class: pseudo_name
rule 32 pseudo_class: pseudo_name pseudo_args
rule 33 pseudo_name: T_COLON T_IDENT
rule 34 pseudo_args: T_LPAREN pseudo_arg T_RPAREN
rule 35 pseudo_arg: integer
rule 36 pseudo_arg: selector
rule 37 string: T_STRING
rule 38 integer: T_INT
------- Symbols -------
**Nonterminals, with rules where they appear
$start (27)
on right:
on left :
css (28)
on right:
on left : 1 2
selectors (29)
on right: 1
on left : 3 4
selector (30)
on right: 3 4 8 9 10 36
on left : 5 6
descendant_or_self (31)
on right: 5
on left : 7
axis_selector (32)
on right: 6
on left : 8 9 10
node_test (33)
on right: 7
on left : 11 12 13 14 15
node_name (34)
on right: 11 13 14 15 27
on left : 16 17 18
predicates (35)
on right: 12 13 15 19
on left : 19 20
attribute_predicate (36)
on right: 14 15
on left : 24
predicate (37)
on right: 19 20
on left : 21 22 23
class (38)
on right: 21
on left : 29
id (39)
on right: 22
on left : 30
pseudo_class (40)
on right: 23
on left : 31 32
attribute_predicate_members (41)
on right: 24
on left : 25 26
attribute (42)
on right: 25 28
on left : 27
operator (43)
on right: 26
on left : 28
string (44)
on right: 28
on left : 37
pseudo_name (45)
on right: 31 32
on left : 33
pseudo_args (46)
on right: 32
on left : 34
pseudo_arg (47)
on right: 34
on left : 35 36
integer (48)
on right: 35
on left : 38
**Terminals, with rules where they appear
$end (0)
error (1)
T_IDENT (2) 16 17 18 29 30 33
T_PIPE (3) 17 18
T_LBRACK (4) 24
T_RBRACK (5) 24
T_COLON (6) 33
T_SPACE (7)
T_LPAREN (8) 34
T_RPAREN (9) 34
T_MINUS (10)
T_EQ (11) 28
T_SPACE_IN (12)
T_STARTS_WITH (13)
T_ENDS_WITH (14)
T_IN (15)
T_HYPHEN_IN (16)
T_CHILD (17) 8
T_FOLLOWING (18) 9
T_FOLLOWING_DIRECT (19) 10
T_NTH (20)
T_INT (21) 38
T_STRING (22) 37
T_ODD (23)
T_EVEN (24)
T_DOT (25) 29
T_HASH (26) 30
--------- State ---------
state 0
T_IDENT shift, and go to state 12
T_PIPE shift, and go to state 13
T_COLON shift, and go to state 21
T_CHILD shift, and go to state 7
T_FOLLOWING shift, and go to state 8
T_FOLLOWING_DIRECT shift, and go to state 9
T_DOT shift, and go to state 18
T_HASH shift, and go to state 19
$default reduce using rule 2 (css)
css go to state 1
selectors go to state 2
selector go to state 3
descendant_or_self go to state 4
axis_selector go to state 5
node_test go to state 6
node_name go to state 10
predicates go to state 11
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 1
$end shift, and go to state 22
state 2
1) css : selectors _
$default reduce using rule 1 (css)
state 3
3) selectors : selector _
4) selectors : selector _ selector
T_IDENT shift, and go to state 12
T_PIPE shift, and go to state 13
T_COLON shift, and go to state 21
T_CHILD shift, and go to state 7
T_FOLLOWING shift, and go to state 8
T_FOLLOWING_DIRECT shift, and go to state 9
T_DOT shift, and go to state 18
T_HASH shift, and go to state 19
$default reduce using rule 3 (selectors)
selector go to state 23
descendant_or_self go to state 4
axis_selector go to state 5
node_test go to state 6
node_name go to state 10
predicates go to state 11
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 4
5) selector : descendant_or_self _
$default reduce using rule 5 (selector)
state 5
6) selector : axis_selector _
$default reduce using rule 6 (selector)
state 6
7) descendant_or_self : node_test _
$default reduce using rule 7 (descendant_or_self)
state 7
8) axis_selector : T_CHILD _ selector
T_IDENT shift, and go to state 12
T_PIPE shift, and go to state 13
T_COLON shift, and go to state 21
T_CHILD shift, and go to state 7
T_FOLLOWING shift, and go to state 8
T_FOLLOWING_DIRECT shift, and go to state 9
T_DOT shift, and go to state 18
T_HASH shift, and go to state 19
descendant_or_self go to state 4
axis_selector go to state 5
node_test go to state 6
selector go to state 24
node_name go to state 10
predicates go to state 11
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 8
9) axis_selector : T_FOLLOWING _ selector
T_IDENT shift, and go to state 12
T_PIPE shift, and go to state 13
T_COLON shift, and go to state 21
T_CHILD shift, and go to state 7
T_FOLLOWING shift, and go to state 8
T_FOLLOWING_DIRECT shift, and go to state 9
T_DOT shift, and go to state 18
T_HASH shift, and go to state 19
descendant_or_self go to state 4
axis_selector go to state 5
node_test go to state 6
selector go to state 25
node_name go to state 10
predicates go to state 11
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 9
10) axis_selector : T_FOLLOWING_DIRECT _ selector
T_IDENT shift, and go to state 12
T_PIPE shift, and go to state 13
T_COLON shift, and go to state 21
T_CHILD shift, and go to state 7
T_FOLLOWING shift, and go to state 8
T_FOLLOWING_DIRECT shift, and go to state 9
T_DOT shift, and go to state 18
T_HASH shift, and go to state 19
descendant_or_self go to state 4
axis_selector go to state 5
node_test go to state 6
selector go to state 26
node_name go to state 10
predicates go to state 11
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 10
11) node_test : node_name _
13) node_test : node_name _ predicates
14) node_test : node_name _ attribute_predicate
15) node_test : node_name _ attribute_predicate predicates
T_LBRACK shift, and go to state 29
T_COLON shift, and go to state 21
T_COLON [reduce using rule 11 (node_test)]
T_DOT shift, and go to state 18
T_DOT [reduce using rule 11 (node_test)]
T_HASH shift, and go to state 19
T_HASH [reduce using rule 11 (node_test)]
$default reduce using rule 11 (node_test)
predicates go to state 27
attribute_predicate go to state 28
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 11
12) node_test : predicates _
19) predicates : predicates _ predicate
T_COLON shift, and go to state 21
T_COLON [reduce using rule 12 (node_test)]
T_DOT shift, and go to state 18
T_DOT [reduce using rule 12 (node_test)]
T_HASH shift, and go to state 19
T_HASH [reduce using rule 12 (node_test)]
$default reduce using rule 12 (node_test)
predicate go to state 30
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 12
16) node_name : T_IDENT _
17) node_name : T_IDENT _ T_PIPE T_IDENT
T_PIPE shift, and go to state 31
T_PIPE [reduce using rule 16 (node_name)]
$default reduce using rule 16 (node_name)
state 13
18) node_name : T_PIPE _ T_IDENT
T_IDENT shift, and go to state 32
state 14
20) predicates : predicate _
$default reduce using rule 20 (predicates)
state 15
21) predicate : class _
$default reduce using rule 21 (predicate)
state 16
22) predicate : id _
$default reduce using rule 22 (predicate)
state 17
23) predicate : pseudo_class _
$default reduce using rule 23 (predicate)
state 18
29) class : T_DOT _ T_IDENT
T_IDENT shift, and go to state 33
state 19
30) id : T_HASH _ T_IDENT
T_IDENT shift, and go to state 34
state 20
31) pseudo_class : pseudo_name _
32) pseudo_class : pseudo_name _ pseudo_args
T_LPAREN shift, and go to state 36
$default reduce using rule 31 (pseudo_class)
pseudo_args go to state 35
state 21
33) pseudo_name : T_COLON _ T_IDENT
T_IDENT shift, and go to state 37
state 22
$end shift, and go to state 38
state 23
4) selectors : selector selector _
$default reduce using rule 4 (selectors)
state 24
8) axis_selector : T_CHILD selector _
$default reduce using rule 8 (axis_selector)
state 25
9) axis_selector : T_FOLLOWING selector _
$default reduce using rule 9 (axis_selector)
state 26
10) axis_selector : T_FOLLOWING_DIRECT selector _
$default reduce using rule 10 (axis_selector)
state 27
13) node_test : node_name predicates _
19) predicates : predicates _ predicate
T_COLON shift, and go to state 21
T_COLON [reduce using rule 13 (node_test)]
T_DOT shift, and go to state 18
T_DOT [reduce using rule 13 (node_test)]
T_HASH shift, and go to state 19
T_HASH [reduce using rule 13 (node_test)]
$default reduce using rule 13 (node_test)
predicate go to state 30
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 28
14) node_test : node_name attribute_predicate _
15) node_test : node_name attribute_predicate _ predicates
T_COLON shift, and go to state 21
T_COLON [reduce using rule 14 (node_test)]
T_DOT shift, and go to state 18
T_DOT [reduce using rule 14 (node_test)]
T_HASH shift, and go to state 19
T_HASH [reduce using rule 14 (node_test)]
$default reduce using rule 14 (node_test)
predicates go to state 39
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 29
24) attribute_predicate : T_LBRACK _ attribute_predicate_members T_RBRACK
T_IDENT shift, and go to state 12
T_PIPE shift, and go to state 13
attribute_predicate_members go to state 40
attribute go to state 41
operator go to state 42
node_name go to state 43
state 30
19) predicates : predicates predicate _
$default reduce using rule 19 (predicates)
state 31
17) node_name : T_IDENT T_PIPE _ T_IDENT
T_IDENT shift, and go to state 44
state 32
18) node_name : T_PIPE T_IDENT _
$default reduce using rule 18 (node_name)
state 33
29) class : T_DOT T_IDENT _
$default reduce using rule 29 (class)
state 34
30) id : T_HASH T_IDENT _
$default reduce using rule 30 (id)
state 35
32) pseudo_class : pseudo_name pseudo_args _
$default reduce using rule 32 (pseudo_class)
state 36
34) pseudo_args : T_LPAREN _ pseudo_arg T_RPAREN
T_IDENT shift, and go to state 12
T_PIPE shift, and go to state 13
T_COLON shift, and go to state 21
T_CHILD shift, and go to state 7
T_FOLLOWING shift, and go to state 8
T_FOLLOWING_DIRECT shift, and go to state 9
T_INT shift, and go to state 48
T_DOT shift, and go to state 18
T_HASH shift, and go to state 19
descendant_or_self go to state 4
axis_selector go to state 5
node_test go to state 6
node_name go to state 10
predicates go to state 11
predicate go to state 14
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
pseudo_arg go to state 45
integer go to state 46
selector go to state 47
state 37
33) pseudo_name : T_COLON T_IDENT _
$default reduce using rule 33 (pseudo_name)
state 38
$default accept
state 39
15) node_test : node_name attribute_predicate predicates _
19) predicates : predicates _ predicate
T_COLON shift, and go to state 21
T_COLON [reduce using rule 15 (node_test)]
T_DOT shift, and go to state 18
T_DOT [reduce using rule 15 (node_test)]
T_HASH shift, and go to state 19
T_HASH [reduce using rule 15 (node_test)]
$default reduce using rule 15 (node_test)
predicate go to state 30
class go to state 15
id go to state 16
pseudo_class go to state 17
pseudo_name go to state 20
state 40
24) attribute_predicate : T_LBRACK attribute_predicate_members _ T_RBRACK
T_RBRACK shift, and go to state 49
state 41
25) attribute_predicate_members : attribute _
28) operator : attribute _ T_EQ string
T_EQ shift, and go to state 50
$default reduce using rule 25 (attribute_predicate_members)
state 42
26) attribute_predicate_members : operator _
$default reduce using rule 26 (attribute_predicate_members)
state 43
27) attribute : node_name _
$default reduce using rule 27 (attribute)
state 44
17) node_name : T_IDENT T_PIPE T_IDENT _
$default reduce using rule 17 (node_name)
state 45
34) pseudo_args : T_LPAREN pseudo_arg _ T_RPAREN
T_RPAREN shift, and go to state 51
state 46
35) pseudo_arg : integer _
$default reduce using rule 35 (pseudo_arg)
state 47
36) pseudo_arg : selector _
$default reduce using rule 36 (pseudo_arg)
state 48
38) integer : T_INT _
$default reduce using rule 38 (integer)
state 49
24) attribute_predicate : T_LBRACK attribute_predicate_members T_RBRACK _
$default reduce using rule 24 (attribute_predicate)
state 50
28) operator : attribute T_EQ _ string
T_STRING shift, and go to state 53
string go to state 52
state 51
34) pseudo_args : T_LPAREN pseudo_arg T_RPAREN _
$default reduce using rule 34 (pseudo_args)
state 52
28) operator : attribute T_EQ string _
$default reduce using rule 28 (operator)
state 53
37) string : T_STRING _
$default reduce using rule 37 (string)
class Oga::CSS::Parser
token T_IDENT T_PIPE T_LBRACK T_RBRACK T_COLON T_SPACE T_LPAREN T_RPAREN T_MINUS
token T_EQ T_SPACE_IN T_STARTS_WITH T_ENDS_WITH T_IN T_HYPHEN_IN
token T_CHILD T_FOLLOWING T_FOLLOWING_DIRECT
token T_NTH T_INT T_STRING T_ODD T_EVEN T_DOT T_HASH
options no_result_var
prechigh
left T_COLON T_HASH T_DOT
left T_CHILD T_FOLLOWING T_FOLLOWING_DIRECT
preclow
rule
css
: selectors { val[0] }
| /* none */ { nil }
;
selectors
: selector
| selector selector # <= this triggers the conflicts (same with proper recursion)
;
selector
: descendant_or_self
| axis_selector
;
descendant_or_self
: node_test { s(:axis, 'descendant-or-self', val[0]) }
;
axis_selector
: T_CHILD selector { s(:axis, 'child', val[1]) }
| T_FOLLOWING selector { s(:axis, 'following', val[1]) }
| T_FOLLOWING_DIRECT selector { s(:axis, 'following-direct', val[1]) }
;
node_test
# foo
: node_name
{
s(:test, *val[0])
}
# .foo, :root, etc
| predicates
{
s(:test, nil, '*', val[0])
}
# foo.bar
| node_name predicates
{
s(:test, *val[0], val[1])
}
# foo[bar]
| node_name attribute_predicate
{
s(:test, *val[0], val[1])
}
# foo[bar].baz
| node_name attribute_predicate predicates
{
s(:test, *val[0], s(:and, val[1], val[2]))
}
;
node_name
# foo
: T_IDENT { [nil, val[0]] }
# ns|foo
| T_IDENT T_PIPE T_IDENT { [val[0], val[2]] }
# |foo
| T_PIPE T_IDENT { [nil, val[1]] }
;
predicates
: predicates predicate { s(:and, val[0], val[1]) }
| predicate
;
predicate
: class
| id
| pseudo_class
;
attribute_predicate
: T_LBRACK attribute_predicate_members T_RBRACK { val[1] }
;
attribute_predicate_members
: attribute
| operator
;
attribute
: node_name { s(:axis, 'attribute', s(:test, *val[0])) }
;
operator
: attribute T_EQ string { s(:eq, val[0], val[2]) }
;
class
: T_DOT T_IDENT
{
axis = s(:axis, 'attribute', s(:test, nil, 'class'))
s(
:call,
'contains',
s(:call, 'concat', s(:string, ' '), axis, s(:string, ' ')),
s(:string, " #{val[1]} ")
)
}
;
id
: T_HASH T_IDENT
{
s(
:eq,
s(:axis, 'attribute', s(:test, nil, 'id')),
s(:string, val[1])
)
}
;
pseudo_class
# :root
: pseudo_name { s(:pseudo, nil, val[0]) }
# :nth-child(2)
| pseudo_name pseudo_args { s(:pseudo, nil, val[0], val[1]) }
;
pseudo_name
: T_COLON T_IDENT { val[1] }
;
pseudo_args
: T_LPAREN pseudo_arg T_RPAREN { val[1] }
;
pseudo_arg
: integer
#| odd
#| even
#| nth
| selector
;
string
: T_STRING { s(:string, val[0]) }
;
integer
: T_INT { s(:int, val[0].to_i) }
;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment