Documentation
¶
Index ¶
- Constants
- Variables
- func Format(data []byte, contentFile string) string
- func P(keyword string, pos Position) error
- func Typing(data interface{}) string
- type Assign
- type BinaryExpression
- type Block
- type Boolen
- type Break
- type BuiltinFunction
- type Comment
- type Continue
- type FORStatement
- type Field
- type Function
- type FunctionCall
- type Funny
- func (i *Funny) Assign(name string, val Value)
- func (i *Funny) AssignField(field *Field, val Value)
- func (i *Funny) Debug() bool
- func (i *Funny) EvalBlock(block *Block) (Value, bool)
- func (i *Funny) EvalDevide(left, right Value) Value
- func (i *Funny) EvalDoubleEq(left, right Value) Value
- func (i *Funny) EvalEqual(left, right Value) Value
- func (i *Funny) EvalExpression(expression Statement) Value
- func (i *Funny) EvalField(item *Field) Value
- func (i *Funny) EvalForStatement(item *FORStatement) (Value, bool)
- func (i *Funny) EvalFunction(item Function, params []Value) (Value, bool)
- func (i *Funny) EvalFunctionCall(item *FunctionCall) (Value, bool)
- func (i *Funny) EvalGt(left, right Value) Value
- func (i *Funny) EvalGte(left, right Value) Value
- func (i *Funny) EvalIfStatement(item *IFStatement) (Value, bool)
- func (i *Funny) EvalIn(leftValue Value, right Statement) Value
- func (i *Funny) EvalLt(left, right Value) Value
- func (i *Funny) EvalLte(left, right Value) Value
- func (i *Funny) EvalMinus(left, right Value) Value
- func (i *Funny) EvalPlus(left, right Value) Value
- func (i *Funny) EvalStatement(item Statement) (Value, bool)
- func (i *Funny) EvalTimes(left, right Value) Value
- func (i *Funny) Lookup(name string) Value
- func (i *Funny) LookupDefault(name string, defaultVal Value) Value
- func (i *Funny) PopScope()
- func (i *Funny) PushScope(scope Scope)
- func (i *Funny) RegisterFunction(name string, fn BuiltinFunction) error
- func (i *Funny) Run(v interface{}) (Value, bool)
- func (i *Funny) RunFile(filename string) (Value, bool)
- type FunnyRuntimeError
- type IFStatement
- type ImportFunctionCall
- 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 *Block, err error)
- func (p *Parser) ReadDict() Statement
- func (p *Parser) ReadExpression() Statement
- func (p *Parser) ReadFOR() Statement
- func (p *Parser) ReadField() Statement
- func (p *Parser) ReadFunction(name string) Statement
- func (p *Parser) ReadFunctionCall(name string) Statement
- func (p *Parser) ReadIF() Statement
- func (p *Parser) ReadList() Statement
- func (p *Parser) ReadStatement() Statement
- type Position
- type Program
- type Return
- type Scope
- type Statement
- type StringExpression
- type SubExpression
- type Token
- type Value
- func Assert(fn *Funny, args []Value) Value
- func Base64Decode(fn *Funny, args []Value) Value
- func Base64Encode(fn *Funny, args []Value) Value
- func DumpRuntimes(fn *Funny, args []Value) Value
- func Echo(fn *Funny, args []Value) Value
- func Echoln(fn *Funny, args []Value) Value
- func Env(fn *Funny, args []Value) Value
- func FormatData(fn *Funny, args []Value) Value
- func HttpRequest(fn *Funny, args []Value) Value
- func Int(fn *Funny, args []Value) Value
- func JwtDecode(fn *Funny, args []Value) Value
- func JwtEncode(fn *Funny, args []Value) Value
- func Len(fn *Funny, args []Value) Value
- func Max(fn *Funny, args []Value) Value
- func Md5(fn *Funny, args []Value) Value
- func Min(fn *Funny, args []Value) Value
- func Now(fn *Funny, args []Value) Value
- func ReadJson(fn *Funny, args []Value) Value
- func ReadText(fn *Funny, args []Value) Value
- func RegexMapMatch(fn *Funny, args []Value) Value
- func RegexMapValue(fn *Funny, args []Value) Value
- func RegexMatch(fn *Funny, args []Value) Value
- func Sh(fn *Funny, args []Value) Value
- func SqlExec(fn *Funny, args []Value) Value
- func SqlExecFile(fn *Funny, args []Value) Value
- func SqlQuery(fn *Funny, args []Value) Value
- func Str(fn *Funny, args []Value) Value
- func StrJoin(fn *Funny, args []Value) Value
- func StrSplit(fn *Funny, args []Value) Value
- func Typeof(fn *Funny, args []Value) Value
- func UUID(fn *Funny, args []Value) Value
- func WriteJson(fn *Funny, args []Value) Value
- func WriteText(fn *Funny, args []Value) Value
- type Variable
Constants ¶
const ( STNewLine = "NewLine" STVariable = "Variable" STLiteral = "Literal" STBinaryExpression = "BinaryExpression" STSubExpression = "SubExpression" 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.2"
)
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, "sqlexecfile": SqlExecFile, "format": FormatData, "dumpruntimes": DumpRuntimes, "readtext": ReadText, "writetext": WriteText, "readjson": ReadJson, "writejson": WriteJson, "regexMatch": RegexMatch, "regexMapMatch": RegexMapMatch, "regexMapValue": RegexMapValue, "sh": Sh, } )
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 ¶
Types ¶
type BinaryExpression ¶
type BinaryExpression struct { Position Position Type string Left Statement Operator Token Right Statement }
BinaryExpression like a > 10
func (*BinaryExpression) GetPosition ¶ added in v0.2.0
func (l *BinaryExpression) GetPosition() Position
func (*BinaryExpression) String ¶
func (b *BinaryExpression) String() string
type Block ¶
Block contains many statments
func (*Block) EndPosition ¶ added in v0.2.0
func (*Block) GetPosition ¶ added in v0.2.0
Position of Block
type BuiltinFunction ¶
BuiltinFunction function handler
type FORStatement ¶
type FORStatement struct { Position Position Type string Iterable IterableExpression Block Block CurrentIndex Variable CurrentItem Statement }
FORStatement like for
func (*FORStatement) GetPosition ¶ added in v0.2.0
func (l *FORStatement) GetPosition() Position
func (*FORStatement) String ¶
func (f *FORStatement) String() string
type Function ¶
type Function struct { Position Position Type string Name string Parameters []Statement Body *Block }
Function like test(a, b){}
func (*Function) GetPosition ¶ added in v0.2.0
func (*Function) SignatureString ¶
type FunctionCall ¶
FunctionCall like test(a, b)
func (*FunctionCall) GetPosition ¶ added in v0.2.0
func (l *FunctionCall) GetPosition() Position
func (*FunctionCall) String ¶
func (c *FunctionCall) String() string
type Funny ¶ added in v0.2.1
type Funny struct { Vars []Scope Functions map[string]BuiltinFunction Current Position }
Funny the virtual machine of funny code
func NewFunnyWithScope ¶ added in v0.2.1
NewFunnyWithScope create a new funny
func (*Funny) AssignField ¶ added in v0.2.1
AssignField assign one field value
func (*Funny) EvalDevide ¶ added in v0.2.1
EvalDevide /
func (*Funny) EvalDoubleEq ¶ added in v0.2.1
EvalDoubleEq ==
func (*Funny) EvalExpression ¶ added in v0.2.1
EvalExpression eval part that is expression
func (*Funny) EvalForStatement ¶ added in v0.2.1
func (i *Funny) EvalForStatement(item *FORStatement) (Value, bool)
EvalForStatement eval for statement
func (*Funny) EvalFunction ¶ added in v0.2.1
EvalFunction eval function
func (*Funny) EvalFunctionCall ¶ added in v0.2.1
func (i *Funny) EvalFunctionCall(item *FunctionCall) (Value, bool)
EvalFunctionCall eval function call like test(a, b)
func (*Funny) EvalIfStatement ¶ added in v0.2.1
func (i *Funny) EvalIfStatement(item *IFStatement) (Value, bool)
EvalIfStatement eval if statement
func (*Funny) EvalStatement ¶ added in v0.2.1
EvalStatement eval statement
func (*Funny) LookupDefault ¶ added in v0.2.1
LookupDefault find one variable named name and get value, if not found, return default
func (*Funny) RegisterFunction ¶ added in v0.2.1
func (i *Funny) RegisterFunction(name string, fn BuiltinFunction) error
RegisterFunction register a builtin or customer function
type FunnyRuntimeError ¶
func (*FunnyRuntimeError) Error ¶
func (fre *FunnyRuntimeError) Error() string
type IFStatement ¶
type IFStatement struct { Position Position Type string Condition Statement Body *Block Else *Block ElseIf Statement }
IFStatement like if
func (*IFStatement) GetPosition ¶ added in v0.2.0
func (l *IFStatement) GetPosition() Position
func (*IFStatement) String ¶
func (i *IFStatement) String() string
type ImportFunctionCall ¶
ImportFunctionCall like test(a, b)
func (*ImportFunctionCall) GetPosition ¶ added in v0.2.0
func (l *ImportFunctionCall) GetPosition() Position
func (*ImportFunctionCall) String ¶
func (c *ImportFunctionCall) String() string
type IterableExpression ¶
type IterableExpression struct { Position Position Type string Name Variable Index int Items []Statement }
IterableExpression like for in
func (*IterableExpression) GetPosition ¶ added in v0.2.0
func (l *IterableExpression) GetPosition() Position
func (*IterableExpression) Next ¶
func (i *IterableExpression) Next() (int, Statement)
Next part of IterableExpression
func (*IterableExpression) String ¶
func (i *IterableExpression) String() string
type Lexer ¶
type Lexer struct { Offset int CurrentPos Position SaveOffset int SavePos Position Data []byte Elements []Token File string }
Lexer the lexer
func (*Lexer) CreateToken ¶
CreateToken create a new token and move position
type ListAccess ¶
ListAccess like a[0]
func (*ListAccess) GetPosition ¶ added in v0.2.0
func (l *ListAccess) GetPosition() Position
func (*ListAccess) String ¶
func (l *ListAccess) String() string
type NewLine ¶
NewLine @impl Statement \n
func (*NewLine) EndPosition ¶ added in v0.2.0
func (*NewLine) GetPosition ¶ added in v0.2.0
type Parser ¶
Parser the parser
func (*Parser) ReadExpression ¶
ReadExpression read next expression
func (*Parser) ReadFunction ¶
ReadFunction read function statement
func (*Parser) ReadFunctionCall ¶ added in v0.2.7
ReadFunctionCall read function statement
func (*Parser) ReadStatement ¶
ReadStatement get next statement
type StringExpression ¶
StringExpression like 'hello world !'
func (*StringExpression) GetPosition ¶ added in v0.2.0
func (l *StringExpression) GetPosition() Position
func (*StringExpression) String ¶
func (s *StringExpression) String() string
type SubExpression ¶ added in v0.2.7
SubExpression like a = a && (b * 3), and then '(b * 3)' is SubExpression
func (*SubExpression) GetPosition ¶ added in v0.2.7
func (l *SubExpression) GetPosition() Position
func (*SubExpression) String ¶ added in v0.2.7
func (b *SubExpression) String() string
type Value ¶
type Value interface { }
Value one value of some like variable
func Base64Decode ¶
Base64Decode return base64 decoded string
func Base64Encode ¶
Base64Encode return base64 encoded string
func DumpRuntimes ¶ added in v0.2.0
DumpRuntimes dumpruntimes()
func FormatData ¶ added in v0.2.0
FormatData format(data, formatStr) string
func HttpRequest ¶
HttpRequest builtin function for http request
func RegexMapMatch ¶ added in v0.2.6
RegexMapMatch regexMapMatch(regexMap, text)
func RegexMapValue ¶ added in v0.2.6
RegexMapValue regexMapValue(regexMap, text)
func RegexMatch ¶ added in v0.2.6
RegexMatch regexMatch(regex, text)
func SqlExecFile ¶ added in v0.2.0
SqlExecFile sqlexecfile(connection, file)