ast

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 7 Imported by: 8

Documentation

Overview

Package ast pipeline ast node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodeStartPos

func NodeStartPos(node *Node) token.LnColPos

Types

type ArithmeticExpr

type ArithmeticExpr struct {
	Op       Op
	LHS, RHS *Node
	OpPos    token.LnColPos
}

func (*ArithmeticExpr) IsExpr

func (e *ArithmeticExpr) IsExpr() bool

func (*ArithmeticExpr) String

func (e *ArithmeticExpr) String() string

type AssignmentExpr

type AssignmentExpr struct {
	LHS, RHS *Node
	Op       Op
	OpPos    token.LnColPos
}

func (*AssignmentExpr) IsExpr

func (e *AssignmentExpr) IsExpr() bool

func (*AssignmentExpr) String

func (e *AssignmentExpr) String() string

type AstNode added in v0.3.0

type AstNode interface {
	String() string
}

type AttrExpr

type AttrExpr struct {
	Obj   *Node
	Attr  *Node
	Start token.LnColPos
}

func (*AttrExpr) IsExpr

func (e *AttrExpr) IsExpr() bool

func (*AttrExpr) String

func (e *AttrExpr) String() string

type BlockStmt

type BlockStmt struct {
	LBracePos token.LnColPos
	RBracePos token.LnColPos
	Stmts     Stmts
}

func (*BlockStmt) String

func (block *BlockStmt) String() string

type BoolLiteral

type BoolLiteral struct {
	Val   bool
	Start token.LnColPos
}

func (*BoolLiteral) String

func (e *BoolLiteral) String() string

type BreakStmt

type BreakStmt struct {
	Start token.LnColPos
}

func (*BreakStmt) String

func (e *BreakStmt) String() string

type CallExpr

type CallExpr struct {

	// temporary record function name location
	NamePos token.LnColPos // as 'Start' (token.FilePos)

	LParen token.LnColPos
	RParen token.LnColPos

	Name string

	Param           []*Node
	ParamNormalized []*Node

	PrivateData interface{}

	Grok *grok.GrokRegexp
	Re   *regexp.Regexp
}

func (*CallExpr) IsExpr

func (e *CallExpr) IsExpr() bool

func (*CallExpr) String

func (e *CallExpr) String() string

type ConditionalExpr

type ConditionalExpr struct {
	Op       Op
	LHS, RHS *Node
	OpPos    token.LnColPos
}

func (*ConditionalExpr) IsExpr

func (e *ConditionalExpr) IsExpr() bool

func (*ConditionalExpr) String

func (e *ConditionalExpr) String() string

type ContinueStmt

type ContinueStmt struct {
	Start token.LnColPos
}

func (*ContinueStmt) String

func (e *ContinueStmt) String() string

type DType

type DType uint
const (
	Invalid DType = iota

	Void // no return value

	Nil // nil

	Bool
	Int    // int64
	Float  // float64
	String // string

	List // []any

	// map[string]any (load json to string map or any array).
	Map
)

func DectDataType

func DectDataType(val any) (any, DType)

func (DType) String

func (t DType) String() string

type FloatLiteral

type FloatLiteral struct {
	Val   float64
	Start token.LnColPos
}

func (*FloatLiteral) IsExpr

func (e *FloatLiteral) IsExpr() bool

func (*FloatLiteral) String

func (e *FloatLiteral) String() string

type ForInStmt

type ForInStmt struct {
	Varb *Node
	Iter *Node
	Body *BlockStmt

	ForPos token.LnColPos
	InPos  token.LnColPos
}

func (*ForInStmt) String

func (e *ForInStmt) String() string

type ForStmt

type ForStmt struct {
	// init
	Init *Node

	// step1: -> step2 or break
	Cond *Node

	// step3: -> step1
	Loop *Node

	// step2: -> step3
	Body *BlockStmt

	ForPos token.LnColPos
}

func (*ForStmt) String

func (e *ForStmt) String() string

type FuncArgList

type FuncArgList []*Node

type Identifier

type Identifier struct {
	Name  string
	Start token.LnColPos
}

func (*Identifier) IsExpr

func (e *Identifier) IsExpr() bool

func (*Identifier) String

func (e *Identifier) String() string

type IfList

type IfList []*IfStmtElem

IfList index [0] is IF, [1..end] is ELIF.

func (IfList) String

func (e IfList) String() string

type IfStmtElem

type IfStmtElem struct {
	Condition *Node
	Block     *BlockStmt

	Start token.LnColPos
}

func (*IfStmtElem) String

func (e *IfStmtElem) String() string

type IfelseStmt

type IfelseStmt struct {
	IfList IfList
	Else   *BlockStmt

	ElsePos token.LnColPos
}

func (*IfelseStmt) IsExpr

func (e *IfelseStmt) IsExpr() bool

func (*IfelseStmt) String

func (e *IfelseStmt) String() string

