56 lines
879 B
JavaScript
56 lines
879 B
JavaScript
module.exports = grammar({
|
|
name: 'dust',
|
|
|
|
rules: {
|
|
source_file: $ => repeat(choice($.comment, $.expression, $.operator)),
|
|
|
|
comment: $ => /(#)(.+?)([\n\r])/,
|
|
|
|
expression: $ => choice(
|
|
$.identifier,
|
|
$.integer,
|
|
$.float,
|
|
$.string,
|
|
$.list,
|
|
$.tool,
|
|
$.empty,
|
|
),
|
|
|
|
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(','))),
|
|
')'
|
|
),
|
|
}
|
|
});
|