parser

package
v0.2.546 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute interface {
	IsAttribute() bool
	String() string
}

type BoolConstantAttribute

type BoolConstantAttribute struct {
	Name string
}

<hr noshade/>

func (BoolConstantAttribute) IsAttribute

func (bca BoolConstantAttribute) IsAttribute() bool

func (BoolConstantAttribute) String

func (bca BoolConstantAttribute) String() string

type BoolExpressionAttribute

type BoolExpressionAttribute struct {
	Name       string
	Expression Expression
}

href={%= templ.Bool(...) }

func (BoolExpressionAttribute) IsAttribute

func (ea BoolExpressionAttribute) IsAttribute() bool

func (BoolExpressionAttribute) String

func (ea BoolExpressionAttribute) String() string

type CSSProperty

type CSSProperty interface {
	IsCSSProperty() bool
	Write(w io.Writer, indent int) error
}

CSSProperty is a CSS property and value pair.

type CSSTemplate

type CSSTemplate struct {
	Name       Expression
	Properties []CSSProperty
}

CSS definition. {% css Name() %}

color: #ffffff;
background-color: {%= constants.BackgroundColor %};
background-image: url('./somewhere.png');

{% endcss %}

func (CSSTemplate) IsTemplateFileNode

func (css CSSTemplate) IsTemplateFileNode() bool

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) Write

func (cte CallTemplateExpression) Write(w io.Writer, indent int) error

type CaseExpression

type CaseExpression struct {
	Expression Expression
	Children   []Node
}

{% case "Something" %} ... {% endcase %}

type ConstantAttribute

type ConstantAttribute struct {
	Name  string
	Value string
}

href=""

func (ConstantAttribute) IsAttribute

func (ca ConstantAttribute) IsAttribute() bool

func (ConstantAttribute) String

func (ca ConstantAttribute) String() string

type ConstantCSSProperty

type ConstantCSSProperty struct {
	Name  string
	Value string
}

color: #ffffff;

func (ConstantCSSProperty) IsCSSProperty

func (c ConstantCSSProperty) IsCSSProperty() bool

func (ConstantCSSProperty) Write

func (c ConstantCSSProperty) Write(w io.Writer, indent int) error

type DocType

type DocType struct {
	Value string
}

<!DOCTYPE html>

func (DocType) IsNode

func (dt DocType) IsNode() bool

func (DocType) Write

func (dt DocType) Write(w io.Writer, indent int) error

type Element

type Element struct {
	Name       string
	Attributes []Attribute
	Children   []Node
}

<a .../> or <div ...>...</div>

func (Element) IsNode

func (e Element) IsNode() bool

func (Element) Validate

func (e Element) Validate() (msgs []string, ok bool)

Validate that no invalid expressions have been used.

func (Element) Write

func (e Element) Write(w io.Writer, indent int) error

type Expression

type Expression struct {
	Value string
	Range Range
}

Expression containing Go code.

func NewExpression

func NewExpression(value string, from, to Position) Expression

NewExpression creates a Go expression.

type ExpressionAttribute

type ExpressionAttribute struct {
	Name       string
	Expression Expression
}

href={%= ... }

func (ExpressionAttribute) IsAttribute

func (ea ExpressionAttribute) IsAttribute() bool

func (ExpressionAttribute) String

func (ea ExpressionAttribute) 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) 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 %}

{% call Address(v) %}

{% endfor %}

func (ForExpression) IsNode

func (fe ForExpression) IsNode() bool

func (ForExpression) Write

func (fe ForExpression) Write(w io.Writer, indent int) error

type HTMLTemplate

type HTMLTemplate struct {
	Name       Expression
	Parameters Expression
	Children   []Node
}

HTMLTemplate definition. {% templ Name(p Parameter) %}

{% if ... %}
<Element></Element>

{% endtempl %}

func (HTMLTemplate) IsTemplateFileNode

func (t HTMLTemplate) IsTemplateFileNode() bool

func (HTMLTemplate) Write

func (t HTMLTemplate) Write(w io.Writer, indent int) error

type IfExpression

type IfExpression struct {
	Expression Expression
	Then       []Node
	Else       []Node
}

{% if p.Type == "test" && p.thing %} {% endif %}

func (IfExpression) IsNode

func (n IfExpression) IsNode() bool

