Add sibling selectors
This commit is contained in:
parent
751c870b80
commit
c8a95409ae
|
@ -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)))
|
||||||
|
|
12
grammar.js
12
grammar.js
|
@ -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(
|
||||||
|
|
|
@ -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,34 +483,38 @@
|
||||||
"value": "*"
|
"value": "*"
|
||||||
},
|
},
|
||||||
"class_selector": {
|
"class_selector": {
|
||||||
"type": "SEQ",
|
"type": "PREC",
|
||||||
"members": [
|
"value": 1,
|
||||||
{
|
"content": {
|
||||||
"type": "CHOICE",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "CHOICE",
|
||||||
"name": "_selector"
|
"members": [
|
||||||
},
|
{
|
||||||
{
|
"type": "SYMBOL",
|
||||||
"type": "BLANK"
|
"name": "_selector"
|
||||||
}
|
},
|
||||||
]
|
{
|
||||||
},
|
"type": "BLANK"
|
||||||
{
|
}
|
||||||
"type": "STRING",
|
]
|
||||||
"value": "."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "ALIAS",
|
|
||||||
"content": {
|
|
||||||
"type": "SYMBOL",
|
|
||||||
"name": "identifier"
|
|
||||||
},
|
},
|
||||||
"named": true,
|
{
|
||||||
"value": "class_name"
|
"type": "STRING",
|
||||||
}
|
"value": "."
|
||||||
]
|
},
|
||||||
|
{
|
||||||
|
"type": "ALIAS",
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
},
|
||||||
|
"named": true,
|
||||||
|
"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,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue