ast

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 7 Imported by: 3

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 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

	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 ListInitExpr

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

func (*ListInitExpr) IsExpr

func (e *ListInitExpr) IsExpr() bool

func (*ListInitExpr) String

func (e *ListInitExpr) String() string

type MapInitExpr

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

func (*MapInitExpr) IsExpr

func (e *MapInitExpr) IsExpr() bool

func (*MapInitExpr) String

func (e *MapInitExpr) 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

	// expr
	Identifier *Identifier

	StringLiteral  *StringLiteral
	IntegerLiteral *IntegerLiteral
	FloatLiteral   *FloatLiteral
	BoolLiteral    *BoolLiteral
	NilLiteral     *NilLiteral

	ListInitExpr *ListInitExpr
	MapInitExpr  *MapInitExpr

	ParenExpr *ParenExpr

	AttrExpr  *AttrExpr
	IndexExpr *IndexExpr
	InExpr    *InExpr

	UnaryExpr       *UnaryExpr
	ArithmeticExpr  *ArithmeticExpr
	ConditionalExpr *ConditionalExpr
	AssignmentExpr  *AssignmentExpr

	CallExpr *CallExpr

	// stmt
	BlockStmt *BlockStmt

	IfelseStmt   *IfelseStmt
	ForStmt      *ForStmt
	ForInStmt    *ForInStmt
	ContinueStmt *ContinueStmt
	BreakStmt    *BreakStmt
}

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 *ListInitExpr) *Node

func WrapMapInitExpr

func WrapMapInitExpr(node *MapInitExpr) *Node

func WrapNilLiteral

func WrapNilLiteral(node *NilLiteral) *Node

func WrapParenExpr

func WrapParenExpr(node *ParenExpr) *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) StartPos

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

func (*Node) String

func (node *Node) String() string

type NodeType

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

	TypeIdentifier
	TypeStringLiteral
	TypeIntegerLiteral
	TypeFloatLiteral
	TypeBoolLiteral
	TypeNilLiteral

	TypeListInitExpr
	TypeMapInitExpr
	TypeInExpr

	TypeParenExpr

	TypeAttrExpr
	TypeIndexExpr

	TypeUnaryExpr
	TypeArithmeticExpr
	TypeConditionalExpr
	TypeAssignmentExpr

	TypeCallExpr

	// 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 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