package parser
import "github.com/a-h/templ/parser/v2"
Index ¶
- Variables
- func ExpressionOf(p parse.Parser[string]) parse.Parser[Expression]
- func StripType[T any](p parse.Parser[T]) parse.Parser[any]
- type Attribute
- type AttributeKey
- type BoolConstantAttribute
- func (bca *BoolConstantAttribute) Copy() Attribute
- func (bca *BoolConstantAttribute) String() string
- func (bca *BoolConstantAttribute) Visit(v Visitor) error
- func (bca *BoolConstantAttribute) Write(w io.Writer, indent int) error
- type BoolExpressionAttribute
- func (bea *BoolExpressionAttribute) Copy() Attribute
- func (bea *BoolExpressionAttribute) String() string
- func (bea *BoolExpressionAttribute) Visit(v Visitor) error
- func (bea *BoolExpressionAttribute) Write(w io.Writer, indent int) error
- type CSSProperty
- type CSSTemplate
- func (css *CSSTemplate) IsTemplateFileNode() bool
- func (css *CSSTemplate) Visit(v Visitor) error
- func (css *CSSTemplate) Write(w io.Writer, indent int) error
- type CallTemplateExpression
- func (cte *CallTemplateExpression) IsNode() bool
- func (cte *CallTemplateExpression) Visit(v Visitor) error
- func (cte *CallTemplateExpression) Write(w io.Writer, indent int) error
- type CaseExpression
- type ChildrenExpression
- func (*ChildrenExpression) IsNode() bool
- func (ce *ChildrenExpression) Visit(v Visitor) error
- func (*ChildrenExpression) Write(w io.Writer, indent int) error
- type CompositeNode
- type ConditionalAttribute
- func (ca *ConditionalAttribute) Copy() Attribute
- func (ca *ConditionalAttribute) String() string
- func (ca *ConditionalAttribute) Visit(v Visitor) error
- func (ca *ConditionalAttribute) Write(w io.Writer, indent int) error
- type ConstantAttribute
- func (ca *ConstantAttribute) Copy() Attribute
- func (ca *ConstantAttribute) String() string
- func (ca *ConstantAttribute) Visit(v Visitor) error
- func (ca *ConstantAttribute) Write(w io.Writer, indent int) error
- type ConstantAttributeKey
- type ConstantCSSProperty
- func (c *ConstantCSSProperty) IsCSSProperty() bool
- func (c ConstantCSSProperty) String(minified bool) string
- func (c *ConstantCSSProperty) Visit(v Visitor) error
- func (c *ConstantCSSProperty) Write(w io.Writer, indent int) error
- type Diagnostic
- type DocType
- func (dt *DocType) IsNode() bool
- func (dt *DocType) Visit(v Visitor) error
- func (dt *DocType) Write(w io.Writer, indent int) error
- type Element
- func (e Element) ChildNodes() []Node
- func (e Element) IsBlockElement() bool
- func (e *Element) IsNode() bool
- func (e Element) IsVoidElement() bool
- func (e Element) Trailing() TrailingSpace
- func (e Element) Validate() (msgs []string, ok bool)
- func (e *Element) Visit(v Visitor) error
- func (e *Element) Write(w io.Writer, indent int) error
- type ElseIfExpression
- type Expression
- type ExpressionAttribute
- func (ea *ExpressionAttribute) Copy() Attribute
- func (ea *ExpressionAttribute) String() string
- func (ea *ExpressionAttribute) Visit(v Visitor) error
- func (ea *ExpressionAttribute) Write(w io.Writer, indent int) (err error)
- type ExpressionAttributeKey
- type ExpressionCSSProperty
- func (c *ExpressionCSSProperty) IsCSSProperty() bool
- func (c *ExpressionCSSProperty) Visit(v Visitor) error
- func (c *ExpressionCSSProperty) Write(w io.Writer, indent int) error
- type ForExpression
- func (fe ForExpression) ChildNodes() []Node
- func (fe *ForExpression) IsNode() bool
- func (fe *ForExpression) Visit(v Visitor) error
- func (fe *ForExpression) Write(w io.Writer, indent int) error
- type GoCode
- func (gc *GoCode) IsNode() bool
- func (gc *GoCode) Trailing() TrailingSpace
- func (gc *GoCode) Visit(v Visitor) error
- func (gc *GoCode) Write(w io.Writer, indent int) error
- type GoComment
- func (c *GoComment) IsNode() bool
- func (c *GoComment) Visit(v Visitor) error
- func (c *GoComment) Write(w io.Writer, indent int) error
- type HTMLComment
- func (c *HTMLComment) IsNode() bool
- func (c *HTMLComment) Visit(v Visitor) error
- func (c *HTMLComment) Write(w io.Writer, indent int) error
- type HTMLTemplate
- func (t *HTMLTemplate) IsTemplateFileNode() bool
- func (t *HTMLTemplate) Visit(v Visitor) error
- func (t *HTMLTemplate) Write(w io.Writer, indent int) error
- type IfExpression
- func (n IfExpression) ChildNodes() []Node
- func (n *IfExpression) IsNode() bool
- func (n *IfExpression) Visit(v Visitor) error
- func (n *IfExpression) Write(w io.Writer, indent int) error
- type Node
- type Nodes
- type Package
- type Position
- type Range
- type RawElement
- func (e *RawElement) IsNode() bool
- func (e *RawElement) Visit(v Visitor) error
- func (e *RawElement) Write(w io.Writer, indent int) error
- type ScriptContents
- func NewScriptContentsGo(code *GoCode, insideStringLiteral bool) ScriptContents
- func NewScriptContentsScriptCode(value string) ScriptContents
- type ScriptElement
- func (se *ScriptElement) IsNode() bool
- func (se *ScriptElement) Visit(v Visitor) error
- func (se *ScriptElement) Write(w io.Writer, indent int) error
- type ScriptTemplate
- func (s *ScriptTemplate) IsTemplateFileNode() bool
- func (s *ScriptTemplate) Visit(v Visitor) error
- func (s *ScriptTemplate) Write(w io.Writer, indent int) error
- type SourceMap
- func NewSourceMap() *SourceMap
- func (sm *SourceMap) Add(src Expression, tgt Range) (updatedFrom Position)
- func (sm *SourceMap) AddSymbolRange(src Range, tgt Range)
- func (sm *SourceMap) SourcePositionFromTarget(line, col uint32) (src Position, ok bool)
- func (sm *SourceMap) SymbolSourceRangeFromTarget(line, col uint32) (src Range, ok bool)
- func (sm *SourceMap) SymbolTargetRangeFromSource(line, col uint32) (tgt Range, ok bool)
- func (sm *SourceMap) TargetPositionFromSource(line, col uint32) (tgt Position, ok bool)
- type SpreadAttributes
- func (sa *SpreadAttributes) Copy() Attribute
- func (sa *SpreadAttributes) String() string
- func (sa *SpreadAttributes) Visit(v Visitor) error
- func (sa *SpreadAttributes) Write(w io.Writer, indent int) error
- type StringExpression
- func (se *StringExpression) IsNode() bool
- func (se *StringExpression) IsStyleDeclarationValue() bool
- func (se *StringExpression) Trailing() TrailingSpace
- func (se *StringExpression) Visit(v Visitor) error
- func (se *StringExpression) Write(w io.Writer, indent int) error
- type SwitchExpression
- func (se SwitchExpression) ChildNodes() []Node
- func (se *SwitchExpression) IsNode() bool
- func (se *SwitchExpression) Visit(v Visitor) error
- func (se *SwitchExpression) Write(w io.Writer, indent int) error
- type TemplElementExpression
- func (tee TemplElementExpression) ChildNodes() []Node
- func (tee *TemplElementExpression) IsNode() bool
- func (tee *TemplElementExpression) Visit(v Visitor) error
- func (tee *TemplElementExpression) Write(w io.Writer, indent int) error
- type TemplateFile
- func Parse(fileName string) (*TemplateFile, error)
- func ParseString(template string) (*TemplateFile, error)
- func (tf *TemplateFile) Visit(v Visitor) error
- func (tf *TemplateFile) Write(w io.Writer) error
- type TemplateFileGoExpression
- func (exp *TemplateFileGoExpression) IsTemplateFileNode() bool
- func (exp *TemplateFileGoExpression) Visit(v Visitor) error
- func (exp *TemplateFileGoExpression) Write(w io.Writer, indent int) error
- type TemplateFileNode
- type TemplateFileParser
- func NewTemplateFileParser(pkg string) TemplateFileParser
- func (p TemplateFileParser) Parse(pi *parse.Input) (tf *TemplateFile, matched bool, err error)
- type Text
- func (t *Text) IsNode() bool
- func (t Text) Trailing() TrailingSpace
- func (t *Text) Visit(v Visitor) error
- func (t *Text) Write(w io.Writer, indent int) error
- type TrailingSpace
- type UntilNotFoundError
- type Visitor
- type Whitespace
- func (ws *Whitespace) IsNode() bool
- func (ws *Whitespace) Visit(v Visitor) error
- func (ws *Whitespace) Write(w io.Writer, indent int) error
- type WhitespaceTrailer
Variables ¶
Functions ¶
func ExpressionOf ¶
func StripType ¶
StripType takes the parser and throws away the return value.
Types ¶
type Attribute ¶
type Attribute interface { // Write out the string*. Write(w io.Writer, indent int) error Visit(v Visitor) error Copy() Attribute }
func CopyAttributes ¶
type AttributeKey ¶
type BoolConstantAttribute ¶
type BoolConstantAttribute struct { Key AttributeKey }
<hr noshade/>
func (*BoolConstantAttribute) Copy ¶
func (bca *BoolConstantAttribute) Copy() Attribute
func (*BoolConstantAttribute) String ¶
func (bca *BoolConstantAttribute) String() string
func (*BoolConstantAttribute) Visit ¶
func (bca *BoolConstantAttribute) Visit(v Visitor) error
func (*BoolConstantAttribute) Write ¶
func (bca *BoolConstantAttribute) Write(w io.Writer, indent int) error
type BoolExpressionAttribute ¶
type BoolExpressionAttribute struct { Key AttributeKey Expression Expression }
noshade={ templ.Bool(...) }
func (*BoolExpressionAttribute) Copy ¶
func (bea *BoolExpressionAttribute) Copy() Attribute
func (*BoolExpressionAttribute) String ¶
func (bea *BoolExpressionAttribute) String() string
func (*BoolExpressionAttribute) Visit ¶
func (bea *BoolExpressionAttribute) Visit(v Visitor) error
func (*BoolExpressionAttribute) Write ¶
func (bea *BoolExpressionAttribute) Write(w io.Writer, indent int) error
type CSSProperty ¶
type CSSProperty interface { IsCSSProperty() bool Write(w io.Writer, indent int) error Visit(v Visitor) error }
CSSProperty is a CSS property and value pair.
type CSSTemplate ¶
type CSSTemplate struct { Range Range Name string Expression Expression Properties []CSSProperty }
CSS definition.
css Name() { color: #ffffff; background-color: { constants.BackgroundColor }; background-image: url('./somewhere.png'); }
func (*CSSTemplate) IsTemplateFileNode ¶
func (css *CSSTemplate) IsTemplateFileNode() bool
func (*CSSTemplate) Visit ¶
func (css *CSSTemplate) Visit(v Visitor) error
func (*CSSTemplate) Write ¶
func (css *CSSTemplate) Write(w io.Writer, indent int) error
type CallTemplateExpression ¶
type CallTemplateExpression struct { // Expression returns a template to execute. Expression Expression }
CallTemplateExpression can be used to create and render a template using data. {! Other(p.First, p.Last) } or it can be used to render a template parameter. {! v }
func (*CallTemplateExpression) IsNode ¶
func (cte *CallTemplateExpression) IsNode() bool
func (*CallTemplateExpression) Visit ¶
func (cte *CallTemplateExpression) Visit(v Visitor) error
func (*CallTemplateExpression) Write ¶
func (cte *CallTemplateExpression) Write(w io.Writer, indent int) error
type CaseExpression ¶
type CaseExpression struct { Expression Expression Children []Node }
case "Something":
type ChildrenExpression ¶
type ChildrenExpression struct{}
ChildrenExpression can be used to rended the children of a templ element. { children ... }
func (*ChildrenExpression) IsNode ¶
func (*ChildrenExpression) IsNode() bool
func (*ChildrenExpression) Visit ¶
func (ce *ChildrenExpression) Visit(v Visitor) error
func (*ChildrenExpression) Write ¶
func (*ChildrenExpression) Write(w io.Writer, indent int) error
type CompositeNode ¶
type ConditionalAttribute ¶
type ConditionalAttribute struct { Expression Expression Then []Attribute Else []Attribute }
<a href="test" \ if active { class="isActive" }
func (*ConditionalAttribute) Copy ¶
func (ca *ConditionalAttribute) Copy() Attribute
func (*ConditionalAttribute) String ¶
func (ca *ConditionalAttribute) String() string
func (*ConditionalAttribute) Visit ¶
func (ca *ConditionalAttribute) Visit(v Visitor) error
func (*ConditionalAttribute) Write ¶
func (ca *ConditionalAttribute) Write(w io.Writer, indent int) error
type ConstantAttribute ¶
type ConstantAttribute struct { Key AttributeKey Value string SingleQuote bool }
href=""
func (*ConstantAttribute) Copy ¶
func (ca *ConstantAttribute) Copy() Attribute
func (*ConstantAttribute) String ¶
func (ca *ConstantAttribute) String() string
func (*ConstantAttribute) Visit ¶
func (ca *ConstantAttribute) Visit(v Visitor) error
func (*ConstantAttribute) Write ¶
func (ca *ConstantAttribute) Write(w io.Writer, indent int) error
type ConstantAttributeKey ¶
func (ConstantAttributeKey) String ¶
func (c ConstantAttributeKey) String() string
type ConstantCSSProperty ¶
color: #ffffff;
func (*ConstantCSSProperty) IsCSSProperty ¶
func (c *ConstantCSSProperty) IsCSSProperty() bool
func (ConstantCSSProperty) String ¶
func (c ConstantCSSProperty) String(minified bool) string
func (*ConstantCSSProperty) Visit ¶
func (c *ConstantCSSProperty) Visit(v Visitor) error
func (*ConstantCSSProperty) Write ¶
func (c *ConstantCSSProperty) Write(w io.Writer, indent int) error
type Diagnostic ¶
Diagnostic for template file.
func Diagnose ¶
func Diagnose(t *TemplateFile) ([]Diagnostic, error)
type DocType ¶
type DocType struct { Value string }
<!DOCTYPE html>
func (*DocType) IsNode ¶
func (*DocType) Visit ¶
func (*DocType) Write ¶
type Element ¶
type Element struct { Name string Attributes []Attribute IndentAttrs bool Children []Node IndentChildren bool TrailingSpace TrailingSpace NameRange Range }
<a .../> or <div ...>...</div>
func (Element) ChildNodes ¶
func (Element) IsBlockElement ¶
func (*Element) IsNode ¶
func (Element) IsVoidElement ¶
https://www.w3.org/TR/2011/WD-html-markup-20110113/syntax.html#void-element
func (Element) Trailing ¶
func (e Element) Trailing() TrailingSpace
func (Element) Validate ¶
Validate that no invalid expressions have been used.
func (*Element) Visit ¶
func (*Element) Write ¶
type ElseIfExpression ¶
type ElseIfExpression struct { Expression Expression Then []Node }
type Expression ¶
Expression containing Go code.
func NewExpression ¶
func NewExpression(value string, from, to parse.Position) Expression
NewExpression creates a Go expression.
type ExpressionAttribute ¶
type ExpressionAttribute struct { Key AttributeKey Expression Expression }
href={ ... }
func (*ExpressionAttribute) Copy ¶
func (ea *ExpressionAttribute) Copy() Attribute
func (*ExpressionAttribute) String ¶
func (ea *ExpressionAttribute) String() string
func (*ExpressionAttribute) Visit ¶
func (ea *ExpressionAttribute) Visit(v Visitor) error
func (*ExpressionAttribute) Write ¶
func (ea *ExpressionAttribute) Write(w io.Writer, indent int) (err error)
type ExpressionAttributeKey ¶
type ExpressionAttributeKey struct { Expression Expression }
func (ExpressionAttributeKey) String ¶
func (e ExpressionAttributeKey) String() string
type ExpressionCSSProperty ¶
type ExpressionCSSProperty struct { Name string Value *StringExpression }
background-color: { constants.BackgroundColor };
func (*ExpressionCSSProperty) IsCSSProperty ¶
func (c *ExpressionCSSProperty) IsCSSProperty() bool
func (*ExpressionCSSProperty) Visit ¶
func (c *ExpressionCSSProperty) Visit(v Visitor) error
func (*ExpressionCSSProperty) Write ¶
func (c *ExpressionCSSProperty) Write(w io.Writer, indent int) error
type ForExpression ¶
type ForExpression struct { Expression Expression Children []Node }
for i, v := range p.Addresses { {! Address(v) } }
func (ForExpression) ChildNodes ¶
func (fe ForExpression) ChildNodes() []Node
func (*ForExpression) IsNode ¶
func (fe *ForExpression) IsNode() bool
func (*ForExpression) Visit ¶
func (fe *ForExpression) Visit(v Visitor) error
func (*ForExpression) Write ¶
func (fe *ForExpression) Write(w io.Writer, indent int) error
type GoCode ¶
type GoCode struct { Expression Expression // TrailingSpace lists what happens after the expression. TrailingSpace TrailingSpace Multiline bool }
GoCode is used within HTML elements, and allows arbitrary go code. {{ ... }}
func (*GoCode) IsNode ¶
func (*GoCode) Trailing ¶
func (gc *GoCode) Trailing() TrailingSpace
func (*GoCode) Visit ¶
func (*GoCode) Write ¶
type GoComment ¶
GoComment.
func (*GoComment) IsNode ¶
func (*GoComment) Visit ¶
func (*GoComment) Write ¶
type HTMLComment ¶
type HTMLComment struct { Contents string }
HTMLComment.
func (*HTMLComment) IsNode ¶
func (c *HTMLComment) IsNode() bool
func (*HTMLComment) Visit ¶
func (c *HTMLComment) Visit(v Visitor) error
func (*HTMLComment) Write ¶
func (c *HTMLComment) Write(w io.Writer, indent int) error
type HTMLTemplate ¶
type HTMLTemplate struct { Range Range Expression Expression Children []Node }
HTMLTemplate definition.
templ Name(p Parameter) { if ... { <Element></Element> } }
func (*HTMLTemplate) IsTemplateFileNode ¶
func (t *HTMLTemplate) IsTemplateFileNode() bool
func (*HTMLTemplate) Visit ¶
func (t *HTMLTemplate) Visit(v Visitor) error
func (*HTMLTemplate) Write ¶
func (t *HTMLTemplate) Write(w io.Writer, indent int) error
type IfExpression ¶
type IfExpression struct { Expression Expression Then []Node ElseIfs []ElseIfExpression Else []Node }
if p.Type == "test" && p.thing { }
func (IfExpression) ChildNodes ¶
func (n IfExpression) ChildNodes() []Node
func (*IfExpression) IsNode ¶
func (n *IfExpression) IsNode() bool
func (*IfExpression) Visit ¶
func (n *IfExpression) Visit(v Visitor) error
func (*IfExpression) Write ¶
func (n *IfExpression) Write(w io.Writer, indent int) error
type Node ¶
type Node interface { IsNode() bool // Write out the string*. Write(w io.Writer, indent int) error Visit(v Visitor) error }
A Node appears within a template, e.g. an StringExpression, Element, IfExpression etc.
type Nodes ¶
type Nodes struct { Nodes []Node }
type Package ¶
type Package struct { Expression Expression }
func (*Package) Visit ¶
func (*Package) Write ¶
type Position ¶
Source mapping to map from the source code of the template to the in-memory representation.
func NewPosition ¶
NewPosition initialises a position.
func (*Position) String ¶
type Range ¶
Range of text within a file.
func NewRange ¶
NewRange creates a Range expression.
type RawElement ¶
func (*RawElement) IsNode ¶
func (e *RawElement) IsNode() bool
func (*RawElement) Visit ¶
func (e *RawElement) Visit(v Visitor) error
func (*RawElement) Write ¶
func (e *RawElement) Write(w io.Writer, indent int) error
type ScriptContents ¶
type ScriptContents struct { // Value is the raw script contents. This is nil if the Type is Go. Value *string // GoCode is the Go expression. This is nil if the Type is JS. GoCode *GoCode // InsideStringLiteral denotes how the result of any Go expression should be escaped in the output. // - Not quoted: JSON encoded. // - InsideStringLiteral: JS escaped (newlines become \n, `"' becomes \`\"\' etc.), HTML escaped so that a string can't contain </script>. InsideStringLiteral bool }
func NewScriptContentsGo ¶
func NewScriptContentsGo(code *GoCode, insideStringLiteral bool) ScriptContents
func NewScriptContentsScriptCode ¶
func NewScriptContentsScriptCode(value string) ScriptContents
type ScriptElement ¶
type ScriptElement struct { Attributes []Attribute Contents []ScriptContents }
func (*ScriptElement) IsNode ¶
func (se *ScriptElement) IsNode() bool
func (*ScriptElement) Visit ¶
func (se *ScriptElement) Visit(v Visitor) error
func (*ScriptElement) Write ¶
func (se *ScriptElement) Write(w io.Writer, indent int) error
type ScriptTemplate ¶
type ScriptTemplate struct { Range Range Name Expression Parameters Expression Value string }
ScriptTemplate is a script block.
func (*ScriptTemplate) IsTemplateFileNode ¶
func (s *ScriptTemplate) IsTemplateFileNode() bool
func (*ScriptTemplate) Visit ¶
func (s *ScriptTemplate) Visit(v Visitor) error
func (*ScriptTemplate) Write ¶
func (s *ScriptTemplate) Write(w io.Writer, indent int) error
type SourceMap ¶
type SourceMap struct { Expressions []string SourceLinesToTarget map[uint32]map[uint32]Position TargetLinesToSource map[uint32]map[uint32]Position SourceSymbolRangeToTarget map[uint32]map[uint32]Range TargetSymbolRangeToSource map[uint32]map[uint32]Range }
func NewSourceMap ¶
func NewSourceMap() *SourceMap
NewSourceMap creates a new lookup to map templ source code to items in the parsed template.
func (*SourceMap) Add ¶
func (sm *SourceMap) Add(src Expression, tgt Range) (updatedFrom Position)
Add an item to the lookup.
func (*SourceMap) AddSymbolRange ¶
func (*SourceMap) SourcePositionFromTarget ¶
SourcePositionFromTarget looks the source position using the target position. If a source exists on the line but not the col, the function will search backwards.
func (*SourceMap) SymbolSourceRangeFromTarget ¶
func (*SourceMap) SymbolTargetRangeFromSource ¶
func (*SourceMap) TargetPositionFromSource ¶
TargetPositionFromSource looks up the target position using the source position.
type SpreadAttributes ¶
type SpreadAttributes struct { Expression Expression }
<a { spread... } />
func (*SpreadAttributes) Copy ¶
func (sa *SpreadAttributes) Copy() Attribute
func (*SpreadAttributes) String ¶
func (sa *SpreadAttributes) String() string
func (*SpreadAttributes) Visit ¶
func (sa *SpreadAttributes) Visit(v Visitor) error
func (*SpreadAttributes) Write ¶
func (sa *SpreadAttributes) Write(w io.Writer, indent int) error
type StringExpression ¶
type StringExpression struct { Expression Expression // TrailingSpace lists what happens after the expression. TrailingSpace TrailingSpace }
StringExpression is used within HTML elements, and for style values. { ... }
func (*StringExpression) IsNode ¶
func (se *StringExpression) IsNode() bool
func (*StringExpression) IsStyleDeclarationValue ¶
func (se *StringExpression) IsStyleDeclarationValue() bool
func (*StringExpression) Trailing ¶
func (se *StringExpression) Trailing() TrailingSpace
func (*StringExpression) Visit ¶
func (se *StringExpression) Visit(v Visitor) error
func (*StringExpression) Write ¶
func (se *StringExpression) Write(w io.Writer, indent int) error
type SwitchExpression ¶
type SwitchExpression struct { Expression Expression Cases []CaseExpression }
switch p.Type { case "Something": }
func (SwitchExpression) ChildNodes ¶
func (se SwitchExpression) ChildNodes() []Node
func (*SwitchExpression) IsNode ¶
func (se *SwitchExpression) IsNode() bool
func (*SwitchExpression) Visit ¶
func (se *SwitchExpression) Visit(v Visitor) error
func (*SwitchExpression) Write ¶
func (se *SwitchExpression) Write(w io.Writer, indent int) error
type TemplElementExpression ¶
type TemplElementExpression struct { // Expression returns a template to execute. Expression Expression // Children returns the elements in a block element. Children []Node }
TemplElementExpression can be used to create and render a template using data. @Other(p.First, p.Last) or it can be used to render a template parameter. @v
func (TemplElementExpression) ChildNodes ¶
func (tee TemplElementExpression) ChildNodes() []Node
func (*TemplElementExpression) IsNode ¶
func (tee *TemplElementExpression) IsNode() bool
func (*TemplElementExpression) Visit ¶
func (tee *TemplElementExpression) Visit(v Visitor) error
func (*TemplElementExpression) Write ¶
func (tee *TemplElementExpression) Write(w io.Writer, indent int) error
type TemplateFile ¶
type TemplateFile struct { // Header contains comments or whitespace at the top of the file. Header []*TemplateFileGoExpression // Package expression. Package Package // Filepath is where the file was loaded from. It is not always available. Filepath string // Nodes in the file. Nodes []TemplateFileNode }
func Parse ¶
func Parse(fileName string) (*TemplateFile, error)
func ParseString ¶
func ParseString(template string) (*TemplateFile, error)
func (*TemplateFile) Visit ¶
func (tf *TemplateFile) Visit(v Visitor) error
func (*TemplateFile) Write ¶
func (tf *TemplateFile) Write(w io.Writer) error
type TemplateFileGoExpression ¶
type TemplateFileGoExpression struct { Expression Expression BeforePackage bool }
TemplateFileGoExpression within a TemplateFile
func (*TemplateFileGoExpression) IsTemplateFileNode ¶
func (exp *TemplateFileGoExpression) IsTemplateFileNode() bool
func (*TemplateFileGoExpression) Visit ¶
func (exp *TemplateFileGoExpression) Visit(v Visitor) error
func (*TemplateFileGoExpression) Write ¶
func (exp *TemplateFileGoExpression) Write(w io.Writer, indent int) error
type TemplateFileNode ¶
type TemplateFileNode interface { IsTemplateFileNode() bool Write(w io.Writer, indent int) error Visit(v Visitor) error }
TemplateFileNode can be a Template, CSS, Script or Go.
type TemplateFileParser ¶
type TemplateFileParser struct { DefaultPackage string }
func NewTemplateFileParser ¶
func NewTemplateFileParser(pkg string) TemplateFileParser
NewTemplateFileParser creates a new TemplateFileParser.
func (TemplateFileParser) Parse ¶
func (p TemplateFileParser) Parse(pi *parse.Input) (tf *TemplateFile, matched bool, err error)
type Text ¶
type Text struct { // Range of the text within the templ file. Range Range // Value is the raw HTML encoded value. Value string // TrailingSpace lists what happens after the text. TrailingSpace TrailingSpace }
Text node within the document.
func (*Text) IsNode ¶
func (Text) Trailing ¶
func (t Text) Trailing() TrailingSpace
func (*Text) Visit ¶
func (*Text) Write ¶
type TrailingSpace ¶
type TrailingSpace string
TrailingSpace defines the whitespace that may trail behind the close of an element, a text node, or string expression.
const ( SpaceNone TrailingSpace = "" SpaceHorizontal TrailingSpace = " " SpaceVertical TrailingSpace = "\n" )
func NewTrailingSpace ¶
func NewTrailingSpace(s string) (ts TrailingSpace, err error)
type UntilNotFoundError ¶
type UntilNotFoundError struct { parse.ParseError }
type Visitor ¶
type Visitor interface { VisitTemplateFile(*TemplateFile) error VisitTemplateFileGoExpression(*TemplateFileGoExpression) error VisitPackage(*Package) error VisitWhitespace(*Whitespace) error VisitCSSTemplate(*CSSTemplate) error VisitConstantCSSProperty(*ConstantCSSProperty) error VisitExpressionCSSProperty(*ExpressionCSSProperty) error VisitDocType(*DocType) error VisitHTMLTemplate(*HTMLTemplate) error VisitText(*Text) error VisitElement(*Element) error VisitScriptElement(*ScriptElement) error VisitRawElement(*RawElement) error VisitBoolConstantAttribute(*BoolConstantAttribute) error VisitConstantAttribute(*ConstantAttribute) error VisitBoolExpressionAttribute(*BoolExpressionAttribute) error VisitExpressionAttribute(*ExpressionAttribute) error VisitSpreadAttributes(*SpreadAttributes) error VisitConditionalAttribute(*ConditionalAttribute) error VisitGoComment(*GoComment) error VisitHTMLComment(*HTMLComment) error VisitCallTemplateExpression(*CallTemplateExpression) error VisitTemplElementExpression(*TemplElementExpression) error VisitChildrenExpression(*ChildrenExpression) error VisitIfExpression(*IfExpression) error VisitSwitchExpression(*SwitchExpression) error VisitForExpression(*ForExpression) error VisitGoCode(*GoCode) error VisitStringExpression(*StringExpression) error VisitScriptTemplate(*ScriptTemplate) error }
Visitor is an interface for visiting nodes in the parse tree.
type Whitespace ¶
type Whitespace struct { Value string }
Whitespace.
func (*Whitespace) IsNode ¶
func (ws *Whitespace) IsNode() bool
func (*Whitespace) Visit ¶
func (ws *Whitespace) Visit(v Visitor) error
func (*Whitespace) Write ¶
func (ws *Whitespace) Write(w io.Writer, indent int) error
type WhitespaceTrailer ¶
type WhitespaceTrailer interface { Trailing() TrailingSpace }
Source Files ¶
calltemplateparser.go childrenparser.go conditionalattributeparser.go cssparser.go diagnostics.go doctypeparser.go elementparser.go expressionparser.go forexpressionparser.go gocodeparser.go gocommentparser.go goparser.go htmlcommentparser.go ifexpressionparser.go packageparser.go parser.go raw.go scriptparser.go scripttemplateparser.go sourcemap.go stringexpressionparser.go structure.go switchexpressionparser.go templatefile.go templateparser.go templelementparser.go textparser.go types.go visitor.go whitespaceparser.go
Directories ¶
Path | Synopsis |
---|---|
parser/v2/goexpression | |
parser/v2/visitor |
- Version
- v0.3.924 (latest)
- Published
- Jul 26, 2025
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 5 days ago –
Tools for package owners.