parser

package
v0.0.0-...-baef74e Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2018 License: MIT Imports: 14 Imported by: 15

Documentation

Index

Constants

View Source
const (
	ItemError lex.ItemType = lex.ItemDefaultMax + 1 + iota
	ItemEOF
	ItemRawString
	ItemComment
	ItemNumber
	ItemComplex
	ItemChar
	ItemSpace
	ItemTagStart
	ItemTagEnd
	ItemSymbol
	ItemIdentifier
	ItemDoubleQuotedString
	ItemSingleQuotedString
	ItemBool
	ItemField
	ItemComma
	ItemOpenParen          // '('
	ItemCloseParen         // ')'
	ItemOpenSquareBracket  // '['
	ItemCloseSquareBracket // ']'
	ItemPeriod             // '.'
	ItemKeyword            // Delimiter
	ItemCall               // CALL
	ItemGet                // GET
	ItemSet                // SET
	ItemMacro              // MACRO
	ItemBlock              // BLOCK
	ItemForeach            // FOREACH
	ItemWhile              // WHILE
	ItemIn                 // IN
	ItemInclude            // INCLUDE
	ItemWith               // WITH
	ItemIf                 // IF
	ItemElse               // ELSE
	ItemElseIf             // ELSIF
	ItemUnless             // UNLESS
	ItemSwitch             // SWITCH
	ItemCase               // CASE
	ItemWrapper            // WRAPPER
	ItemDefault            // DEFAULT
	ItemEnd                // END
	ItemOperator           // Delimiter
	ItemRange              // ..
	ItemEquals             // ==
	ItemNotEquals          // !=
	ItemGT                 // >
	ItemLT                 // <
	ItemCmp                // <=>
	ItemLE                 // <=
	ItemGE                 // >=
	ItemShiftLeft          // <<
	ItemShiftRight         // >>
	ItemAssignAdd          // +=
	ItemAssignSub          // -=
	ItemAssignMul          // *=
	ItemAssignDiv          // /=
	ItemAssignMod          // %=
	ItemAnd                // &&
	ItemOr                 // ||
	ItemFatComma           // =>
	ItemIncr               // ++
	ItemDecr               // --
	ItemPlus
	ItemMinus
	ItemAsterisk
	ItemSlash
	ItemVerticalSlash
	ItemMod
	ItemAssign // =

	DefaultItemTypeMax
)

Variables

View Source
var DefaultSymbolSet = NewLexSymbolSet()

DefaultSymbolSet is the LexSymbolSet for symbols that are common to all syntax

Functions

This section is empty.

Types

type AST

type AST struct {
	Name      string         // name of the template
	ParseName string         // name of the top-level template during parsing
	Root      *node.ListNode // root of the tree
	Timestamp time.Time      // last-modified date of this template
	// contains filtered or unexported fields
}

AST is represents the syntax tree for an Xslate template

func (*AST) String

func (ast *AST) String() string

String returns the textual representation of this AST

func (*AST) Visit

func (ast *AST) Visit() <-chan node.Node

Visit returns a channel which you can receive Node structs in order that that they would be processed

type Builder

type Builder struct {
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) Backup

func (b *Builder) Backup(ctx *builderCtx)

func (*Builder) Backup2

func (b *Builder) Backup2(ctx *builderCtx, t1 lex.LexItem)

func (*Builder) DeclareLocalVarIfNew

func (b *Builder) DeclareLocalVarIfNew(ctx *builderCtx, symbol lex.LexItem)

func (*Builder) LocalVarOrFetchSymbol

func (b *Builder) LocalVarOrFetchSymbol(ctx *builderCtx, token lex.LexItem) node.Node

func (*Builder) Next

func (b *Builder) Next(ctx *builderCtx) lex.LexItem

func (*Builder) NextNonSpace

func (b *Builder) NextNonSpace(ctx *builderCtx) lex.LexItem

func (*Builder) Parse

func (b *Builder) Parse(name string, l lex.Lexer) (ast *AST, err error)

func (*Builder) ParseArrayElementFetch

func (b *Builder) ParseArrayElementFetch(ctx *builderCtx, invocant node.Node) node.Node

func (*Builder) ParseAssignment

func (b *Builder) ParseAssignment(ctx *builderCtx) node.Node

func (*Builder) ParseElse

func (b *Builder) ParseElse(ctx *builderCtx) node.Node

func (*Builder) ParseExpression

func (b *Builder) ParseExpression(ctx *builderCtx, canPrint bool) (n node.Node)

func (*Builder) ParseExpressionOrAssignment

func (b *Builder) ParseExpressionOrAssignment(ctx *builderCtx, canPrint bool) node.Node

func (*Builder) ParseFilter

func (b *Builder) ParseFilter(ctx *builderCtx, n node.Node) node.Node

func (*Builder) ParseForeach

func (b *Builder) ParseForeach(ctx *builderCtx) node.Node

func (*Builder) ParseFunCall

func (b *Builder) ParseFunCall(ctx *builderCtx, invocant node.Node) node.Node

func (*Builder) ParseGroup

func (b *Builder) ParseGroup(ctx *builderCtx) node.Node

func (*Builder) ParseIf

func (b *Builder) ParseIf(ctx *builderCtx) node.Node

func (*Builder) ParseInclude

func (b *Builder) ParseInclude(ctx *builderCtx) node.Node

