Allow top-level declarations

This commit is contained in:
Max Brunsfeld 2018-10-30 15:54:37 -07:00
parent c63a7cd74a
commit 53d1095d4a
4 changed files with 3297 additions and 3232 deletions

View File

@ -229,3 +229,16 @@ a {
(integer_value (unit))
(integer_value (unit))
(integer_value (unit))))))))
=================================
Declarations at the top level
=================================
--a-variable: -5px;
a-property: calc(5px + var(--a-variable));
---
(stylesheet
(declaration (property_name) (plain_value))
(declaration (property_name) (call_expression (function_name) (arguments (binary_expression (integer_value (unit)) (call_expression (function_name) (arguments (plain_value))))))))

View File

@ -10,6 +10,10 @@ module.exports = grammar({
$._descendant_operator,
],
conflicts: $ => [
[$._selector, $.declaration],
],
inline: $ => [
$._top_level_item,
$._block_item,
@ -19,6 +23,7 @@ module.exports = grammar({
stylesheet: $ => repeat($._top_level_item),
_top_level_item: $ => choice(
$.declaration,
$.rule_set,
$.import_statement,
$.media_statement,
@ -109,7 +114,14 @@ module.exports = grammar({
_block_item: $ => choice(
$.declaration,
$._top_level_item
$.rule_set,
$.import_statement,
$.media_statement,
$.charset_statement,
$.namespace_statement,
$.keyframes_statement,
$.supports_statement,
$.at_rule
),
// Selectors
@ -186,7 +198,7 @@ module.exports = grammar({
// Declarations
declaration: $ => prec(1, seq(
declaration: $ => seq(
alias($.identifier, $.property_name),
':',
$._value,
@ -196,7 +208,7 @@ module.exports = grammar({
)),
optional($.important),
';'
)),
),
last_declaration: $ => prec(1, seq(
alias($.identifier, $.property_name),

147
src/grammar.json vendored
View File

@ -11,6 +11,10 @@
"_top_level_item": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "declaration"
},
{
"type": "SYMBOL",
"name": "rule_set"
@ -439,7 +443,35 @@
},
{
"type": "SYMBOL",
"name": "_top_level_item"
"name": "rule_set"
},
{
"type": "SYMBOL",
"name": "import_statement"
},
{
"type": "SYMBOL",
"name": "media_statement"
},
{
"type": "SYMBOL",
"name": "charset_statement"
},
{
"type": "SYMBOL",
"name": "namespace_statement"
},
{
"type": "SYMBOL",
"name": "keyframes_statement"
},
{
"type": "SYMBOL",
"name": "supports_statement"
},
{
"type": "SYMBOL",
"name": "at_rule"
}
]
},
@ -892,70 +924,66 @@
]
},
"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": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_value"
"name": "identifier"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_value"
}
]
}
},
{
"type": "CHOICE",
"named": true,
"value": "property_name"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "_value"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "important"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "BLANK"
}
]
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "_value"
}
]
},
{
"type": "STRING",
"value": ";"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "important"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ";"
}
]
},
"last_declaration": {
"type": "PREC",
@ -1695,7 +1723,12 @@
"name": "comment"
}
],
"conflicts": [],
"conflicts": [
[
"_selector",
"declaration"
]
],
"externals": [
{
"type": "SYMBOL",

6351
src/parser.c vendored

File diff suppressed because it is too large Load Diff