Documentation
¶
Overview ¶
Package parser implements a parser for Next 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 Next source.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseExpr ¶
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.
func ParseExprFrom ¶
func ParseExprFrom(fset *token.FileSet, filename string, src any, mode Mode) (expr ast.Expr, err error)
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 Next (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.
func ParseFile ¶
ParseFile parses a single Next source file and returns the corresponding ast.File node. It takes the following parameters:
- fset: A token.FileSet for position information (must not be nil)
- filename: The filename of the source (used for recording positions)
- src: The source code (string, []byte, io.Reader, or nil to read from filename)
- mode: Parser mode flags
If parsing fails, it returns a nil ast.File and an error. For syntax errors, it returns a partial AST and a scanner.ErrorList sorted by source position.