-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
68 lines (57 loc) · 1.54 KB
/
grammar.js
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
module.exports = grammar({
name: "august",
rules: {
source_file: ($) => repeat($._defintion),
_defintion: ($) =>
choice(
$.unit,
$.expose,
$.cmd_call
),
expose: ($) => seq("expose", field("unit", $.ident), "as", $.ident),
meta_attr: ($) => seq("@", $.ident),
unit: ($) =>
seq(
"unit",
field("name", $.ident),
"{",
repeat($.cmd_call),
"}"
),
cmd_call: ($) => choice(
seq(optional(seq(field("ns", $.ident), "::")), field("name", choice("~", "@", $.ident)), "(", repeat(seq($.cmd_arg, optional(","))), ")"),
$.block
),
cmd_arg: ($) => choice($.meta_attr, $.str_lit, $.ident, /[\[\]{}<>]/, "=>", $.raw_ident),
block: $ => seq(field("name", $.ident), "{", choice(repeat($.cmd_call)), "}"),
str_lit: ($) => /"[^"]*"/,
ident: ($) => /[A-Za-z-_]+/,
raw_ident: ($) => /[!-&*-+--.0-;=?-Z^-z|]+/,
encap: ($) => /[\(\)\[\]{}<>]/,
},
});
// From tree-sitter-rust
/**
* Creates a rule to match one or more of the rules separated by the separator.
*
* @param {RuleOrLiteral} sep - The separator to use.
* @param {RuleOrLiteral} rule
*
* @return {SeqRule}
*
*/
function sepBy1(sep, rule) {
return seq(rule, repeat(seq(sep, rule)));
}
/**
* Creates a rule to optionally match one or more of the rules separated by the separator.
*
* @param {RuleOrLiteral} sep - The separator to use.
* @param {RuleOrLiteral} rule
*
* @return {ChoiceRule}
*
*/
function sepBy(sep, rule) {
return optional(sepBy1(sep, rule));
}