Documentation
¶
Overview ¶
Package model holds the shared data structures (AST, runtime values, class metadata) used by both the parser and the runner packages.
The split is deliberate: parser/ produces these structures from PHP source, runner/ consumes them. Neither package depends on the other; they only share model/.
Index ¶
- type Array
- type ArrayItem
- type ArrayItemValue
- type ArrayLit
- type Assign
- type AssignExpr
- type Binary
- type Break
- type Call
- type Cast
- type Catch
- type Class
- type ClassConst
- type ClassDecl
- type Closure
- type Continue
- type Echo
- type Expr
- type ExprStmt
- type Field
- type For
- type Foreach
- type Func
- type FuncDecl
- type If
- type Include
- type Index
- type InlineHTML
- type ListExpr
- type Lit
- type MethodCall
- type New
- type Node
- type Object
- type Param
- type Program
- type PropAccess
- type Return
- type Stmt
- type Switch
- type SwitchCase
- type Ternary
- type Throw
- type Try
- type Unary
- type Var
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array is PHP's ordered hash map. It preserves insertion order and allows both integer and string keys, so it doubles as list and dictionary.
type ArrayItemValue ¶
ArrayItemValue is a runtime (already-evaluated) array entry, the value-level counterpart of the ArrayItem AST node. The transpiled __array/__pair helpers produce these. Key is nil for list-style appends.
type ArrayLit ¶
type ArrayLit struct {
Items []ArrayItem
}
ArrayLit is `array(...)`, `[...]` or `{...}` (map/list literal).
type Assign ¶
Assign is `Target = Value`. Op may be "=", ".=", "+=", "[]=" (append). expr-lang cannot mutate, so assignment is handled entirely by the runner.
type AssignExpr ¶
AssignExpr is assignment used as an expression, e.g. the PHP idiom `if (($x = f()) !== false)`. The README forbids assignment in conditions, but minitpl relies on it, so it is supported with Var/Index/Prop targets. As a statement it is lowered to *Assign by the parser.
type Binary ¶
Binary is an infix operator. Op covers arithmetic (+ - * / %), string concat ("."), comparison (== != === !== < <= > >=) and logical (&& ||).
type Call ¶
Call is a free-function call: `name(args...)`.
Name is the primary (possibly namespace-qualified) function name. Fallback is the global-namespace name to try if Name is undefined — PHP resolves an unqualified call inside a namespace by first looking in the current namespace and then falling back to the global function of the same short name. Fallback is "" for calls that need no fallback (the common, non-namespaced case), in which case the call resolves as a bare env identifier exactly as before.
type Catch ¶
Catch is one `catch (...) { ... }` clause. Var is the bound variable name (without `$`); the caught error is assigned to it so `echo $e` prints it.
type Class ¶
type Class struct {
Name string
Fields []Field
Consts []Field // class constants (Name + value Expr)
Methods map[string]*FuncDecl
}
Class is the resolved, runnable form of a ClassDecl: field defaults plus a method table keyed by method name.
type ClassConst ¶
ClassConst is `Class::NAME` / `self::NAME` class-constant access.
type ClassDecl ¶
type ClassDecl struct {
Name string
Abstract bool
Fields []Field
Consts []Field // class constants (Name + value Expr), referenced as Class::NAME
Methods []*FuncDecl
}
ClassDecl is a trimmed-down class: fields + methods + class constants, no inheritance. Abstract is tolerated (parsed) but not enforced (README omits abstract classes; minitpl's Hook is abstract only to declare constants).
type Closure ¶
Closure is an anonymous function expression `function($a,$b){ ... }`. minitpl uses one as the usort() comparator. `use (...)` capture is not supported (the engine's closures capture nothing).
type Echo ¶
type Echo struct {
Args []Expr
}
Echo writes the evaluated arguments to the output buffer.
type Expr ¶
type Expr interface {
Node
// contains filtered or unexported methods
}
Expr is an expression: something that evaluates to a value. Expressions are the unit the runner transpiles into go-expr (expr-lang) source and evaluates through the embedded VM.
type ExprStmt ¶
type ExprStmt struct {
X Expr
}
ExprStmt is an expression evaluated for its side effects (e.g. a method call).
type For ¶
For is `for (Init; Cond; Post) { Body }`. `while` is parsed into a For with nil Init/Post.
type Func ¶
type Func struct {
Decl *FuncDecl
Go any // an arbitrary Go func, invoked via reflection by the runtime
}
Func is a callable value: either a user-defined PHP function (Decl set) or a host Go function (Go set). Registered host functions use Go.
type FuncDecl ¶
type FuncDecl struct {
Class string // "" for free functions
Name string
Params []Param
Body []Stmt
}
FuncDecl is a free function or a class method declared with the `function Class::method()` syntax described in the README.
type If ¶
type If struct {
Cond Expr
Then []Stmt
Else []Stmt // may itself contain a single nested *If for elseif chains
}
If is `if (Cond) { Then } elseif... else { Else }`.
type InlineHTML ¶
type InlineHTML struct {
Text string
}
InlineHTML is raw text outside of <?php ... ?> tags. It is emitted verbatim.
type ListExpr ¶
type ListExpr struct {
Elems []Expr
}
ListExpr is `list($a, $b, ...)`, valid only as an assignment target. Elements may be nil for skipped positions (`list(, $b)`).
type Lit ¶
type Lit struct {
Value any
}
Lit is a literal scalar: nil, bool, int64, float64 or string.
type MethodCall ¶
MethodCall is `Base->method(args...)` or `Base.method(args...)`.
type Node ¶
type Node interface {
// contains filtered or unexported methods
}
Node is the root interface for every AST element.
type Object ¶
Object is a class instance: a property bag plus a pointer back to its class. Because methods live on the Class (resolved by the runtime), an Object passed into expr-lang exposes its Props for `$obj->field` style access.
type Program ¶
type Program struct {
Stmts []Stmt
}
Program is the top-level result of parsing a single PHP file.
type PropAccess ¶
PropAccess is field access. The README allows both `$obj->field` and the new `obj.field` notation; both parse to this node.
type Return ¶
type Return struct {
Value Expr // may be nil
}
Return exits the current function with an optional value.
type Stmt ¶
type Stmt interface {
Node
// contains filtered or unexported methods
}
Stmt is a statement: something executed for its side effects (echo, control flow, assignment, declarations). Statements are interpreted directly by the runner because expr-lang has no concept of statements, loops or mutation.
type Switch ¶
type Switch struct {
Cond Expr
Cases []SwitchCase
Default []Stmt
}
Switch is `switch (Cond) { case V: ...; default: ... }`. Case bodies fall through unless they break (PHP semantics); the runner handles break/return.
type SwitchCase ¶
SwitchCase is one `case Value:` arm of a Switch.
type Throw ¶
type Throw struct {
X Expr
}
Throw raises an exception. The VM has no exception model; it surfaces as a runtime error (sufficient for minitpl's error-path `throw`s, which the happy compile path never hits).