Documentation
¶
Overview ¶
Package xxscript provides a simple scripting language for XxSql.
Package xxscript provides a simple scripting language for XxSql.
Package xxscript provides a simple scripting language for XxSql.
Index ¶
- type ArrayExpr
- type AssignExpr
- type BinaryExpr
- type BlockStmt
- type BoolExpr
- type BreakStmt
- type CallExpr
- type Callable
- type Context
- type ContinueStmt
- type DBExecFunc
- type DBObject
- type DBQueryFunc
- type DBQueryRowFunc
- type ErrorValue
- type ExprStmt
- type Expression
- type ForStmt
- type FuncStmt
- type HTTPBodyFunc
- type HTTPBodyJSONFunc
- type HTTPCookieFunc
- type HTTPHeaderFunc
- type HTTPJSONFunc
- type HTTPObject
- type HTTPParamFunc
- type HTTPRedirectFunc
- type HTTPSetCookieFunc
- type HTTPSetHeaderFunc
- type HTTPStatusFunc
- type HTTPWriteFunc
- type IdentExpr
- type IfStmt
- type IndexExpr
- type Interpreter
- type Lexer
- type MapExpr
- type MemberExpr
- type Node
- type NullExpr
- type NumberExpr
- type Parser
- type Program
- type ReturnStmt
- type SQLExecutor
- type Statement
- type StringExpr
- type ThrowError
- type ThrowStmt
- type Token
- type TokenType
- type TryStmt
- type UnaryExpr
- type UserFunc
- type Value
- type ValueObject
- type VarStmt
- type WhileStmt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayExpr ¶
type ArrayExpr struct {
Elements []Expression
}
ArrayExpr represents an array literal.
type AssignExpr ¶
type AssignExpr struct {
Left Expression
Value Expression
}
AssignExpr represents an assignment expression.
func (*AssignExpr) String ¶
func (e *AssignExpr) String() string
type BinaryExpr ¶
type BinaryExpr struct {
Left Expression
Op TokenType
Right Expression
}
BinaryExpr represents a binary expression.
func (*BinaryExpr) String ¶
func (e *BinaryExpr) String() string
type BlockStmt ¶
type BlockStmt struct {
Statements []Statement
}
BlockStmt represents a block of statements.
type CallExpr ¶
type CallExpr struct {
Func Expression
Args []Expression
}
CallExpr represents a function call.
type Context ¶
type Context struct {
Variables map[string]Value
Functions map[string]*UserFunc
Executor SQLExecutor
Engine *storage.Engine
HTTPWriter http.ResponseWriter
HTTPRequest *http.Request
MaxSteps int
BaseDir string // Base directory for file operations
Timezone *time.Location
// contains filtered or unexported fields
}
Context provides the execution context.
func (*Context) SetupBuiltins ¶
func (ctx *Context) SetupBuiltins()
SetupBuiltins sets up built-in objects.
type ContinueStmt ¶
type ContinueStmt struct{}
ContinueStmt represents a continue statement.
func (*ContinueStmt) String ¶
func (s *ContinueStmt) String() string
type DBExecFunc ¶
type DBExecFunc struct {
// contains filtered or unexported fields
}
DBExecFunc executes a statement.
type DBObject ¶
type DBObject struct {
// contains filtered or unexported fields
}
DBObject provides database-related methods.
type DBQueryFunc ¶
type DBQueryFunc struct {
// contains filtered or unexported fields
}
DBQueryFunc executes a query and returns results.
type DBQueryRowFunc ¶
type DBQueryRowFunc struct {
// contains filtered or unexported fields
}
DBQueryRowFunc executes a query and returns a single row.
type ErrorValue ¶ added in v0.0.7
ErrorValue is a special type for error values
type ExprStmt ¶
type ExprStmt struct {
Expr Expression
}
ExprStmt represents an expression statement.
type Expression ¶
type Expression interface {
Node
// contains filtered or unexported methods
}
Expression represents an expression.
type ForStmt ¶
type ForStmt struct {
Init Statement
Condition Expression
Update Statement
Body *BlockStmt
}
ForStmt represents a for loop.
type HTTPBodyFunc ¶
type HTTPBodyFunc struct {
// contains filtered or unexported fields
}
HTTPBodyFunc reads the request body.
type HTTPBodyJSONFunc ¶
type HTTPBodyJSONFunc struct {
// contains filtered or unexported fields
}
HTTPBodyJSONFunc parses the request body as JSON.
type HTTPCookieFunc ¶
type HTTPCookieFunc struct {
// contains filtered or unexported fields
}
HTTPCookieFunc gets a cookie value.
type HTTPHeaderFunc ¶
type HTTPHeaderFunc struct {
// contains filtered or unexported fields
}
HTTPHeaderFunc gets a header value.
type HTTPJSONFunc ¶
type HTTPJSONFunc struct {
// contains filtered or unexported fields
}
HTTPJSONFunc writes JSON response.
type HTTPObject ¶
type HTTPObject struct {
// contains filtered or unexported fields
}
HTTPObject provides HTTP-related methods.
func NewHTTPObject ¶
func NewHTTPObject(ctx *Context) *HTTPObject
NewHTTPObject creates a new HTTP object.
type HTTPParamFunc ¶
type HTTPParamFunc struct {
// contains filtered or unexported fields
}
HTTPParamFunc gets a query parameter.
type HTTPRedirectFunc ¶
type HTTPRedirectFunc struct {
// contains filtered or unexported fields
}
HTTPRedirectFunc redirects the client.
type HTTPSetCookieFunc ¶
type HTTPSetCookieFunc struct {
// contains filtered or unexported fields
}
HTTPSetCookieFunc sets a cookie.
type HTTPSetHeaderFunc ¶
type HTTPSetHeaderFunc struct {
// contains filtered or unexported fields
}
HTTPSetHeaderFunc sets a response header.
type HTTPStatusFunc ¶
type HTTPStatusFunc struct {
// contains filtered or unexported fields
}
HTTPStatusFunc sets the HTTP status code.
type HTTPWriteFunc ¶
type HTTPWriteFunc struct {
// contains filtered or unexported fields
}
HTTPWriteFunc writes to the response.
type IfStmt ¶
type IfStmt struct {
Condition Expression
Then *BlockStmt
Else Statement // can be *BlockStmt or *IfStmt
}
IfStmt represents an if statement.
type IndexExpr ¶
type IndexExpr struct {
Object Expression
Index Expression
}
IndexExpr represents an index access (arr[index]).
type Interpreter ¶
type Interpreter struct {
// contains filtered or unexported fields
}
Interpreter interprets XxScript AST.
func NewInterpreter ¶
func NewInterpreter(ctx *Context) *Interpreter
NewInterpreter creates a new interpreter.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer tokenizes XxScript source code.
type MapExpr ¶
type MapExpr struct {
Pairs map[string]Expression
}
MapExpr represents a map/object literal.
type MemberExpr ¶
type MemberExpr struct {
Object Expression
Member Expression
}
MemberExpr represents a member access (obj.field or obj["field"]).
func (*MemberExpr) String ¶
func (e *MemberExpr) String() string
type Node ¶
type Node interface {
String() string
// contains filtered or unexported methods
}
Node represents an AST node.
type NumberExpr ¶
type NumberExpr struct {
Value float64
}
NumberExpr represents a number literal.
func (*NumberExpr) String ¶
func (e *NumberExpr) String() string
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses XxScript source code.
type Program ¶
type Program struct {
Statements []Statement
}
Program represents a complete script.
type ReturnStmt ¶
type ReturnStmt struct {
Value Expression
}
ReturnStmt represents a return statement.
func (*ReturnStmt) String ¶
func (s *ReturnStmt) String() string
type SQLExecutor ¶ added in v0.0.6
SQLExecutor is an interface for executing SQL queries. This interface breaks the circular dependency between xxscript and executor packages.
type Statement ¶
type Statement interface {
Node
// contains filtered or unexported methods
}
Statement represents a statement.
type StringExpr ¶
type StringExpr struct {
Value string
}
StringExpr represents a string literal.
func (*StringExpr) String ¶
func (e *StringExpr) String() string
type ThrowError ¶
type ThrowError struct {
Value Value
}
ThrowError represents an error thrown by the throw statement.
func (*ThrowError) Error ¶
func (e *ThrowError) Error() string
type TokenType ¶
type TokenType int
TokenType represents a token type.
const ( TokEOF TokenType = iota TokError TokComment // Literals TokIdent // identifier TokString // "string" or 'string' TokNumber // 123 or 123.45 TokBool // true or false TokNull // null // Keywords TokVar // var TokIf // if TokElse // else TokFor // for TokWhile // while TokFunc // func TokReturn // return TokBreak // break TokContinue // continue TokTry // try TokCatch // catch TokThrow // throw // Operators TokPlus // + TokMinus // - TokStar // * TokSlash // / TokPercent // % TokEq // == TokNe // != TokLt // < TokLe // <= TokGt // > TokGe // >= TokAnd // && TokOr // || TokNot // ! TokAssign // = // Delimiters TokLParen // ( TokRParen // ) TokLBrace // { TokRBrace // } TokLBracket // [ TokRBracket // ] TokComma // , TokSemicolon // ; TokDot // . TokColon // : )
type TryStmt ¶
type TryStmt struct {
TryBlock *BlockStmt
CatchVar string // variable name for caught error
CatchBlock *BlockStmt
}
TryStmt represents a try-catch statement.
type UnaryExpr ¶
type UnaryExpr struct {
Op TokenType
Expr Expression
}
UnaryExpr represents a unary expression.
type ValueObject ¶
ValueObject interface for objects with members
type VarStmt ¶
type VarStmt struct {
Name string
Value Expression
}
VarStmt represents a variable declaration.