Documentation
¶
Index ¶
- Constants
- Variables
- func CombinedCode(basePath, filename string) (string, error)
- func Format(data []byte, contentFile string) string
- func P(keyword string, posContent FunnyContent) error
- func Typing(data interface{}) string
- type Assign
- type AstDescriptor
- type BinaryExpression
- type Block
- type Boolen
- type Break
- type BuiltinFunction
- type Comment
- type Continue
- type Expression
- type FORStatement
- type Field
- type Function
- type FunctionCall
- type FunnyContent
- type FunnyRuntimeError
- type IFStatement
- type ImportFunctionCall
- type Interpreter
- func (i *Interpreter) Assign(name string, val Value)
- func (i *Interpreter) AssignField(field *Field, val Value)
- func (i *Interpreter) Debug() bool
- func (i *Interpreter) EvalBlock(block Block) (Value, bool)
- func (i *Interpreter) EvalDevide(left, right Value) Value
- func (i *Interpreter) EvalDoubleEq(left, right Value) Value
- func (i *Interpreter) EvalEqual(left, right Value) Value
- func (i *Interpreter) EvalExpression(expression Expression) Value
- func (i *Interpreter) EvalField(item *Field) Value
- func (i *Interpreter) EvalForStatement(item *FORStatement) (Value, bool)
- func (i *Interpreter) EvalFunction(item Function, params []Value) (Value, bool)
- func (i *Interpreter) EvalFunctionCall(item *FunctionCall) (Value, bool)
- func (i *Interpreter) EvalGt(left, right Value) Value
- func (i *Interpreter) EvalGte(left, right Value) Value
- func (i *Interpreter) EvalIfStatement(item *IFStatement) (Value, bool)
- func (i *Interpreter) EvalLt(left, right Value) Value
- func (i *Interpreter) EvalLte(left, right Value) Value
- func (i *Interpreter) EvalMinus(left, right Value) Value
- func (i *Interpreter) EvalPlus(left, right Value) Value
- func (i *Interpreter) EvalStatement(item Statement) (Value, bool)
- func (i *Interpreter) EvalTimes(left, right Value) Value
- func (i *Interpreter) Lookup(name string) Value
- func (i *Interpreter) LookupDefault(name string, defaultVal Value) Value
- func (i *Interpreter) PopScope()
- func (i *Interpreter) PushScope(scope Scope)
- func (i *Interpreter) RegisterFunction(name string, fn BuiltinFunction) error
- func (i *Interpreter) Run(v interface{}) (Value, bool)
- func (i *Interpreter) RunFile(filename string) (Value, bool)
- type IterableExpression
- type Lexer
- func (l *Lexer) Consume(n int) rune
- func (l *Lexer) CreateToken(kind string) Token
- func (l *Lexer) LA(n int) rune
- func (l *Lexer) NewLine() Token
- func (l *Lexer) Next() Token
- func (l *Lexer) ReadComments() Token
- func (l *Lexer) ReadInt() Token
- func (l *Lexer) ReadString() Token
- func (l *Lexer) Reset()
- type List
- type ListAccess
- type Literal
- type NewLine
- type Parser
- func (p *Parser) Consume(kind string) Token
- func (p *Parser) Parse() Block
- func (p *Parser) ReadDict() Expression
- func (p *Parser) ReadExpression() Expression
- func (p *Parser) ReadFOR() Statement
- func (p *Parser) ReadField() Expression
- func (p *Parser) ReadFunction(name string) Statement
- func (p *Parser) ReadIF() Statement
- func (p *Parser) ReadList() Expression
- func (p *Parser) ReadStatement() Statement
- type Position
- type Program
- type Return
- type Scope
- type Statement
- type StringExpression
- type Token
- type Value
- func Assert(interpreter *Interpreter, args []Value) Value
- func Base64Decode(interpreter *Interpreter, args []Value) Value
- func Base64Encode(interpreter *Interpreter, args []Value) Value
- func Echo(interpreter *Interpreter, args []Value) Value
- func Echoln(interpreter *Interpreter, args []Value) Value
- func Env(interpreter *Interpreter, args []Value) Value
- func HttpRequest(interpreter *Interpreter, args []Value) Value
- func Int(interpreter *Interpreter, args []Value) Value
- func JwtDecode(interpreter *Interpreter, args []Value) Value
- func JwtEncode(interpreter *Interpreter, args []Value) Value
- func Len(interpreter *Interpreter, args []Value) Value
- func Max(interpreter *Interpreter, args []Value) Value
- func Md5(interpreter *Interpreter, args []Value) Value
- func Min(interpreter *Interpreter, args []Value) Value
- func Now(interpreter *Interpreter, args []Value) Value
- func SqlExec(interpreter *Interpreter, args []Value) Value
- func SqlQuery(interpreter *Interpreter, args []Value) Value
- func Str(interpreter *Interpreter, args []Value) Value
- func StrJoin(interpreter *Interpreter, args []Value) Value
- func StrSplit(interpreter *Interpreter, args []Value) Value
- func Typeof(interpreter *Interpreter, args []Value) Value
- func UUID(interpreter *Interpreter, args []Value) Value
- type Variable
Constants ¶
const ( STNewLine = "NewLine" STVariable = "Variable" STLiteral = "Literal" STBinaryExpression = "BinaryExpression" STAssign = "Assign" STBlock = "Block" STList = "List" STListAccess = "ListAccess" STFunction = "Function" STFunctionCall = "FunctionCall" STImportFunctionCall = "Import" STIfStatement = "IfStatement" STForStatement = "ForStatement" STIterableExpression = "IterableExpression" STBreak = "Break" STContinue = "Continue" STReturn = "Return" STField = "Field" STBoolean = "Boolean" STStringExpression = "StringExpression" STComment = "Comment" )
const ( LBrace = "{" RBrace = "}" LBracket = "[" RBracket = "]" LParenthese = "(" RParenthese = ")" EQ = "=" DOUBLE_EQ = "==" PLUS = "+" MINUS = "-" TIMES = "*" DEVIDE = "/" Quote = "\"" GT = ">" LT = "<" GTE = ">=" LTE = "<=" NOTEQ = "!=" COMMA = "," DOT = "." EOF = "EOF" INT = "INT" NAME = "NAME" STRING = "STRING" IF = "if" ELSE = "else" TRUE = "true" FALSE = "false" FOR = "for" AND = "and" IN = "in" NIL = "nil" NOT = "not" OR = "or" RETURN = "return" BREAK = "break" CONTINUE = "continue" NEW_LINE = "\\n" COMMENT = "comment" )
const (
// VERSION of funny
VERSION = "0.0.1"
)
Variables ¶
var BuiltinsDotFunny string
var ( // FUNCTIONS all builtin functions FUNCTIONS = map[string]BuiltinFunction{ "echo": Echo, "echoln": Echoln, "now": Now, "b64en": Base64Encode, "b64de": Base64Decode, "assert": Assert, "len": Len, "md5": Md5, "max": Max, "min": Min, "typeof": Typeof, "uuid": UUID, "httpreq": HttpRequest, "env": Env, "strjoin": StrJoin, "strsplit": StrSplit, "str": Str, "int": Int, "jwten": JwtEncode, "jwtde": JwtDecode, "sqlquery": SqlQuery, "sqlexec": SqlExec, } )
var Keywords = map[string]string{
"and": "and",
"else": "else",
"false": "false",
"for": "for",
"if": "if",
"in": "in",
"nil": "nil",
"not": "not",
"or": "or",
"return": "return",
"true": "true",
"break": "break",
"continue": "continue",
}
Functions ¶
func CombinedCode ¶
CombinedCode get combined code that using import
Types ¶
type Assign ¶
type Assign struct {
Target Expression
Value Expression
// contains filtered or unexported fields
}
Assign like a = 2
func (*Assign) Descriptor ¶
func (n *Assign) Descriptor() *AstDescriptor
type AstDescriptor ¶
type AstDescriptor struct {
Type string
Position Position
Name string
Text string
Children []*AstDescriptor
}
type BinaryExpression ¶
type BinaryExpression struct {
Left Expression
Operator Token
Right Expression
// contains filtered or unexported fields
}
BinaryExpression like a > 10
func (*BinaryExpression) Descriptor ¶
func (n *BinaryExpression) Descriptor() *AstDescriptor
func (*BinaryExpression) Position ¶
func (b *BinaryExpression) Position() Position
Position of BinaryExpression
func (*BinaryExpression) String ¶
func (b *BinaryExpression) String() string
func (*BinaryExpression) Type ¶
func (n *BinaryExpression) Type() string
type Block ¶
type Block []Statement
Block contains many statments
func (*Block) Descriptor ¶
func (b *Block) Descriptor() *AstDescriptor
type Boolen ¶
type Boolen struct {
Value bool
// contains filtered or unexported fields
}
Boolen like true, false
func (*Boolen) Descriptor ¶
func (n *Boolen) Descriptor() *AstDescriptor
type Break ¶
type Break struct {
// contains filtered or unexported fields
}
Break like break in for
func (*Break) Descriptor ¶
func (n *Break) Descriptor() *AstDescriptor
type BuiltinFunction ¶
type BuiltinFunction func(interpreter *Interpreter, args []Value) Value
BuiltinFunction function handler
type Comment ¶
type Comment struct {
Value string
// contains filtered or unexported fields
}
Comment line for sth
func (*Comment) Descriptor ¶
func (n *Comment) Descriptor() *AstDescriptor
type Continue ¶
type Continue struct {
// contains filtered or unexported fields
}
Continue like continue in for
func (*Continue) Descriptor ¶
func (n *Continue) Descriptor() *AstDescriptor
type Expression ¶
type Expression interface {
Position() Position
String() string
Type() string
Descriptor() *AstDescriptor
}
Expression abstract
type FORStatement ¶
type FORStatement struct {
Iterable IterableExpression
Block Block
CurrentIndex Variable
CurrentItem Expression
// contains filtered or unexported fields
}
FORStatement like for
func (*FORStatement) Descriptor ¶
func (n *FORStatement) Descriptor() *AstDescriptor
func (*FORStatement) String ¶
func (f *FORStatement) String() string
func (*FORStatement) Type ¶
func (i *FORStatement) Type() string
type Field ¶
type Field struct {
Variable Variable
Value Expression
// contains filtered or unexported fields
}
Field like obj.age
func (*Field) Descriptor ¶
func (n *Field) Descriptor() *AstDescriptor
type Function ¶
type Function struct {
Name string
Parameters []Expression
Body Block
// contains filtered or unexported fields
}
Function like test(a, b){}
func (*Function) Descriptor ¶
func (n *Function) Descriptor() *AstDescriptor
func (*Function) SignatureString ¶
type FunctionCall ¶
type FunctionCall struct {
Name string
Parameters []Expression
// contains filtered or unexported fields
}
FunctionCall like test(a, b)
func (*FunctionCall) Descriptor ¶
func (c *FunctionCall) Descriptor() *AstDescriptor
func (*FunctionCall) String ¶
func (c *FunctionCall) String() string
func (*FunctionCall) Type ¶
func (c *FunctionCall) Type() string
type FunnyContent ¶
type FunnyContent interface {
String() string
}
type FunnyRuntimeError ¶
type FunnyRuntimeError struct {
FunnyContent FunnyContent
Msg string
}
func (*FunnyRuntimeError) Error ¶
func (fre *FunnyRuntimeError) Error() string
type IFStatement ¶
type IFStatement struct {
Condition Expression
Body Block
Else Block
// contains filtered or unexported fields
}
IFStatement like if
func (*IFStatement) Descriptor ¶
func (i *IFStatement) Descriptor() *AstDescriptor
func (*IFStatement) String ¶
func (i *IFStatement) String() string
func (*IFStatement) Type ¶
func (i *IFStatement) Type() string
type ImportFunctionCall ¶
type ImportFunctionCall struct {
ModulePath string
Block *Block
// contains filtered or unexported fields
}
ImportFunctionCall like test(a, b)
func (*ImportFunctionCall) Descriptor ¶
func (c *ImportFunctionCall) Descriptor() *AstDescriptor
func (*ImportFunctionCall) Position ¶
func (c *ImportFunctionCall) Position() Position
Position of ImportFunctionCall
func (*ImportFunctionCall) String ¶
func (c *ImportFunctionCall) String() string
func (*ImportFunctionCall) Type ¶
func (c *ImportFunctionCall) Type() string
type Interpreter ¶
type Interpreter struct {
Vars []Scope
Functions map[string]BuiltinFunction
}
Interpreter the virtual machine of funny code
func NewInterpreterWithScope ¶
func NewInterpreterWithScope(vars Scope) *Interpreter
NewInterpreterWithScope create a new interpreter
func (*Interpreter) Assign ¶
func (i *Interpreter) Assign(name string, val Value)
Assign assign one variable
func (*Interpreter) AssignField ¶
func (i *Interpreter) AssignField(field *Field, val Value)
AssignField assign one field value
func (*Interpreter) EvalBlock ¶
func (i *Interpreter) EvalBlock(block Block) (Value, bool)
EvalBlock eval a block
func (*Interpreter) EvalDevide ¶
func (i *Interpreter) EvalDevide(left, right Value) Value
EvalDevide /
func (*Interpreter) EvalDoubleEq ¶
func (i *Interpreter) EvalDoubleEq(left, right Value) Value
EvalDoubleEq ==
func (*Interpreter) EvalEqual ¶
func (i *Interpreter) EvalEqual(left, right Value) Value
EvalEqual ==
func (*Interpreter) EvalExpression ¶
func (i *Interpreter) EvalExpression(expression Expression) Value
EvalExpression eval part that is expression
func (*Interpreter) EvalField ¶
func (i *Interpreter) EvalField(item *Field) Value
EvalField person.age
func (*Interpreter) EvalForStatement ¶
func (i *Interpreter) EvalForStatement(item *FORStatement) (Value, bool)
EvalForStatement eval for statement
func (*Interpreter) EvalFunction ¶
func (i *Interpreter) EvalFunction(item Function, params []Value) (Value, bool)
EvalFunction eval function
func (*Interpreter) EvalFunctionCall ¶
func (i *Interpreter) EvalFunctionCall(item *FunctionCall) (Value, bool)
EvalFunctionCall eval function call like test(a, b)
func (*Interpreter) EvalIfStatement ¶
func (i *Interpreter) EvalIfStatement(item *IFStatement) (Value, bool)
EvalIfStatement eval if statement
func (*Interpreter) EvalMinus ¶
func (i *Interpreter) EvalMinus(left, right Value) Value
EvalMinus -
func (*Interpreter) EvalStatement ¶
func (i *Interpreter) EvalStatement(item Statement) (Value, bool)
EvalStatement eval statement
func (*Interpreter) EvalTimes ¶
func (i *Interpreter) EvalTimes(left, right Value) Value
EvalTimes *
func (*Interpreter) Lookup ¶
func (i *Interpreter) Lookup(name string) Value
Lookup find one variable named name and get value
func (*Interpreter) LookupDefault ¶
func (i *Interpreter) LookupDefault(name string, defaultVal Value) Value
LookupDefault find one variable named name and get value, if not found, return default
func (*Interpreter) PushScope ¶
func (i *Interpreter) PushScope(scope Scope)
PushScope push scope into current
func (*Interpreter) RegisterFunction ¶
func (i *Interpreter) RegisterFunction(name string, fn BuiltinFunction) error
RegisterFunction register a builtin or customer function
func (*Interpreter) Run ¶
func (i *Interpreter) Run(v interface{}) (Value, bool)
Run the part of the code
type IterableExpression ¶
type IterableExpression struct {
Name Variable
Index int
Items []Expression
// contains filtered or unexported fields
}
IterableExpression like for in
func (*IterableExpression) Descriptor ¶
func (n *IterableExpression) Descriptor() *AstDescriptor
func (*IterableExpression) Next ¶
func (i *IterableExpression) Next() (int, Expression)
Next part of IterableExpression
func (*IterableExpression) Position ¶
func (i *IterableExpression) Position() Position
Position of IterableExpression
func (*IterableExpression) String ¶
func (i *IterableExpression) String() string
func (*IterableExpression) Type ¶
func (i *IterableExpression) Type() string
type Lexer ¶
type Lexer struct {
Offset int
CurrentPos Position
SaveOffset int
SavePos Position
Data []byte
Elements []Token
}
Lexer the lexer
func (*Lexer) CreateToken ¶
CreateToken create a new token and move position
type List ¶
type List struct {
Values []Expression
// contains filtered or unexported fields
}
List like [1, 2, 3]
func (*List) Descriptor ¶
func (n *List) Descriptor() *AstDescriptor
type ListAccess ¶
ListAccess like a[0]
func (*ListAccess) Descriptor ¶
func (n *ListAccess) Descriptor() *AstDescriptor
func (*ListAccess) String ¶
func (l *ListAccess) String() string
func (*ListAccess) Type ¶
func (l *ListAccess) Type() string
type Literal ¶
type Literal struct {
Value interface{}
// contains filtered or unexported fields
}
Literal like 1
func (*Literal) Descriptor ¶
func (n *Literal) Descriptor() *AstDescriptor
type NewLine ¶
type NewLine struct {
// contains filtered or unexported fields
}
NewLine @impl Statement \n
func (*NewLine) Descriptor ¶
func (n *NewLine) Descriptor() *AstDescriptor
type Parser ¶
Parser the parser
func (*Parser) ReadExpression ¶
func (p *Parser) ReadExpression() Expression
ReadExpression read next expression
func (*Parser) ReadFunction ¶
ReadFunction read function statement
func (*Parser) ReadStatement ¶
ReadStatement get next statement
type Return ¶
type Return struct {
Value Expression
// contains filtered or unexported fields
}
Return like return varA
func (*Return) Descriptor ¶
func (n *Return) Descriptor() *AstDescriptor
type Statement ¶
type Statement interface {
Position() Position
String() string
Type() string
Descriptor() *AstDescriptor
}
Statement abstract
type StringExpression ¶
type StringExpression struct {
Value string
// contains filtered or unexported fields
}
StringExpression like 'hello world !'
func (*StringExpression) Descriptor ¶
func (n *StringExpression) Descriptor() *AstDescriptor
func (*StringExpression) Position ¶
func (s *StringExpression) Position() Position
Position of StringExpression
func (*StringExpression) String ¶
func (s *StringExpression) String() string
func (*StringExpression) Type ¶
func (b *StringExpression) Type() string
type Value ¶
type Value interface {
}
Value one value of some like variable
func Assert ¶
func Assert(interpreter *Interpreter, args []Value) Value
Assert return the value that has been given
func Base64Decode ¶
func Base64Decode(interpreter *Interpreter, args []Value) Value
Base64Decode return base64 decoded string
func Base64Encode ¶
func Base64Encode(interpreter *Interpreter, args []Value) Value
Base64Encode return base64 encoded string
func Echo ¶
func Echo(interpreter *Interpreter, args []Value) Value
Echo builtin function echos one or every item in a array
func Echoln ¶
func Echoln(interpreter *Interpreter, args []Value) Value
Echoln builtin function echos one or every item in a array
func HttpRequest ¶
func HttpRequest(interpreter *Interpreter, args []Value) Value
HttpRequest builtin function for http request
func JwtDecode ¶
func JwtDecode(interpreter *Interpreter, args []Value) Value
JwtDecode jwtde(method, secret, token) string
func JwtEncode ¶
func JwtEncode(interpreter *Interpreter, args []Value) Value
JwtEncode jwten(method, secret, claims) string
func Len ¶
func Len(interpreter *Interpreter, args []Value) Value
Len return then length of the given list
func Max ¶
func Max(interpreter *Interpreter, args []Value) Value
Max return then length of the given list
func Md5 ¶
func Md5(interpreter *Interpreter, args []Value) Value
Md5 return then length of the given list
func Min ¶
func Min(interpreter *Interpreter, args []Value) Value
Min return then length of the given list
func Now ¶
func Now(interpreter *Interpreter, args []Value) Value
Now builtin function return now time
func SqlExec ¶
func SqlExec(interpreter *Interpreter, args []Value) Value
SqlExec sqlexec(connection, sqlRaw, args) string
func SqlQuery ¶
func SqlQuery(interpreter *Interpreter, args []Value) Value
SqlQuery sqlquery(connection, sqlRaw, args) string
func StrJoin ¶
func StrJoin(interpreter *Interpreter, args []Value) Value
StrJoin equal strings.Join
func StrSplit ¶
func StrSplit(interpreter *Interpreter, args []Value) Value
StrSplit equal strings.Split
func Typeof ¶
func Typeof(interpreter *Interpreter, args []Value) Value
Typeof builtin function echos one or every item in a array
func UUID ¶
func UUID(interpreter *Interpreter, args []Value) Value
UUID builtin function return a uuid string value
type Variable ¶
type Variable struct {
Name string
// contains filtered or unexported fields
}
Variable means var
func (*Variable) Descriptor ¶
func (n *Variable) Descriptor() *AstDescriptor