Documentation
¶
Index ¶
- Variables
- func GetNextId(input string, start int) (string, int, error)
- func PeekToken(token Token) string
- func PrettyPrint(v interface{})
- func PyTypeToString(v PyType) string
- func VariableResToString(res VariableType) (string, error)
- type AndTest
- type AnonArgument
- type ArgList
- type Argument
- type ArithExpr
- type Atom
- type AtomExpr
- type CallableArg
- type Comparison
- type Context
- type DictDisplay
- type DummyChunk
- type ElifChunk
- type ElifStatement
- type ElifToken
- type ElseToken
- type EndforToken
- type EndifToken
- type EndrawToken
- type Expr
- type ExprList
- type Factor
- type ForChunk
- type ForStatement
- type ForToken
- type IfChunk
- type IfStatement
- type IfToken
- type J2Filter
- type J2Test
- type KeyDatum
- type ListDisplay
- type ModFactor
- type NamedArgument
- type NotTest
- type OpArithExpr
- type OpExpr
- type OpTerm
- type OrTest
- type Power
- type PyCallable
- type PyType
- type RawChunk
- type RawToken
- type Renderable
- func ParseBlocks(tokens []Token, pos int, inside string) (int, []Renderable, error)
- func ParseElse(tokens []Token, pos int, in string) (int, []Renderable, error)
- func ParseFor(tokens []Token, pos int) (int, Renderable, error)
- func ParseIf(tokens []Token, pos int) (int, Renderable, error)
- func ParseRaw(tokens []Token, pos int) (int, Renderable, error)
- func ParseText(tokens []Token, pos int) (int, Renderable, error)
- func ParseVariable(tokens []Token, pos int) (int, Renderable, error)
- type Target
- type TargetList
- type Template
- type Term
- type Test
- type TestList
- type TextChunk
- type TextToken
- type Token
- type TokenBase
- type TokenBoundary
- type Trailer
- type TupleDisplay
- type VariableChunk
- type VariableStatement
- type VariableToken
- type VariableType
- func GoVarToPyVar(v interface{}) (VariableType, error)
- func MakeCall(call PyCallable, incoming_args []CallableArg, c *Context) (VariableType, error)
- func ProcessJ2Filters(val VariableType, filters []*J2Filter, c *Context) (VariableType, error)
- func ProcessJ2Test(val VariableType, test *J2Test, c *Context) (VariableType, error)
Constants ¶
This section is empty.
Variables ¶
var (
PythonLexer = lexer.Unquote(lexer.Must(lexer.Regexp(`(\s+)`+
`|(?P<Bool>[Tt]rue|[Ff]alse)`+
`|(?P<Ident>[a-zA-Z_][a-zA-Z0-9_]*)`+
`|(?P<String>'[^']*'|"[^"]*")`+
`|(?P<Operators>\||<>|==|!=|<=|>=|[-+*/%,.=<>])`+
`|(?P<Delimiters>[()\[\]{}:])`+
`|(?P<None>None)`+
`|(?P<Float>[-+]?\d*\.\d+([eE][-+]?\d+)?)`+
`|(?P<Int>[-+]?\d*)`+
`|(?P<Keyword>or|and|is|in|not|if|elif|else)`,
)), "String")
)
Functions ¶
func PrettyPrint ¶
func PrettyPrint(v interface{})
func PyTypeToString ¶
func VariableResToString ¶
func VariableResToString(res VariableType) (string, error)
Types ¶
type AndTest ¶
type AndTest struct {
Nots []*NotTest `@@ { "and" @@ }`
}
-------------------------------------------------------------------------------------------------
type AnonArgument ¶
type AnonArgument struct {
ArgValue *Expr `@@`
}
-------------------------------------------------------------------------------------------------
func (*AnonArgument) Eval ¶
func (self *AnonArgument) Eval(c *Context) (VariableType, error)
type ArgList ¶
type ArgList struct {
Arguments []*Argument `"(" [ @@ { "," @@ }[","] ] ")"`
}
-------------------------------------------------------------------------------------------------
type Argument ¶
type Argument struct {
//NamedArg *NamedArgument ` @@`
//AnonArg *AnonArgument `| @@`
AnonValue *Test `@@ |`
Name *string `( @Ident`
Value *Test `"=" @@ )`
}
-------------------------------------------------------------------------------------------------
type ArithExpr ¶
-------------------------------------------------------------------------------------------------
type Atom ¶
type Atom struct {
Name *string ` @Ident`
Str *string `| @String`
Float *float64 `| @Float`
Int *int64 `| @Int`
Bool *string `| @Bool`
None *string `| @None`
List *ListDisplay `| @@`
Dict *DictDisplay `| @@`
}
-------------------------------------------------------------------------------------------------
type AtomExpr ¶
-------------------------------------------------------------------------------------------------
type CallableArg ¶
type CallableArg struct {
Name string
Value VariableType
}
------------------------------------------------------------------------------------------------- The PyCallable describes:
- A method used to run something natively in go
- A mapping of python variable types. If set to a value other than PY_TYPE_UNDEFINED, this will become the default value when the call is made.
func CreateArgumentList ¶
func CreateArgumentList(a *ArgList, c *Context) ([]CallableArg, error)
type Comparison ¶
-------------------------------------------------------------------------------------------------
func (*Comparison) Eval ¶
func (self *Comparison) Eval(c *Context) (VariableType, error)
type Context ¶
type Context struct {
Variables map[string]VariableType
Filters map[string]PyCallable
Tests map[string]PyCallable
PyCalls map[string]PyCallable
}
func NewContext ¶
func (*Context) AddVariables ¶
func (*Context) LoadDefaultFilters ¶
func (self *Context) LoadDefaultFilters()
func (*Context) LoadDefaultTests ¶
func (self *Context) LoadDefaultTests()
type DictDisplay ¶
type DictDisplay struct {
Entries []*KeyDatum `"{" [ @@ {"," @@ }[","] ] "}"`
}
-------------------------------------------------------------------------------------------------
func (*DictDisplay) Eval ¶
func (self *DictDisplay) Eval(c *Context) (VariableType, error)
type DummyChunk ¶
type DummyChunk struct {
}
type ElifChunk ¶
type ElifChunk struct {
ElifAst *ElifStatement
ElifChunks []Renderable
}
type ElifStatement ¶
type ElifStatement struct {
Test *Test `"elif" @@`
}
-------------------------------------------------------------------------------------------------
func ParseElifStatement ¶
func ParseElifStatement(statement string) (*ElifStatement, error)
func (*ElifStatement) Eval ¶
func (self *ElifStatement) Eval(c *Context) (VariableType, error)
type EndforToken ¶
type EndforToken struct {
TokenBase
}
type EndifToken ¶
type EndifToken struct {
TokenBase
}
type EndrawToken ¶
type EndrawToken struct {
TokenBase
}
type Expr ¶
type Expr struct {
Lhs *ArithExpr `@@`
Rhs []*OpArithExpr `{ @@ }`
}
-------------------------------------------------------------------------------------------------
type ExprList ¶
type ExprList struct {
Exprs []*Expr `@@ {"," @@ }[","]`
}
-------------------------------------------------------------------------------------------------
type Factor ¶
-------------------------------------------------------------------------------------------------
type ForChunk ¶
type ForChunk struct {
ForAst *ForStatement
IfAst *IfStatement
Chunks []Renderable
ElseChunks []Renderable
}
type ForStatement ¶
type ForStatement struct {
TargetList *TargetList `"for" @@ `
TestList *TestList `"in" @@`
IfStatement *IfStatement `[ @@ ]`
Recursive bool `[@"recursive"]`
}
-------------------------------------------------------------------------------------------------
func ParseForStatement ¶
func ParseForStatement(statement string) (*ForStatement, error)
type IfChunk ¶
type IfChunk struct {
IfAst *IfStatement
IfChunks []Renderable
ElifChunks []ElifChunk
ElseChunks []Renderable
}
type IfStatement ¶
type IfStatement struct {
Test *Test `"if" @@`
}
-------------------------------------------------------------------------------------------------
func ParseIfStatement ¶
func ParseIfStatement(statement string) (*IfStatement, error)
func (*IfStatement) Eval ¶
func (self *IfStatement) Eval(c *Context) (VariableType, error)
type J2Filter ¶
-------------------------------------------------------------------------------------------------
type KeyDatum ¶
-------------------------------------------------------------------------------------------------
type ListDisplay ¶
type ListDisplay struct {
Items []*Expr `"[" [ @@ {"," @@ }[","] ] "]"`
}
-------------------------------------------------------------------------------------------------
func (*ListDisplay) Eval ¶
func (self *ListDisplay) Eval(c *Context) (VariableType, error)
type ModFactor ¶
-------------------------------------------------------------------------------------------------
type NamedArgument ¶
-------------------------------------------------------------------------------------------------
func (*NamedArgument) Eval ¶
func (self *NamedArgument) Eval(c *Context) (VariableType, error)
type NotTest ¶
type NotTest struct {
Negated *NotTest `"not" @@`
Comparison *Comparison `| @@`
}
-------------------------------------------------------------------------------------------------
type OpArithExpr ¶
-------------------------------------------------------------------------------------------------
func (*OpArithExpr) Eval ¶
func (self *OpArithExpr) Eval(c *Context) (VariableType, error)
type OpExpr ¶
type OpExpr struct {
Op *string `@("<"|">"|"=="|">="|"<="|"<>"|"!="|"in"|"is"|"not" "in"|"is" "not")`
ArithExpr *ArithExpr `@@`
}
-------------------------------------------------------------------------------------------------
type OpTerm ¶
-------------------------------------------------------------------------------------------------
type OrTest ¶
type OrTest struct {
Ands []*AndTest `@@ { "or" @@ }`
}
-------------------------------------------------------------------------------------------------
type Power ¶
type Power struct {
AtomExpr *AtomExpr `@@`
Factor *Factor `[ "**" @@ ]`
Filters []*J2Filter `{ "|" @@ }`
Test *J2Test `[ @@ ]`
}
-------------------------------------------------------------------------------------------------
type PyCallable ¶
type PyCallable struct {
Method func([]VariableType) (VariableType, error)
Args []CallableArg
}
type Renderable ¶
func ParseBlocks ¶
func ParseVariable ¶
func ParseVariable(tokens []Token, pos int) (int, Renderable, error)
type Target ¶
type Target struct {
Name *string `@Ident`
}
-------------------------------------------------------------------------------------------------
type TargetList ¶
type TargetList struct {
Targets []*Target ` @@ { "," @@ }[","] `
}
-------------------------------------------------------------------------------------------------
type Term ¶
type Term struct {
Factor *Factor `@@`
}
-------------------------------------------------------------------------------------------------
type Test ¶
type Test struct {
Or *OrTest ` @@ `
}
-------------------------------------------------------------------------------------------------
type TestList ¶
type TestList struct {
Tests []*Test `@@ { "," @@ }[","]`
}
-------------------------------------------------------------------------------------------------
type TokenBoundary ¶
func FindTokenBoundaries ¶
func FindTokenBoundaries(input string) []TokenBoundary
type Trailer ¶
-------------------------------------------------------------------------------------------------
type TupleDisplay ¶
type TupleDisplay struct {
Items []*Expr `"(" @@ {"," @@ }[","] ")"`
}
-------------------------------------------------------------------------------------------------
type VariableChunk ¶
type VariableChunk struct {
VarAst *VariableStatement
}
type VariableStatement ¶
type VariableStatement struct {
Test *Test `@@`
}
-------------------------------------------------------------------------------------------------
func ParseVariableStatement ¶
func ParseVariableStatement(statement string) (*VariableStatement, error)
func (*VariableStatement) Eval ¶
func (self *VariableStatement) Eval(c *Context) (VariableType, error)
type VariableToken ¶
type VariableType ¶
type VariableType struct {
Type PyType
Data interface{}
}
func GoVarToPyVar ¶
func GoVarToPyVar(v interface{}) (VariableType, error)
func MakeCall ¶
func MakeCall(call PyCallable, incoming_args []CallableArg, c *Context) (VariableType, error)
func ProcessJ2Filters ¶
func ProcessJ2Filters(val VariableType, filters []*J2Filter, c *Context) (VariableType, error)
func ProcessJ2Test ¶
func ProcessJ2Test(val VariableType, test *J2Test, c *Context) (VariableType, error)
-------------------------------------------------------------------------------------------------
func (*VariableType) AsBool ¶
func (self *VariableType) AsBool() (bool, error)
func (*VariableType) AsFloat ¶
func (self *VariableType) AsFloat() (float64, error)
func (*VariableType) AsInt ¶
func (self *VariableType) AsInt() (int64, error)
func (*VariableType) AsString ¶
func (self *VariableType) AsString() (string, error)