type Tree … type Mode … const ParseComments … const SkipFuncCheck … // Copy returns a copy of the [Tree]. Any parsing state is discarded. func (t *Tree) Copy() *Tree { … } // Parse returns a map from template name to [Tree], created by parsing the // templates described in the argument string. The top-level template will be // given the specified name. If an error is encountered, parsing stops and an // empty map is returned with the error. func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]any) (map[string]*Tree, error) { … } // next returns the next token. func (t *Tree) next() item { … } // backup backs the input stream up one token. func (t *Tree) backup() { … } // backup2 backs the input stream up two tokens. // The zeroth token is already there. func (t *Tree) backup2(t1 item) { … } // backup3 backs the input stream up three tokens // The zeroth token is already there. func (t *Tree) backup3(t2, t1 item) { … } // peek returns but does not consume the next token. func (t *Tree) peek() item { … } // nextNonSpace returns the next non-space token. func (t *Tree) nextNonSpace() (token item) { … } // peekNonSpace returns but does not consume the next non-space token. func (t *Tree) peekNonSpace() item { … } // New allocates a new parse tree with the given name. func New(name string, funcs ...map[string]any) *Tree { … } // ErrorContext returns a textual representation of the location of the node in the input text. // The receiver is only used when the node does not have a pointer to the tree inside, // which can occur in old code. func (t *Tree) ErrorContext(n Node) (location, context string) { … } // errorf formats the error and terminates processing. func (t *Tree) errorf(format string, args ...any) { … } // error terminates processing. func (t *Tree) error(err error) { … } // expect consumes the next token and guarantees it has the required type. func (t *Tree) expect(expected itemType, context string) item { … } // expectOneOf consumes the next token and guarantees it has one of the required types. func (t *Tree) expectOneOf(expected1, expected2 itemType, context string) item { … } // unexpected complains about the token and terminates processing. func (t *Tree) unexpected(token item, context string) { … } // recover is the handler that turns panics into returns from the top level of Parse. func (t *Tree) recover(errp *error) { … } // startParse initializes the parser, using the lexer. func (t *Tree) startParse(funcs []map[string]any, lex *lexer, treeSet map[string]*Tree) { … } // stopParse terminates parsing. func (t *Tree) stopParse() { … } // Parse parses the template definition string to construct a representation of // the template for execution. If either action delimiter string is empty, the // default ("{{" or "}}") is used. Embedded template definitions are added to // the treeSet map. func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]any) (tree *Tree, err error) { … } // add adds tree to t.treeSet. func (t *Tree) add() { … } // IsEmptyTree reports whether this tree (node) is empty of everything but space or comments. func IsEmptyTree(n Node) bool { … } // parse is the top-level parser for a template, essentially the same // as itemList except it also parses {{define}} actions. // It runs to EOF. func (t *Tree) parse() { … } // parseDefinition parses a {{define}} ... {{end}} template definition and // installs the definition in t.treeSet. The "define" keyword has already // been scanned. func (t *Tree) parseDefinition() { … } // itemList: // // textOrAction* // // Terminates at {{end}} or {{else}}, returned separately. func (t *Tree) itemList() (list *ListNode, next Node) { … } // textOrAction: // // text | comment | action func (t *Tree) textOrAction() Node { … } func (t *Tree) clearActionLine() { … } // Action: // // control // command ("|" command)* // // Left delim is past. Now get actions. // First word could be a keyword such as range. func (t *Tree) action() (n Node) { … } // Break: // // {{break}} // // Break keyword is past. func (t *Tree) breakControl(pos Pos, line int) Node { … } // Continue: // // {{continue}} // // Continue keyword is past. func (t *Tree) continueControl(pos Pos, line int) Node { … } // Pipeline: // // declarations? command ('|' command)* func (t *Tree) pipeline(context string, end itemType) (pipe *PipeNode) { … } func (t *Tree) checkPipeline(pipe *PipeNode, context string) { … } func (t *Tree) parseControl(context string) (pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) { … } // If: // // {{if pipeline}} itemList {{end}} // {{if pipeline}} itemList {{else}} itemList {{end}} // // If keyword is past. func (t *Tree) ifControl() Node { … } // Range: // // {{range pipeline}} itemList {{end}} // {{range pipeline}} itemList {{else}} itemList {{end}} // // Range keyword is past. func (t *Tree) rangeControl() Node { … } // With: // // {{with pipeline}} itemList {{end}} // {{with pipeline}} itemList {{else}} itemList {{end}} // // If keyword is past. func (t *Tree) withControl() Node { … } // End: // // {{end}} // // End keyword is past. func (t *Tree) endControl() Node { … } // Else: // // {{else}} // // Else keyword is past. func (t *Tree) elseControl() Node { … } // Block: // // {{block stringValue pipeline}} // // Block keyword is past. // The name must be something that can evaluate to a string. // The pipeline is mandatory. func (t *Tree) blockControl() Node { … } // Template: // // {{template stringValue pipeline}} // // Template keyword is past. The name must be something that can evaluate // to a string. func (t *Tree) templateControl() Node { … } func (t *Tree) parseTemplateName(token item, context string) (name string) { … } // command: // // operand (space operand)* // // space-separated arguments up to a pipeline character or right delimiter. // we consume the pipe character but leave the right delim to terminate the action. func (t *Tree) command() *CommandNode { … } // operand: // // term .Field* // // An operand is a space-separated component of a command, // a term possibly followed by field accesses. // A nil return means the next item is not an operand. func (t *Tree) operand() Node { … } // term: // // literal (number, string, nil, boolean) // function (identifier) // . // .Field // $ // '(' pipeline ')' // // A term is a simple "expression". // A nil return means the next item is not a term. func (t *Tree) term() Node { … } // hasFunction reports if a function name exists in the Tree's maps. func (t *Tree) hasFunction(name string) bool { … } // popVars trims the variable list to the specified length func (t *Tree) popVars(n int) { … } // useVar returns a node for a variable reference. It errors if the // variable is not defined. func (t *Tree) useVar(pos Pos, name string) Node { … }