-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnegi.lark
More file actions
40 lines (31 loc) · 1.32 KB
/
negi.lark
File metadata and controls
40 lines (31 loc) · 1.32 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
//python interpreter is ditched, this file is purely for demostrational purposes
%import common.NUMBER
%import common.ESCAPED_STRING
%import common.CNAME
//whitespace handling
%ignore /\s+/
?start: sequence
// Statements are sequences
?sequence: (product ";")* [creturn]
?creturn: product
// Product: tuple or single term
?product: tuple | negotiation
// Tuple: explicit product construction
tuple: negotiation ("," negotiation)+ [","] | negotiation ","
// Negotiation: explicit call. 2 terms without separation shouldn't be anything else.
//NegI always parses calls with 1 term in front of it, making ((f :) 2) possible.
//But due to how LALR(1) parses `term term` as (term (term term)),
//I have to combine that on python side as ((term term) term)
//if user needs multiple stuff packed and in different order, we already have tuples for this
?negotiation: term+ // the parser would add negotiation node, if there are more than 1 element
// Terms: atomic values, contracts, or applications
?term: atomic | membrane
// Atomic leaf nodes
?atomic: NUMBER | ESCAPED_STRING | label
label: CNAME | SNAME
SNAME: /[+\-*\/%=<>!&|^~:@#\.]+/
// Contracts, part of grammar, because user can't change them without breaking parsing
membrane: isolated | dynamic | grounded
isolated: "(" [sequence] ")"
dynamic: "{" [sequence] "}"
grounded: "[" [sequence] "]"