type InExpr added in v0.2.5

type InExpr struct {
	Op       Op
	LHS, RHS *Node
	OpPos    token.LnColPos
}

func (*InExpr) IsExpr added in v0.2.5

func (e *InExpr) IsExpr() bool

func (*InExpr) String added in v0.2.5

func (e *InExpr) String() string

type IndexExpr

type IndexExpr struct {
	Obj      *Identifier
	Index    []*Node // int float string bool
	LBracket []token.LnColPos
	RBracket []token.LnColPos
}

func (*IndexExpr) IsExpr

func (e *IndexExpr) IsExpr() bool

func (*IndexExpr) String

func (e *IndexExpr) String() string

type IntegerLiteral

type IntegerLiteral struct {
	Val   int64
	Start token.LnColPos
}

func (*IntegerLiteral) IsExpr

func (e *IntegerLiteral) IsExpr() bool

func (*IntegerLiteral) String

func (e *IntegerLiteral) String() string

type KwArgs

type KwArgs map[string]*Node

func (KwArgs) String

func (e KwArgs) String() string

type ListLiteral added in v0.3.0

type ListLiteral struct {
	List     []*Node
	LBracket token.LnColPos
	RBracket token.LnColPos
}

func (*ListLiteral) IsExpr added in v0.3.0

func (e *ListLiteral) IsExpr() bool

func (*ListLiteral) String added in v0.3.0

func (e *ListLiteral) String() string

type MapLiteral added in v0.3.0

type MapLiteral struct {
	KeyValeList [][2]*Node // key,value list
	LBrace      token.LnColPos
	RBrace      token.LnColPos
}

func (*MapLiteral) IsExpr added in v0.3.0

func (e *MapLiteral) IsExpr() bool

func (*MapLiteral) String added in v0.3.0

func (e *MapLiteral) String() string

type NilLiteral

type NilLiteral struct {
	Start token.LnColPos
}

func (*NilLiteral) IsExpr

func (e *NilLiteral) IsExpr() bool

func (*NilLiteral) String

func (e *NilLiteral) String() string

type Node

type Node struct {
	// node type
	NodeType NodeType
	// contains filtered or unexported fields
}

func WrapArithmeticExpr

func WrapArithmeticExpr(node *ArithmeticExpr) *Node

func WrapAssignmentStmt added in v0.2.6

func WrapAssignmentStmt(node *AssignmentExpr) *Node

func WrapAttrExpr

func WrapAttrExpr(node *AttrExpr) *Node

func WrapBoolLiteral

func WrapBoolLiteral(node *BoolLiteral) *Node

func WrapBreakStmt

func WrapBreakStmt(node *BreakStmt) *Node

func WrapCallExpr

func WrapCallExpr(node *CallExpr) *Node

func WrapConditionExpr

func WrapConditionExpr(node *ConditionalExpr) *Node

func WrapContinueStmt

func WrapContinueStmt(node *ContinueStmt) *Node

func WrapFloatLiteral

func WrapFloatLiteral(node *FloatLiteral) *Node

func WrapForInStmt

func WrapForInStmt(node *ForInStmt) *Node

func WrapForStmt

func WrapForStmt(node *ForStmt) *Node

func WrapIdentifier

func WrapIdentifier(node *Identifier) *Node

func WrapIfelseStmt

func WrapIfelseStmt(node *IfelseStmt) *Node

func WrapInExpr added in v0.2.5

func WrapInExpr(node *InExpr) *Node

func WrapIndexExpr

func WrapIndexExpr(node *IndexExpr) *Node

func WrapIntegerLiteral

func WrapIntegerLiteral(node *IntegerLiteral) *Node

func WrapListInitExpr

func WrapListInitExpr(node *ListLiteral) *Node

func WrapMapLiteral added in v0.3.0

func WrapMapLiteral(node *MapLiteral) *Node

func WrapNilLiteral

func WrapNilLiteral(node *NilLiteral) *Node

func WrapParenExpr

func WrapParenExpr(node *ParenExpr) *Node

func WrapSliceExpr added in v0.3.0

func WrapSliceExpr(node *SliceExpr) *Node

func WrapStringLiteral

func WrapStringLiteral(node *StringLiteral) *Node

func WrapUnaryExpr added in v0.2.6

func WrapUnaryExpr(node *UnaryExpr) *Node

func WrapeBlockStmt

func WrapeBlockStmt(node *BlockStmt) *Node

func (*Node) ArithmeticExpr

func (n *Node) ArithmeticExpr() *ArithmeticExpr

func (*Node) AssignmentExpr

func (n *Node) AssignmentExpr() *AssignmentExpr

func (*Node) AttrExpr

func (n *Node) AttrExpr() *AttrExpr

func (*Node) BlockStmt

func (n *Node) BlockStmt() *BlockStmt

func (*Node) BoolLiteral

