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_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(
'@keyframes', choice(
'@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)))
} }

View File

@ -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"
} }
} }

82
src/grammar.json vendored
View File

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

6532
src/parser.c vendored

File diff suppressed because it is too large Load Diff