parser

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseExpr

func ParseExpr(x string, trace io.Writer) (ast.Expr, error)

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, specifier string, src any, trace io.Writer) (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 Goose (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

func ParseFile(fset *token.FileSet, specifier string, src any, trace io.Writer) (f *ast.Module, err error)

ParseFile parses the source code of a single Goose 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.

Types

type ParseError

type ParseError struct{}

func (*ParseError) Error

func (e *ParseError) Error() string

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func (*Parser) Errors

func (p *Parser) Errors() scanner.ErrorList

func (*Parser) Init

func (p *Parser) Init(fset *token.FileSet, specifier string, src []byte, trace io.Writer)

func (*Parser) ParseExpr

func (p *Parser) ParseExpr() ast.Expr

func (*Parser) ParseFile

func (p *Parser) ParseFile() (f *ast.Module, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL