parser包的作用是将go源文件 转换为 抽象语法树(AST)
FUNC
// ParseDir 对指定path下以".go"结尾的文件做ParseFile操作// filter 过滤".go"文件,只用返回true 时才会被考虑func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, mode Mode)(pkgs map[string]*ast.Package, first error)// ParseExpr是一个方便的函数,用于获取表达式x的ASTfunc ParseExpr(x string) (ast.Expr, error)// ParseFile解析单个Go源文件的源代码,并返回相应的ast.File节点。// 源代码可以通过源文件的文件名或src参数提供。// 如果src为nil,才会去读filenamefunc ParseFile(fset *token.FileSet, filename string, src interface{}, mode Mode)(f *ast.File, err error)
type Mode
控制解析行为
const (PackageClauseOnly Mode = 1 << iota // stop parsing after package clauseImportsOnly // stop parsing after import declarationsParseComments // parse comments and add them to ASTTrace // print a trace of parsed productionsDeclarationErrors // report declaration errorsSpuriousErrors // same as AllErrors, for backward-compatibilityAllErrors = SpuriousErrors // report all errors (not just the first 10 on different lines))
