const debug … const trace … type parser … func (p *parser) init(file *PosBase, r io.Reader, errh ErrorHandler, pragh PragmaHandler, mode Mode) { … } // takePragma returns the current parsed pragmas // and clears them from the parser state. func (p *parser) takePragma() Pragma { … } // clearPragma is called at the end of a statement or // other Go form that does NOT accept a pragma. // It sends the pragma back to the pragma handler // to be reported as unused. func (p *parser) clearPragma() { … } // updateBase sets the current position base to a new line base at pos. // The base's filename, line, and column values are extracted from text // which is positioned at (tline, tcol) (only needed for error messages). func (p *parser) updateBase(pos Pos, tline, tcol uint, text string) { … } func commentText(s string) string { … } func trailingDigits(text string) (uint, uint, bool) { … } func (p *parser) got(tok token) bool { … } func (p *parser) want(tok token) { … } // gotAssign is like got(_Assign) but it also accepts ":=" // (and reports an error) for better parser error recovery. func (p *parser) gotAssign() bool { … } // posAt returns the Pos value for (line, col) and the current position base. func (p *parser) posAt(line, col uint) Pos { … } // errorAt reports an error at the given position. func (p *parser) errorAt(pos Pos, msg string) { … } // syntaxErrorAt reports a syntax error at the given position. func (p *parser) syntaxErrorAt(pos Pos, msg string) { … } // tokstring returns the English word for selected punctuation tokens // for more readable error messages. Use tokstring (not tok.String()) // for user-facing (error) messages; use tok.String() for debugging // output. func tokstring(tok token) string { … } // Convenience methods using the current token position. func (p *parser) pos() Pos { … } func (p *parser) error(msg string) { … } func (p *parser) syntaxError(msg string) { … } const stopset … // advance consumes tokens until it finds a token of the stopset or followlist. // The stopset is only considered if we are inside a function (p.fnest > 0). // The followlist is the list of valid tokens that can follow a production; // if it is empty, exactly one (non-EOF) token is consumed to ensure progress. func (p *parser) advance(followlist ...token) { … } // usage: defer p.trace(msg)() func (p *parser) trace(msg string) func() { … } func (p *parser) print(msg string) { … } // SourceFile = PackageClause ";" { ImportDecl ";" } { TopLevelDecl ";" } . func (p *parser) fileOrNil() *File { … } func isEmptyFuncDecl(dcl Decl) bool { … } // list parses a possibly empty, sep-separated list of elements, optionally // followed by sep, and closed by close (or EOF). sep must be one of _Comma // or _Semi, and close must be one of _Rparen, _Rbrace, or _Rbrack. // // For each list element, f is called. Specifically, unless we're at close // (or EOF), f is called at least once. After f returns true, no more list // elements are accepted. list returns the position of the closing token. // // list = [ f { sep f } [sep] ] close . func (p *parser) list(context string, sep, close token, f func() bool) Pos { … } // appendGroup(f) = f | "(" { f ";" } ")" . // ";" is optional before ")" func (p *parser) appendGroup(list []Decl, f func(*Group) Decl) []Decl { … } // ImportSpec = [ "." | PackageName ] ImportPath . // ImportPath = string_lit . func (p *parser) importDecl(group *Group) Decl { … } // ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] . func (p *parser) constDecl(group *Group) Decl { … } // TypeSpec = identifier [ TypeParams ] [ "=" ] Type . func (p *parser) typeDecl(group *Group) Decl { … } // 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 Expr, force bool) (*Name, 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 Expr) bool { … } // VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) . func (p *parser) varDecl(group *Group) Decl { … } // FunctionDecl = "func" FunctionName [ TypeParams ] ( Function | Signature ) . // FunctionName = identifier . // Function = Signature FunctionBody . // MethodDecl = "func" Receiver MethodName ( Function | Signature ) . // Receiver = Parameters . func (p *parser) funcDeclOrNil() *FuncDecl { … } func (p *parser) funcBody() *BlockStmt { … } func (p *parser) expr() Expr { … } // Expression = UnaryExpr | Expression binary_op Expression . func (p *parser) binaryExpr(x Expr, prec int) Expr { … } // UnaryExpr = PrimaryExpr | unary_op UnaryExpr . func (p *parser) unaryExpr() Expr { … } // callStmt parses call-like statements that can be preceded by 'defer' and 'go'. func (p *parser) callStmt() *CallStmt { … } // Operand = Literal | OperandName | MethodExpr | "(" Expression ")" . // Literal = BasicLit | CompositeLit | FunctionLit . // BasicLit = int_lit | float_lit | imaginary_lit | rune_lit | string_lit . // OperandName = identifier | QualifiedIdent. func (p *parser) operand(keep_parens bool) Expr { … } // pexpr parses a PrimaryExpr. // // PrimaryExpr = // Operand | // Conversion | // PrimaryExpr Selector | // PrimaryExpr Index | // PrimaryExpr Slice | // PrimaryExpr TypeAssertion | // PrimaryExpr Arguments . // // Selector = "." identifier . // Index = "[" Expression "]" . // Slice = "[" ( [ Expression ] ":" [ Expression ] ) | // ( [ Expression ] ":" Expression ":" Expression ) // "]" . // TypeAssertion = "." "(" Type ")" . // Arguments = "(" [ ( ExpressionList | Type [ "," ExpressionList ] ) [ "..." ] [ "," ] ] ")" . func (p *parser) pexpr(x Expr, keep_parens bool) Expr { … } // isValue reports whether x syntactically must be a value (and not a type) expression. func isValue(x Expr) bool { … } // Element = Expression | LiteralValue . func (p *parser) bare_complitexpr() Expr { … } // LiteralValue = "{" [ ElementList [ "," ] ] "}" . func (p *parser) complitexpr() *CompositeLit { … } func (p *parser) type_() Expr { … } func newIndirect(pos Pos, typ Expr) Expr { … } // typeOrNil is like type_ but it returns nil if there was no type // instead of reporting an error. // // Type = TypeName | TypeLit | "(" Type ")" . // TypeName = identifier | QualifiedIdent . // TypeLit = ArrayType | StructType | PointerType | FunctionType | InterfaceType | // SliceType | MapType | Channel_Type . func (p *parser) typeOrNil() Expr { … } func (p *parser) typeInstance(typ Expr) Expr { … } // If context != "", type parameters are not permitted. func (p *parser) funcType(context string) ([]*Field, *FuncType) { … } // "[" has already been consumed, and pos is its position. // If len != nil it is the already consumed array length. func (p *parser) arrayType(pos Pos, len Expr) Expr { … } // "[" and "]" have already been consumed, and pos is the position of "[". func (p *parser) sliceType(pos Pos) Expr { … } func (p *parser) chanElem() Expr { … } // StructType = "struct" "{" { FieldDecl ";" } "}" . func (p *parser) structType() *StructType { … } // InterfaceType = "interface" "{" { ( MethodDecl | EmbeddedElem ) ";" } "}" . func (p *parser) interfaceType() *InterfaceType { … } // Result = Parameters | Type . func (p *parser) funcResult() []*Field { … } func (p *parser) addField(styp *StructType, pos Pos, name *Name, typ Expr, tag *BasicLit) { … } // FieldDecl = (IdentifierList Type | AnonymousField) [ Tag ] . // AnonymousField = [ "*" ] TypeName . // Tag = string_lit . func (p *parser) fieldDecl(styp *StructType) { … } func (p *parser) arrayOrTArgs() Expr { … } func (p *parser) oliteral() *BasicLit { … } // MethodSpec = MethodName Signature | InterfaceTypeName . // MethodName = identifier . // InterfaceTypeName = TypeName . func (p *parser) methodDecl() *Field { … } // EmbeddedElem = MethodSpec | EmbeddedTerm { "|" EmbeddedTerm } . func (p *parser) embeddedElem(f *Field) *Field { … } // EmbeddedTerm = [ "~" ] Type . func (p *parser) embeddedTerm() Expr { … } // ParameterDecl = [ IdentifierList ] [ "..." ] Type . func (p *parser) paramDeclOrNil(name *Name, follow token) *Field { … } // Parameters = "(" [ ParameterList [ "," ] ] ")" . // ParameterList = ParameterDecl { "," ParameterDecl } . // "(" or "[" has already been consumed. // If name != nil, it is the first name after "(" or "[". // If typ != nil, name must be != nil, and (name, typ) is the first field in the list. // In the result list, either all fields have a name, or no field has a name. func (p *parser) paramList(name *Name, typ Expr, close token, requireNames bool) (list []*Field) { … } func (p *parser) badExpr() *BadExpr { … } // SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDecl . func (p *parser) simpleStmt(lhs Expr, keyword token) SimpleStmt { … } func (p *parser) newRangeClause(lhs Expr, def bool) *RangeClause { … } func (p *parser) newAssignStmt(pos Pos, op Operator, lhs, rhs Expr) *AssignStmt { … } func (p *parser) labeledStmtOrNil(label *Name) Stmt { … } // context must be a non-empty string unless we know that p.tok == _Lbrace. func (p *parser) blockStmt(context string) *BlockStmt { … } func (p *parser) declStmt(f func(*Group) Decl) *DeclStmt { … } func (p *parser) forStmt() Stmt { … } func (p *parser) header(keyword token) (init SimpleStmt, cond Expr, post SimpleStmt) { … } // emphasize returns a string representation of x, with (top-level) // binary expressions emphasized by enclosing them in parentheses. func emphasize(x Expr) string { … } func (p *parser) ifStmt() *IfStmt { … } func (p *parser) switchStmt() *SwitchStmt { … } func (p *parser) selectStmt() *SelectStmt { … } func (p *parser) caseClause() *CaseClause { … } func (p *parser) commClause() *CommClause { … } // stmtOrNil parses a statement if one is present, or else returns nil. // // Statement = // Declaration | LabeledStmt | SimpleStmt | // GoStmt | ReturnStmt | BreakStmt | ContinueStmt | GotoStmt | // FallthroughStmt | Block | IfStmt | SwitchStmt | SelectStmt | ForStmt | // DeferStmt . func (p *parser) stmtOrNil() Stmt { … } // StatementList = { Statement ";" } . func (p *parser) stmtList() (l []Stmt) { … } // argList parses a possibly empty, comma-separated list of arguments, // optionally followed by a comma (if not empty), and closed by ")". // The last argument may be followed by "...". // // argList = [ arg { "," arg } [ "..." ] [ "," ] ] ")" . func (p *parser) argList() (list []Expr, hasDots bool) { … } func (p *parser) name() *Name { … } // IdentifierList = identifier { "," identifier } . // The first name must be provided. func (p *parser) nameList(first *Name) []*Name { … } // The first name may be provided, or nil. func (p *parser) qualifiedName(name *Name) Expr { … } // ExpressionList = Expression { "," Expression } . func (p *parser) exprList() Expr { … } // typeList parses a non-empty, comma-separated list of types, // optionally followed by a comma. If strict is set to false, // the first element may also be a (non-type) expression. // If there is more than one argument, the result is a *ListExpr. // The comma result indicates whether there was a (separating or // trailing) comma. // // typeList = arg { "," arg } [ "," ] . func (p *parser) typeList(strict bool) (x Expr, comma bool) { … } // Unparen returns e with any enclosing parentheses stripped. func Unparen(x Expr) Expr { … } // UnpackListExpr unpacks a *ListExpr into a []Expr. func UnpackListExpr(x Expr) []Expr { … }