tree-sitter-cmake/grammar.js

48 lines
1 KiB
JavaScript
Raw Normal View History

2021-04-06 16:55:44 -04:00
module.exports = grammar({
name: 'CMake',
rules: {
2021-04-06 17:38:23 -04:00
source_file: $ => repeat($.command_invocation),
line_ending: $ => $.newline,
2021-04-10 15:55:47 -04:00
seperation: $ => choice($.space, $.line_ending),
2021-04-06 17:38:23 -04:00
space: $ => /[ \t]+/,
newline: $ => /\n/,
identifier: $ => /[A-Za-z_][A-Za-z0-9_]*/,
2021-04-10 15:55:47 -04:00
argument: $ => choice(
$.unquoted_argument,
$.bracket_argument,
),
unquoted_argument: $ => repeat1(/[^ ()#\"\\]/),
bracket_argument: $ => seq(
$.bracket_open,
optional($.bracket_content),
$.bracket_close,
),
bracket_open: $ => seq('[', repeat('='), '['),
bracket_content: $ => repeat1(/[^\]]/),
bracket_close: $ => seq(']', repeat('='), ']'),
arguments: $ => seq($.argument, repeat($._seperated_arguments)),
2021-04-10 15:55:47 -04:00
_seperated_arguments: $ => prec.left(seq(
repeat1($.seperation),
optional($.argument)
)),
2021-04-06 17:38:23 -04:00
command_invocation: $ => seq(
repeat($.space),
$.identifier,
repeat($.space),
'(',
repeat($.seperation),
optional($.arguments),
2021-04-06 17:38:23 -04:00
')'
),
2021-04-06 16:55:44 -04:00
}
})