Generalize plain value definition, add examples to parse

This commit is contained in:
Max Brunsfeld 2018-10-30 11:10:03 -07:00
parent 8e5769d025
commit 9dda3cfe4c
6 changed files with 16941 additions and 3037 deletions

5749
examples/atom.io.css vendored Normal file

File diff suppressed because it is too large Load Diff

7574
examples/github.com.css vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -34,13 +34,13 @@ module.exports = grammar({
import_statement: $ => seq(
'@import',
$._value,
commaSep($._query),
sep(',', $._query),
';'
),
media_statement: $ => seq(
'@media',
commaSep1($._query),
sep1(',', $._query),
$.block
),
@ -58,7 +58,10 @@ module.exports = grammar({
),
keyframes_statement: $ => seq(
'@keyframes',
choice(
'@keyframes',
alias(/@[-a-z]+keyframes/, $.at_keyword)
),
alias($.identifier, $.keyframes_name),
$.keyframe_block_list,
),
@ -85,7 +88,7 @@ module.exports = grammar({
at_rule: $ => seq(
$.at_keyword,
commaSep($._query),
sep(',', $._query),
choice(';', $.block)
),
@ -96,7 +99,7 @@ module.exports = grammar({
$.block
),
selectors: $ => commaSep1($._selector),
selectors: $ => sep1(',', $._selector),
block: $ => seq('{',
repeat($._block_item),
@ -177,7 +180,7 @@ module.exports = grammar({
pseudo_class_arguments: $ => seq(
token.immediate('('),
commaSep(choice($._selector, repeat1($._value))),
sep(',', choice($._selector, repeat1($._value))),
')'
),
@ -223,7 +226,7 @@ module.exports = grammar({
'(',
alias($.identifier, $.feature_name),
':',
$._value,
repeat1($._value),
')'
),
@ -314,7 +317,7 @@ module.exports = grammar({
arguments: $ => seq(
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) {
return optional(commaSep1(rule))
function sep (separator, rule) {
return optional(sep1(separator, rule))
}
function commaSep1 (rule) {
return seq(rule, repeat(seq(',', rule)))
function sep1 (separator, rule) {
return seq(rule, repeat(seq(separator, rule)))
}

View File

@ -16,6 +16,6 @@
"tree-sitter-cli": "^0.13.10"
},
"scripts": {
"test": "tree-sitter test"
"test": "tree-sitter test && tree-sitter parse examples --quiet --time"
}
}

82
src/grammar.json vendored
View File

@ -197,8 +197,22 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "@keyframes"
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "@keyframes"
},
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "@[-a-z]+keyframes"
},
"named": true,
"value": "at_keyword"
}
]
},
{
"type": "ALIAS",
@ -1064,8 +1078,11 @@
"value": ":"
},
{
"type": "SYMBOL",
"name": "_value"
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_value"
}
},
{
"type": "STRING",
@ -1560,8 +1577,17 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "STRING",
"value": ";"
}
]
},
{
"type": "REPEAT1",
@ -1615,8 +1641,48 @@
}
},
"plain_value": {
"type": "PATTERN",
"value": "[-_]*[a-zA-Z]([^\\/,;()\\[\\]\\s]|\\/[^\\*])*"
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"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": [

6532
src/parser.c vendored

File diff suppressed because it is too large Load Diff