tree-sitter-dust/grammar.js
2023-08-24 10:12:08 -04:00

70 lines
1.1 KiB
JavaScript

module.exports = grammar({
name: 'Dust',
rules: {
source_file: $ => repeat(choice(
$.comment,
$.expression,
$.value,
$.yield,
$.chain
)),
comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice(
$.identifier,
$.tool,
seq($.identifier, $.operator, $.expression),
seq($.value, $.operator, $.value)
),
value: $ => choice(
$.integer,
$.float,
$.string,
$.list,
$.empty,
),
yield: $ => "->",
chain: $ => ";",
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
operator: $ => choice(
'=',
'-',
'+',
'/',
'|',
'&'
),
tool: $ => choice(
"random",
"random_boolean",
"random_integer",
"random_string",
"random_float"
),
float: $ => /\d+\.\d*/,
integer: $ => /\d+/,
string: $ => /"(.*?)\"/,
function: $ => /'(.*?)\'/,
empty: $ => "()",
list: $ => seq(
'(',
repeat1(seq($.expression, optional(','))),
')'
),
}
});