tree-sitter-bp/grammar.js
2024-04-08 20:15:59 +01:00

46 lines
786 B
JavaScript

module.exports = grammar({
name: "blueprint",
extras: ($) => [
/\s+/,
$.comment,
],
rules: {
source_file: ($) => repeat($._definition),
_definition: ($) => choice(
$.assignment,
),
comment: (_) => seq("#", /.*/),
// Definitions {{{
assignment: ($) => seq(
field("left", $.identifier),
field("operator", choice("=", "+=")),
field("right", $._expr),
),
// }}}
// Expressions {{{
_expr: ($) => choice(
// Literals
$.identifier,
$.integer_literal,
),
// The Blueprint scanner makes use of Go's lexer, so copy their rule
identifier: (_) => /[_\p{XID_Start}][_\p{XID_Continue}]*/,
integer_literal: (_) => /[0-9]+/,
// }}}
}
});
// vim: foldmethod=marker sw=2