2023-05-24 21:48:37 +02:00
|
|
|
module.exports = grammar({
|
2023-05-25 05:49:04 +02:00
|
|
|
name: 'spl',
|
2023-05-24 21:48:37 +02:00
|
|
|
|
|
|
|
rules: {
|
2024-11-15 11:36:15 +01:00
|
|
|
source_file: $ => seq(repeat($._statement)),
|
2024-09-30 19:04:31 +02:00
|
|
|
_unspaced_statement: $ => seq(
|
2023-05-24 21:48:37 +02:00
|
|
|
choice(
|
|
|
|
$.string,
|
|
|
|
$.function_definition,
|
|
|
|
$.type_definition,
|
|
|
|
$.with_expr,
|
|
|
|
$.array,
|
|
|
|
$.if,
|
|
|
|
$.while,
|
|
|
|
$.catch,
|
|
|
|
$.use,
|
|
|
|
$.include,
|
|
|
|
$.def,
|
|
|
|
$.number,
|
2024-09-30 19:04:31 +02:00
|
|
|
$.call_expr,
|
2023-05-24 21:48:37 +02:00
|
|
|
seq(
|
|
|
|
repeat('&'),
|
|
|
|
$.call
|
|
|
|
),
|
|
|
|
),
|
|
|
|
optional(';'),
|
2024-09-30 19:04:31 +02:00
|
|
|
optional($.call_expr),
|
|
|
|
),
|
|
|
|
_statement: $ => seq(
|
|
|
|
$._unspaced_statement,
|
2023-05-24 21:48:37 +02:00
|
|
|
$._spacing,
|
|
|
|
),
|
|
|
|
function_definition: $ => choice($.func, $.block),
|
|
|
|
func: $ => seq(
|
|
|
|
'func', $._spacing,
|
2024-11-15 11:28:03 +01:00
|
|
|
$.identifier, $._spacing, choice(seq('@', $.identifier, $._spacing, '!', $.blocky), $.block),
|
2023-05-24 21:48:37 +02:00
|
|
|
),
|
2023-08-04 22:33:39 +02:00
|
|
|
blocky: $ => seq('{', repeat(choice($.blocky, /./)), '}'),
|
2023-05-24 21:48:37 +02:00
|
|
|
block: $ => seq(
|
2023-08-04 22:29:48 +02:00
|
|
|
'{', $._spacing, repeat(seq(/[^ \n\r\t|]+/, $._spacing)), '|',
|
2023-05-24 21:48:37 +02:00
|
|
|
repeat($._statement),
|
|
|
|
'}',
|
|
|
|
),
|
2024-11-15 11:28:03 +01:00
|
|
|
identifier: $ => /[^ \n\r\t<>:;&{}"'\[\]]+/,
|
2024-11-15 11:36:15 +01:00
|
|
|
call: $ => choice(
|
|
|
|
seq(
|
|
|
|
optional($.call),
|
|
|
|
':',
|
|
|
|
optional(repeat('&')),
|
2023-05-24 21:48:37 +02:00
|
|
|
$.identifier,
|
|
|
|
),
|
2024-11-15 11:36:15 +01:00
|
|
|
$.operation,
|
|
|
|
$.identifier,
|
2023-05-24 21:48:37 +02:00
|
|
|
),
|
|
|
|
number: $ => /\d+(\.\d+)?/,
|
|
|
|
string: $ => seq('"', repeat(choice(/\\./, /./)), '"'),
|
2024-09-30 19:04:31 +02:00
|
|
|
call_expr: $ => seq('<', optional($._spacing), repeat($._statement), $._unspaced_statement, '>'),
|
2023-05-24 21:48:37 +02:00
|
|
|
with_expr: $ => seq(
|
|
|
|
'with', $._spacing,
|
|
|
|
repeat($.identifier),
|
|
|
|
';',
|
|
|
|
),
|
2024-11-15 11:28:03 +01:00
|
|
|
array: $ => seq('[', $._spacing, optional(repeat($._statement)), ']'),
|
2024-11-15 14:40:17 +01:00
|
|
|
operation: $ => choice(/[+\-*\/%&]/, "=>!", "=>?", "=>?!", "=>"),
|
2023-05-24 21:48:37 +02:00
|
|
|
variable: $ => choice(
|
|
|
|
seq('def', $._spacing, $.identifier),
|
|
|
|
seq('=', $.identifier),
|
|
|
|
),
|
|
|
|
type_definition: $ => seq(
|
|
|
|
'construct', $._spacing,
|
|
|
|
$.call, $._spacing,
|
|
|
|
optional(seq('namespace', $._spacing)),
|
|
|
|
'{', $._spacing,
|
|
|
|
repeat(seq($.identifier, $._spacing)),
|
|
|
|
optional(seq(
|
|
|
|
';',
|
|
|
|
repeat(seq($.identifier, $.block, $._spacing)),
|
|
|
|
)),
|
|
|
|
'}',
|
|
|
|
),
|
2024-11-15 11:36:15 +01:00
|
|
|
_spacing: $ => /[ \n\r\t\(\)]+/,
|
2023-05-24 21:48:37 +02:00
|
|
|
if: $ => seq(
|
|
|
|
'if', $._spacing,
|
|
|
|
'{', $._spacing,
|
|
|
|
repeat($._statement),
|
|
|
|
'}',
|
|
|
|
),
|
|
|
|
while: $ => seq(
|
|
|
|
'while', $._spacing,
|
|
|
|
'{', $._spacing,
|
|
|
|
repeat($._statement),
|
|
|
|
'}', $._spacing,
|
|
|
|
'{', $._spacing,
|
|
|
|
repeat($._statement),
|
|
|
|
'}',
|
|
|
|
),
|
|
|
|
catch: $ => seq(
|
|
|
|
'catch', $._spacing,
|
2024-11-15 11:28:03 +01:00
|
|
|
optional(repeat(seq($.identifier, $._spacing))),
|
2023-05-24 21:48:37 +02:00
|
|
|
'{', $._spacing,
|
|
|
|
repeat($._statement),
|
|
|
|
'}', $._spacing,
|
|
|
|
'{', $._spacing,
|
|
|
|
repeat($._statement),
|
|
|
|
'}',
|
|
|
|
),
|
|
|
|
include: $ => seq(
|
|
|
|
'include', $.identifier, $._spacing,
|
|
|
|
'in', $.identifier,
|
|
|
|
),
|
|
|
|
use: $ => seq(
|
|
|
|
'use', $._spacing,
|
|
|
|
$.call,
|
|
|
|
),
|
|
|
|
def: $ => seq(
|
|
|
|
'def', $._spacing,
|
|
|
|
$.identifier,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
|