add => and =>? support

This commit is contained in:
Daniella / Tove 2024-11-15 11:28:03 +01:00
parent 5a1cba177f
commit 4246b7a44c
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
6 changed files with 2932 additions and 2368 deletions

View file

@ -2,7 +2,7 @@ module.exports = grammar({
name: 'spl', name: 'spl',
rules: { rules: {
source_file: $ => repeat($._statement), source_file: $ => seq(repeat($._statement), optional($._unspaced_statement)),
_unspaced_statement: $ => seq( _unspaced_statement: $ => seq(
choice( choice(
$.string, $.string,
@ -33,7 +33,7 @@ module.exports = grammar({
function_definition: $ => choice($.func, $.block), function_definition: $ => choice($.func, $.block),
func: $ => seq( func: $ => seq(
'func', $._spacing, 'func', $._spacing,
$.identifier, $._spacing, choice(seq('@', $.identifier, '!', $.blocky), $.block), $.identifier, $._spacing, choice(seq('@', $.identifier, $._spacing, '!', $.blocky), $.block),
), ),
blocky: $ => seq('{', repeat(choice($.blocky, /./)), '}'), blocky: $ => seq('{', repeat(choice($.blocky, /./)), '}'),
block: $ => seq( block: $ => seq(
@ -41,7 +41,7 @@ module.exports = grammar({
repeat($._statement), repeat($._statement),
'}', '}',
), ),
identifier: $ => /[^ \n\r\t<>:;&{}"']+/, identifier: $ => /[^ \n\r\t<>:;&{}"'\[\]]+/,
call: $ => seq( call: $ => seq(
choice( choice(
seq( seq(
@ -49,6 +49,7 @@ module.exports = grammar({
':', ':',
$.identifier, $.identifier,
), ),
$.operation,
$.identifier, $.identifier,
), ),
), ),
@ -60,8 +61,8 @@ module.exports = grammar({
repeat($.identifier), repeat($.identifier),
';', ';',
), ),
array: $ => seq('[', $._spacing, repeat($._statement), ']'), array: $ => seq('[', $._spacing, optional(repeat($._statement)), ']'),
operation: $ => /[+\-*\/%&]/, operation: $ => choice(/[+\-*\/%&]/, "=>", "=>?"),
variable: $ => choice( variable: $ => choice(
seq('def', $._spacing, $.identifier), seq('def', $._spacing, $.identifier),
seq('=', $.identifier), seq('=', $.identifier),
@ -96,6 +97,7 @@ module.exports = grammar({
), ),
catch: $ => seq( catch: $ => seq(
'catch', $._spacing, 'catch', $._spacing,
optional(repeat(seq($.identifier, $._spacing))),
'{', $._spacing, '{', $._spacing,
repeat($._statement), repeat($._statement),
'}', $._spacing, '}', $._spacing,

View file

@ -35,16 +35,6 @@
"tree-sitter-cli": "^0.20.8", "tree-sitter-cli": "^0.20.8",
"prebuildify": "^6.0.0" "prebuildify": "^6.0.0"
}, },
"tree-sitter": [
{
"scope": "source.spl",
"injection-regex": "spl",
"file-types": [
"spl",
"sbl"
]
}
],
"files": [ "files": [
"grammar.js", "grammar.js",
"binding.gyp", "binding.gyp",

View file

@ -1,4 +1,5 @@
{ {
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
"name": "spl", "name": "spl",
"rules": { "rules": {
"source_file": { "source_file": {
@ -295,6 +296,10 @@
} }
] ]
}, },
{
"type": "SYMBOL",
"name": "operation"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
@ -421,8 +426,17 @@
] ]
}, },
"operation": { "operation": {
"type": "PATTERN", "type": "CHOICE",
"value": "[+\\-*\\/%&]" "members": [
{
"type": "PATTERN",
"value": "[+\\-*\\/%&]"
},
{
"type": "STRING",
"value": "=>"
}
]
}, },
"variable": { "variable": {
"type": "CHOICE", "type": "CHOICE",
@ -668,6 +682,30 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "_spacing" "name": "_spacing"
}, },
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_spacing"
}
]
}
},
{
"type": "BLANK"
}
]
},
{ {
"type": "STRING", "type": "STRING",
"value": "{" "value": "{"

View file

@ -163,6 +163,10 @@
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
},
{
"type": "operation",
"named": true
} }
] ]
} }
@ -266,6 +270,10 @@
"type": "function_definition", "type": "function_definition",
"named": true "named": true
}, },
{
"type": "identifier",
"named": true
},
{ {
"type": "if", "type": "if",
"named": true "named": true
@ -440,9 +448,15 @@
] ]
} }
}, },
{
"type": "operation",
"named": true,
"fields": {}
},
{ {
"type": "source_file", "type": "source_file",
"named": true, "named": true,
"root": true,
"fields": {}, "fields": {},
"children": { "children": {
"multiple": true, "multiple": true,
@ -657,7 +671,7 @@
"named": false "named": false
}, },
{ {
"type": "=", "type": "=>",
"named": false "named": false
}, },
{ {

File diff suppressed because it is too large Load diff

View file

@ -47,6 +47,7 @@ struct TSLexer {
uint32_t (*get_column)(TSLexer *); uint32_t (*get_column)(TSLexer *);
bool (*is_at_included_range_start)(const TSLexer *); bool (*is_at_included_range_start)(const TSLexer *);
bool (*eof)(const TSLexer *); bool (*eof)(const TSLexer *);
void (*log)(const TSLexer *, const char *, ...);
}; };
typedef enum { typedef enum {