2023-08-22 21:02:40 +00:00
|
|
|
module.exports = grammar({
|
|
|
|
name: 'Dust',
|
|
|
|
|
|
|
|
rules: {
|
|
|
|
source_file: $ => repeat(choice($.comment, $.expression)),
|
|
|
|
|
|
|
|
comment: $ => /(#)(.+?)([\n\r])/,
|
|
|
|
|
|
|
|
expression: $ => choice(
|
2023-08-22 21:28:19 +00:00
|
|
|
$.identifier,
|
2023-08-22 22:28:34 +00:00
|
|
|
$.integer,
|
|
|
|
$.string,
|
|
|
|
$.list,
|
2023-08-22 23:02:07 +00:00
|
|
|
$.macro,
|
2023-08-22 21:28:19 +00:00
|
|
|
seq($.identifier, $.operator, $.identifier)
|
2023-08-22 21:02:40 +00:00
|
|
|
),
|
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
|
|
|
),
|
|
|
|
|
|
|
|
integer: $ => /\d/,
|
2023-08-22 22:28:34 +00:00
|
|
|
|
|
|
|
string: $ => /"(.*?)\"/,
|
|
|
|
|
|
|
|
function: $ => /'(.*?)\'/,
|
|
|
|
|
|
|
|
list: $ => seq(
|
|
|
|
'(',
|
|
|
|
repeat1(seq($.expression, optional(','))),
|
|
|
|
')'
|
|
|
|
),
|
2023-08-22 23:02:07 +00:00
|
|
|
|
|
|
|
macro: $ => choice(
|
|
|
|
"assert",
|
|
|
|
"assert_equal"
|
|
|
|
)
|
2023-08-22 21:02:40 +00:00
|
|
|
}
|
|
|
|
});
|