119 lines
1.6 KiB
Go
119 lines
1.6 KiB
Go
package internal
|
|
|
|
type Node interface {
|
|
nodeType() string
|
|
}
|
|
|
|
type Pos struct {
|
|
Line int
|
|
Col int
|
|
}
|
|
|
|
type TextNode struct {
|
|
Pos Pos
|
|
Text string
|
|
}
|
|
|
|
func (n *TextNode) nodeType() string { return "Text" }
|
|
|
|
type ParamNode struct {
|
|
Pos Pos
|
|
Name string
|
|
}
|
|
|
|
func (n *ParamNode) nodeType() string { return "Param" }
|
|
|
|
type RawNode struct {
|
|
Pos Pos
|
|
Name string
|
|
}
|
|
|
|
func (n *RawNode) nodeType() string { return "Raw" }
|
|
|
|
type IfNode struct {
|
|
Pos Pos
|
|
Cond *Expr
|
|
Body []Node
|
|
Else []Node
|
|
ElseIf []*ElseIfBranch
|
|
}
|
|
|
|
func (n *IfNode) nodeType() string { return "If" }
|
|
|
|
type ElseIfBranch struct {
|
|
Pos Pos
|
|
Cond *Expr
|
|
Body []Node
|
|
}
|
|
|
|
type ForNode struct {
|
|
Pos Pos
|
|
KeyVar string
|
|
ValVar string
|
|
List *Expr
|
|
Body []Node
|
|
}
|
|
|
|
func (n *ForNode) nodeType() string { return "For" }
|
|
|
|
type BlockNode struct {
|
|
Pos Pos
|
|
Name string
|
|
Body []Node
|
|
}
|
|
|
|
func (n *BlockNode) nodeType() string { return "Block" }
|
|
|
|
type IncludeNode struct {
|
|
Pos Pos
|
|
Path string
|
|
}
|
|
|
|
func (n *IncludeNode) nodeType() string { return "Include" }
|
|
|
|
type NamespaceNode struct {
|
|
Pos Pos
|
|
Name string
|
|
}
|
|
|
|
func (n *NamespaceNode) nodeType() string { return "Namespace" }
|
|
|
|
type CommentNode struct {
|
|
Pos Pos
|
|
Text string
|
|
}
|
|
|
|
func (n *CommentNode) nodeType() string { return "Comment" }
|
|
|
|
type UseNode struct {
|
|
Pos Pos
|
|
Name string
|
|
}
|
|
|
|
func (n *UseNode) nodeType() string { return "Use" }
|
|
|
|
type ExprType int
|
|
|
|
const (
|
|
ExprLiteral ExprType = iota
|
|
ExprVariable
|
|
ExprBinary
|
|
ExprUnary
|
|
ExprFuncCall
|
|
ExprNil
|
|
)
|
|
|
|
type Expr struct {
|
|
Pos Pos
|
|
ExprType ExprType
|
|
Name string
|
|
Value any
|
|
Left *Expr
|
|
Op string
|
|
Right *Expr
|
|
UnaryOp string
|
|
Operand *Expr
|
|
FuncName string
|
|
FuncArgs []*Expr
|
|
}
|