Add sibling selectors

This commit is contained in:
Max Brunsfeld 2018-10-26 14:13:39 -07:00
parent 751c870b80
commit c8a95409ae
4 changed files with 2835 additions and 2532 deletions

View File

@ -158,3 +158,24 @@ a {
(rule_set (selectors (class_selector (nesting_selector) (class_name))) (block)) (rule_set (selectors (class_selector (nesting_selector) (class_name))) (block))
(rule_set (selectors (descendant_selector (nesting_selector) (tag_name))) (block)) (rule_set (selectors (descendant_selector (nesting_selector) (tag_name))) (block))
(rule_set (selectors (child_selector (nesting_selector) (tag_name))) (block))))) (rule_set (selectors (child_selector (nesting_selector) (tag_name))) (block)))))
===========================
Sibling selectors
===========================
a.b ~ c.d {}
.e.f + .g.h {}
---
(stylesheet
(rule_set
(selectors (sibling_selector
(class_selector (tag_name) (class_name))
(class_selector (tag_name) (class_name))))
(block))
(rule_set
(selectors (adjacent_sibling_selector
(class_selector (class_selector (class_name)) (class_name))
(class_selector (class_selector (class_name)) (class_name))))
(block)))

View File

@ -118,18 +118,20 @@ module.exports = grammar({
$.attribute_selector, $.attribute_selector,
$.string_value, $.string_value,
$.child_selector, $.child_selector,
$.descendant_selector $.descendant_selector,
$.sibling_selector,
$.adjacent_sibling_selector
), ),
nesting_selector: $ => '&', nesting_selector: $ => '&',
universal_selector: $ => '*', universal_selector: $ => '*',
class_selector: $ => seq( class_selector: $ => prec(1, seq(
optional($._selector), optional($._selector),
'.', '.',
alias($.identifier, $.class_name), alias($.identifier, $.class_name),
), )),
pseudo_class_selector: $ => seq( pseudo_class_selector: $ => seq(
optional($._selector), optional($._selector),
@ -165,6 +167,10 @@ module.exports = grammar({
descendant_selector: $ => prec.left(seq($._selector, $._descendant_operator, $._selector)), descendant_selector: $ => prec.left(seq($._selector, $._descendant_operator, $._selector)),
sibling_selector: $ => prec.left(seq($._selector, '~', $._selector)),
adjacent_sibling_selector: $ => prec.left(seq($._selector, '+', $._selector)),
// Declarations // Declarations
declaration: $ => prec(1, seq( declaration: $ => prec(1, seq(

54
src/grammar.json vendored
View File

@ -463,6 +463,14 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "descendant_selector" "name": "descendant_selector"
},
{
"type": "SYMBOL",
"name": "sibling_selector"
},
{
"type": "SYMBOL",
"name": "adjacent_sibling_selector"
} }
] ]
}, },
@ -475,6 +483,9 @@
"value": "*" "value": "*"
}, },
"class_selector": { "class_selector": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
{ {
@ -503,6 +514,7 @@
"value": "class_name" "value": "class_name"
} }
] ]
}
}, },
"pseudo_class_selector": { "pseudo_class_selector": {
"type": "SEQ", "type": "SEQ",
@ -728,6 +740,48 @@
] ]
} }
}, },
"sibling_selector": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_selector"
},
{
"type": "STRING",
"value": "~"
},
{
"type": "SYMBOL",
"name": "_selector"
}
]
}
},
"adjacent_sibling_selector": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_selector"
},
{
"type": "STRING",
"value": "+"
},
{
"type": "SYMBOL",
"name": "_selector"
}
]
}
},
"declaration": { "declaration": {
"type": "PREC", "type": "PREC",
"value": 1, "value": 1,

5226
src/parser.c vendored

File diff suppressed because it is too large Load Diff