generic

package
v0.0.0-...-ad647fd Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dump

func Dump(src Expressioner)

Dump recursively prints an expression

func DumpTokens

func DumpTokens(tokens []Tokener)

DumpTokens prints a list of tokens

func DumpTokensWithNamer

func DumpTokensWithNamer(tokens []Tokener, typer TokenTyper)

DumpTokensWithNamer prints a list of tokens

func DumpWithNamer

func DumpWithNamer(src Expressioner, typer TokenTyper, lvl int)

DumpWithNamer recursively prints an expression

Types

type ExprReceiver

type ExprReceiver interface {
	AddExpr(expr Tokener)
	AddExprs(expr []Tokener)
}

ExprReceiver receives tokens

type Expression

type Expression struct {
	Tokens []Tokener
}

Expression isa token of tokens.

func (*Expression) AddExpr

func (f *Expression) AddExpr(expr Tokener)

AddExpr appends a Tokener

func (*Expression) AddExprs

func (f *Expression) AddExprs(exprs []Tokener)

AddExprs appends many Tokener

func (*Expression) Filter

func (f *Expression) Filter(T lexer.TokenType) []Tokener

Filter root tokens of type T.

func (*Expression) FilterToken

func (f *Expression) FilterToken(T lexer.TokenType) Tokener

FilterToken filter root tokens of type T and returns the first one.

func (*Expression) FindAll

func (f *Expression) FindAll(T lexer.TokenType) []Expressioner

FindAll returns all expressions of type T.

func (*Expression) First

func (f *Expression) First() Tokener

First get 1st.

func (*Expression) GetExprIndex

func (f *Expression) GetExprIndex(e Expressioner) int

GetExprIndex returns index of a root token matching given expression.

func (*Expression) GetExprs

func (f *Expression) GetExprs() []Expressioner

GetExprs returns a list of root expression.

func (*Expression) GetPos

func (f *Expression) GetPos() TokenPos

GetPos get 1st pos.

func (*Expression) GetToken

func (f *Expression) GetToken(T lexer.TokenType) Tokener

GetToken implements Tokener.

func (*Expression) GetTokenIndex

func (f *Expression) GetTokenIndex(e lexer.TokenType) int

GetTokenIndex returns index of a root token matching given Tokener.

func (*Expression) GetTokens

func (f *Expression) GetTokens() []Tokener

GetTokens returns the list of root-tokens.

func (*Expression) GetTokensAtLine

func (f *Expression) GetTokensAtLine(line int) []Tokener

GetTokensAtLine finds all tokens at line.

func (*Expression) GetType

func (f *Expression) GetType() lexer.TokenType

GetType get 1st TokenType.

func (*Expression) GetValue

func (f *Expression) GetValue() string

GetValue get 1st value.

func (*Expression) HasToken

func (f *Expression) HasToken(T lexer.TokenType) bool

HasToken recursively for a token of the given type.

func (*Expression) InsertAfter

func (f *Expression) InsertAfter(ref Expressioner, nnew Tokener) bool

InsertAfter a nnew root token after given ref expression.

func (*Expression) InsertAt

func (f *Expression) InsertAt(index int, nnew Tokener)

InsertAt a nnew root token at index.

func (*Expression) MustInsertAfter

func (f *Expression) MustInsertAfter(ref Expressioner, nnew Tokener)

MustInsertAfter ...

func (*Expression) MustRemove

func (f *Expression) MustRemove(e Expressioner)

MustRemove ...

func (*Expression) PrependExpr

func (f *Expression) PrependExpr(expr Tokener)

PrependExpr prepends a Tokener

func (*Expression) PrependExprs

func (f *Expression) PrependExprs(exprs []Tokener)

PrependExprs prepends many Tokener

func (*Expression) Remove

func (f *Expression) Remove(e Expressioner) bool

Remove a root token of this expression.

func (*Expression) RemoveAll

func (f *Expression) RemoveAll(e []Expressioner) int

RemoveAll root tokens matching those expressions.

func (*Expression) RemoveAt

func (f *Expression) RemoveAt(index int)

RemoveAt removes root token at index.

func (*Expression) RemoveT

func (f *Expression) RemoveT(t lexer.TokenType) bool

RemoveT a root token of type T.

func (*Expression) Replace

func (f *Expression) Replace(old Expressioner, nnew Tokener) bool

Replace a root token with given expression.

func (*Expression) SetTokenValue

func (f *Expression) SetTokenValue(T lexer.TokenType, v string)

SetTokenValue recusrively change the Value of tokens of type T.

func (*Expression) SetType

func (f *Expression) SetType(T lexer.TokenType)

SetType set 1st TokenType.

func (*Expression) SetValue

func (f *Expression) SetValue(v string)

SetValue set 1st value.

func (*Expression) String

func (f *Expression) String() string

func (*Expression) Until

func (f *Expression) Until(u lexer.TokenType) *Expression

Until returns all tokens until it met u.

type Expressioner

type Expressioner interface {
	GetExprs() []Expressioner
	GetTokens() []Tokener
	HasToken(lexer.TokenType) bool
	Remove(Expressioner) bool
	String() string
	PrependExpr(Tokener)
	PrependExprs([]Tokener)
	GetToken(lexer.TokenType) Tokener
	SetTokenValue(lexer.TokenType, string)
	GetTokensAtLine(int) []Tokener
	FindAll(lexer.TokenType) []Expressioner
}

Expressioner is an interface that defines methods to manipulate a token of tokens.

type FileSyntaxError

type FileSyntaxError struct {
	ParseError
	Src string
}

FileSyntaxError is a syntax error in the scope of a File

func (*FileSyntaxError) Error

func (f *FileSyntaxError) Error() string

func (*FileSyntaxError) Format

func (f *FileSyntaxError) Format(s fmt.State, verb rune)

Format implements fmt.Formatter

func (*FileSyntaxError) PrettyPrint

func (f *FileSyntaxError) PrettyPrint() string

PrettyPrint a syntax error

func (*FileSyntaxError) String

func (f *FileSyntaxError) String() string

type Interpreter

type Interpreter struct {
	Namer TokenTyper

	Reader TokenerReader
	Tokens []Tokener
	Scope  ScopeReceiver
	// contains filtered or unexported fields
}

Interpreter navigates a tokens list to produce a tokens tree.

func NewInterpreter

func NewInterpreter(r TokenerReader) *Interpreter

NewInterpreter makes an Interpreter starting at -1

func (*Interpreter) Current

func (I *Interpreter) Current() []Tokener

Current unemitted tokens.

func (*Interpreter) Debug

func (I *Interpreter) Debug(reason string, wantedTypes ...lexer.TokenType) error

Debug produces a SyntaxError when unexpected tokens are found.

func (*Interpreter) DebugAtToken

func (I *Interpreter) DebugAtToken(atToken Tokener, reason string, wantedTypes ...lexer.TokenType) error

DebugAtToken produces a SyntaxError at token T.

func (*Interpreter) Emit

func (I *Interpreter) Emit() []Tokener

Emit current tokens in buffer.

func (*Interpreter) Ended

func (I *Interpreter) Ended() bool

Ended when the tokens list is empty.

func (*Interpreter) Flush

func (I *Interpreter) Flush()

Flush current tokens in buffer.

func (*Interpreter) Get

func (I *Interpreter) Get(T ...lexer.TokenType) Tokener

Get reads a token T and flushes the buffer. bad idea ?

func (*Interpreter) GetMany

func (I *Interpreter) GetMany(T ...lexer.TokenType) []Tokener

GetMany reads tokens until it is not of types T and flushes the buffer. bad idea ?

func (*Interpreter) Last

func (I *Interpreter) Last() Tokener

Last is the token at current position.

func (*Interpreter) Next

func (I *Interpreter) Next() Tokener

Next gives the next token.

func (*Interpreter) Peek

func (I *Interpreter) Peek(T ...lexer.TokenType) Tokener

Peek returns nil if the next token is not of type T.

func (*Interpreter) PeekN

func (I *Interpreter) PeekN(n int) []Tokener

PeekN returns N tokens without changing position.

func (*Interpreter) PeekOne

func (I *Interpreter) PeekOne() Tokener

PeekOne returns next token without changing position.

func (*Interpreter) PeekUntil

func (I *Interpreter) PeekUntil(T ...lexer.TokenType) Tokener

PeekUntil peeks anything until it met with any of T.

func (*Interpreter) Read

func (I *Interpreter) Read(Ts ...lexer.TokenType) Tokener

Read advances the position if next token is of type T.

