@@ -382,34 +382,43 @@ extension AST.Atom.CharacterProperty {
382
382
}
383
383
}
384
384
385
+ extension AST . Atom {
386
+ public struct Reference : Hashable {
387
+ @frozen
388
+ public enum Kind : Hashable {
389
+ // \n \gn \g{n} \g<n> \g'n' (?n) (?(n)...
390
+ // Oniguruma: \k<n>, \k'n'
391
+ case absolute( Int )
392
+
393
+ // \g{-n} \g<+n> \g'+n' \g<-n> \g'-n' (?+n) (?-n)
394
+ // (?(+n)... (?(-n)...
395
+ // Oniguruma: \k<-n> \k<+n> \k'-n' \k'+n'
396
+ case relative( Int )
397
+
398
+ // \k<name> \k'name' \g{name} \k{name} (?P=name)
399
+ // \g<name> \g'name' (?&name) (?P>name)
400
+ // (?(<name>)... (?('name')... (?(name)...
401
+ case named( String )
402
+
403
+ /// (?R), (?(R)..., which are equivalent to (?0), (?(0)...
404
+ static var recurseWholePattern : Kind { . absolute( 0 ) }
405
+ }
406
+ public var kind : Kind
385
407
386
- // TODO: I haven't thought through this a bunch; this seems like
387
- // a sensible type to have and break down this way. But it could
388
- // easily get folded in with the kind of reference
389
- @frozen
390
- public enum Reference : Hashable {
391
- // \n \gn \g{n} \g<n> \g'n' (?n) (?(n)...
392
- // Oniguruma: \k<n>, \k'n'
393
- case absolute( Int )
394
-
395
- // \g{-n} \g<+n> \g'+n' \g<-n> \g'-n' (?+n) (?-n)
396
- // (?(+n)... (?(-n)...
397
- // Oniguruma: \k<-n> \k<+n> \k'-n' \k'+n'
398
- case relative( Int )
399
-
400
- // \k<name> \k'name' \g{name} \k{name} (?P=name)
401
- // \g<name> \g'name' (?&name) (?P>name)
402
- // (?(<name>)... (?('name')... (?(name)...
403
- case named( String )
404
-
405
- // TODO: I'm not sure the below goes here
406
- //
407
- // ?(R) (?(R)...
408
- case recurseWholePattern
409
- }
410
-
408
+ /// The location of the inner numeric or textual reference, e.g the location
409
+ /// of '-2' in '\g{-2}'.
410
+ public var innerLoc : SourceLocation
411
411
412
+ public init ( _ kind: Kind , innerLoc: SourceLocation ) {
413
+ self . kind = kind
414
+ self . innerLoc = innerLoc
415
+ }
412
416
417
+ /// Whether this is a reference that recurses the whole pattern, rather than
418
+ /// a group.
419
+ public var recursesWholePattern : Bool { kind == . recurseWholePattern }
420
+ }
421
+ }
413
422
414
423
extension AST . Atom {
415
424
/// Anchors and other built-in zero-width assertions
0 commit comments