template

package
v0.0.0-...-dd1d5c9 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SectionMarkerToken = SymbolId(256)
	PackageToken       = SymbolId(257)
	ImportToken        = SymbolId(258)
	TemplateDeclToken  = SymbolId(259)
	ForToken           = SymbolId(260)
	SwitchToken        = SymbolId(261)
	CaseToken          = SymbolId(262)
	IfToken            = SymbolId(263)
	ElseIfToken        = SymbolId(264)
	DefaultToken       = SymbolId(265)
	ElseToken          = SymbolId(266)
	EndToken           = SymbolId(267)
	TextToken          = SymbolId(268)
	SubstitutionToken  = SymbolId(269)
	EmbedToken         = SymbolId(270)
	CopySectionToken   = SymbolId(271)
	CommentToken       = SymbolId(272)
	ContinueToken      = SymbolId(273)
	BreakToken         = SymbolId(274)
	ReturnToken        = SymbolId(275)
	ErrorToken         = SymbolId(276)
)
View Source
const (
	FileType            = SymbolId(277)
	OptionalImportsType = SymbolId(278)
	BodyType            = SymbolId(279)
	StatementType       = SymbolId(280)
	AtomType            = SymbolId(281)
	ForType             = SymbolId(282)
	SwitchType          = SymbolId(283)
	CaseListType        = SymbolId(284)
	OptionalDefaultType = SymbolId(285)
	IfType              = SymbolId(286)
	ElseIfListType      = SymbolId(287)
	OptionalElseType    = SymbolId(288)
)

Variables

View Source
var (
	OutputablePrimitiveTypes = []string{
		"bool",
		"uint",
		"uint8",
		"uint16",
		"uint32",
		"uint64",
		"int",
		"int8",
		"int16",
		"int32",
		"int64",
		"float32",
		"float64",
		"complex64",
		"complex128",
	}
)

Functions

This section is empty.

Types

type Argument

type Argument struct {
	Name string
	Type string
}

type Atom

type Atom struct {
	*TToken

	Value string
}

func NewAtom

func NewAtom(
	id SymbolId,
	loc Location,
	val string,
	trimLeading bool,
	trimTrailing bool) *Atom

func (Atom) IsStatement

func (Atom) IsStatement()

type BodyToken

type BodyToken interface {
	Token

	// When true, and the previous statement is text, remove the whitespaces
	// in the text that are adjacent to this statement, potentially up to and
	// including the previous line's newline character.
	TrimLeadingWhitespaces() bool

	// When true, and the next statement is text, remove the whitespaces
	// in the text taht are adjacent to this statement, potentially up to and
	// including the current line's newline character.
	TrimTrailingWhitespaces() bool
}

type Branch

type Branch struct {
	Predicate *Value
	Body      []Statement
}

type DefaultParseErrorHandler

type DefaultParseErrorHandler struct{}

func (DefaultParseErrorHandler) Error

func (DefaultParseErrorHandler) Error(nextToken Token, stack _Stack) error

type File

type File struct {
	PackageName string

	Imports string

	*TemplateDeclaration

	Body []Statement
}

func Parse

func Parse(lexer Lexer, reducer Reducer) (*File, error)

func ParseWithCustomErrorHandler

func ParseWithCustomErrorHandler(
	lexer Lexer,
	reducer Reducer,
	errHandler ParseErrorHandler) (
	*File,
	error)

type For

type For struct {
	Branch
}

func (For) Id

func (For) Id() SymbolId

func (For) IsStatement

func (For) IsStatement()

func (*For) Loc

func (f *For) Loc() Location

type GenericSymbol

type GenericSymbol struct {
	SymbolId
	Location
}

func (*GenericSymbol) Id

func (t *GenericSymbol) Id() SymbolId

func (*GenericSymbol) Loc

func (t *GenericSymbol) Loc() Location

type If

type If struct {
	If      Branch
	ElseIfs []*Branch
	Else    *Branch
}

func (If) Id

func (If) Id() SymbolId