func (*Builder) ParseList

func (b *Builder) ParseList(ctx *builderCtx) node.Node

func (*Builder) ParseListVariableOrMakeArray

func (b *Builder) ParseListVariableOrMakeArray(ctx *builderCtx) node.Node

func (*Builder) ParseLiteral

func (b *Builder) ParseLiteral(ctx *builderCtx) node.Node

func (*Builder) ParseMacro

func (b *Builder) ParseMacro(ctx *builderCtx) node.Node

func (*Builder) ParseMakeArray

func (b *Builder) ParseMakeArray(ctx *builderCtx) node.Node

func (*Builder) ParseMethodCallOrMapLookup

func (b *Builder) ParseMethodCallOrMapLookup(ctx *builderCtx, invocant node.Node) node.Node

func (*Builder) ParseRange

func (b *Builder) ParseRange(ctx *builderCtx) node.Node

func (*Builder) ParseRawString

func (b *Builder) ParseRawString(ctx *builderCtx) node.Node

func (*Builder) ParseStatements

func (b *Builder) ParseStatements(ctx *builderCtx) node.Node

func (*Builder) ParseTemplate

func (b *Builder) ParseTemplate(ctx *builderCtx) node.Node

func (*Builder) ParseTemplateOrText

func (b *Builder) ParseTemplateOrText(ctx *builderCtx) node.Node

func (*Builder) ParseTerm

func (b *Builder) ParseTerm(ctx *builderCtx) node.Node

func (*Builder) ParseWhile

func (b *Builder) ParseWhile(ctx *builderCtx) node.Node

func (*Builder) ParseWrapper

func (b *Builder) ParseWrapper(ctx *builderCtx) node.Node

func (*Builder) Peek

func (b *Builder) Peek(ctx *builderCtx) lex.LexItem

func (*Builder) PeekNonSpace

func (b *Builder) PeekNonSpace(ctx *builderCtx) lex.LexItem

func (*Builder) Start

func (b *Builder) Start(ctx *builderCtx)

func (*Builder) Unexpected

func (b *Builder) Unexpected(ctx *builderCtx, format string, args ...interface{})

type Frame

type Frame struct {
	*frame.Frame
	Node node.Appender

	// This contains names of local variables, mapped to their
	// respective location in the framestack
	LvarNames map[string]int
}

Frame is the frame struct used during parsing, which has a bit of extension over the common Frame struct.

func NewFrame

func NewFrame(s stack.Stack) *Frame

type LexSymbol

type LexSymbol struct {
	Name     string
	Type     lex.ItemType
	Priority float32
}

LexSymbol holds the pre-defined symbols to be lexed

type LexSymbolList

type LexSymbolList []LexSymbol

LexSymbolList a list of LexSymbols. Normally you do not need to use it. This is mainly only useful for sorting LexSymbols

func (LexSymbolList) Sort

func (list LexSymbolList) Sort() LexSymbolList

Sort returns a sorted list of LexSymbols, sorted by Priority

type LexSymbolSet

type LexSymbolSet struct {
	Map        map[string]LexSymbol
	SortedList LexSymbolList
}

LexSymbolSet is the container for symbols.

func NewLexSymbolSet

func NewLexSymbolSet() *LexSymbolSet

NewLexSymbolSet creates a new LexSymbolSet

func (*LexSymbolSet) Copy

func (l *LexSymbolSet) Copy() *LexSymbolSet

Copy creates a new copy of the given LexSymbolSet

func (*LexSymbolSet) Count

func (l *LexSymbolSet) Count() int

Count returns the number of symbols registered

func (*LexSymbolSet) Get

func (l *LexSymbolSet) Get(name string) LexSymbol

Get returns the LexSymbol associated with `name`

func (*LexSymbolSet) GetSortedList

func (l *LexSymbolSet) GetSortedList() LexSymbolList

GetSortedList returns the lsit of LexSymbols in order that they should be searched for in the tempalte

func (*LexSymbolSet) Set

func (l *LexSymbolSet) Set(name string, typ lex.ItemType, prio ...float32)

Set creates and sets a new LexItem to `name`

type LexSymbolSorter

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

LexSymbolSorter sorts a list of LexSymbols by priority

func (LexSymbolSorter) Len

func (s LexSymbolSorter) Len() int

Len returns the length of the list

func (LexSymbolSorter) Less

func (s LexSymbolSorter) Less(i, j int) bool

Less returns true if the i-th element's Priority is less than the j-th element

func (LexSymbolSorter) Swap

func (s LexSymbolSorter) Swap(i, j int)

Swap swaps the elements at i and j

type Lexer

type Lexer struct {
	lex.Lexer
	// contains filtered or unexported fields
}

func NewReaderLexer

func NewReaderLexer(rdr io.Reader, ss *LexSymbolSet) *Lexer

func NewStringLexer

func NewStringLexer(template string, ss *LexSymbolSet) *Lexer

func (*Lexer) SetTagEnd

func (l *Lexer) SetTagEnd(s string)

func (*Lexer) SetTagStart

func (l *Lexer) SetTagStart(s string)

type Parser

type Parser interface {
	Parse(string, []byte) (*AST, error)
	ParseString(string, string) (*AST, error)
	ParseReader(string, io.Reader) (*AST, error)
}

Parser defines the interface for Xslate parsers

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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