Documentation ¶
Overview ¶
Package parser is an internal package that parses template source into an abstract syntax tree.
Index ¶
- func Errorf(loc Locatable, format string, a ...interface{}) *sourceLocError
- type ASTBlock
- type ASTNode
- type ASTObject
- type ASTRaw
- type ASTSeq
- type ASTTag
- type ASTText
- type ASTTrim
- type BlockSyntax
- type Config
- type Error
- type Grammar
- type Locatable
- type SourceLoc
- type Token
- type TokenType
- type TrimDirection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ASTBlock ¶
type ASTBlock struct { Token Body []ASTNode // Body is the nodes before the first branch Clauses []*ASTBlock // E.g. else and elseif w/in an if // contains filtered or unexported fields }
ASTBlock represents a {% tag %}…{% endtag %}.
type ASTObject ¶
type ASTObject struct { Token Expr expressions.Expression }
ASTObject is an {{ object }} object.
type ASTRaw ¶
type ASTRaw struct { Slices []string // contains filtered or unexported fields }
ASTRaw holds the text between the start and end of a raw tag.
func (*ASTRaw) SourceLocation ¶
func (n *ASTRaw) SourceLocation() SourceLoc
func (*ASTRaw) SourceText ¶
func (n *ASTRaw) SourceText() string
type ASTSeq ¶
type ASTSeq struct { Children []ASTNode // contains filtered or unexported fields }
ASTSeq is a sequence of nodes.
func (*ASTSeq) SourceLocation ¶
func (n *ASTSeq) SourceLocation() SourceLoc
func (*ASTSeq) SourceText ¶
func (n *ASTSeq) SourceText() string
type ASTTag ¶
type ASTTag struct {
Token
}
ASTTag is a tag {% tag %} that is not a block start or end.
type ASTTrim ¶
type ASTTrim struct { TrimDirection // contains filtered or unexported fields }
ASTTrim is a trim object.
func (*ASTTrim) SourceLocation ¶
func (n *ASTTrim) SourceLocation() SourceLoc
func (*ASTTrim) SourceText ¶
func (n *ASTTrim) SourceText() string
type BlockSyntax ¶
type BlockSyntax interface { IsBlock() bool CanHaveParent(BlockSyntax) bool IsBlockEnd() bool IsBlockStart() bool IsClause() bool ParentTags() []string RequiresParent() bool TagName() string }
BlockSyntax supplies the parser with syntax information about blocks.
type Config ¶
type Config struct { expressions.Config Grammar Grammar Delims []string }
A Config holds configuration information for parsing and rendering.
type Grammar ¶
type Grammar interface {
BlockSyntax(string) (BlockSyntax, bool)
}
Grammar supplies the parser with syntax information about blocks.
type SourceLoc ¶
SourceLoc contains a Token's source location. Pathname is in the local file system; for example "dir/file.html" on Linux and macOS; "dir\file.html" on Windows.
type Token ¶
type Token struct { Type TokenType SourceLoc SourceLoc Name string // Name is the tag name of a tag Chunk. E.g. the tag name of "{% if 1 %}" is "if". Args string // Parameters is the tag arguments of a tag Chunk. E.g. the tag arguments of "{% if 1 %}" is "1". Source string // Source is the entirety of the token, including the "{{", "{%", etc. markers. }
A Token is an object {{ a.b }}, a tag {% if a>b %}, or a text chunk (anything outside of {{}} and {%%}.)
func (Token) SourceLocation ¶
SourceLocation returns the token's source location, for use in error reporting.
func (Token) SourceText ¶
SourceText returns the token's source text, for use in error reporting.
type TokenType ¶
type TokenType int
TokenType is the type of a Chunk
const ( // TextTokenType is the type of a text Chunk TextTokenType TokenType = iota // TagTokenType is the type of a tag Chunk "{%…%}" TagTokenType // ObjTokenType is the type of an object Chunk "{{…}}" ObjTokenType // TrimLeftTokenType is the type of a left trim tag "-" TrimLeftTokenType // TrimRightTokenType is the type of a right trim tag "-" TrimRightTokenType )
type TrimDirection ¶
type TrimDirection int
TrimDirection determines the trim direction of an ASTTrim object.
const ( Left TrimDirection = iota Right )