func (If) IsStatement

func (If) IsStatement()

func (*If) Loc

func (i *If) Loc() Location

type Lexer

type Lexer interface {
	// Note: Return io.EOF to indicate end of stream
	// Token with unspecified value type should return *GenericSymbol
	Next() (Token, error)

	CurrentLocation() Location
}

func NewLexer

func NewLexer(filename string, input io.Reader) (Lexer, error)

type LexerImpl

type LexerImpl struct {
	// contains filtered or unexported fields
}

func (*LexerImpl) CurrentLocation

func (lexer *LexerImpl) CurrentLocation() Location

func (*LexerImpl) Next

func (lexer *LexerImpl) Next() (Token, error)

type Location

type Location struct {
	FileName string
	Line     int
	Column   int
}

func (Location) ShortString

func (l Location) ShortString() string

func (Location) String

func (l Location) String() string

type ParseErrorHandler

type ParseErrorHandler interface {
	Error(nextToken Token, parseStack _Stack) error
}

type Reducer

type Reducer interface {
	// 22:8: file -> ...
	ToFile(Package_ *Value, OptionalImports_ *Value, TemplateDecl_ *TemplateDeclaration, SectionMarker_ *GenericSymbol, Body_ []Statement) (*File, error)

	// 29:4: optional_imports -> imports: ...
	ImportsToOptionalImports(Import_ *Value) (*Value, error)

	// 30:4: optional_imports -> nil: ...
	NilToOptionalImports() (*Value, error)

	// 33:4: body -> add: ...
	AddToBody(Body_ []Statement, Statement_ Statement) ([]Statement, error)

	// 34:4: body -> nil: ...
	NilToBody() ([]Statement, error)

	// 37:4: statement -> atom: ...
	AtomToStatement(Atom_ Statement) (Statement, error)

	// 38:4: statement -> for: ...
	ForToStatement(For_ Statement) (Statement, error)

	// 39:4: statement -> switch: ...
	SwitchToStatement(Switch_ Statement) (Statement, error)

	// 40:4: statement -> if: ...
	IfToStatement(If_ Statement) (Statement, error)

	// 43:4: atom -> text: ...
	TextToAtom(Text_ *Atom) (Statement, error)

	// 44:4: atom -> substitution: ...
	SubstitutionToAtom(Substitution_ *Atom) (Statement, error)

	// 45:4: atom -> embed: ...
	EmbedToAtom(Embed_ *Atom) (Statement, error)

	// 46:4: atom -> copy_section: ...
	CopySectionToAtom(CopySection_ *Atom) (Statement, error)

	// 47:4: atom -> comment: ...
	CommentToAtom(Comment_ *Atom) (Statement, error)

	// 48:4: atom -> continue: ...
	ContinueToAtom(Continue_ *Atom) (Statement, error)

	// 49:4: atom -> break: ...
	BreakToAtom(Break_ *Atom) (Statement, error)

	// 50:4: atom -> return: ...
	ReturnToAtom(Return_ *Atom) (Statement, error)

	// 51:4: atom -> error: ...
	ErrorToAtom(Error_ *Atom) (Statement, error)

	// 53:7: for -> ...
	ToFor(For_ *Value, Body_ []Statement, End_ *TToken) (Statement, error)

	// 57:4: switch -> with_whitespace: ...
	WithWhitespaceToSwitch(Switch_ *Value, Text_ *Atom, CaseList_ []*Branch, OptionalDefault_ *Branch, End_ *TToken) (Statement, error)

	// 58:4: switch -> without_whitespace: ...
	WithoutWhitespaceToSwitch(Switch_ *Value, CaseList_ []*Branch, OptionalDefault_ *Branch, End_ *TToken) (Statement, error)

	// 61:4: case_list -> add: ...
	AddToCaseList(CaseList_ []*Branch, Case_ *Value, Body_ []Statement) ([]*Branch, error)

	// 62:4: case_list -> case: ...
	CaseToCaseList(Case_ *Value, Body_ []Statement) ([]*Branch, error)

	// 65:4: optional_default -> default: ...
	DefaultToOptionalDefault(Default_ *TToken, Body_ []Statement) (*Branch, error)

	// 66:4: optional_default -> nil: ...
	NilToOptionalDefault() (*Branch, error)

	// 68:6: if -> ...
	ToIf(If_ *Value, Body_ []Statement, ElseIfList_ []*Branch, OptionalElse_ *Branch, End_ *TToken) (Statement, error)

	// 71:4: else_if_list -> add: ...
	AddToElseIfList(ElseIfList_ []*Branch, ElseIf_ *Value, Body_ []Statement) ([]*Branch, error)

	// 72:4: else_if_list -> nil: ...
	NilToElseIfList() ([]*Branch, error)

	// 75:4: optional_else -> else: ...
	ElseToOptionalElse(Else_ *TToken, Body_ []Statement) (*Branch, error)

	// 76:4: optional_else -> nil: ...
	NilToOptionalElse() (*Branch, error)
}

type ReducerImpl

type ReducerImpl struct{}

func (ReducerImpl) AddToBody

func (ReducerImpl) AddToBody(
	body []Statement,
	statement Statement) (
	[]Statement,
	error)

func (ReducerImpl) AddToCaseList

func (ReducerImpl) AddToCaseList(
	cases []*Branch,
	predicate *Value,
	body []Statement) (
	[]*Branch,
	error)

func (ReducerImpl) AddToElseIfList

func (ReducerImpl) AddToElseIfList(
	elseIfs []*Branch,
	predicate *Value,
	body []Statement) (
	[]*Branch,
	error)

func (ReducerImpl) AtomToStatement

func (ReducerImpl) AtomToStatement(atom Statement) (Statement, error)

func (ReducerImpl) BreakToAtom

func (ReducerImpl) BreakToAtom(break_ *Atom) (Statement, error)

func (ReducerImpl) CaseToCaseList

func (ReducerImpl) CaseToCaseList(
	predicate *Value,
	body []Statement) (
	[]*Branch,
	error)

func (ReducerImpl) CommentToAtom

func (ReducerImpl) CommentToAtom(comment *Atom) (Statement, error)

func (ReducerImpl) ContinueToAtom

func (ReducerImpl) ContinueToAtom(cont *Atom) (Statement, error)

func (ReducerImpl) CopySectionToAtom

func (ReducerImpl) CopySectionToAtom(copySection *Atom) (Statement, error)

func (ReducerImpl) DefaultToOptionalDefault

func (ReducerImpl) DefaultToOptionalDefault(
	default_ *TToken,
	body []Statement) (
	*Branch,
	error)

func (ReducerImpl) ElseToOptionalElse

func (ReducerImpl) ElseToOptionalElse(
	else_ *TToken,
	body []Statement) (
	*Branch,
	error)

func (ReducerImpl) EmbedToAtom

func (ReducerImpl) EmbedToAtom(embed *Atom) (Statement, error)

func (ReducerImpl) ErrorToAtom

func (ReducerImpl) ErrorToAtom(err *Atom) (Statement, error)

func (ReducerImpl) ForToStatement

func (ReducerImpl) ForToStatement(for_ Statement) (Statement, error)

func (ReducerImpl) IfToStatement

func (ReducerImpl) IfToStatement(if_ Statement) (Statement, error)

func (ReducerImpl) ImportsToOptionalImports

func (ReducerImpl) ImportsToOptionalImports(imports *Value) (*Value, error)

func (ReducerImpl) NilToBody

func (ReducerImpl) NilToBody() ([]Statement, error)

func (ReducerImpl) NilToElseIfList

func (ReducerImpl) NilToElseIfList() ([]*Branch, error)

func (ReducerImpl) NilToOptionalDefault

func (ReducerImpl) NilToOptionalDefault() (*Branch, error)

func (ReducerImpl) NilToOptionalElse

func (ReducerImpl) NilToOptionalElse() (*Branch, error)