func (*Interpreter) ReadBlock

func (I *Interpreter) ReadBlock(open lexer.TokenType, close lexer.TokenType) []Tokener

ReadBlock reads the tokens as a block delimited by open/close Type ({..}).

func (*Interpreter) ReadMany

func (I *Interpreter) ReadMany(Ts ...lexer.TokenType) []Tokener

ReadMany advances until next token is not of types T.

func (*Interpreter) ReadN

func (I *Interpreter) ReadN(n int) []Tokener

ReadN advances the position of n.

func (*Interpreter) Rewind

func (I *Interpreter) Rewind()

Rewind returns to the previous token, if any.

func (*Interpreter) RewindAll

func (I *Interpreter) RewindAll()

RewindAll returns to first position

type ParseError

type ParseError struct {
	SyntaxError
	// contains filtered or unexported fields
}

ParseError is an error about parsing

func NewParseError

func NewParseError(reason error, n Tokener, got string, wanted []string) *ParseError

NewParseError creates a parse error

func (*ParseError) Error

func (f *ParseError) Error() string

func (*ParseError) Format

func (f *ParseError) Format(s fmt.State, verb rune)

Format implements fmt.Formatter

type ReadNPrettyPrint

type ReadNPrettyPrint struct {
	Reader TokenerReader
	Namer  TokenerNamer
	// contains filtered or unexported fields
}

ReadNPrettyPrint is a TokenerReader that pretty prints what it reads.

func NewReadNPrettyPrint

func NewReadNPrettyPrint(r TokenerReader, Namer TokenerNamer, out io.Writer) *ReadNPrettyPrint

NewReadNPrettyPrint initializes a prety printer reader to out, Namer resolves token types.

func (*ReadNPrettyPrint) Flush

func (r *ReadNPrettyPrint) Flush()

Flush prints on the underlying write.

func (*ReadNPrettyPrint) NextToken

func (r *ReadNPrettyPrint) NextToken() Tokener

NextToken returns next token and prints it.

type ReadTokenWithPos

type ReadTokenWithPos struct {
	Reader TokenReader
	// contains filtered or unexported fields
}

ReadTokenWithPos reads lexer.Token, outputs Tokener

func NewReadTokenWithPos

func NewReadTokenWithPos(r TokenReader) *ReadTokenWithPos

NewReadTokenWithPos initializes a TokenerReader from a TokenerReader

func (*ReadTokenWithPos) NextToken

func (r *ReadTokenWithPos) NextToken() Tokener

NextToken advance to the next token. returns nil on eof.

type ScopeReceiver

type ScopeReceiver interface {
	ExprReceiver
	GetName() string
	FinalizeErr(*ParseError) error
}

ScopeReceiver is a context of token reception

type StringSyntaxError

type StringSyntaxError struct {
	ParseError
	Filepath string
	Src      string
}

StringSyntaxError is a syntax error in the scope of a Str

func (*StringSyntaxError) Error

func (f *StringSyntaxError) Error() string

func (*StringSyntaxError) Format

func (f *StringSyntaxError) Format(s fmt.State, verb rune)

Format implements fmt.Formatter

func (*StringSyntaxError) PrettyPrint

func (f *StringSyntaxError) PrettyPrint() string

PrettyPrint a syntax error

func (*StringSyntaxError) String

func (f *StringSyntaxError) String() string

type StringTplSyntaxError

type StringTplSyntaxError struct {
	SyntaxError
	Name string
	Src  string
}

StringTplSyntaxError is a syntax error in the scope of a Str

func NewStringTplSyntaxError

func NewStringTplSyntaxError(from error, name, tplContent string) *StringTplSyntaxError

NewStringTplSyntaxError creates a new syntax error for a template

func (*StringTplSyntaxError) Error

func (f *StringTplSyntaxError) Error() string

func (*StringTplSyntaxError) Format

func (f *StringTplSyntaxError) Format(s fmt.State, verb rune)

Format implements fmt.Formatter

func (*StringTplSyntaxError) PrettyPrint

func (f *StringTplSyntaxError) PrettyPrint() string

PrettyPrint a syntax error

func (*StringTplSyntaxError) String

func (f *StringTplSyntaxError) String() string

type SyntaxError

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

SyntaxError is a syntax error

func NewSyntaxError

