75 lines
1.1 KiB
JavaScript
75 lines
1.1 KiB
JavaScript
module.exports = grammar({
|
|
name: 'Dust',
|
|
|
|
rules: {
|
|
source_file: $ => repeat(choice(
|
|
$.comment,
|
|
$.expression,
|
|
$.yield,
|
|
$.chain
|
|
)),
|
|
|
|
expression: $ => choice(
|
|
prec(2, $.value),
|
|
prec(1, $.identifier),
|
|
$.tool,
|
|
seq($.identifier, $.operator, $.expression),
|
|
),
|
|
|
|
value: $ => choice(
|
|
$.integer,
|
|
$.float,
|
|
$.string,
|
|
$.list,
|
|
$.empty,
|
|
$.boolean,
|
|
),
|
|
|
|
comment: $ => /(#)(.+?)([\n\r])/,
|
|
|
|
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: $ => "()",
|
|
|
|
boolean: $ => choice(
|
|
"true",
|
|
"false"
|
|
),
|
|
|
|
list: $ => seq(
|
|
'(',
|
|
repeat1(seq($.expression, optional(','))),
|
|
')'
|
|
),
|
|
}
|
|
});
|