1
0

Improve highlight queries

This commit is contained in:
Jeff 2023-12-11 11:17:37 -05:00
parent 06da345333
commit e1a7c3ff72
11 changed files with 13383 additions and 9984 deletions

View File

@ -1,6 +1,6 @@
const fs = require('node:fs'); const fs = require('node:fs');
const data = fs.readFileSync("examples/assets/jq_data.json"); const data = fs.readFileSync("examples/assets/jq_data.json");
const items = JSON.parse(data); const items = JSON.parse(data);
const output = items.map((item) => item.commit.committer.name); const output = items.map((item) => item:commit:committer:name);
console.log(output) console.log(output)

View File

@ -13,7 +13,8 @@ async { (output 'Whaddup') }
(expression (expression
(function_call (function_call
(expression (expression
(identifier)) (identifier
(built_in_function)))
(expression (expression
(value (value
(string))))))))) (string)))))))))

View File

@ -29,7 +29,8 @@ for i in [1, 2, 3] {
(expression (expression
(function_call (function_call
(expression (expression
(identifier)) (identifier
(built_in_function)))
(expression (expression
(identifier))))))))) (identifier)))))))))
@ -62,6 +63,7 @@ for list in list_of_lists {
(expression (expression
(function_call (function_call
(expression (expression
(identifier)) (identifier
(built_in_function)))
(expression (expression
(identifier)))))))))))) (identifier))))))))))))

View File

@ -85,14 +85,16 @@ fn |message number| {
(expression (expression
(function_call (function_call
(expression (expression
(identifier)) (identifier
(built_in_function)))
(expression (expression
(identifier))))) (identifier)))))
(statement (statement
(expression (expression
(function_call (function_call
(expression (expression
(identifier)) (identifier
(built_in_function)))
(expression (expression
(identifier))))))))))) (identifier)))))))))))

View File

@ -19,7 +19,8 @@ while true {
(expression (expression
(function_call (function_call
(expression (expression
(identifier)) (identifier
(built_in_function)))
(expression (expression
(value (value
(string)))))))))) (string))))))))))

View File

@ -14,7 +14,8 @@ Simple Yield
(value (value
(integer))) (integer)))
(expression (expression
(identifier)))))) (identifier
(built_in_function)))))))
================================================================================ ================================================================================
Yield Chain Yield Chain

View File

@ -1,7 +1,7 @@
module.exports = grammar({ module.exports = grammar({
name: 'dust', name: 'dust',
word: $ => $.identifier, word: $ => $._identifier_pattern,
extras: $ => [/\s/, $._comment], extras: $ => [/\s/, $._comment],
@ -31,7 +31,6 @@ module.exports = grammar({
$.index_assignment, $.index_assignment,
$.match, $.match,
$.return, $.return,
$.use,
$.while, $.while,
), ),
optional(';'), optional(';'),
@ -61,8 +60,12 @@ module.exports = grammar({
), ),
), ),
identifier: $ => identifier: $ => choice(
/[_a-zA-Z]+[_a-zA-Z0-9]?/, $._identifier_pattern,
$.built_in_function,
),
_identifier_pattern: $ => /[_a-zA-Z]+[_a-zA-Z0-9]?/,
value: $ => value: $ =>
choice( choice(
@ -319,8 +322,6 @@ module.exports = grammar({
seq('return', $.expression), seq('return', $.expression),
), ),
use: $ => seq('use', $.string),
type_definition: $ => type_definition: $ =>
seq('<', $.type, '>'), seq('<', $.type, '>'),
@ -384,5 +385,22 @@ module.exports = grammar({
')', ')',
), ),
), ),
built_in_function: $ =>
choice(
"assert",
"assert_equal",
"bash",
"download",
"fish",
"length",
"metadata",
"output",
"output_error",
"random",
"random_boolean",
"random_float",
"random_integer",
),
}, },
}); });

View File

@ -1,6 +1,5 @@
(expression) @expression (expression) @expression
(value) @value (value) @value
(comment) @comment
(identifier) @identifier (identifier) @identifier
(value) @value (value) @value
(string) @string (string) @string
@ -24,6 +23,8 @@
"}" "}"
"<" "<"
">" ">"
"("
")"
] @punctuation.bracket ] @punctuation.bracket
[ [
@ -33,38 +34,22 @@
] @operator ] @operator
[ [
"if" "any"
"async"
"else" "else"
"false"
"float"
"fn"
"for" "for"
"if"
"in" "in"
"function" "int"
"map"
"match"
"num"
"str"
"true"
"while"
] @keyword ] @keyword
[ (built_in_function) @function.builtin
"assert"
"assert_equal"
"download"
"help"
"length"
"output"
"output_error"
"type"
"workdir"
"append"
"metadata"
"move"
"read"
"remove"
"write"
"bash"
"fish"
"raw"
"sh"
"zsh"
"random"
"random_boolean"
"random_float"
"random_integer"
"columns"
"rows"
] @function.builtin