func (n *Node) BoolLiteral() *BoolLiteral

func (*Node) BreakStmt

func (n *Node) BreakStmt() *BreakStmt

func (*Node) CallExpr

func (n *Node) CallExpr() *CallExpr

func (*Node) ConditionalExpr

func (n *Node) ConditionalExpr() *ConditionalExpr

func (*Node) ContinueStmt

func (n *Node) ContinueStmt() *ContinueStmt

func (*Node) FloatLiteral

func (n *Node) FloatLiteral() *FloatLiteral

func (*Node) ForInStmt

func (n *Node) ForInStmt() *ForInStmt

func (*Node) ForStmt

func (n *Node) ForStmt() *ForStmt

func (*Node) Identifier

func (n *Node) Identifier() *Identifier

func (*Node) IfelseStmt

func (n *Node) IfelseStmt() *IfelseStmt

func (*Node) InExpr added in v0.2.5

func (n *Node) InExpr() *InExpr

func (*Node) IndexExpr

func (n *Node) IndexExpr() *IndexExpr

func (*Node) IntegerLiteral

func (n *Node) IntegerLiteral() *IntegerLiteral

func (*Node) ListLiteral added in v0.3.0

func (n *Node) ListLiteral() *ListLiteral

func (*Node) MapLiteral added in v0.3.0

func (n *Node) MapLiteral() *MapLiteral

func (*Node) NilLiteral

func (n *Node) NilLiteral() *NilLiteral

func (*Node) ParenExpr

func (n *Node) ParenExpr() *ParenExpr

func (*Node) SliceExpr added in v0.3.0

func (n *Node) SliceExpr() *SliceExpr

func (*Node) StartPos

func (n *Node) StartPos() token.LnColPos

func (*Node) String

func (n *Node) String() string

func (*Node) StringLiteral

func (n *Node) StringLiteral() *StringLiteral

func (*Node) UnaryExpr added in v0.2.6

func (n *Node) UnaryExpr() *UnaryExpr

type NodeType

type NodeType uint
const (
	// expr.
	TypeInvalid NodeType = iota

	TypeIdentifier
	TypeStringLiteral
	TypeIntegerLiteral
	TypeFloatLiteral
	TypeBoolLiteral
	TypeNilLiteral

	TypeListLiteral
	TypeMapLiteral

	TypeInExpr

	TypeParenExpr

	TypeAttrExpr
	TypeIndexExpr

	TypeUnaryExpr
	TypeArithmeticExpr
	TypeConditionalExpr
	TypeAssignmentExpr

	TypeCallExpr
	TypeSliceExpr

	// stmt.
	TypeBlockStmt
	TypeIfelseStmt
	TypeForStmt
	TypeForInStmt
	TypeContinueStmt
	TypeBreakStmt
)

func (NodeType) String

func (t NodeType) String() string

type Op

type Op string
const (
	ADD Op = "+"
	SUB Op = "-"
	MUL Op = "*"
	DIV Op = "/"
	MOD Op = "%"

	EQEQ Op = "=="
	NEQ  Op = "!="
	LTE  Op = "<="
	LT   Op = "<"
	GTE  Op = ">="
	GT   Op = ">"

	AND Op = "&&"
	OR  Op = "||"
	NOT Op = "!"

	EQ    Op = "="
	ADDEQ Op = "+="
	SUBEQ Op = "-="
	MULEQ Op = "*="
	DIVEQ Op = "/="
	MODEQ Op = "%="
)

type ParenExpr

type ParenExpr struct {
	Param  *Node
	LParen token.LnColPos
	RParen token.LnColPos
}

func (*ParenExpr) IsExpr

func (e *ParenExpr) IsExpr() bool

func (*ParenExpr) String

func (e *ParenExpr) String() string

type SliceExpr added in v0.3.0

type SliceExpr struct {
	Obj      *Node
	Start    *Node
	End      *Node
	Step     *Node
	Colon2   bool
	LBracket token.LnColPos
	RBracket token.LnColPos
}

func (*SliceExpr) IsExpr added in v0.3.0

func (e *SliceExpr) IsExpr() bool

func (*SliceExpr) String added in v0.3.0

func (e *SliceExpr) String() string

type Stmts

type Stmts []*Node

func (Stmts) String

func (e Stmts) String() string

type StringLiteral

type StringLiteral struct {
	Val   string
	Start token.LnColPos
}

func (*StringLiteral) IsExpr

func (e *StringLiteral) IsExpr() bool

func (*StringLiteral) String

func (e *StringLiteral) String() string

type UnaryExpr added in v0.2.6

type UnaryExpr struct {
	Op    Op
	RHS   *Node
	OpPos token.LnColPos
}

func (*UnaryExpr) IsExpr added in v0.2.6

func (e *UnaryExpr) IsExpr() bool

func (*UnaryExpr) String added in v0.2.6

func (e *UnaryExpr) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL