MCPcopy
hub / github.com/sqlc-dev/sqlc / MatchCompile

Function MatchCompile

internal/pattern/match.go:22–42  ·  view source on GitHub ↗

Compile takes our match expression as a string, and compiles it into a *Match object. Will return an error on an invalid pattern.

(pattern string)

Source from the content-addressed store, hash-verified

20// Compile takes our match expression as a string, and compiles it into a *Match object.
21// Will return an error on an invalid pattern.
22func MatchCompile(pattern string) (*Match, error) {
23 // check for pattern in cache
24 matchCacheLock.RLock()
25 matcher, ok := matchCache[pattern]
26 matchCacheLock.RUnlock()
27 if ok {
28 return matcher, nil
29 }
30
31 // pattern isn't in cache, compile it
32 matcher, err := matchCompile(pattern)
33 if err != nil {
34 return nil, err
35 }
36 // add it to the cache
37 matchCacheLock.Lock()
38 matchCache[pattern] = matcher
39 matchCacheLock.Unlock()
40
41 return matcher, nil
42}
43
44func matchCompile(pattern string) (match *Match, err error) {
45 regex := ""

Callers 2

parseMethod · 0.92
MatchStringFunction · 0.92

Calls 1

matchCompileFunction · 0.85

Tested by

no test coverage detected