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 (descendant_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,
|
||||
$.string_value,
|
||||
$.child_selector,
|
||||
$.descendant_selector
|
||||
$.descendant_selector,
|
||||
$.sibling_selector,
|
||||
$.adjacent_sibling_selector
|
||||
),
|
||||
|
||||
nesting_selector: $ => '&',
|
||||
|
||||
universal_selector: $ => '*',
|
||||
|
||||
class_selector: $ => seq(
|
||||
class_selector: $ => prec(1, seq(
|
||||
optional($._selector),
|
||||
'.',
|
||||
alias($.identifier, $.class_name),
|
||||
),
|
||||
)),
|
||||
|
||||
pseudo_class_selector: $ => seq(
|
||||
optional($._selector),
|
||||
|
@ -165,6 +167,10 @@ module.exports = grammar({
|
|||
|
||||
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
|
||||
|
||||
declaration: $ => prec(1, seq(
|
||||
|
|
|
@ -463,6 +463,14 @@
|
|||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "descendant_selector"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "sibling_selector"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "adjacent_sibling_selector"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -475,34 +483,38 @@
|
|||
"value": "*"
|
||||
},
|
||||
"class_selector": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_selector"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_selector"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
"named": true,
|
||||
"value": "class_name"
|
||||
}
|
||||
]
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "."
|
||||
},
|
||||
{
|
||||
"type": "ALIAS",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
"named": true,
|
||||
"value": "class_name"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"pseudo_class_selector": {
|
||||
"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": {
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue