tree-sitter-dust/grammar.js
2023-08-22 18:28:34 -04:00

42 lines
671 B
JavaScript

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