2024-04-07 20:59:34 +02:00
|
|
|
module.exports = grammar({
|
|
|
|
name: "blueprint",
|
|
|
|
|
2024-04-07 22:37:52 +02:00
|
|
|
extras: ($) => [
|
|
|
|
/\s+/,
|
2024-04-07 23:20:57 +02:00
|
|
|
$.comment,
|
2024-04-07 22:37:52 +02:00
|
|
|
],
|
|
|
|
|
2024-04-07 20:59:34 +02:00
|
|
|
rules: {
|
2024-04-07 22:37:52 +02:00
|
|
|
source_file: ($) => repeat($._definition),
|
|
|
|
|
|
|
|
_definition: ($) => choice(
|
|
|
|
$.assignment,
|
|
|
|
),
|
|
|
|
|
2024-04-07 23:20:57 +02:00
|
|
|
comment: (_) => seq("#", /.*/),
|
|
|
|
|
2024-04-07 22:37:52 +02:00
|
|
|
// Definitions {{{
|
|
|
|
|
|
|
|
assignment: ($) => seq(
|
|
|
|
field("left", $.identifier),
|
2024-04-07 22:40:17 +02:00
|
|
|
field("operator", choice("=", "+=")),
|
2024-04-07 22:37:52 +02:00
|
|
|
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]+/,
|
|
|
|
|
|
|
|
// }}}
|
2024-04-07 20:59:34 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// vim: foldmethod=marker sw=2
|