func NewSyntaxError(r error, l, p int) SyntaxError

NewSyntaxError creates a new syntax error of reason r and pos l:p

func (*SyntaxError) Error

func (f *SyntaxError) Error() string

func (*SyntaxError) Format

func (f *SyntaxError) Format(s fmt.State, verb rune)

Format implements fmt.Formatter

func (*SyntaxError) PrettyPrint

func (f *SyntaxError) PrettyPrint(lines []string, startAtLine int) string

PrettyPrint a syntax error

func (*SyntaxError) String

func (f *SyntaxError) String() string

type TokenNamer

type TokenNamer func(lexer.Token) string

TokenNamer gives the name of a Token.

type TokenPos

type TokenPos struct {
	Line int
	Pos  int
}

TokenPos is a token position

func (TokenPos) String

func (t TokenPos) String() string

type TokenReader

type TokenReader interface {
	NextToken() *lexer.Token
}

TokenReader reads *lexer.Token

type TokenTyper

type TokenTyper func(lexer.TokenType) string

TokenTyper gives the name of a Token type.

type TokenWithPos

type TokenWithPos struct {
	lexer.Token
	Pos TokenPos
}

TokenWithPos is a token with a pos.

func NewTokenEOF

func NewTokenEOF() *TokenWithPos

NewTokenEOF creates an EOF Tokener.

func NewTokenWithPos

func NewTokenWithPos(t lexer.Token, line, pos int) *TokenWithPos

NewTokenWithPos creates a positionned Tokener of token.

func (*TokenWithPos) FindAll

func (f *TokenWithPos) FindAll(T lexer.TokenType) []Expressioner

FindAll implements Expressioner. It returns the token if its type matches T.

func (*TokenWithPos) GetExprs

func (f *TokenWithPos) GetExprs() []Expressioner

GetExprs implements Expressioner. its a noop.

func (*TokenWithPos) GetPos

func (f *TokenWithPos) GetPos() TokenPos

GetPos implements Expressioner.

func (*TokenWithPos) GetToken

func (f *TokenWithPos) GetToken(T lexer.TokenType) Tokener

GetToken implements Expressioner. returns the token if its type matches T.

func (*TokenWithPos) GetTokens

func (f *TokenWithPos) GetTokens() []Tokener

GetTokens implements Expressioner. returns an array of one token.

func (*TokenWithPos) GetTokensAtLine

func (f *TokenWithPos) GetTokensAtLine(line int) []Tokener

GetTokensAtLine implements Expressioner. It returns the tokens if its pos matches line.

func (*TokenWithPos) HasToken

func (f *TokenWithPos) HasToken(T lexer.TokenType) bool

HasToken implements Expressioner. returns true if token type is T.

func (*TokenWithPos) PrependExpr

func (f *TokenWithPos) PrependExpr(expr Tokener)

PrependExpr implements Expressioner. It is a noop.

func (*TokenWithPos) PrependExprs

func (f *TokenWithPos) PrependExprs(exprs []Tokener)

PrependExprs implements Expressioner. It is a noop.

func (*TokenWithPos) Remove

func (f *TokenWithPos) Remove(e Expressioner) bool

Remove implements Expressioner. It is a noop.

func (*TokenWithPos) SetTokenValue

func (f *TokenWithPos) SetTokenValue(T lexer.TokenType, v string)

SetTokenValue implements Expressioner. It changes value of the token if its type matches T.

func (*TokenWithPos) SetType

func (f *TokenWithPos) SetType(s lexer.TokenType)

SetType implements Tokener.

func (*TokenWithPos) SetValue

func (f *TokenWithPos) SetValue(s string)

SetValue implements Tokener.

type Tokener

type Tokener interface {
	GetType() lexer.TokenType
	GetValue() string
	SetValue(string)
	SetType(lexer.TokenType)
	String() string
	GetPos() TokenPos
}

Tokener is an interface that defiens methods to change value of an underlyong token.

type TokenerNamer

type TokenerNamer func(Tokener) string

TokenerNamer gives the name of a Tokener.

func TokenerName

func TokenerName(h TokenNamer) TokenerNamer

TokenerName turns a TokenNamer into a TokenerNamer.

type TokenerReader

type TokenerReader interface {
	NextToken() Tokener
}

TokenerReader reads Tokener

Jump to

Keyboard shortcuts

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