2023-08-22 21:02:40 +00:00
|
|
|
module.exports = grammar({
|
2023-08-24 17:01:12 +00:00
|
|
|
name: 'dust',
|
2023-08-22 21:02:40 +00:00
|
|
|
|
|
|
|
rules: {
|
2023-08-24 14:12:08 +00:00
|
|
|
source_file: $ => repeat(choice(
|
|
|
|
$.comment,
|
|
|
|
$.expression,
|
|
|
|
$.yield,
|
|
|
|
$.chain
|
|
|
|
)),
|
2023-08-22 21:02:40 +00:00
|
|
|
|
|
|
|
expression: $ => choice(
|
2023-08-24 16:53:42 +00:00
|
|
|
prec(2, $.value),
|
|
|
|
prec(1, $.identifier),
|
2023-08-24 14:12:08 +00:00
|
|
|
$.tool,
|
|
|
|
seq($.identifier, $.operator, $.expression),
|
|
|
|
),
|
|
|
|
|
|
|
|
value: $ => choice(
|
2023-08-22 22:28:34 +00:00
|
|
|
$.integer,
|
2023-08-24 13:31:26 +00:00
|
|
|
$.float,
|
2023-08-22 22:28:34 +00:00
|
|
|
$.string,
|
|
|
|
$.list,
|
2023-08-24 13:31:26 +00:00
|
|
|
$.empty,
|
2023-08-24 16:53:42 +00:00
|
|
|
$.boolean,
|
2023-08-22 21:02:40 +00:00
|
|
|
),
|
2023-08-24 16:53:42 +00:00
|
|
|
|
|
|
|
comment: $ => /(#)(.+?)([\n\r])/,
|
2023-08-24 14:12:08 +00:00
|
|
|
|
|
|
|
yield: $ => "->",
|
|
|
|
|
|
|
|
chain: $ => ";",
|
2023-08-22 22:28:34 +00:00
|
|
|
|
|
|
|
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
|
2023-08-22 21:02:40 +00:00
|
|
|
|
|
|
|
operator: $ => choice(
|
|
|
|
'=',
|
2023-08-22 21:28:19 +00:00
|
|
|
'-',
|
|
|
|
'+',
|
|
|
|
'/',
|
|
|
|
'|',
|
|
|
|
'&'
|
2023-08-22 21:02:40 +00:00
|
|
|
),
|
|
|
|
|
2023-08-24 13:31:26 +00:00
|
|
|
tool: $ => choice(
|
|
|
|
"random",
|
|
|
|
"random_boolean",
|
|
|
|
"random_integer",
|
|
|
|
"random_string",
|
|
|
|
"random_float"
|
|
|
|
),
|
|
|
|
|
|
|
|
float: $ => /\d+\.\d*/,
|
|
|
|
|
|
|
|
integer: $ => /\d+/,
|
2023-08-22 22:28:34 +00:00
|
|
|
|
2023-09-25 09:57:08 +00:00
|
|
|
string: $ => seq(
|
|
|
|
'"',
|
|
|
|
repeat(),
|
|
|
|
'"'
|
|
|
|
),
|
2023-08-22 22:28:34 +00:00
|
|
|
|
2023-09-25 09:57:08 +00:00
|
|
|
function: $ => /\{(.*?)\}/,
|
2023-08-22 22:28:34 +00:00
|
|
|
|
2023-08-24 13:31:26 +00:00
|
|
|
empty: $ => "()",
|
|
|
|
|
2023-08-24 16:53:42 +00:00
|
|
|
boolean: $ => choice(
|
|
|
|
"true",
|
|
|
|
"false"
|
|
|
|
),
|
|
|
|
|
2023-08-22 22:28:34 +00:00
|
|
|
list: $ => seq(
|
|
|
|
'(',
|
|
|
|
repeat1(seq($.expression, optional(','))),
|
|
|
|
')'
|
|
|
|
),
|
2023-08-22 21:02:40 +00:00
|
|
|
}
|
|
|
|
});
|