tree-sitter-dust/grammar.js

42 lines
671 B
JavaScript
Raw Normal View History

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 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 21:02:40 +00:00
}
});