-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
40 lines (30 loc) · 941 Bytes
/
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
module.exports = grammar({
name: 'pplh',
word: $ => $.identifier,
rules: {
program: $ => seq(repeat1($.edges), repeat1($.imports), $.probability),
edges: $ =>
choice(
seq($.identifier, choice('->', '→'), $.identifier),
seq($.edges, choice('->', '→'), $.identifier)
),
imports: $ => seq('import', '"', $.url, '"'),
probability: $ => seq('Pr', '(', $.query, optional($.cond), ')'),
cond: $ => seq('|', $.query),
land: $ => choice(',', '∧'),
lor: $ => choice('+', '∨'),
lxor: $ => choice('^', '⊕'),
lnot: $ => choice('!', '¬'),
leq: $ => '=',
op: $ => choice($.land, $.lor, $.lxor, $.leq),
query: $ =>
choice(
$.identifier,
prec.left(1, seq($.lnot, $.query)),
prec.left(1, seq($.query, $.op, $.query)),
seq('(', $.query, ')')
),
identifier: $ => /[a-zA-Z_]+/,
url: $ => /[^\s"]+/,
},
})