func (IfExpression) Write

func (n IfExpression) Write(w io.Writer, indent int) error

type Import

type Import struct {
	Expression Expression
}

{% import "strings" %} {% import strs "strings" %}

func (Import) Write

func (imp Import) 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
}

A Node appears within a template, e.g. an StringExpression, Element, IfExpression etc.

type Package

type Package struct {
	Expression Expression
}

{% package parser %}

func (Package) Write

func (p Package) Write(w io.Writer, indent int) error

type ParseError

type ParseError struct {
	Message string
	From    Position
	To      Position
}

ParseError details where the error occurred in the file.

func (ParseError) Error

func (pe ParseError) Error() string

type Position

type Position struct {
	Index int64
	Line  int
	Col   int
}

Source mapping to map from the source code of the template to the in-memory representation.

func NewPosition

func NewPosition() Position

NewPosition initialises a position.

func NewPositionFromInput

func NewPositionFromInput(pi parse.Input) Position

NewPositionFromInput creates a position from a parse input.

func NewPositionFromValues

func NewPositionFromValues(index int64, line, col int) Position

NewPositionFromValues initialises a position.

func (Position) String

func (p Position) String() string

type Range

type Range struct {
	From Position
	To   Position
}

Range of text within a file.

func NewRange

func NewRange(from, to Position) Range

NewRange creates a range.

type ScriptTemplate

type ScriptTemplate struct {
	Name       Expression
	Parameters Expression
	Value      string
}

ScriptTemplate is a script block.

func (ScriptTemplate) IsTemplateFileNode

func (s ScriptTemplate) IsTemplateFileNode() bool

func (ScriptTemplate) Write

func (s ScriptTemplate) Write(w io.Writer, indent int) error

type SourceExpressionTo

type SourceExpressionTo struct {
	Source Expression
	Target Range
}

SourceExpressionTo is a record of an expression, along with its start and end positions.

type SourceMap

type SourceMap struct {
	Items []SourceExpressionTo
}

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) SourcePositionFromTarget

func (sm *SourceMap) SourcePositionFromTarget(line, col int) (src Position, mapping SourceExpressionTo, ok bool)

SourcePositionFromTarget looks the source position using the target position.

func (*SourceMap) TargetPositionFromSource

func (sm *SourceMap) TargetPositionFromSource(line, col int) (tgt Position, mapping SourceExpressionTo, ok bool)

TargetPositionFromSource looks up the target position using the source position.

type StringExpression

type StringExpression struct {
	Expression Expression
}

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) Write

func (se StringExpression) Write(w io.Writer, indent int) error

type SwitchExpression

type SwitchExpression struct {
	Expression Expression
	Cases      []CaseExpression
	Default    []Node
}

{% switch p.Type %}

{% case "Something" %}
{% endcase %}

{% endswitch %}

func (SwitchExpression) IsNode

func (se SwitchExpression) IsNode() bool

func (SwitchExpression) Write

func (se SwitchExpression) Write(w io.Writer, indent int) error

type TemplateFile

type TemplateFile struct {
	Package Package
	Imports []Import
	Nodes   []TemplateFileNode
}

func Parse

func Parse(fileName string) (TemplateFile, error)

func ParseString

func ParseString(template string) (TemplateFile, error)

func (TemplateFile) Write

func (tf TemplateFile) Write(w io.Writer) error

type TemplateFileNode

type TemplateFileNode interface {
	IsTemplateFileNode() bool
	Write(w io.Writer, indent int) error
}

TemplateFileNode can be a Template or a CSS.

type TemplateFileParser

type TemplateFileParser struct {
	DefaultPackage string
}

func NewTemplateFileParser

func NewTemplateFileParser(pkg string) TemplateFileParser

NewTemplateFileParser creates a new TemplateFileParser.

func (TemplateFileParser) Parse

type Text

type Text struct {
	// Value is the raw HTML encoded value.
	Value string
}

Text node within the document.

func (Text) IsNode

func (t Text) IsNode() bool

func (Text) Write

func (t Text) Write(w io.Writer, indent int) error

type Whitespace

type Whitespace struct {
	Value string
}

Whitespace.

func (Whitespace) IsNode

func (ws Whitespace) IsNode() bool

func (Whitespace) Write

func (ws Whitespace) Write(w io.Writer, indent int) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL