inferCaprefType determines a type for the nth capturing group in re, based on contents of that capture group.
(re *syntax.Regexp, n int)
| 537 | // inferCaprefType determines a type for the nth capturing group in re, based on contents |
| 538 | // of that capture group. |
| 539 | func InferCaprefType(re *syntax.Regexp, n int) Type { |
| 540 | group := getCaptureGroup(re, n) |
| 541 | if group == nil { |
| 542 | return None |
| 543 | } |
| 544 | |
| 545 | if group.Op != syntax.OpAlternate { |
| 546 | return inferGroupType(group) |
| 547 | } |
| 548 | |
| 549 | subType := Type(Undef) |
| 550 | for _, sub := range group.Sub { |
| 551 | subType = LeastUpperBound(subType, inferGroupType(sub)) |
| 552 | } |
| 553 | return subType |
| 554 | } |
| 555 | |
| 556 | func inferGroupType(group *syntax.Regexp) Type { |
| 557 | switch { |