技术问询:codesearch中regexp/syntax来自Go标准库还是本地目录?
Let’s break this down clearly for you:
- The
regexp/syntaximported inindex/regexp_test.gocomes from the Go standard library, not the project’s localregexpdirectory.
Why this is the case:
Go’s import resolution works like this: when an import path doesn’t include a relative prefix (like ./ or ../) or a custom module namespace, it defaults to checking the standard library first. Looking at the codesearch project structure, the local regexp directory doesn’t have a syntax subfolder — it only contains project-specific regex handling files like regexp.go. If the team wanted to use a local syntax package, the import would need to reference the full module path (e.g., github.com/google/codesearch/regexp/syntax) or a relative path, which isn’t what’s written in the test file.
Where regexp/syntax is defined:
For a standard Go installation, the source code for regexp/syntax lives in your Go root directory’s src folder, usually at a path like $GOROOT/src/regexp/syntax. The core definitions (including regex syntax parsing logic, AST structures, and tokenization rules) are mostly contained in the syntax.go file within that directory.
内容的提问来源于stack exchange,提问作者user1424739

