Documentation ¶
Overview ¶
Package ast provides structures to represent a handlebars Abstract Syntax Tree, and a Visitor interface to visit that tree.
Index ¶
- func HelperNameStr(node Node) (string, bool)
- func LiteralStr(node Node) (string, bool)
- func PathExpressionStr(node Node) (string, bool)
- func Print(node Node) string
- type BlockStatement
- type BooleanLiteral
- type CommentStatement
- type ContentStatement
- type Expression
- type Hash
- type HashPair
- type Loc
- type MustacheStatement
- type Node
- type NodeType
- type NumberLiteral
- type PartialStatement
- type PathExpression
- type Program
- type StringLiteral
- type Strip
- type SubExpression
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HelperNameStr ¶
HelperNameStr returns the string representation of a helper name, with a boolean set to false if this is not a valid helper name.
helperName : path | dataName | STRING | NUMBER | BOOLEAN | UNDEFINED | NULL
func LiteralStr ¶
LiteralStr returns the string representation of literal value, with a boolean set to false if this is not a literal.
func PathExpressionStr ¶
PathExpressionStr returns the string representation of path expression value, with a boolean set to false if this is not a path expression.
Types ¶
type BlockStatement ¶
type BlockStatement struct { NodeType Loc Expression *Expression Program *Program Inverse *Program // whitespace management OpenStrip *Strip InverseStrip *Strip CloseStrip *Strip }
BlockStatement represents a block node.
func NewBlockStatement ¶
func NewBlockStatement(pos int, line int) *BlockStatement
NewBlockStatement instanciates a new block node.
func (*BlockStatement) Accept ¶
func (node *BlockStatement) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*BlockStatement) String ¶
func (node *BlockStatement) String() string
String returns a string representation of receiver that can be used for debugging.
type BooleanLiteral ¶
BooleanLiteral represents a boolean node.
func NewBooleanLiteral ¶
func NewBooleanLiteral(pos int, line int, val bool, original string) *BooleanLiteral
NewBooleanLiteral instanciates a new boolean node.
func (*BooleanLiteral) Accept ¶
func (node *BooleanLiteral) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*BooleanLiteral) Canonical ¶
func (node *BooleanLiteral) Canonical() string
Canonical returns the canonical form of boolean node as a string (ie. "true" | "false").
func (*BooleanLiteral) String ¶
func (node *BooleanLiteral) String() string
String returns a string representation of receiver that can be used for debugging.
type CommentStatement ¶
CommentStatement represents a comment node.
func NewCommentStatement ¶
func NewCommentStatement(pos int, line int, val string) *CommentStatement
NewCommentStatement instanciates a new comment node.
func (*CommentStatement) Accept ¶
func (node *CommentStatement) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*CommentStatement) String ¶
func (node *CommentStatement) String() string
String returns a string representation of receiver that can be used for debugging.
type ContentStatement ¶
type ContentStatement struct { NodeType Loc Value string Original string // whitespace management RightStripped bool LeftStripped bool }
ContentStatement represents a content node.
func NewContentStatement ¶
func NewContentStatement(pos int, line int, val string) *ContentStatement
NewContentStatement instanciates a new content node.
func (*ContentStatement) Accept ¶
func (node *ContentStatement) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*ContentStatement) String ¶
func (node *ContentStatement) String() string
String returns a string representation of receiver that can be used for debugging.
type Expression ¶
type Expression struct { NodeType Loc Path Node // PathExpression | StringLiteral | BooleanLiteral | NumberLiteral Params []Node // [ Expression ... ] Hash *Hash }
Expression represents an expression node.
func NewExpression ¶
func NewExpression(pos int, line int) *Expression
NewExpression instanciates a new expression node.
func (*Expression) Accept ¶
func (node *Expression) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*Expression) Canonical ¶
func (node *Expression) Canonical() string
Canonical returns the canonical form of expression node as a string.
func (*Expression) FieldPath ¶
func (node *Expression) FieldPath() *PathExpression
FieldPath returns path expression representing a field path, or nil if this is not a field path.
func (*Expression) HelperName ¶
func (node *Expression) HelperName() string
HelperName returns helper name, or an empty string if this expression can't be a helper.
func (*Expression) LiteralStr ¶
func (node *Expression) LiteralStr() (string, bool)
LiteralStr returns the string representation of literal value, with a boolean set to false if this is not a literal.
func (*Expression) String ¶
func (node *Expression) String() string
String returns a string representation of receiver that can be used for debugging.
type Hash ¶
Hash represents a hash node.
type HashPair ¶
HashPair represents a hash pair node.
func NewHashPair ¶
NewHashPair instanciates a new hash pair node.
type MustacheStatement ¶
type MustacheStatement struct { NodeType Loc Unescaped bool Expression *Expression // whitespace management Strip *Strip }
MustacheStatement represents a mustache node.
func NewMustacheStatement ¶
func NewMustacheStatement(pos int, line int, unescaped bool) *MustacheStatement
NewMustacheStatement instanciates a new mustache node.
func (*MustacheStatement) Accept ¶
func (node *MustacheStatement) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*MustacheStatement) String ¶
func (node *MustacheStatement) String() string
String returns a string representation of receiver that can be used for debugging.
type Node ¶
type Node interface { // node type Type() NodeType // location of node in original input string Location() Loc // string representation, used for debugging String() string // accepts visitor Accept(Visitor) interface{} }
Node is an element in the AST.
type NodeType ¶
type NodeType int
NodeType represents an AST Node type.
const ( // NodeProgram is the program node NodeProgram NodeType = iota // NodeMustache is the mustache statement node NodeMustache // NodeBlock is the block statement node NodeBlock // NodePartial is the partial statement node NodePartial // NodeContent is the content statement node NodeContent // NodeComment is the comment statement node NodeComment // NodeExpression is the expression node NodeExpression // NodeSubExpression is the subexpression node NodeSubExpression // NodePath is the expression path node NodePath // NodeBoolean is the literal boolean node NodeBoolean // NodeNumber is the literal number node NodeNumber // NodeString is the literal string node NodeString // NodeHash is the hash node NodeHash // NodeHashPair is the hash pair node NodeHashPair )
type NumberLiteral ¶
NumberLiteral represents a number node.
func NewNumberLiteral ¶
NewNumberLiteral instanciates a new number node.
func (*NumberLiteral) Accept ¶
func (node *NumberLiteral) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*NumberLiteral) Canonical ¶
func (node *NumberLiteral) Canonical() string
Canonical returns the canonical form of number node as a string (eg: "12", "-1.51").
func (*NumberLiteral) Number ¶
func (node *NumberLiteral) Number() interface{}
Number returns an integer or a float.
func (*NumberLiteral) String ¶
func (node *NumberLiteral) String() string
String returns a string representation of receiver that can be used for debugging.
type PartialStatement ¶
type PartialStatement struct { NodeType Loc Name Node // PathExpression | SubExpression Params []Node // [ Expression ... ] Hash *Hash // whitespace management Strip *Strip Indent string }
PartialStatement represents a partial node.
func NewPartialStatement ¶
func NewPartialStatement(pos int, line int) *PartialStatement
NewPartialStatement instanciates a new partial node.
func (*PartialStatement) Accept ¶
func (node *PartialStatement) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*PartialStatement) String ¶
func (node *PartialStatement) String() string
String returns a string representation of receiver that can be used for debugging.
type PathExpression ¶
type PathExpression struct { NodeType Loc Original string Depth int Parts []string Data bool Scoped bool }
PathExpression represents a path expression node.
func NewPathExpression ¶
func NewPathExpression(pos int, line int, data bool) *PathExpression
NewPathExpression instanciates a new path expression node.
func (*PathExpression) Accept ¶
func (node *PathExpression) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*PathExpression) IsDataRoot ¶
func (node *PathExpression) IsDataRoot() bool
IsDataRoot returns true if path expression is @root.
func (*PathExpression) Sep ¶
func (node *PathExpression) Sep(separator string)
Sep adds path separator.
func (*PathExpression) String ¶
func (node *PathExpression) String() string
String returns a string representation of receiver that can be used for debugging.
type Program ¶
type Program struct { NodeType Loc Body []Node // [ Statement ... ] BlockParams []string Chained bool // whitespace management Strip *Strip }
Program represents a program node.
func NewProgram ¶
NewProgram instanciates a new program node.
func (*Program) AddStatement ¶
AddStatement adds given statement to program.
type StringLiteral ¶
StringLiteral represents a string node.
func NewStringLiteral ¶
func NewStringLiteral(pos int, line int, val string) *StringLiteral
NewStringLiteral instanciates a new string node.
func (*StringLiteral) Accept ¶
func (node *StringLiteral) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*StringLiteral) String ¶
func (node *StringLiteral) String() string
String returns a string representation of receiver that can be used for debugging.
type Strip ¶
type Strip struct { Open bool Close bool OpenStandalone bool CloseStandalone bool InlineStandalone bool }
Strip describes node whitespace management.
func NewStripForStr ¶
NewStripForStr instanciates a Strip for given tag.
type SubExpression ¶
type SubExpression struct { NodeType Loc Expression *Expression }
SubExpression represents a subexpression node.
func NewSubExpression ¶
func NewSubExpression(pos int, line int) *SubExpression
NewSubExpression instanciates a new subexpression node.
func (*SubExpression) Accept ¶
func (node *SubExpression) Accept(visitor Visitor) interface{}
Accept is the receiver entry point for visitors.
func (*SubExpression) String ¶
func (node *SubExpression) String() string
String returns a string representation of receiver that can be used for debugging.
type Visitor ¶
type Visitor interface { VisitProgram(*Program) interface{} // statements VisitMustache(*MustacheStatement) interface{} VisitBlock(*BlockStatement) interface{} VisitPartial(*PartialStatement) interface{} VisitContent(*ContentStatement) interface{} VisitComment(*CommentStatement) interface{} // expressions VisitExpression(*Expression) interface{} VisitSubExpression(*SubExpression) interface{} VisitPath(*PathExpression) interface{} // literals VisitString(*StringLiteral) interface{} VisitBoolean(*BooleanLiteral) interface{} VisitNumber(*NumberLiteral) interface{} // miscellaneous VisitHash(*Hash) interface{} VisitHashPair(*HashPair) interface{} }
Visitor is the interface to visit an AST.