Don't require a ; on the last declaration in a block

This commit is contained in:
Max Brunsfeld 2018-10-28 14:19:40 -07:00
parent 90369e3d66
commit 7add08036c
4 changed files with 1448 additions and 1129 deletions

View File

@ -166,3 +166,21 @@ a {
(selectors (tag_name)) (selectors (tag_name))
(block (block
(declaration (property_name) (plain_value) (important))))) (declaration (property_name) (plain_value) (important)))))
============================
Declarations without trailing semicolons
============================
a {
b: c;
d: e
}
---
(stylesheet
(rule_set
(selectors (tag_name))
(block
(declaration (property_name) (plain_value))
(declaration (property_name) (plain_value)))))

View File

@ -98,7 +98,11 @@ module.exports = grammar({
selectors: $ => commaSep1($._selector), selectors: $ => commaSep1($._selector),
block: $ => seq('{', repeat($._block_item), '}'), block: $ => seq('{',
repeat($._block_item),
optional(alias($.last_declaration, $.declaration)),
'}'
),
_block_item: $ => choice( _block_item: $ => choice(
$.declaration, $.declaration,
@ -191,6 +195,17 @@ module.exports = grammar({
';' ';'
)), )),
last_declaration: $ => prec(1, seq(
alias($.identifier, $.property_name),
':',
$._value,
repeat(seq(
optional(','),
$._value
)),
optional($.important)
)),
important: $ => '!important', important: $ => '!important',
// Media queries // Media queries

79
src/grammar.json vendored
View File

@ -393,6 +393,23 @@
"name": "_block_item" "name": "_block_item"
} }
}, },
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "last_declaration"
},
"named": true,
"value": "declaration"
},
{
"type": "BLANK"
}
]
},
{ {
"type": "STRING", "type": "STRING",
"value": "}" "value": "}"
@ -926,6 +943,68 @@
] ]
} }
}, },
"last_declaration": {
"type": "PREC",
"value": 1,
"content": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "identifier"
},
"named": true,
"value": "property_name"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "_value"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_value"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "important"
},
{
"type": "BLANK"
}
]
}
]
}
},
"important": { "important": {
"type": "STRING", "type": "STRING",
"value": "!important" "value": "!important"

2463
src/parser.c vendored

File diff suppressed because it is too large Load Diff