add => and =>? support
This commit is contained in:
parent
5a1cba177f
commit
4246b7a44c
6 changed files with 2932 additions and 2368 deletions
12
grammar.js
12
grammar.js
|
@ -2,7 +2,7 @@ module.exports = grammar({
|
|||
name: 'spl',
|
||||
|
||||
rules: {
|
||||
source_file: $ => repeat($._statement),
|
||||
source_file: $ => seq(repeat($._statement), optional($._unspaced_statement)),
|
||||
_unspaced_statement: $ => seq(
|
||||
choice(
|
||||
$.string,
|
||||
|
@ -33,7 +33,7 @@ module.exports = grammar({
|
|||
function_definition: $ => choice($.func, $.block),
|
||||
func: $ => seq(
|
||||
'func', $._spacing,
|
||||
$.identifier, $._spacing, choice(seq('@', $.identifier, '!', $.blocky), $.block),
|
||||
$.identifier, $._spacing, choice(seq('@', $.identifier, $._spacing, '!', $.blocky), $.block),
|
||||
),
|
||||
blocky: $ => seq('{', repeat(choice($.blocky, /./)), '}'),
|
||||
block: $ => seq(
|
||||
|
@ -41,7 +41,7 @@ module.exports = grammar({
|
|||
repeat($._statement),
|
||||
'}',
|
||||
),
|
||||
identifier: $ => /[^ \n\r\t<>:;&{}"']+/,
|
||||
identifier: $ => /[^ \n\r\t<>:;&{}"'\[\]]+/,
|
||||
call: $ => seq(
|
||||
choice(
|
||||
seq(
|
||||
|
@ -49,6 +49,7 @@ module.exports = grammar({
|
|||
':',
|
||||
$.identifier,
|
||||
),
|
||||
$.operation,
|
||||
$.identifier,
|
||||
),
|
||||
),
|
||||
|
@ -60,8 +61,8 @@ module.exports = grammar({
|
|||
repeat($.identifier),
|
||||
';',
|
||||
),
|
||||
array: $ => seq('[', $._spacing, repeat($._statement), ']'),
|
||||
operation: $ => /[+\-*\/%&]/,
|
||||
array: $ => seq('[', $._spacing, optional(repeat($._statement)), ']'),
|
||||
operation: $ => choice(/[+\-*\/%&]/, "=>", "=>?"),
|
||||
variable: $ => choice(
|
||||
seq('def', $._spacing, $.identifier),
|
||||
seq('=', $.identifier),
|
||||
|
@ -96,6 +97,7 @@ module.exports = grammar({
|
|||
),
|
||||
catch: $ => seq(
|
||||
'catch', $._spacing,
|
||||
optional(repeat(seq($.identifier, $._spacing))),
|
||||
'{', $._spacing,
|
||||
repeat($._statement),
|
||||
'}', $._spacing,
|
||||
|
|
10
package.json
10
package.json
|
@ -35,16 +35,6 @@
|
|||
"tree-sitter-cli": "^0.20.8",
|
||||
"prebuildify": "^6.0.0"
|
||||
},
|
||||
"tree-sitter": [
|
||||
{
|
||||
"scope": "source.spl",
|
||||
"injection-regex": "spl",
|
||||
"file-types": [
|
||||
"spl",
|
||||
"sbl"
|
||||
]
|
||||
}
|
||||
],
|
||||
"files": [
|
||||
"grammar.js",
|
||||
"binding.gyp",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/grammar.schema.json",
|
||||
"name": "spl",
|
||||
"rules": {
|
||||
"source_file": {
|
||||
|
@ -295,6 +296,10 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "operation"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
|
@ -421,8 +426,17 @@
|
|||
]
|
||||
},
|
||||
"operation": {
|
||||
"type": "PATTERN",
|
||||
"value": "[+\\-*\\/%&]"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "PATTERN",
|
||||
"value": "[+\\-*\\/%&]"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "=>"
|
||||
}
|
||||
]
|
||||
},
|
||||
"variable": {
|
||||
"type": "CHOICE",
|
||||
|
@ -668,6 +682,30 @@
|
|||
"type": "SYMBOL",
|
||||
"name": "_spacing"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_spacing"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
|
|
|
@ -163,6 +163,10 @@
|
|||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "operation",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -266,6 +270,10 @@
|
|||
"type": "function_definition",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if",
|
||||
"named": true
|
||||
|
@ -440,9 +448,15 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "operation",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "source_file",
|
||||
"named": true,
|
||||
"root": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
|
@ -657,7 +671,7 @@
|
|||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "=",
|
||||
"type": "=>",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
|
|
5217
src/parser.c
5217
src/parser.c
File diff suppressed because it is too large
Load diff
|
@ -47,6 +47,7 @@ struct TSLexer {
|
|||
uint32_t (*get_column)(TSLexer *);
|
||||
bool (*is_at_included_range_start)(const TSLexer *);
|
||||
bool (*eof)(const TSLexer *);
|
||||
void (*log)(const TSLexer *, const char *, ...);
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
|
Loading…
Add table
Reference in a new issue