fix => and =>? support

This commit is contained in:
Daniella / Tove 2024-11-15 11:36:15 +01:00
parent 4246b7a44c
commit 9c9856d9ee
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
4 changed files with 2503 additions and 2475 deletions

View file

@ -2,7 +2,7 @@ module.exports = grammar({
name: 'spl', name: 'spl',
rules: { rules: {
source_file: $ => seq(repeat($._statement), optional($._unspaced_statement)), source_file: $ => seq(repeat($._statement)),
_unspaced_statement: $ => seq( _unspaced_statement: $ => seq(
choice( choice(
$.string, $.string,
@ -42,17 +42,16 @@ module.exports = grammar({
'}', '}',
), ),
identifier: $ => /[^ \n\r\t<>:;&{}"'\[\]]+/, identifier: $ => /[^ \n\r\t<>:;&{}"'\[\]]+/,
call: $ => seq( call: $ => choice(
choice(
seq( seq(
optional($.call), optional($.call),
':', ':',
optional(repeat('&')),
$.identifier, $.identifier,
), ),
$.operation, $.operation,
$.identifier, $.identifier,
), ),
),
number: $ => /\d+(\.\d+)?/, number: $ => /\d+(\.\d+)?/,
string: $ => seq('"', repeat(choice(/\\./, /./)), '"'), string: $ => seq('"', repeat(choice(/\\./, /./)), '"'),
call_expr: $ => seq('<', optional($._spacing), repeat($._statement), $._unspaced_statement, '>'), call_expr: $ => seq('<', optional($._spacing), repeat($._statement), $._unspaced_statement, '>'),
@ -62,7 +61,7 @@ module.exports = grammar({
';', ';',
), ),
array: $ => seq('[', $._spacing, optional(repeat($._statement)), ']'), array: $ => seq('[', $._spacing, optional(repeat($._statement)), ']'),
operation: $ => choice(/[+\-*\/%&]/, "=>", "=>?"), operation: $ => choice(/[+\-*\/%&]/, "=>?", "=>"),
variable: $ => choice( variable: $ => choice(
seq('def', $._spacing, $.identifier), seq('def', $._spacing, $.identifier),
seq('=', $.identifier), seq('=', $.identifier),
@ -79,7 +78,7 @@ module.exports = grammar({
)), )),
'}', '}',
), ),
_spacing: $ => /[ \n\r\t]+/, _spacing: $ => /[ \n\r\t\(\)]+/,
if: $ => seq( if: $ => seq(
'if', $._spacing, 'if', $._spacing,
'{', $._spacing, '{', $._spacing,

View file

@ -3,11 +3,16 @@
"name": "spl", "name": "spl",
"rules": { "rules": {
"source_file": { "source_file": {
"type": "SEQ",
"members": [
{
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_statement" "name": "_statement"
} }
}
]
}, },
"_unspaced_statement": { "_unspaced_statement": {
"type": "SEQ", "type": "SEQ",
@ -170,6 +175,10 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
}, },
{
"type": "SYMBOL",
"name": "_spacing"
},
{ {
"type": "STRING", "type": "STRING",
"value": "!" "value": "!"
@ -263,12 +272,9 @@
}, },
"identifier": { "identifier": {
"type": "PATTERN", "type": "PATTERN",
"value": "[^ \\n\\r\\t<>:;&{}\"']+" "value": "[^ \\n\\r\\t<>:;&{}\"'\\[\\]]+"
}, },
"call": { "call": {
"type": "SEQ",
"members": [
{
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{ {
@ -290,6 +296,21 @@
"type": "STRING", "type": "STRING",
"value": ":" "value": ":"
}, },
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "STRING",
"value": "&"
}
},
{
"type": "BLANK"
}
]
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
@ -305,8 +326,6 @@
"name": "identifier" "name": "identifier"
} }
] ]
}
]
}, },
"number": { "number": {
"type": "PATTERN", "type": "PATTERN",
@ -412,6 +431,9 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "_spacing" "name": "_spacing"
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "REPEAT", "type": "REPEAT",
"content": { "content": {
@ -419,6 +441,11 @@
"name": "_statement" "name": "_statement"
} }
}, },
{
"type": "BLANK"
}
]
},
{ {
"type": "STRING", "type": "STRING",
"value": "]" "value": "]"
@ -432,6 +459,10 @@
"type": "PATTERN", "type": "PATTERN",
"value": "[+\\-*\\/%&]" "value": "[+\\-*\\/%&]"
}, },
{
"type": "STRING",
"value": "=>?"
},
{ {
"type": "STRING", "type": "STRING",
"value": "=>" "value": "=>"
@ -582,7 +613,7 @@
}, },
"_spacing": { "_spacing": {
"type": "PATTERN", "type": "PATTERN",
"value": "[ \\n\\r\\t]+" "value": "[ \\n\\r\\t\\(\\)]+"
}, },
"if": { "if": {
"type": "SEQ", "type": "SEQ",

View file

@ -674,6 +674,10 @@
"type": "=>", "type": "=>",
"named": false "named": false
}, },
{
"type": "=>?",
"named": false
},
{ {
"type": ">", "type": ">",
"named": false "named": false

File diff suppressed because it is too large Load diff