tree-sitter-dust/grammar.js
2023-08-22 19:59:15 -04:00

48 lines
754 B
JavaScript

module.exports = grammar({
name: 'dust',
rules: {
source_file: $ => repeat(choice($.comment, $.expression)),
comment: $ => /(#)(.+?)([\n\r])/,
expression: $ => choice(
$.identifier,
$.integer,
$.string,
$.list,
$.macro,
seq($.identifier, $.operator, $.identifier)
),
identifier: $ => /[a-zA-Z|_|.]+(_[a-zA-Z]+)*/,
operator: $ => choice(
'=',
'-',
'+',
';',
'/',
'|',
'&'
),
integer: $ => /\d/,
string: $ => /"(.*?)\"/,
function: $ => /'(.*?)\'/,
list: $ => seq(
'(',
repeat1(seq($.expression, optional(','))),
')'
),
macro: $ => choice(
"assert",
"assert_equal"
)
}
});