@@ -295,101 +295,6 @@ extension DSLTree.CustomCharacterClass.Member {
295
295
}
296
296
}
297
297
298
- extension AST . CustomCharacterClass . Member {
299
- func generateConsumer(
300
- _ opts: MatchingOptions
301
- ) throws -> MEProgram < String > . ConsumeFunction {
302
- switch self {
303
- case . custom( let ccc) :
304
- return try ccc. generateConsumer ( opts)
305
-
306
- case . range( let r) :
307
- guard let lhs = r. lhs. literalCharacterValue else {
308
- throw Unsupported ( " \( r. lhs) in range " )
309
- }
310
- guard let rhs = r. rhs. literalCharacterValue else {
311
- throw Unsupported ( " \( r. rhs) in range " )
312
- }
313
-
314
- return { input, bounds in
315
- // TODO: check for out of bounds?
316
- let curIdx = bounds. lowerBound
317
- if ( lhs... rhs) . contains ( input [ curIdx] ) {
318
- // TODO: semantic level
319
- return input. index ( after: curIdx)
320
- }
321
- return nil
322
- }
323
-
324
- case . atom( let atom) :
325
- guard let gen = try atom. generateConsumer ( opts) else {
326
- throw Unsupported ( " TODO " )
327
- }
328
- return gen
329
-
330
- case . quote( let q) :
331
- // TODO: Not optimal.
332
- let consumers = try q. literal. map {
333
- try AST . Atom ( . char( $0) , . fake) . generateConsumer ( opts) !
334
- }
335
- return { input, bounds in
336
- for consumer in consumers {
337
- if let idx = consumer ( input, bounds) {
338
- return idx
339
- }
340
- }
341
- return nil
342
- }
343
-
344
- case . trivia:
345
- throw Unreachable (
346
- " Should have been stripped by caller " )
347
-
348
- case . setOperation( let lhs, let op, let rhs) :
349
- // TODO: We should probably have a component type
350
- // instead of a members array... for now we reconstruct
351
- // an AST node...
352
- let start = AST . Located (
353
- faking: AST . CustomCharacterClass. Start. normal)
354
-
355
- let lhs = try AST . CustomCharacterClass (
356
- start, lhs, . fake
357
- ) . generateConsumer ( opts)
358
- let rhs = try AST . CustomCharacterClass (
359
- start, rhs, . fake
360
- ) . generateConsumer ( opts)
361
-
362
- return { input, bounds in
363
- // NOTE: Easy way to implement, not performant
364
- let lhsIdxOpt = lhs ( input, bounds)
365
- let rhsIdxOpt = rhs ( input, bounds)
366
-
367
- // TODO: What if lengths don't line up?
368
- assert ( lhsIdxOpt == rhsIdxOpt || lhsIdxOpt == nil
369
- || rhsIdxOpt == nil )
370
-
371
- switch op. value {
372
- case . subtraction:
373
- guard rhsIdxOpt == nil else { return nil }
374
- return lhsIdxOpt
375
-
376
- case . intersection:
377
- if let idx = lhsIdxOpt {
378
- return rhsIdxOpt == nil ? nil : idx
379
- }
380
- return nil
381
-
382
- case . symmetricDifference:
383
- if let idx = lhsIdxOpt {
384
- return rhsIdxOpt == nil ? idx : nil
385
- }
386
- return rhsIdxOpt
387
- }
388
- }
389
- }
390
- }
391
- }
392
-
393
298
extension DSLTree . CustomCharacterClass {
394
299
func generateConsumer(
395
300
_ opts: MatchingOptions
@@ -413,29 +318,6 @@ extension DSLTree.CustomCharacterClass {
413
318
}
414
319
}
415
320
416
- extension AST . CustomCharacterClass {
417
- func generateConsumer(
418
- _ opts: MatchingOptions
419
- ) throws -> MEProgram < String > . ConsumeFunction {
420
- // NOTE: Easy way to implement, obviously not performant
421
- let consumers = try strippingTriviaShallow. members. map {
422
- try $0. generateConsumer ( opts)
423
- }
424
- return { input, bounds in
425
- for consumer in consumers {
426
- if let idx = consumer ( input, bounds) {
427
- return isInverted ? nil : idx
428
- }
429
- }
430
- if isInverted {
431
- // FIXME: semantic level
432
- return input. index ( after: bounds. lowerBound)
433
- }
434
- return nil
435
- }
436
- }
437
- }
438
-
439
321
// NOTE: Conveniences, though not most performant
440
322
private func consumeScalarScript(
441
323
_ s: Unicode . Script
0 commit comments