Namespace: go.std.go.parser
v1.0Contents
Summary
Provides a low-level interface to the go/parser package.
Package parser implements a parser for Go source files. Input may be
provided in a variety of forms (see the various Parse* functions); the
output is an abstract syntax tree (AST) representing the Go source. The
parser is invoked through one of the Parse* functions.
The parser accepts a larger language than is syntactically permitted by
the Go spec, for simplicity, and for improved robustness in the presence
of syntax errors. For instance, in method declarations, the receiver is
treated like an ordinary parameter list and thus may contain multiple
entries where the spec permits exactly one. Consequently, the corresponding
field in the AST (ast.FuncDecl.Recv) field is not restricted to one entry.
Index
- *Mode
- AllErrors
- DeclarationErrors
- ImportsOnly
- Mode
- PackageClauseOnly
- ParseComments
- ParseExpr
- ParseExprFrom
- ParseFile
- SkipObjectResolution
- SpuriousErrors
- Trace
- arrayOfMode
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
AllErrors
GoObject v1.0report all errors (not just the first 10 on different lines)
-
DeclarationErrors
GoObject v1.0report declaration errors
-
ImportsOnly
GoObject v1.0stop parsing after import declarations
-
PackageClauseOnly
GoObject v1.0stop parsing after package clause
-
ParseComments
GoObject v1.0parse comments and add them to AST
-
SkipObjectResolution
GoObject v1.0don't resolve identifiers to objects - see ParseFile
-
SpuriousErrors
GoObject v1.0same as AllErrors, for backward-compatibility
-
Trace
GoObject v1.0print a trace of parsed productions
Functions, Macros, and Special Forms
-
ParseExpr
Function v1.0(ParseExpr x)
ParseExpr is a convenience function for obtaining the AST of an expression x.
The position information recorded in the AST is undefined. The filename used
in error messages is the empty string.
If syntax errors were found, the result is a partial AST (with ast.Bad* nodes
representing the fragments of erroneous source code). Multiple errors are
returned via a scanner.ErrorList which is sorted by source position.
Go input arguments: (x string)
Go returns: (go/ast.Expr, error)
Joker input arguments: [^String x]
Joker returns: [^go.std.go.ast/Expr, ^Error] -
ParseExprFrom
Function v1.0(ParseExprFrom fset filename src mode)
ParseExprFrom is a convenience function for parsing an expression.
The arguments have the same meaning as for ParseFile, but the source must
be a valid Go (type or value) expression. Specifically, fset must not
be nil.
If the source couldn't be read, the returned AST is nil and the error
indicates the specific failure. If the source was read but syntax
errors were found, the result is a partial AST (with ast.Bad* nodes
representing the fragments of erroneous source code). Multiple errors
are returned via a scanner.ErrorList which is sorted by source position.
Go input arguments: (fset *go/token.FileSet, filename string, src any, mode Mode)
Go returns: (expr go/ast.Expr, err error)
Joker input arguments: [^go.std.go.token/*FileSet fset, ^String filename, ^GoObject src, ^Mode mode]
Joker returns: [^go.std.go.ast/Expr expr, ^Error err] -
ParseFile
Function v1.0(ParseFile fset filename src mode)
ParseFile parses the source code of a single Go source file and returns
the corresponding ast.File node. The source code may be provided via
the filename of the source file, or via the src parameter.
If src != nil, ParseFile parses the source from src and the filename is
only used when recording position information. The type of the argument
for the src parameter must be string, []byte, or io.Reader.
If src == nil, ParseFile parses the file specified by filename.
The mode parameter controls the amount of source text parsed and other
optional parser functionality. If the SkipObjectResolution mode bit is set,
the object resolution phase of parsing will be skipped, causing File.Scope,
File.Unresolved, and all Ident.Obj fields to be nil.
Position information is recorded in the file set fset, which must not be
nil.
If the source couldn't be read, the returned AST is nil and the error
indicates the specific failure. If the source was read but syntax
errors were found, the result is a partial AST (with ast.Bad* nodes
representing the fragments of erroneous source code). Multiple errors
are returned via a scanner.ErrorList which is sorted by source position.
Go input arguments: (fset *go/token.FileSet, filename string, src any, mode Mode)
Go returns: (f *go/ast.File, err error)
Joker input arguments: [^go.std.go.token/*FileSet fset, ^String filename, ^GoObject src, ^Mode mode]
Joker returns: [^go.std.go.ast/*File f, ^Error err]
Types
-
*Mode
Concrete Type v1.0A Mode value is a set of flags (or 0).
They control the amount of source code parsed and other optional
parser functionality.
-
Mode
Concrete Type v1.0A Mode value is a set of flags (or 0).
They control the amount of source code parsed and other optional
parser functionality.
-
arrayOfMode
Concrete Type v1.0A Mode value is a set of flags (or 0).
They control the amount of source code parsed and other optional
parser functionality.