tree-sitter-cmake/grammar.js

63 lines
1.4 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_]*/,
escape_sequence: $ => choice(
$._escape_identity,
$._escape_encoded,
$._escape_semicolon,
),
_escape_identity: $ => /\\[^A-Za-z0-9;]/,
_escape_encoded: $ => choice('\\t', '\\r', '\\n'),
_escape_semicolon: $ => '\;',
2021-04-10 15:55:47 -04:00
argument: $ => choice(
$.unquoted_argument,
$.bracket_argument,
),
unquoted_argument: $ => repeat1(
choice(
/[^ ()#\"\\]/,
$.escape_sequence,
)
),
2021-04-10 15:55:47 -04:00
bracket_argument: $ => seq(
2021-04-10 19:10:37 -04:00
$._bracket_open,
optional($._bracket_content),
$._bracket_close,
2021-04-10 15:55:47 -04:00
),
2021-04-10 19:10:37 -04:00
_bracket_open: $ => seq('[', repeat('='), '['),
_bracket_content: $ => repeat1(/[^\]]/),
_bracket_close: $ => seq(']', repeat('='), ']'),
2021-04-10 15:55:47 -04:00
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($.seperation),
2021-04-06 17:38:23 -04:00
'(',
repeat($.seperation),
optional($.arguments),
2021-04-06 17:38:23 -04:00
')'
),
2021-04-06 16:55:44 -04:00
}
})