func (ReducerImpl) NilToOptionalImports

func (ReducerImpl) NilToOptionalImports() (*Value, error)

func (ReducerImpl) ReturnToAtom

func (ReducerImpl) ReturnToAtom(ret *Atom) (Statement, error)

func (ReducerImpl) SubstitutionToAtom

func (ReducerImpl) SubstitutionToAtom(sub *Atom) (Statement, error)

func (ReducerImpl) SwitchToStatement

func (ReducerImpl) SwitchToStatement(switch_ Statement) (Statement, error)

func (ReducerImpl) TextToAtom

func (ReducerImpl) TextToAtom(text *Atom) (Statement, error)

func (ReducerImpl) ToFile

func (ReducerImpl) ToFile(
	pkg *Value,
	imports *Value,
	template *TemplateDeclaration,
	sectionMarker *GenericSymbol,
	body []Statement) (
	*File,
	error)

func (ReducerImpl) ToFor

func (ReducerImpl) ToFor(
	for_ *Value,
	body []Statement,
	end *TToken) (
	Statement,
	error)

func (ReducerImpl) ToIf

func (ReducerImpl) ToIf(
	predicate *Value,
	body []Statement,
	elseIfs []*Branch,
	else_ *Branch,
	end *TToken) (
	Statement,
	error)

func (ReducerImpl) WithWhitespaceToSwitch

func (ReducerImpl) WithWhitespaceToSwitch(
	switch_ *Value,
	whitespace *Atom,
	cases []*Branch,
	default_ *Branch,
	end *TToken) (
	Statement,
	error)

func (ReducerImpl) WithoutWhitespaceToSwitch

func (ReducerImpl) WithoutWhitespaceToSwitch(
	switch_ *Value,
	cases []*Branch,
	default_ *Branch,
	end *TToken) (
	Statement,
	error)

type Statement

type Statement interface {
	IsStatement()

	Id() SymbolId
	Loc() Location
}

type Switch

type Switch struct {
	Switch  *Value
	Cases   []*Branch
	Default *Branch
}

func (Switch) Id

func (Switch) Id() SymbolId

func (Switch) IsStatement

func (Switch) IsStatement()

func (*Switch) Loc

func (s *Switch) Loc() Location

type Symbol

type Symbol struct {
	SymbolId_ SymbolId

	Generic_ *GenericSymbol

	Atom         *Atom
	Branch       *Branch
	Branches     []*Branch
	File         *File
	Statement    Statement
	Statements   []Statement
	TemplateDecl *TemplateDeclaration
	Token        *TToken
	Value        *Value
}

func NewSymbol

func NewSymbol(token Token) (*Symbol, error)

func (*Symbol) Id

func (s *Symbol) Id() SymbolId

func (*Symbol) Loc

func (s *Symbol) Loc() Location

type SymbolId

type SymbolId int

func ExpectedTerminals

func ExpectedTerminals(id _StateId) []SymbolId

func (SymbolId) String

func (i SymbolId) String() string

type TToken

type TToken struct {
	GenericSymbol
	// contains filtered or unexported fields
}

func NewTToken

func NewTToken(
	id SymbolId,
	loc Location,
	trimLeading bool,
	trimTrailing bool) *TToken

func (*TToken) TrimLeadingWhitespaces

func (token *TToken) TrimLeadingWhitespaces() bool

func (*TToken) TrimTrailingWhitespaces

func (token *TToken) TrimTrailingWhitespaces() bool

type TemplateDeclaration

type TemplateDeclaration struct {
	GenericSymbol

	TemplateName string
	Arguments    []Argument
}

func NewTemplateDeclaration

func NewTemplateDeclaration(
	loc Location,
	name string,
	args []Argument) *TemplateDeclaration

type Token

type Token interface {
	Id() SymbolId
	Loc() Location
}

type Value

type Value struct {
	*TToken

	Value string
}

func NewValue

func NewValue(
	id SymbolId,
	loc Location,
	val string,
	trimLeading bool,
	trimTrailing bool) *Value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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