MCPcopy
hub / github.com/google/mtail / InferCaprefType

Function InferCaprefType

internal/runtime/compiler/types/types.go:539–554  ·  view source on GitHub ↗

inferCaprefType determines a type for the nth capturing group in re, based on contents of that capture group.

(re *syntax.Regexp, n int)

Source from the content-addressed store, hash-verified

537// inferCaprefType determines a type for the nth capturing group in re, based on contents
538// of that capture group.
539func 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
556func inferGroupType(group *syntax.Regexp) Type {
557 switch {

Callers 2

checkRegexMethod · 0.92
TestInferCaprefTypeFunction · 0.85

Calls 4

getCaptureGroupFunction · 0.85
inferGroupTypeFunction · 0.85
LeastUpperBoundFunction · 0.85
TypeInterface · 0.70

Tested by 1

TestInferCaprefTypeFunction · 0.68