7
7
"strconv"
8
8
"strings"
9
9
10
- "github.com/arr-ai/wbnf/bootstrap "
10
+ "github.com/arr-ai/wbnf/wbnf "
11
11
"github.com/arr-ai/wbnf/errors"
12
12
"github.com/arr-ai/wbnf/parser"
13
13
)
@@ -19,18 +19,18 @@ const (
19
19
quantTag = "?"
20
20
)
21
21
22
- func ParserNodeToNode (g bootstrap .Grammar , v interface {}) Branch {
23
- rule := bootstrap .NodeRule (v )
22
+ func ParserNodeToNode (g wbnf .Grammar , v interface {}) Branch {
23
+ rule := wbnf .NodeRule (v )
24
24
term := g [rule ]
25
25
result := Branch {}
26
26
result .one ("@rule" , Extra {extra : rule })
27
27
result .fromTerm (g , term , newCounters (term ), v )
28
28
return result
29
29
}
30
30
31
- func NodeToParserNode (g bootstrap .Grammar , branch Branch ) interface {} {
31
+ func NodeToParserNode (g wbnf .Grammar , branch Branch ) interface {} {
32
32
branch = branch .clone ().(Branch )
33
- rule := branch .pullOne ("@rule" ).(Extra ).extra .(bootstrap .Rule )
33
+ rule := branch .pullOne ("@rule" ).(Extra ).extra .(wbnf .Rule )
34
34
term := g [rule ]
35
35
ctrs := newCounters (term )
36
36
return relabelNode (string (rule ), branch .toTerm (g , term , ctrs ))
@@ -162,43 +162,43 @@ func (n Branch) singular() Children {
162
162
return nil
163
163
}
164
164
165
- func (n Branch ) fromTerm (g bootstrap .Grammar , term bootstrap .Term , ctrs counters , v interface {}) {
165
+ func (n Branch ) fromTerm (g wbnf .Grammar , term wbnf .Term , ctrs counters , v interface {}) {
166
166
switch t := term .(type ) {
167
- case bootstrap .S , bootstrap .RE , bootstrap .REF :
167
+ case wbnf .S , wbnf .RE , wbnf .REF :
168
168
n .add ("" , 0 , Leaf (v .(parser.Scanner )), ctrs ["" ], nil )
169
- case bootstrap .Rule :
169
+ case wbnf .Rule :
170
170
term := g [t ]
171
171
ctrs2 := newCounters (term )
172
172
b := Branch {}
173
173
b .fromTerm (g , term , ctrs2 , v )
174
174
unleveled , level := unlevel (string (t ))
175
175
n .add (unleveled , level , b , ctrs [string (t )], ctrs2 )
176
- case bootstrap .Seq :
176
+ case wbnf .Seq :
177
177
node := v .(parser.Node )
178
178
for i , child := range node .Children {
179
179
n .fromTerm (g , t [i ], ctrs , child )
180
180
}
181
- case bootstrap .Oneof :
181
+ case wbnf .Oneof :
182
182
node := v .(parser.Node )
183
183
n .many ("@choice" , Extra {extra : node .Extra .(int )})
184
184
n .fromTerm (g , t [node .Extra .(int )], ctrs , node .Children [0 ])
185
- case bootstrap .Delim :
185
+ case wbnf .Delim :
186
186
node := v .(parser.Node )
187
- if node .Extra .(bootstrap .Associativity ) != bootstrap .NonAssociative {
187
+ if node .Extra .(wbnf .Associativity ) != wbnf .NonAssociative {
188
188
panic (errors .Unfinished )
189
189
}
190
190
L , R := t .LRTerms (node )
191
- terms := [2 ]bootstrap .Term {L , t .Sep }
191
+ terms := [2 ]wbnf .Term {L , t .Sep }
192
192
for i , child := range node .Children {
193
193
n .fromTerm (g , terms [i % 2 ], ctrs , child )
194
194
terms [0 ] = R
195
195
}
196
- case bootstrap .Quant :
196
+ case wbnf .Quant :
197
197
node := v .(parser.Node )
198
198
for _ , child := range node .Children {
199
199
n .fromTerm (g , t .Term , ctrs , child )
200
200
}
201
- case bootstrap .Named :
201
+ case wbnf .Named :
202
202
b := Branch {}
203
203
ctrs2 := newCounters (t .Term )
204
204
b .fromTerm (g , t .Term , ctrs2 , v )
@@ -271,23 +271,23 @@ func (n Branch) pullMany(name string) Node {
271
271
return nil
272
272
}
273
273
274
- func (n Branch ) toTerm (g bootstrap .Grammar , term bootstrap .Term , ctrs counters ) (out interface {}) {
274
+ func (n Branch ) toTerm (g wbnf .Grammar , term wbnf .Term , ctrs counters ) (out interface {}) {
275
275
// defer enterf("%T %[1]v %v", term, ctrs).exitf("%v", &out)
276
276
switch t := term .(type ) {
277
- case bootstrap .S , bootstrap .RE :
277
+ case wbnf .S , wbnf .RE :
278
278
if node := n .pull ("" , 0 , ctrs ["" ], nil ); node != nil {
279
279
return parser .Scanner (node .(Leaf ))
280
280
}
281
281
return nil
282
- case bootstrap .Rule :
282
+ case wbnf .Rule :
283
283
term := g [t ]
284
284
ctrs2 := newCounters (term )
285
285
unleveled , level := unlevel (string (t ))
286
286
if b := n .pull (unleveled , level , ctrs [string (t )], ctrs2 ); b != nil {
287
287
return relabelNode (string (t ), b .(Branch ).toTerm (g , term , ctrs2 ))
288
288
}
289
289
return nil
290
- case bootstrap .Seq :
290
+ case wbnf .Seq :
291
291
result := parser.Node {Tag : seqTag }
292
292
for _ , child := range t {
293
293
if node := n .toTerm (g , child , ctrs ); node != nil {
@@ -297,19 +297,19 @@ func (n Branch) toTerm(g bootstrap.Grammar, term bootstrap.Term, ctrs counters)
297
297
}
298
298
}
299
299
return result
300
- case bootstrap .Oneof :
300
+ case wbnf .Oneof :
301
301
extra := n .pullMany ("@choice" ).(Extra ).extra .(int )
302
302
return parser.Node {
303
303
Tag : oneofTag ,
304
304
Extra : extra ,
305
305
Children : []interface {}{n .toTerm (g , t [extra ], ctrs )},
306
306
}
307
- case bootstrap .Delim :
307
+ case wbnf .Delim :
308
308
v := parser.Node {
309
309
Tag : delimTag ,
310
- Extra : bootstrap .NonAssociative ,
310
+ Extra : wbnf .NonAssociative ,
311
311
}
312
- terms := [2 ]bootstrap .Term {t .Term , t .Sep }
312
+ terms := [2 ]wbnf .Term {t .Term , t .Sep }
313
313
i := 0
314
314
for ; ; i ++ {
315
315
if child := n .toTerm (g , terms [i % 2 ], ctrs ); child != nil {
@@ -322,7 +322,7 @@ func (n Branch) toTerm(g bootstrap.Grammar, term bootstrap.Term, ctrs counters)
322
322
panic (errors .Inconceivable )
323
323
}
324
324
return v
325
- case bootstrap .Quant :
325
+ case wbnf .Quant :
326
326
result := parser.Node {Tag : quantTag }
327
327
for {
328
328
if v := n .toTerm (g , t .Term , ctrs ); v != nil {
@@ -335,7 +335,7 @@ func (n Branch) toTerm(g bootstrap.Grammar, term bootstrap.Term, ctrs counters)
335
335
panic (errors .Inconceivable )
336
336
}
337
337
return result
338
- case bootstrap .Named :
338
+ case wbnf .Named :
339
339
ctrs2 := newCounters (t .Term )
340
340
if b := n .pull (t .Name , 0 , ctrs [t .Name ], ctrs2 ); b != nil {
341
341
return relabelNode (t .Name , b .(Branch ).toTerm (g , t .Term , ctrs2 ))
0 commit comments