tree-sitter-dust/grammar.js
2023-09-27 17:41:39 -04:00

63 lines
949 B
JavaScript

module.exports = grammar({
name: 'dust',
rules: {
source: $ => repeat(choice(
$.statement,
)),
statement: $ => choice(
seq($.value, $.close),
seq($.identifier, $.close),
seq($.identifier, $.operator, $.statement),
),
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(
'+',
'-',
$.assignment,
),
assignment: $ => choice(
'=',
'+=',
'-=',
),
}
});