1+ (* ================================================================= *)
2+ (* BRIDGE LANGUAGE V1.5 (ISO/IEC 14977 COMPLIANT) *)
3+ (* ================================================================= *)
4+ (* --- 1. TOP LEVEL BLOCKS --- *)
5+ program
6+ = " version 1.5" , { const
7+ | bridge
8+ | define
9+ | tool };
10+
11+ const
12+ = " const" , identifier , " =" , json ;
13+
14+ bridge
15+ = " bridge" , identifier , " {" , { statement }, " }" ;
16+
17+ define
18+ = " define" , identifier , " {" , { statement }, " }" ;
19+
20+ tool
21+ = " tool" , identifier , " from" , identifier , " {" , { statement }, [ " on error" , " =" , json ], " }" ;
22+
23+ (* --- 2. STATEMENTS & SCOPE --- *)
24+ statement
25+ = with
26+ | wire
27+ | wire_alias
28+ | scope
29+ | spread
30+ | force ;
31+
32+ with
33+ = " with" , identifier , [ " as" , identifier ];
34+
35+ scope
36+ = target , " {" , { statement }, " }" ;
37+
38+ (* Standard assignment *)
39+ wire
40+ = target , ( routing
41+ | " =" , json );
42+
43+ (* Local memory assignment *)
44+ wire_alias
45+ = " alias" , identifier , routing ;
46+
47+ (* Merge into current scope object *)
48+ spread
49+ = " ..." , routing ;
50+
51+ (* Eager side-effect evaluation *)
52+ force
53+ = " force" , identifier , [ " catch" , " null" ];
54+
55+ (* --- 3. SHARED PATHS & ROUTING --- *)
56+ target
57+ = [ " ." ], identifier , { " ." , identifier };
58+
59+ (* The Right-Hand Side Evaluation Chain *)
60+ routing
61+ = " <-" , expression , { ( " ||"
62+ | " ??" ), expression }, [ " catch" , expression ];
63+
64+ (* --- 4. EXPRESSIONS & REFERENCES --- *)
65+ ref
66+ = identifier , [ [ " ?" ], " ." , identifier ], { [ " ?" ], " ." , identifier };
67+
68+ (* An expression is a piped value, optionally followed by a ternary gate *)
69+ expression
70+ = pipe_chain , [ " ?" , expression , " :" , expression ];
71+
72+ (* A pipe chain allows infinite routing: handle:handle:source *)
73+ pipe_chain
74+ = { identifier , [ " ." , identifier ], " :" }, base_expression ;
75+
76+ base_expression
77+ = json
78+ | ref , " []" , " as" , identifier , " {" , { statement }, " }"
79+ | ref
80+ | ( " throw"
81+ | " panic" ), [ string ]
82+ | ( " continue"
83+ | " break" ), [ integer ];
84+
85+ (* --- 5. EMBEDDED JSON (RFC 8259) --- *)
86+ json
87+ = object
88+ | array
89+ | string
90+ | number
91+ | " true"
92+ | " false"
93+ | " null" ;
94+
95+ object
96+ = " {" , [ string , " :" , json , { " ," , string , " :" , json } ], " }" ;
97+
98+ array
99+ = " [" , [ json , { " ," , json } ], " ]" ;
100+
101+ (* --- 6. LEXICAL RULES (TOKENS) --- *)
102+ identifier
103+ = letter , { letter
104+ | digit
105+ | " _" };
106+
107+ string
108+ = ' "' , { character - ' "' }, ' "'
109+ | " '" , { character - " '" }, " '" ;
110+
111+ number
112+ = [ " -" ], integer , [ " ." , integer ];
113+
114+ integer
115+ = digit , { digit };
116+
117+ letter
118+ = " a"
119+ | " b"
120+ | " c"
121+ | " d"
122+ | " e"
123+ | " f"
124+ | " g"
125+ | " h"
126+ | " i"
127+ | " j"
128+ | " k"
129+ | " l"
130+ | " m"
131+ | " n"
132+ | " o"
133+ | " p"
134+ | " q"
135+ | " r"
136+ | " s"
137+ | " t"
138+ | " u"
139+ | " v"
140+ | " w"
141+ | " x"
142+ | " y"
143+ | " z"
144+ | " A"
145+ | " B"
146+ | " C"
147+ | " D"
148+ | " E"
149+ | " F"
150+ | " G"
151+ | " H"
152+ | " I"
153+ | " J"
154+ | " K"
155+ | " L"
156+ | " M"
157+ | " N"
158+ | " O"
159+ | " P"
160+ | " Q"
161+ | " R"
162+ | " S"
163+ | " T"
164+ | " U"
165+ | " V"
166+ | " W"
167+ | " X"
168+ | " Y"
169+ | " Z" ;
170+
171+ digit
172+ = " 0"
173+ | " 1"
174+ | " 2"
175+ | " 3"
176+ | " 4"
177+ | " 5"
178+ | " 6"
179+ | " 7"
180+ | " 8"
181+ | " 9" ;
182+
183+ character
184+ = ? any valid unicode character ? ;
0 commit comments