Source File
interface.go
Belonging Package
go/parser
package parser
import (
)
type Mode uint
const (
PackageClauseOnly Mode = 1 << iota // stop parsing after package clause
ImportsOnly // stop parsing after import declarations
ParseComments // parse comments and add them to AST
Trace // print a trace of parsed productions
DeclarationErrors // report declaration errors
SpuriousErrors // same as AllErrors, for backward-compatibility
AllErrors = SpuriousErrors // report all errors (not just the first 10 on different lines)
)
, := readSource(, )
if != nil {
return nil,
}
var parser
defer func() {
func ( *token.FileSet, string, func(fs.FileInfo) bool, Mode) ( map[string]*ast.Package, error) {
, := os.ReadDir()
if != nil {
return nil,
}
= make(map[string]*ast.Package)
for , := range {
if .IsDir() || !strings.HasSuffix(.Name(), ".go") {
continue
}
if != nil {
, := .Info()
if != nil {
return nil,
}
if !() {
continue
}
}
:= filepath.Join(, .Name())
if , := ParseFile(, , nil, ); == nil {
:= .Name.Name
, := []
if ! {
= &ast.Package{
Name: ,
Files: make(map[string]*ast.File),
}
[] =
}
.Files[] =
} else if == nil {
=
}
}
return
}
, := readSource(, )
if != nil {
return nil,
}
var parser
defer func() {
.openScope()
.pkgScope = .topScope
= .parseRhsOrType()
.closeScope()
assert(.topScope == nil, "unbalanced scopes")
func ( string) (ast.Expr, error) {
return ParseExprFrom(token.NewFileSet(), "", []byte(), 0)
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |