tree-sitter-dust/grammar.js
2023-09-27 19:10:21 -04:00

69 lines
1.0 KiB
JavaScript

module.exports = grammar({
name: 'dust',
rules: {
source: $ => repeat(choice(
$.statement,
)),
statement: $ => seq($.expression, $.close),
expression: $ => choice(
$.identifier,
prec(1, $.value),
prec(2, seq(
choice(
$.value,
$.identifier,
),
$.operator,
choice(
$.value,
$.identifier,
$.expression,
))),
),
close: $ => ";",
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
value: $ => choice(
$.integer,
$.float,
$.string,
$.list,
$.empty,
$.boolean,
$.function,
),
float: $ => /\d+\.\d*/,
integer: $ => /\d+/,
string: $ => /("|'|`)(.*?)("|'|`)/,
function: $ => /{(.*?)}/,
empty: $ => '()',
boolean: $ => choice(
'true',
'false',
),
list: $ => seq(
'(',
repeat1(seq($.value, optional(','))),
')'
),
operator: $ => choice(
'+',
'-',
'=',
),
}
});