MCPcopy Create free account
hub / github.com/google/codesearch / analyze

Function analyze

index/regexp.go:420–540  ·  view source on GitHub ↗

analyze returns the regexpInfo for the regexp re.

(re *syntax.Regexp)

Source from the content-addressed store, hash-verified

418
419// analyze returns the regexpInfo for the regexp re.
420func analyze(re *syntax.Regexp) (ret regexpInfo) {
421 //println("analyze", re.String())
422 //defer func() { println("->", ret.String()) }()
423 var info regexpInfo
424 switch re.Op {
425 case syntax.OpNoMatch:
426 return noMatch()
427
428 case syntax.OpEmptyMatch,
429 syntax.OpBeginLine, syntax.OpEndLine,
430 syntax.OpBeginText, syntax.OpEndText,
431 syntax.OpWordBoundary, syntax.OpNoWordBoundary:
432 return emptyString()
433
434 case syntax.OpLiteral:
435 if re.Flags&syntax.FoldCase != 0 {
436 switch len(re.Rune) {
437 case 0:
438 return emptyString()
439 case 1:
440 // Single-letter case-folded string:
441 // rewrite into char class and analyze.
442 re1 := &syntax.Regexp{
443 Op: syntax.OpCharClass,
444 }
445 re1.Rune = re1.Rune0[:0]
446 r0 := re.Rune[0]
447 re1.Rune = append(re1.Rune, r0, r0)
448 for r1 := unicode.SimpleFold(r0); r1 != r0; r1 = unicode.SimpleFold(r1) {
449 re1.Rune = append(re1.Rune, r1, r1)
450 }
451 info = analyze(re1)
452 return info
453 }
454 // Multi-letter case-folded string:
455 // treat as concatenation of single-letter case-folded strings.
456 re1 := &syntax.Regexp{
457 Op: syntax.OpLiteral,
458 Flags: syntax.FoldCase,
459 }
460 info = emptyString()
461 for i := range re.Rune {
462 re1.Rune = re.Rune[i : i+1]
463 info = concat(info, analyze(re1))
464 }
465 return info
466 }
467 info.exact = stringSet{string(re.Rune)}
468 info.match = allQuery
469
470 case syntax.OpAnyCharNotNL, syntax.OpAnyChar:
471 return anyChar()
472
473 case syntax.OpCapture:
474 return analyze(re.Sub[0])
475
476 case syntax.OpConcat:
477 return fold(concat, re.Sub, emptyString())

Callers 2

RegexpQueryFunction · 0.85
foldFunction · 0.85

Calls 11

simplifyMethod · 0.95
noMatchFunction · 0.85
emptyStringFunction · 0.85
concatFunction · 0.85
anyCharFunction · 0.85
foldFunction · 0.85
alternateFunction · 0.85
anyMatchFunction · 0.85
haveMethod · 0.80
copyMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…