tree-sitter-dfraw/grammar.js

47 lines
799 B
JavaScript
Raw Normal View History

2021-09-24 00:22:14 +03:00
module.exports = grammar({
name: 'dfraw',
rules: {
source_file: $ => repeat($._statement),
_statement: $ => choice(
$.bracket_statement,
$.comment
),
bracket_statement: $ => seq(
'[',
$.parameter_list,
']'
),
parameter_list: $ => seq(
$.declaration,
optional($.separator),
repeat(seq(
$._parameter,
optional($.separator)
))
),
_parameter: $ => choice(
$.number,
2021-09-29 08:20:28 +03:00
$.reference,
2021-09-24 00:22:14 +03:00
$.string,
),
2021-09-29 18:01:10 +03:00
// same as `reference`, different rule to give it different highlighting group
declaration: $ => /(?:VOLUME_mB)|(?:!?[0-9]*[A-Z][A-Z_0-9]*)/,
2021-09-24 00:22:14 +03:00
2021-09-29 08:35:43 +03:00
number: $ => /-?[0-9]+/,
2021-09-24 00:22:14 +03:00
2021-09-29 08:35:43 +03:00
reference: $ => /(?:VOLUME_mB)|(?:!?[0-9]*[A-Z][A-Z_0-9]*)/,
2021-09-24 00:22:14 +03:00
2021-09-29 08:20:28 +03:00
string: $ => /[A-Za-z \-,.'/\\=0-9]+/,
2021-09-24 00:22:14 +03:00
separator: $ => /:/,
comment: $ => /[^\[\]\s]+/
}
});