parser

package
v0.0.0-...-4cc5765 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileOpener

type FileOpener = func() (filename string, src io.ReadCloser)

type Mode

type Mode uint32
const (
	ParseImports  Mode       = 1 << iota // also parse 'import ...'
	ParseDecls                           // also parse declarations
	ParseComments                        // add parsed comments to each ast.Node
	ParseAll      = ^Mode(0)             // parse everything
)

type Parser

type Parser struct {
	Mode Mode        // Parser Mode is exported
	Lang config.Lang // Parser Lang is exported
	// contains filtered or unexported fields
}

Go syntax parser. Supports reading from a io.Reader. callers should invoke Init() before any Parse*() method. The only method that clears accumulated errors is ClearErrors()

func (*Parser) ClearErrors

func (p *Parser) ClearErrors()

clear accumulated errors

func (*Parser) CurrToken

func (p *Parser) CurrToken() token.Token

return current token lookahead buffer

func (*Parser) Errors

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

return accumulated errors

func (*Parser) Init

func (p *Parser) Init(file *token.File, src io.Reader, mode Mode, lang config.Lang)

initialize parser and read the first non-comment token from src does NOT clear accumulated errors

func (*Parser) InitParseDir

func (p *Parser) InitParseDir(fset *token.FileSet, opener FileOpener, mode Mode, lang config.Lang) *ast.Dir

parse all files in a directory. repeatedly calls Parser.InitParseFile() until opener returns nil. does NOT clear accumulated errors

func (*Parser) InitParseFile

func (p *Parser) InitParseFile(fset *token.FileSet, opener FileOpener, mode Mode, lang config.Lang) *ast.File

open and parse a single file in a directory. calls in sequence: opener(), Parser.Init(), Parser.ParseFile() does NOT clear accumulated errors

func (*Parser) InitString

func (p *Parser) InitString(source string, mode Mode, lang config.Lang)

initialize parser to read from specified string. does NOT clear accumulated errors

func (*Parser) Parse

func (p *Parser) Parse() (node ast.Node)

parse a single declaration, statement or expression

func (*Parser) ParseExpr

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

func (*Parser) ParseFile

func (p *Parser) ParseFile() *ast.File

parse a whole file.

func (*Parser) ParseStmt

func (p *Parser) ParseStmt() (node ast.Node)

parse a single statement. does NOT consume the following ';' if present

func (*Parser) ParseTopLevelDecl

func (p *Parser) ParseTopLevelDecl() (node ast.Node)

parse a top-level declaration. does NOT consume the following ';' if present

func (*Parser) ParseType

func (p *Parser) ParseType(isTypeDecl bool) (node ast.Node)

parse a type. if isTypeDecl is true and p.Mode & parseGenerics != 0, then also parse any generic type declaration prefix '[T1 constraint1, T2 constraint2 ...]'

func (*Parser) SkipToken

func (p *Parser) SkipToken() token.Token

skip one token, return next one (which is kept in lookahead buffer)

Jump to

Keyboard shortcuts

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