ast

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package ast pipeline ast node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NodeStartPos added in v0.1.0

func NodeStartPos(node *Node) token.Pos

Types

type ArithmeticExpr

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

func (*ArithmeticExpr) IsExpr

func (e *ArithmeticExpr) IsExpr() bool

func (*ArithmeticExpr) String

func (e *ArithmeticExpr) String() string

type AssignmentExpr

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

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.Pos
}

func (*AttrExpr) IsExpr

func (e *AttrExpr) IsExpr() bool

func (*AttrExpr) String

func (e *AttrExpr) String() string

type BlockStmt added in v0.1.0

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

func (*BlockStmt) String added in v0.1.0

func (block *BlockStmt) String() string

type BoolLiteral

type BoolLiteral struct {
	Val   bool
	Start token.Pos
}

func (*BoolLiteral) String

func (e *BoolLiteral) String() string

type BreakStmt

type BreakStmt struct {
	Start token.Pos
}

func (*BreakStmt) String

func (e *BreakStmt) String() string

type CallExpr

type CallExpr struct {

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

	LParen token.Pos
	RParen token.Pos

	Name string

	Param []*Node

	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.Pos
}

func (*ConditionalExpr) IsExpr

func (e *ConditionalExpr) IsExpr() bool

func (*ConditionalExpr) String

func (e *ConditionalExpr) String() string

type ContinueStmt

type ContinueStmt struct {
	Start token.Pos
}

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 added in v0.1.0

type FloatLiteral struct {
	Val   float64
	Start token.Pos
}

func (*FloatLiteral) IsExpr added in v0.1.0

func (e *FloatLiteral) IsExpr() bool

func (*FloatLiteral) String added in v0.1.0

func (e *FloatLiteral) String() string

type ForInStmt

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

	ForPos token.Pos
	InPos  token.Pos
}

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.Pos
}

func (*ForStmt) String

func (e *ForStmt) String() string

type FuncArgList

type FuncArgList []*Node

type Identifier

type Identifier struct {
	Name  string
	Start token.Pos
}

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.Pos
}

func (*IfStmtElem) String

func (e *IfStmtElem) String() string

type IfelseStmt

type IfelseStmt struct {
	IfList IfList
	Else   *BlockStmt

	ElsePos token.Pos
}

func (*IfelseStmt) IsExpr

func (e *IfelseStmt) IsExpr() bool

func (*IfelseStmt) String

func (e *IfelseStmt) String() string

type IndexExpr

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

func (*IndexExpr) IsExpr

func (e *IndexExpr) IsExpr() bool

func (*IndexExpr) String

func (e *IndexExpr) String() string

type IntegerLiteral added in v0.1.0

type IntegerLiteral struct {
	Val   int64
	Start token.Pos
}

func (*IntegerLiteral) IsExpr added in v0.1.0

func (e *IntegerLiteral) IsExpr() bool

func (*IntegerLiteral) String added in v0.1.0

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.Pos
	RBracket token.Pos
}

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.Pos
	RBrace      token.Pos
}

func (*MapInitExpr) IsExpr

func (e *MapInitExpr) IsExpr() bool

func (*MapInitExpr) String

func (e *MapInitExpr) String() string

type NilLiteral

type NilLiteral struct {
	Start token.Pos
}

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

	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 WrapAssignmentExpr

func WrapAssignmentExpr(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 added in v0.1.0

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 WrapIndexExpr

func WrapIndexExpr(node *IndexExpr) *Node

func WrapIntegerLiteral added in v0.1.0

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 WrapeBlockStmt added in v0.1.0

func WrapeBlockStmt(node *BlockStmt) *Node

func (*Node) StartPos added in v0.1.0

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

func (*Node) String

func (node *Node) String() string

type NodeType

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

	TypeIdentifier
	TypeStringLiteral
	TypeIntegerLiteral
	TypeFloatLiteral
	TypeBoolLiteral
	TypeNilLiteral

	TypeListInitExpr
	TypeMapInitExpr

	TypeParenExpr

	TypeAttrExpr
	TypeIndexExpr

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

	EQ Op = "="
)

type ParenExpr

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

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.Pos
}

func (*StringLiteral) IsExpr

func (e *StringLiteral) IsExpr() bool

func (*StringLiteral) String

func (e *StringLiteral) String() string

Jump to

Keyboard shortcuts

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