Documentation ¶
Index ¶
- func Dump(src Expressioner)
- func DumpTokens(tokens []Tokener)
- func DumpTokensWithNamer(tokens []Tokener, typer TokenTyper)
- func DumpWithNamer(src Expressioner, typer TokenTyper, lvl int)
- type ExprReceiver
- type Expression
- func (f *Expression) AddExpr(expr Tokener)
- func (f *Expression) AddExprs(exprs []Tokener)
- func (f *Expression) Filter(T lexer.TokenType) []Tokener
- func (f *Expression) FilterToken(T lexer.TokenType) Tokener
- func (f *Expression) FindAll(T lexer.TokenType) []Expressioner
- func (f *Expression) First() Tokener
- func (f *Expression) GetExprIndex(e Expressioner) int
- func (f *Expression) GetExprs() []Expressioner
- func (f *Expression) GetPos() TokenPos
- func (f *Expression) GetToken(T lexer.TokenType) Tokener
- func (f *Expression) GetTokenIndex(e lexer.TokenType) int
- func (f *Expression) GetTokens() []Tokener
- func (f *Expression) GetTokensAtLine(line int) []Tokener
- func (f *Expression) GetType() lexer.TokenType
- func (f *Expression) GetValue() string
- func (f *Expression) HasToken(T lexer.TokenType) bool
- func (f *Expression) InsertAfter(ref Expressioner, nnew Tokener) bool
- func (f *Expression) InsertAt(index int, nnew Tokener)
- func (f *Expression) MustInsertAfter(ref Expressioner, nnew Tokener)
- func (f *Expression) MustRemove(e Expressioner)
- func (f *Expression) PrependExpr(expr Tokener)
- func (f *Expression) PrependExprs(exprs []Tokener)
- func (f *Expression) Remove(e Expressioner) bool
- func (f *Expression) RemoveAll(e []Expressioner) int
- func (f *Expression) RemoveAt(index int)
- func (f *Expression) RemoveT(t lexer.TokenType) bool
- func (f *Expression) Replace(old Expressioner, nnew Tokener) bool
- func (f *Expression) SetTokenValue(T lexer.TokenType, v string)
- func (f *Expression) SetType(T lexer.TokenType)
- func (f *Expression) SetValue(v string)
- func (f *Expression) String() string
- func (f *Expression) Until(u lexer.TokenType) *Expression
- type Expressioner
- type FileSyntaxError
- type Interpreter
- func (I *Interpreter) Current() []Tokener
- func (I *Interpreter) Debug(reason string, wantedTypes ...lexer.TokenType) error
- func (I *Interpreter) DebugAtToken(atToken Tokener, reason string, wantedTypes ...lexer.TokenType) error
- func (I *Interpreter) Emit() []Tokener
- func (I *Interpreter) Ended() bool
- func (I *Interpreter) Flush()
- func (I *Interpreter) Get(T ...lexer.TokenType) Tokener
- func (I *Interpreter) GetMany(T ...lexer.TokenType) []Tokener
- func (I *Interpreter) Last() Tokener
- func (I *Interpreter) Next() Tokener
- func (I *Interpreter) Peek(T ...lexer.TokenType) Tokener
- func (I *Interpreter) PeekN(n int) []Tokener
- func (I *Interpreter) PeekOne() Tokener
- func (I *Interpreter) PeekUntil(T ...lexer.TokenType) Tokener
- func (I *Interpreter) Read(Ts ...lexer.TokenType) Tokener
- func (I *Interpreter) ReadBlock(open lexer.TokenType, close lexer.TokenType) []Tokener
- func (I *Interpreter) ReadMany(Ts ...lexer.TokenType) []Tokener
- func (I *Interpreter) ReadN(n int) []Tokener
- func (I *Interpreter) Rewind()
- func (I *Interpreter) RewindAll()
- type ParseError
- type ReadNPrettyPrint
- type ReadTokenWithPos
- type ScopeReceiver
- type StringSyntaxError
- type StringTplSyntaxError
- type SyntaxError
- type TokenNamer
- type TokenPos
- type TokenReader
- type TokenTyper
- type TokenWithPos
- func (f *TokenWithPos) FindAll(T lexer.TokenType) []Expressioner
- func (f *TokenWithPos) GetExprs() []Expressioner
- func (f *TokenWithPos) GetPos() TokenPos
- func (f *TokenWithPos) GetToken(T lexer.TokenType) Tokener
- func (f *TokenWithPos) GetTokens() []Tokener
- func (f *TokenWithPos) GetTokensAtLine(line int) []Tokener
- func (f *TokenWithPos) HasToken(T lexer.TokenType) bool
- func (f *TokenWithPos) PrependExpr(expr Tokener)
- func (f *TokenWithPos) PrependExprs(exprs []Tokener)
- func (f *TokenWithPos) Remove(e Expressioner) bool
- func (f *TokenWithPos) SetTokenValue(T lexer.TokenType, v string)
- func (f *TokenWithPos) SetType(s lexer.TokenType)
- func (f *TokenWithPos) SetValue(s string)
- type Tokener
- type TokenerNamer
- type TokenerReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
ExprReceiver receives tokens
type Expression ¶
type Expression struct {
Tokens []Tokener
}
Expression isa token of tokens.
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) 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) 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) 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) 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) 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) 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) 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) 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 ¶
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
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 TokenReader ¶
TokenReader reads *lexer.Token
type TokenTyper ¶
TokenTyper gives the name of a Token type.
type TokenWithPos ¶
TokenWithPos is a token with a pos.
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 ¶
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