View File

@ -1,6 +1,6 @@
{ {
"name": "dust", "name": "dust",
"word": "identifier", "word": "_identifier_pattern",
"rules": { "rules": {
"root": { "root": {
"type": "PREC", "type": "PREC",
@ -90,10 +90,6 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "return" "name": "return"
}, },
{
"type": "SYMBOL",
"name": "use"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "while" "name": "while"
@ -181,6 +177,19 @@
} }
}, },
"identifier": { "identifier": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_identifier_pattern"
},
{
"type": "SYMBOL",
"name": "built_in_function"
}
]
},
"_identifier_pattern": {
"type": "PATTERN", "type": "PATTERN",
"value": "[_a-zA-Z]+[_a-zA-Z0-9]?" "value": "[_a-zA-Z]+[_a-zA-Z0-9]?"
}, },
@ -1006,19 +1015,6 @@
] ]
} }
}, },
"use": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "use"
},
{
"type": "SYMBOL",
"name": "string"
}
]
},
"type_definition": { "type_definition": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -1266,6 +1262,63 @@
} }
] ]
} }
},
"built_in_function": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "assert"
},
{
"type": "STRING",
"value": "assert_equal"
},
{
"type": "STRING",
"value": "bash"
},
{
"type": "STRING",
"value": "download"
},
{
"type": "STRING",
"value": "fish"
},
{
"type": "STRING",
"value": "length"
},
{
"type": "STRING",
"value": "metadata"
},
{
"type": "STRING",
"value": "output"
},
{
"type": "STRING",
"value": "output_error"
},
{
"type": "STRING",
"value": "random"
},
{
"type": "STRING",
"value": "random_boolean"
},
{
"type": "STRING",
"value": "random_float"
},
{
"type": "STRING",
"value": "random_integer"
}
]
} }
}, },
"extras": [ "extras": [

View File

@ -51,6 +51,11 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "built_in_function",
"named": true,
"fields": {}
},
{ {
"type": "else", "type": "else",
"named": true, "named": true,
@ -181,6 +186,21 @@
] ]
} }
}, },
{
"type": "identifier",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "built_in_function",
"named": true
}
]
}
},
{ {
"type": "if", "type": "if",
"named": true, "named": true,
@ -432,10 +452,6 @@
"type": "return", "type": "return",
"named": true "named": true
}, },
{
"type": "use",
"named": true
},
{ {
"type": "while", "type": "while",
"named": true "named": true
@ -473,21 +489,6 @@
] ]
} }
}, },
{
"type": "use",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "string",
"named": true
}
]
}
},
{ {
"type": "value", "type": "value",
"named": true, "named": true,
@ -665,6 +666,14 @@
"type": "any", "type": "any",
"named": false "named": false
}, },
{
"type": "assert",
"named": false
},
{
"type": "assert_equal",
"named": false
},
{ {
"type": "async", "type": "async",
"named": false "named": false
@ -673,10 +682,18 @@
"type": "async for", "type": "async for",
"named": false "named": false
}, },
{
"type": "bash",
"named": false
},
{ {
"type": "bool", "type": "bool",
"named": false "named": false
}, },
{
"type": "download",
"named": false
},
{ {
"type": "else", "type": "else",
"named": false "named": false
@ -690,13 +707,17 @@
"named": false "named": false
}, },
{ {
"type": "float", "type": "fish",
"named": true "named": false
}, },
{ {
"type": "float", "type": "float",
"named": false "named": false
}, },
{
"type": "float",
"named": true
},
{ {
"type": "fn", "type": "fn",
"named": false "named": false
@ -705,10 +726,6 @@
"type": "for", "type": "for",
"named": false "named": false
}, },
{
"type": "identifier",
"named": true
},
{ {
"type": "if", "type": "if",
"named": false "named": false
@ -725,6 +742,10 @@
"type": "integer", "type": "integer",
"named": true "named": true
}, },
{
"type": "length",
"named": false
},
{ {
"type": "map", "type": "map",
"named": false "named": false
@ -733,10 +754,38 @@
"type": "match", "type": "match",
"named": false "named": false
}, },
{
"type": "metadata",
"named": false
},
{ {
"type": "num", "type": "num",
"named": false "named": false
}, },
{
"type": "output",
"named": false
},
{
"type": "output_error",
"named": false
},
{
"type": "random",
"named": false
},
{
"type": "random_boolean",
"named": false
},
{
"type": "random_float",
"named": false
},
{
"type": "random_integer",
"named": false
},
{ {
"type": "return", "type": "return",
"named": false "named": false
@ -753,10 +802,6 @@
"type": "true", "type": "true",
"named": false "named": false
}, },
{
"type": "use",
"named": false
},
{ {
"type": "while", "type": "while",
"named": false "named": false

File diff suppressed because it is too large Load Diff