-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
31 lines (29 loc) · 1.15 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
module.exports = grammar({
name: "newick",
rules: {
source_file: $ => repeat($.tree),
tree: $ => seq($._node, ";"),
_node: $ => choice(field("leaf", $.leaf), field("clade", $.clade)),
leaf: $ => choice(
field("attributes", $.attributes),
seq(field("name", $.name), optional(field("attributes", $.attributes))),
),
clade: $ => seq(
"(",
optional($._node),
repeat(seq(",", optional($._node))),
")", optional($.name), optional($.attributes)
),
attributes: $ => choice(
seq(":", field("length", $.length)),
seq(optional(seq(":", field("length", $.length))), field("data", $.data))
),
data: $ => seq("[&&NHX", repeat1(field("entry", $.nhx_entry)), "]"),
nhx_entry: $ => seq(":", field("key", $.nhx_val), "=", optional(field("value", $.nhx_val))),
length: $ => $.float,
_data_safe: $ => /[^:,;()\[\]=\s]+/,
nhx_val: $ => repeat1($._data_safe),
float: $ => /\d(_?\d)*(\.\d)?(_?\d)*([eE][\+-]?\d(_?\d)*)?/,
name: $ => /[^:,;()\[\]\s]+/,
}
});