-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrammar.js
More file actions
84 lines (68 loc) · 1.78 KB
/
grammar.js
File metadata and controls
84 lines (68 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @file Tree-sitter for the latest version of Minecraft mcfunction syntax
* @author BubbleFish <daforsastudia@gmail.com>
* @license ISC
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
const grammar_rules = require("./grammar/99_all.js");
module.exports = grammar({
name: "mcfunction",
conflicts: ($) => [
[$.subcommand_keyword, $.argument_keyword],
[$.item_slot, $._constant],
[$.selector_identifier, $._word],
[$.selector_identifier, $._data_path_node],
],
// Handle whitespace manually.
extras: (_) => [],
word: ($) => $.identifier,
reserved: {
global: (_) => ["execute", "return run", "run", "say"],
},
rules: {
source_file: ($) =>
// Although this looks rather complicated,
// all this does is make $._newline of the LAST $._statement
// optional.
optional(
choice(
seq(
repeat(
seq(
choice(optional($._statement), $._indentation),
seq(optional($._indentation), $._newline),
),
),
$._statement,
optional($._newline),
),
$._newline,
),
),
identifier: (_) => /[a-z_]+/,
backslash: (_) => /[ \t]*\\[ \t]*\r?\n[ \t]*/,
_whitespace: ($) => choice(/ +/, $.backslash),
_statement: ($) =>
seq(
optional($._indentation),
choice($.comment, $.special_comment, $.command),
),
// Languages such as 'github.com/bbfh-dev/vintage' & 'github.com/mcbeet/mecha'
_indentation: (_) => /[ \t]+/,
// Allows for ":" from Python 'github.com/mcbeet/mecha'
_newline: (_) => seq(optional(":"), /(?: *\r?\n)+/),
macro: (_) =>
token(
prec(
2,
choice(
seq("$(", /[0-9a-zA-Z._-]+/, ")"),
// Compile-time macros from 'github.com/bbfh-dev/vintage'
seq("%[", /[0-9a-zA-Z._-]+/, "]"),
),
),
),
...grammar_rules,
},
});