Generalize plain value definition, add examples to parse
This commit is contained in:
parent
8e5769d025
commit
9dda3cfe4c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
37
grammar.js
37
grammar.js
|
@ -34,13 +34,13 @@ module.exports = grammar({
|
||||||
import_statement: $ => seq(
|
import_statement: $ => seq(
|
||||||
'@import',
|
'@import',
|
||||||
$._value,
|
$._value,
|
||||||
commaSep($._query),
|
sep(',', $._query),
|
||||||
';'
|
';'
|
||||||
),
|
),
|
||||||
|
|
||||||
media_statement: $ => seq(
|
media_statement: $ => seq(
|
||||||
'@media',
|
'@media',
|
||||||
commaSep1($._query),
|
sep1(',', $._query),
|
||||||
$.block
|
$.block
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -58,7 +58,10 @@ module.exports = grammar({
|
||||||
),
|
),
|
||||||
|
|
||||||
keyframes_statement: $ => seq(
|
keyframes_statement: $ => seq(
|
||||||
|
choice(
|
||||||
'@keyframes',
|
'@keyframes',
|
||||||
|
alias(/@[-a-z]+keyframes/, $.at_keyword)
|
||||||
|
),
|
||||||
alias($.identifier, $.keyframes_name),
|
alias($.identifier, $.keyframes_name),
|
||||||
$.keyframe_block_list,
|
$.keyframe_block_list,
|
||||||
),
|
),
|
||||||
|
@ -85,7 +88,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
at_rule: $ => seq(
|
at_rule: $ => seq(
|
||||||
$.at_keyword,
|
$.at_keyword,
|
||||||
commaSep($._query),
|
sep(',', $._query),
|
||||||
choice(';', $.block)
|
choice(';', $.block)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -96,7 +99,7 @@ module.exports = grammar({
|
||||||
$.block
|
$.block
|
||||||
),
|
),
|
||||||
|
|
||||||
selectors: $ => commaSep1($._selector),
|
selectors: $ => sep1(',', $._selector),
|
||||||
|
|
||||||
block: $ => seq('{',
|
block: $ => seq('{',
|
||||||
repeat($._block_item),
|
repeat($._block_item),
|
||||||
|
@ -177,7 +180,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
pseudo_class_arguments: $ => seq(
|
pseudo_class_arguments: $ => seq(
|
||||||
token.immediate('('),
|
token.immediate('('),
|
||||||
commaSep(choice($._selector, repeat1($._value))),
|
sep(',', choice($._selector, repeat1($._value))),
|
||||||
')'
|
')'
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -223,7 +226,7 @@ module.exports = grammar({
|
||||||
'(',
|
'(',
|
||||||
alias($.identifier, $.feature_name),
|
alias($.identifier, $.feature_name),
|
||||||
':',
|
':',
|
||||||
$._value,
|
repeat1($._value),
|
||||||
')'
|
')'
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -314,7 +317,7 @@ module.exports = grammar({
|
||||||
|
|
||||||
arguments: $ => seq(
|
arguments: $ => seq(
|
||||||
token.immediate('('),
|
token.immediate('('),
|
||||||
commaSep(repeat1($._value)),
|
sep(choice(',', ';'), repeat1($._value)),
|
||||||
')'
|
')'
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -328,14 +331,24 @@ module.exports = grammar({
|
||||||
'/'
|
'/'
|
||||||
)),
|
)),
|
||||||
|
|
||||||
plain_value: $ => /[-_]*[a-zA-Z]([^/,;()\[\]\s]|\/[^\*])*/
|
plain_value: $ => token(seq(
|
||||||
|
repeat(choice(
|
||||||
|
/[-_]/,
|
||||||
|
/\/[^\*\s,;!{}()\[\]]/ // Slash not followed by a '*' (which would be a comment)
|
||||||
|
)),
|
||||||
|
/[a-zA-Z]/,
|
||||||
|
repeat(choice(
|
||||||
|
/[^/\s,;!{}()\[\]]/, // Not a slash, not a delimiter character
|
||||||
|
/\/[^\*\s,;!{}()\[\]]/ // Slash not followed by a '*' (which would be a comment)
|
||||||
|
))
|
||||||
|
))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function commaSep (rule) {
|
function sep (separator, rule) {
|
||||||
return optional(commaSep1(rule))
|
return optional(sep1(separator, rule))
|
||||||
}
|
}
|
||||||
|
|
||||||
function commaSep1 (rule) {
|
function sep1 (separator, rule) {
|
||||||
return seq(rule, repeat(seq(',', rule)))
|
return seq(rule, repeat(seq(separator, rule)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,6 @@
|
||||||
"tree-sitter-cli": "^0.13.10"
|
"tree-sitter-cli": "^0.13.10"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tree-sitter test"
|
"test": "tree-sitter test && tree-sitter parse examples --quiet --time"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,11 +195,25 @@
|
||||||
},
|
},
|
||||||
"keyframes_statement": {
|
"keyframes_statement": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": "@keyframes"
|
"value": "@keyframes"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "ALIAS",
|
||||||
|
"content": {
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "@[-a-z]+keyframes"
|
||||||
|
},
|
||||||
|
"named": true,
|
||||||
|
"value": "at_keyword"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "ALIAS",
|
"type": "ALIAS",
|
||||||
"content": {
|
"content": {
|
||||||
|
@ -1064,8 +1078,11 @@
|
||||||
"value": ":"
|
"value": ":"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"type": "REPEAT1",
|
||||||
|
"content": {
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_value"
|
"name": "_value"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
|
@ -1558,11 +1575,20 @@
|
||||||
"type": "REPEAT",
|
"type": "REPEAT",
|
||||||
"content": {
|
"content": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": ","
|
"value": ","
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": ";"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT1",
|
"type": "REPEAT1",
|
||||||
"content": {
|
"content": {
|
||||||
|
@ -1615,8 +1641,48 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"plain_value": {
|
"plain_value": {
|
||||||
|
"type": "TOKEN",
|
||||||
|
"content": {
|
||||||
|
"type": "SEQ",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
"type": "PATTERN",
|
"type": "PATTERN",
|
||||||
"value": "[-_]*[a-zA-Z]([^\\/,;()\\[\\]\\s]|\\/[^\\*])*"
|
"value": "[-_]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "\\/[^\\*\\s,;!{}()\\[\\]]"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[a-zA-Z]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "REPEAT",
|
||||||
|
"content": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "[^\\/\\s,;!{}()\\[\\]]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "PATTERN",
|
||||||
|
"value": "\\/[^\\*\\s,;!{}()\\[\\]]"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"extras": [
|
"extras": [
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue