68 lines
988 B
JavaScript
68 lines
988 B
JavaScript
module.exports = grammar({
|
|
name: 'dust',
|
|
|
|
rules: {
|
|
source: $ => repeat(choice(
|
|
$.comment,
|
|
$.identifier,
|
|
$.value,
|
|
$.tool,
|
|
$.operator,
|
|
)),
|
|
|
|
comment: $ => seq('#', /.*/),
|
|
|
|
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
|
|
|
|
value: $ => choice(
|
|
$.integer,
|
|
$.float,
|
|
$.string,
|
|
$.list,
|
|
$.empty,
|
|
$.boolean,
|
|
$.function,
|
|
),
|
|
|
|
tool: $ => choice(
|
|
"random",
|
|
"random_boolean",
|
|
"random_integer",
|
|
"random_string",
|
|
"random_float",
|
|
),
|
|
|
|
operator: $ => choice(
|
|
'=',
|
|
'-',
|
|
'+',
|
|
'/',
|
|
'|',
|
|
'&',
|
|
';',
|
|
"->",
|
|
),
|
|
|
|
float: $ => /\d+\.\d*/,
|
|
|
|
integer: $ => /\d+/,
|
|
|
|
string: $ => /("|')(.*?)("|')/,
|
|
|
|
function: $ => /{(.*?)}/,
|
|
|
|
empty: $ => "()",
|
|
|
|
boolean: $ => choice(
|
|
"true",
|
|
"false"
|
|
),
|
|
|
|
list: $ => seq(
|
|
'(',
|
|
repeat1(seq($.value, optional(','))),
|
|
')'
|
|
),
|
|
}
|
|
});
|