go/src/go/parser/parser.go

type parser

func (p *parser) init(fset *token.FileSet, filename string, src []byte, mode Mode) {}

func (p *parser) printTrace(a ...any) {}

func trace(p *parser, msg string) *parser {}

// Usage pattern: defer un(trace(p, "..."))
func un(p *parser) {}

const maxNestLev

func incNestLev(p *parser) *parser {}

// decNestLev is used to track nesting depth during parsing to prevent stack exhaustion.
// It is used along with incNestLev in a similar fashion to how un and trace are used.
func decNestLev(p *parser) {}

// Advance to the next token.
func (p *parser) next0() {}

// Consume a comment and return it and the line on which it ends.
func (p *parser) consumeComment() (comment *ast.Comment, endline int) {}

// Consume a group of adjacent comments, add it to the parser's
// comments list, and return it together with the line at which
// the last comment in the group ends. A non-comment token or n
// empty lines terminate a comment group.
func (p *parser) consumeCommentGroup(n int) (comments *ast.CommentGroup, endline int) {}

// Advance to the next non-comment token. In the process, collect
// any comment groups encountered, and remember the last lead and
// line comments.
//
// A lead comment is a comment group that starts and ends in a
// line without any other tokens and that is followed by a non-comment
// token on the line immediately after the comment group.
//
// A line comment is a comment group that follows a non-comment
// token on the same line, and that has no tokens after it on the line
// where it ends.
//
// Lead and line comments may be considered documentation that is
// stored in the AST.
func (p *parser) next() {}

type bailout

func (p *parser) error(pos token.Pos, msg string) {}

func (p *parser) errorExpected(pos token.Pos, msg string) {}

func (p *parser) expect(tok token.Token) token.Pos {}

// expect2 is like expect, but it returns an invalid position
// if the expected token is not found.
func (p *parser) expect2(tok token.Token) (pos token.Pos) {}

// expectClosing is like expect but provides a better error message
// for the common case of a missing comma before a newline.
func (p *parser) expectClosing(tok token.Token, context string) token.Pos {}

// expectSemi consumes a semicolon and returns the applicable line comment.
func (p *parser) expectSemi() (comment *ast.CommentGroup) {}

func (p *parser) atComma(context string, follow token.Token) bool {}

func assert(cond bool, msg string) {}

// advance consumes tokens until the current token p.tok
// is in the 'to' set, or token.EOF. For error recovery.
func (p *parser) advance(to map[token.Token]bool) {}

var stmtStart

var declStart

var exprEnd

// safePos returns a valid file position for a given position: If pos
// is valid to begin with, safePos returns pos. If pos is out-of-range,
// safePos returns the EOF position.
//
// This is hack to work around "artificial" end positions in the AST which
// are computed by adding 1 to (presumably valid) token positions. If the
// token positions are invalid due to parse errors, the resulting end position
// may be past the file's EOF position, which would lead to panics if used
// later on.
func (p *parser) safePos(pos token.Pos) (res token.Pos) {}

func (p *parser) parseIdent() *ast.Ident {}

func (p *parser) parseIdentList() (list []*ast.Ident) {}

// If lhs is set, result list elements which are identifiers are not resolved.
func (p *parser) parseExprList() (list []ast.Expr) {}

func (p *parser) parseList(inRhs bool) []ast.Expr {}

func (p *parser) parseType() ast.Expr {}

func (p *parser) parseQualifiedIdent(ident *ast.Ident) ast.Expr {}

// If the result is an identifier, it is not resolved.
func (p *parser) parseTypeName(ident *ast.Ident) ast.Expr {}

// "[" has already been consumed, and lbrack is its position.
// If len != nil it is the already consumed array length.
func (p *parser) parseArrayType(lbrack token.Pos, len ast.Expr) *ast.ArrayType {}

func (p *parser) parseArrayFieldOrTypeInstance(x *ast.Ident) (*ast.Ident, ast.Expr) {}

func (p *parser) parseFieldDecl() *ast.Field {}

func (p *parser) parseStructType() *ast.StructType {}

func (p *parser) parsePointerType() *ast.StarExpr {}

func (p *parser) parseDotsType() *ast.Ellipsis {}

type field

func (p *parser) parseParamDecl(name *ast.Ident, typeSetsOK bool) (f field) {}

func (p *parser) parseParameterList(name0 *ast.Ident, typ0 ast.Expr, closing token.Token) (params []*ast.Field) {}

func (p *parser) parseParameters(acceptTParams bool) (tparams, params *ast.FieldList) {}

func (p *parser) parseResult() *ast.FieldList {}

func (p *parser) parseFuncType() *ast.FuncType {}

func (p *parser) parseMethodSpec() *ast.Field {}

func (p *parser) embeddedElem(x ast.Expr) ast.Expr {}

func (p *parser) embeddedTerm() ast.Expr {}

func (p *parser) parseInterfaceType() *ast.InterfaceType {}

func (p *parser) parseMapType() *ast.MapType {}

func (p *parser) parseChanType() *ast.ChanType {}

func (p *parser) parseTypeInstance(typ ast.Expr) ast.Expr {}

func (p *parser) tryIdentOrType() ast.Expr {}

func (p *parser) parseStmtList() (list []ast.Stmt) {}

func (p *parser) parseBody() *ast.BlockStmt {}

