sourcelibs/Parsing/demos/pieces.xtl
1⍝!/usr/bin/env xetal
2⍝│ Taking a notation apart safely: the pieces of an equation's right
3⍝│ side, each parser using all of its text; what a macro library does
4⍝│ with Parsing before it writes code. Run with "just demo Parsing pieces".
5"pa:" u̲se< "Parsing"
6
7call ← "(sum j:=0..M-1 | W[i,j] * x[j]) + b[i]"
8⍝ The top-level chain: one + between two terms.
9"+-" ᵖᵃt̲op call
10"+" ᵖᵃs̲plit call
11⍝ The first term is a group; inside it, the binding and the body.
12term ← d̲isclose f̲irst "+" ᵖᵃs̲plit call
13ᵖᵃg̲roup? term
14"|" ᵖᵃs̲plit ᵖᵃi̲nner term
15⍝ A reference's name and indices are read whole.
16ᵖᵃa̲pplied? "exp(z[i])"
17ᵖᵃn̲ame? "j"
18ᵖᵃn̲umber? "0.5"