tree-sitter-dust/grammar.js

48 lines
754 B
JavaScript
Raw Normal View History

2023-08-22 21:02:40 +00:00
module.exports = grammar({
2023-08-22 23:59:15 +00:00
name: 'dust',
2023-08-22 21:02:40 +00:00
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
}
});