func (p *parser) parseBlockStmt() *ast.BlockStmt {}

func (p *parser) parseFuncTypeOrLit() ast.Expr {}

// parseOperand may return an expression or a raw type (incl. array
// types of the form [...]T). Callers must verify the result.
func (p *parser) parseOperand() ast.Expr {}

func (p *parser) parseSelector(x ast.Expr) ast.Expr {}

func (p *parser) parseTypeAssertion(x ast.Expr) ast.Expr {}

func (p *parser) parseIndexOrSliceOrInstance(x ast.Expr) ast.Expr {}

func (p *parser) parseCallOrConversion(fun ast.Expr) *ast.CallExpr {}

func (p *parser) parseValue() ast.Expr {}

func (p *parser) parseElement() ast.Expr {}

func (p *parser) parseElementList() (list []ast.Expr) {}

func (p *parser) parseLiteralValue(typ ast.Expr) ast.Expr {}

func (p *parser) parsePrimaryExpr(x ast.Expr) ast.Expr {}

func (p *parser) parseUnaryExpr() ast.Expr {}

func (p *parser) tokPrec() (token.Token, int) {}

// parseBinaryExpr parses a (possibly) binary expression.
// If x is non-nil, it is used as the left operand.
//
// TODO(rfindley): parseBinaryExpr has become overloaded. Consider refactoring.
func (p *parser) parseBinaryExpr(x ast.Expr, prec1 int) ast.Expr {}

// The result may be a type or even a raw type ([...]int).
func (p *parser) parseExpr() ast.Expr {}

func (p *parser) parseRhs() ast.Expr {}

const basic

const labelOk

const rangeOk

// parseSimpleStmt returns true as 2nd result if it parsed the assignment
// of a range clause (with mode == rangeOk). The returned statement is an
// assignment with a right-hand side that is a single unary expression of
// the form "range x". No guarantees are given for the left-hand side.
func (p *parser) parseSimpleStmt(mode int) (ast.Stmt, bool) {}

func (p *parser) parseCallExpr(callType string) *ast.CallExpr {}

func (p *parser) parseGoStmt() ast.Stmt {}

func (p *parser) parseDeferStmt() ast.Stmt {}

func (p *parser) parseReturnStmt() *ast.ReturnStmt {}

func (p *parser) parseBranchStmt(tok token.Token) *ast.BranchStmt {}

func (p *parser) makeExpr(s ast.Stmt, want string) ast.Expr {}

// parseIfHeader is an adjusted version of parser.header
// in cmd/compile/internal/syntax/parser.go, which has
// been tuned for better error handling.
func (p *parser) parseIfHeader() (init ast.Stmt, cond ast.Expr) {}

func (p *parser) parseIfStmt() *ast.IfStmt {}

func (p *parser) parseCaseClause() *ast.CaseClause {}

func isTypeSwitchAssert(x ast.Expr) bool {}

func (p *parser) isTypeSwitchGuard(s ast.Stmt) bool {}

func (p *parser) parseSwitchStmt() ast.Stmt {}

func (p *parser) parseCommClause() *ast.CommClause {}

func (p *parser) parseSelectStmt() *ast.SelectStmt {}

func (p *parser) parseForStmt() ast.Stmt {}

func (p *parser) parseStmt() (s ast.Stmt) {}

type parseSpecFunction

func (p *parser) parseImportSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.Spec {}

func (p *parser) parseValueSpec(doc *ast.CommentGroup, keyword token.Token, iota int) ast.Spec {}

func (p *parser) parseGenericType(spec *ast.TypeSpec, openPos token.Pos, name0 *ast.Ident, typ0 ast.Expr) {}

func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.Spec {}

// extractName splits the expression x into (name, expr) if syntactically
// x can be written as name expr. The split only happens if expr is a type
// element (per the isTypeElem predicate) or if force is set.
// If x is just a name, the result is (name, nil). If the split succeeds,
// the result is (name, expr). Otherwise the result is (nil, x).
// Examples:
//
//	x           force    name    expr
//	------------------------------------
//	P*[]int     T/F      P       *[]int
//	P*E         T        P       *E
//	P*E         F        nil     P*E
//	P([]int)    T/F      P       ([]int)
//	P(E)        T        P       (E)
//	P(E)        F        nil     P(E)
//	P*E|F|~G    T/F      P       *E|F|~G
//	P*E|F|G     T        P       *E|F|G
//	P*E|F|G     F        nil     P*E|F|G
func extractName(x ast.Expr, force bool) (*ast.Ident, ast.Expr) {}

// isTypeElem reports whether x is a (possibly parenthesized) type element expression.
// The result is false if x could be a type element OR an ordinary (value) expression.
func isTypeElem(x ast.Expr) bool {}

func (p *parser) parseGenDecl(keyword token.Token, f parseSpecFunction) *ast.GenDecl {}

func (p *parser) parseFuncDecl() *ast.FuncDecl {}

func (p *parser) parseDecl(sync map[token.Token]bool) ast.Decl {}

func (p *parser) parseFile() *ast.File {}

// packIndexExpr returns an IndexExpr x[expr0] or IndexListExpr x[expr0, ...].
func packIndexExpr(x ast.Expr, lbrack token.Pos, exprs []ast.Expr, rbrack token.Pos) ast.Expr {}