ast

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalChain

type AdditionalChain int

AdditionalChain is an Enum for additional chain context.

const (
	// Vanilla is a Type showing no additional chains.
	Vanilla AdditionalChain = iota
	// Lonely is a Type for `&` chain.
	Lonely
	// Thoughtful is a Type for `~` chain.
	Thoughtful
	// Strict is a Type for `=` chain.
	Strict
)

type ArgList

type ArgList struct {
	Args   []Expr
	Kwargs map[*Ident]Expr
}

ArgList is an ast element for argument list.

func ExprToArgList

func ExprToArgList(e Expr) *ArgList

ExprToArgList makes ArgList with the passed expression.

func KwargPairToArgList

func KwargPairToArgList(pair *KwargPair) *ArgList

KwargPairToArgList makes ArgList with the passed keyword argument.

func SelfIdentArgList

func SelfIdentArgList(src *Source) *ArgList

SelfIdentArgList returns ArgList only with identifier `self`.

func (*ArgList) AppendArg

func (al *ArgList) AppendArg(arg Expr) *ArgList

AppendArg appends a positional argument, then returns self.

func (*ArgList) AppendKwarg

func (al *ArgList) AppendKwarg(key *Ident, arg Expr) *ArgList

AppendKwarg appends a keyword argument and its value, then returns self.

func (*ArgList) PrependSelf

func (al *ArgList) PrependSelf(src *Source) *ArgList

PrependSelf prepends `self` ident to its arguments, then returns self.

func (*ArgList) String

func (al *ArgList) String() string

type ArrLiteral

type ArrLiteral struct {
	Token string
	Elems []Expr
	Src   *Source
}

ArrLiteral is an ast node for arr literal like `[1, 2]`.

func (*ArrLiteral) Source

func (al *ArrLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*ArrLiteral) String

func (al *ArrLiteral) String() string

func (*ArrLiteral) TokenLiteral

func (al *ArrLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type AssignExpr

type AssignExpr struct {
	Token string // ":="
	Left  *Ident
	Right Expr
	Src   *Source
}

AssignExpr is an ast node of assign expression like `a := 2`.

func (*AssignExpr) Source

func (ae *AssignExpr) Source() *Source

Source returns stacktrace information used for error massages.

func (*AssignExpr) String

func (ae *AssignExpr) String() string

func (*AssignExpr) TokenLiteral

func (ae *AssignExpr) TokenLiteral() string

TokenLiteral returns token given by lexer.

type CallExpr

type CallExpr interface {
	ChainToken() string
	ChainArg() Expr
	Expr
}

CallExpr is an ast node interface for chain expression.

type Chain

type Chain struct {
	Token      string
	Additional AdditionalChain
	Main       MainChain
	Arg        Expr
}

Chain is an ast element for chain like `.`.

func MakeChain

func MakeChain(addChain string, mainChain string, chainArg Expr) *Chain

MakeChain makes new Chain from main chain literal and additional chain literal.

func (*Chain) String

func (c *Chain) String() string

type DiamondLiteral

type DiamondLiteral struct {
	Token string
	Src   *Source
}

DiamondLiteral is an ast node for diamond literal `<>`.

func (*DiamondLiteral) Source

func (dl *DiamondLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*DiamondLiteral) String

func (dl *DiamondLiteral) String() string

func (*DiamondLiteral) TokenLiteral

func (dl *DiamondLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type EmbeddedStr

type EmbeddedStr struct {
	Token  string
	Former *FormerStrPiece
	Latter string
	Src    *Source
}

EmbeddedStr is an ast node of embedded string like `"value=#{1 + 1}"`.

func (*EmbeddedStr) Source

func (es *EmbeddedStr) Source() *Source

Source returns stacktrace information used for error massages.

func (*EmbeddedStr) String

func (es *EmbeddedStr) String() string

func (*EmbeddedStr) TokenLiteral

func (es *EmbeddedStr) TokenLiteral() string

TokenLiteral returns token given by lexer.

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr is an interface of ast expression node.

type ExprStmt

type ExprStmt struct {
	Token string
	Expr  Expr
	Src   *Source
}

ExprStmt is an ast node of statement which consists of just one expression.

func (*ExprStmt) Source

func (es *ExprStmt) Source() *Source

Source returns stacktrace information used for error massages.

func (*ExprStmt) String

func (es *ExprStmt) String() string

func (*ExprStmt) TokenLiteral

func (es *ExprStmt) TokenLiteral() string

TokenLiteral returns token given by lexer.

type FloatLiteral

type FloatLiteral struct {
	Token string
	Value float64
	Src   *Source
}

FloatLiteral is an ast node for float literal like `1.0`.

func (*FloatLiteral) Source

func (fl *FloatLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*FloatLiteral) String

func (fl *FloatLiteral) String() string

func (*FloatLiteral) TokenLiteral

func (fl *FloatLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type FormerStrPiece

type FormerStrPiece struct {
	Token  string
	Former *FormerStrPiece
	Str    string
	Expr   Expr
}

FormerStrPiece is a former part of EmbeddedStr expression. NOTE: EmbeddedStr consists of recursive FormerStrPieces and each FormerStrPiece corresponds to string literal and expression.

func (*FormerStrPiece) String

func (fs *FormerStrPiece) String() string

type FuncComponent

type FuncComponent struct {
	Args   []Expr
	Kwargs map[*Ident]Expr
	Body   []Stmt
	Src    *Source
}

FuncComponent is an ast container for elements of func/iter/match literal.

func (*FuncComponent) PrependSelf

func (fc *FuncComponent) PrependSelf(src *Source) *FuncComponent

PrependSelf prepends `self` parameter to its paramters. This is helper function to parse methods like `m{}` (, which is a syntax sugar of `{|self| }`)

func (*FuncComponent) String

func (fc *FuncComponent) String() string

type FuncLiteral

type FuncLiteral struct {
	FuncComponent
	Token string
	Src   *Source
}

FuncLiteral is an ast node of func literal like `{|i| i * 2}`.

func (*FuncLiteral) Source

func (fl *FuncLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*FuncLiteral) String

func (fl *FuncLiteral) String() string

func (*FuncLiteral) TokenLiteral

func (fl *FuncLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type Ident

type Ident struct {
	Token     string
	Value     string
	Src       *Source
	IsPrivate bool
	IdentAttr IdentAttr
}

Ident is an ast node of identifier expression.

func (*Ident) Source

func (i *Ident) Source() *Source

Source returns stacktrace information used for error massages.

func (*Ident) String

func (i *Ident) String() string

func (*Ident) TokenLiteral

func (i *Ident) TokenLiteral() string

TokenLiteral returns token given by lexer.

type IdentAttr

type IdentAttr int

IdentAttr is enum for identifier kinds.

const (
	// NormalIdent is a Type for ordinally ident like `a`.
	NormalIdent IdentAttr = iota
	// ArgIdent is a Type for arg ident like `\1`.
	ArgIdent
	// KwargIdent is a Type for kwarg ident like `\a`.
	KwargIdent
)

type IfExpr

type IfExpr struct {
	Token string
	Cond  Expr
	Then  Expr
	Else  Expr
	Src   *Source
}

IfExpr is an ast node of if expression.

func (*IfExpr) Source

func (ie *IfExpr) Source() *Source

Source returns stacktrace information used for error massages.

func (*IfExpr) String

func (ie *IfExpr) String() string

func (*IfExpr) TokenLiteral

func (ie *IfExpr) TokenLiteral() string

TokenLiteral returns token given by lexer.

type InfixExpr

type InfixExpr struct {
	Token    string // i.e.: "+"
	Left     Expr
	Operator string
	Right    Expr
	Src      *Source
}

InfixExpr is an ast node of infix expression.

func (*InfixExpr) Source

func (ie *InfixExpr) Source() *Source

Source returns stacktrace information used for error massages.

func (*InfixExpr) String

func (ie *InfixExpr) String() string

func (*InfixExpr) TokenLiteral

func (ie *InfixExpr) TokenLiteral() string

TokenLiteral returns token given by lexer.

type IntLiteral

type IntLiteral struct {
	Token string
	Value int64
	Src   *Source
}

IntLiteral is an ast node for int literal like `1`.

func (*IntLiteral) Source

func (il *IntLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*IntLiteral) String

func (il *IntLiteral) String() string

func (*IntLiteral) TokenLiteral

func (il *IntLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type IterLiteral

type IterLiteral struct {
	FuncComponent
	Token string
	Src   *Source
}

IterLiteral is an ast node of func literal like `<{|i| yield i if i; recur(i-1)}>`.

func (*IterLiteral) Source

func (il *IterLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*IterLiteral) String

func (il *IterLiteral) String() string

func (*IterLiteral) TokenLiteral

func (il *IterLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type JumpIfStmt

type JumpIfStmt struct {
	Token    string
	JumpStmt *JumpStmt
	Cond     Expr
	Src      *Source
}

JumpIfStmt is an ast node of JumpStmt with `if` clause.

func (*JumpIfStmt) Source

func (js *JumpIfStmt) Source() *Source

Source returns stacktrace information used for error massages.

func (*JumpIfStmt) String

func (js *JumpIfStmt) String() string

func (*JumpIfStmt) TokenLiteral

func (js *JumpIfStmt) TokenLiteral() string

TokenLiteral returns token given by lexer.

type JumpStmt

type JumpStmt struct {
	Token    string
	Val      Expr
	JumpType JumpType
	Src      *Source
}

JumpStmt is an ast node of statement such as `return` or `yield`.

func (*JumpStmt) Source

func (js *JumpStmt) Source() *Source

Source returns stacktrace information used for error massages.

func (*JumpStmt) String

func (js *JumpStmt) String() string

func (*JumpStmt) TokenLiteral

func (js *JumpStmt) TokenLiteral() string

TokenLiteral returns token given by lexer.

type JumpType

type JumpType int

JumpType is an Enum for jump keywords, used for JumpStmt.

const (
	// ReturnJump is JumpType for `return`.
	ReturnJump JumpType = iota
	// RaiseJump is JumpType for `raise`.
	RaiseJump
	// YieldJump is JumpType for `yield`.
	YieldJump
	// DeferJump is JumpType for `defer`.
	// NOTE: treat `defer` as JumpType because syntax is equivalent to the other JumpTypes
	DeferJump
)

type KwargPair

type KwargPair struct {
	Key *Ident
	Val Expr
}

KwargPair is an ast element for keyword argument and its value.

func (*KwargPair) String

func (qp *KwargPair) String() string

type LiteralCallExpr

type LiteralCallExpr struct {
	Token    string
	Chain    *Chain
	Receiver Expr
	Func     *FuncLiteral
	Args     []Expr
	Kwargs   map[*Ident]Expr
	Src      *Source
}

LiteralCallExpr is an ast node of literalcall expression like `1.{|i| i * 2}`.

func (*LiteralCallExpr) ChainArg

func (lc *LiteralCallExpr) ChainArg() Expr

ChainArg returns chain arg expression of this call.

func (*LiteralCallExpr) ChainToken

func (lc *LiteralCallExpr) ChainToken() string

ChainToken returns chain string of this call.

func (*LiteralCallExpr) Source

func (lc *LiteralCallExpr) Source() *Source

Source returns stacktrace information used for error massages.

func (*LiteralCallExpr) String

func (lc *LiteralCallExpr) String() string

func (*LiteralCallExpr) TokenLiteral

func (lc *LiteralCallExpr) TokenLiteral() string

TokenLiteral returns token given by lexer.

type MainChain

type MainChain int

MainChain is an Enum for main chain context.

const (
	// Scalar is a Type for `.` chain.
	Scalar MainChain = iota
	// List is a Type for `@` chain.
	List
	// Reduce is a Type for `$` chain.
	Reduce
)

type MapLiteral

type MapLiteral struct {
	Token         string
	Pairs         []*Pair
	EmbeddedExprs []Expr
	Src           *Source
}

MapLiteral is an ast node for map literal like `%{"a": 1}`.

func (*MapLiteral) Source

func (ml *MapLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*MapLiteral) String

func (ml *MapLiteral) String() string

func (*MapLiteral) TokenLiteral

func (ml *MapLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type MatchLiteral

type MatchLiteral struct {
	Token    string
	Patterns []*FuncComponent
	Src      *Source
}

MatchLiteral is an ast node of match literal like `%{|1| 2, |3| 4}`.

func (*MatchLiteral) Source

func (ml *MatchLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*MatchLiteral) String

func (ml *MatchLiteral) String() string

func (*MatchLiteral) TokenLiteral

func (ml *MatchLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type Node

type Node interface {
	TokenLiteral() string
	String() string
	Source() *Source
}

Node is a base interface of ast node.

type ObjLiteral

type ObjLiteral struct {
	Token         string
	Pairs         []*Pair
	EmbeddedExprs []Expr
	Src           *Source
}

ObjLiteral is an ast node for obj literal like `{a: 1}`.

func (*ObjLiteral) Source

func (ol *ObjLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*ObjLiteral) String

func (ol *ObjLiteral) String() string

func (*ObjLiteral) TokenLiteral

func (ol *ObjLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type Pair

type Pair struct {
	Key Expr
	Val Expr
}

Pair is an ast element for key-value pair.

func (*Pair) String

func (p *Pair) String() string

type PinnedIdent

type PinnedIdent struct {
	Ident
}

PinnedIdent is an ast node of identifier with pinned operation `^`.

func (*PinnedIdent) String

func (pi *PinnedIdent) String() string

type Position

type Position struct {
	Line     int
	Column   int
	FileName string
}

Position is a location of source code.

func (*Position) String

func (p *Position) String() string

type PrefixExpr

type PrefixExpr struct {
	Token    string
	Operator string
	Right    Expr
	Src      *Source
}

PrefixExpr is an ast node of prefix expression.

func (*PrefixExpr) Source

func (pe *PrefixExpr) Source() *Source

Source returns stacktrace information used for error massages.

func (*PrefixExpr) String

func (pe *PrefixExpr) String() string

func (*PrefixExpr) TokenLiteral

func (pe *PrefixExpr) TokenLiteral() string

TokenLiteral returns token given by lexer.

type Program

type Program struct {
	Stmts []Stmt
	Src   *Source
}

Program is an ast node of program, corresponding to the whole source code.

func (*Program) Source

func (p *Program) Source() *Source

Source returns stacktrace information used for error massages.

func (*Program) String

func (p *Program) String() string

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

TokenLiteral returns token given by lexer.

type PropCallExpr

type PropCallExpr struct {
	Token    string
	Chain    *Chain
	Receiver Expr
	Prop     *Ident
	Args     []Expr
	Kwargs   map[*Ident]Expr
	Src      *Source
}

PropCallExpr is an ast node of propcall expression like `"hello".p`.

func (*PropCallExpr) ChainArg

func (pc *PropCallExpr) ChainArg() Expr

ChainArg returns chain arg expression of this call.

func (*PropCallExpr) ChainToken

func (pc *PropCallExpr) ChainToken() string

ChainToken returns chain string of this call.

func (*PropCallExpr) Source

func (pc *PropCallExpr) Source() *Source

Source returns stacktrace information used for error massages.

func (*PropCallExpr) String

func (pc *PropCallExpr) String() string

func (*PropCallExpr) TokenLiteral

func (pc *PropCallExpr) TokenLiteral() string

TokenLiteral returns token given by lexer.

type RangeLiteral

type RangeLiteral struct {
	Token string
	Start Expr
	Stop  Expr
	Step  Expr
	Src   *Source
}

RangeLiteral is an ast node of range literal like `(1:10)`.

func (*RangeLiteral) Source

func (rl *RangeLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*RangeLiteral) String

func (rl *RangeLiteral) String() string

func (*RangeLiteral) TokenLiteral

func (rl *RangeLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type RecvAndChain

type RecvAndChain struct {
	Recv  Expr
	Chain *Chain
}

RecvAndChain is a container for receiver and chain of CallExpr. This type is only used to make parser rules simple.

type Source

type Source struct {
	Line         string
	Pos          Position
	TokenLiteral string
}

Source is a stacktrace information used for error massages.

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Stmt is an interface of ast statement node.

type StrLiteral

type StrLiteral struct {
	Token string
	Value string
	IsRaw bool
	Src   *Source
}

StrLiteral is an ast node of str literal like `"a"`.

func (*StrLiteral) Source

func (sl *StrLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*StrLiteral) String

func (sl *StrLiteral) String() string

func (*StrLiteral) TokenLiteral

func (sl *StrLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type SymLiteral

type SymLiteral struct {
	Token string
	Value string
	Src   *Source
}

SymLiteral is an ast node of sym literal like `'a`.

func (*SymLiteral) Source

func (sl *SymLiteral) Source() *Source

Source returns stacktrace information used for error massages.

func (*SymLiteral) String

func (sl *SymLiteral) String() string

func (*SymLiteral) TokenLiteral

func (sl *SymLiteral) TokenLiteral() string

TokenLiteral returns token given by lexer.

type VarCallExpr

type VarCallExpr struct {
	Token    string
	Chain    *Chain
	Receiver Expr
	Var      *Ident
	Args     []Expr
	Kwargs   map[*Ident]Expr
	Src      *Source
}

VarCallExpr is an ast node of varcall expression like `foo.^bar`.

func (*VarCallExpr) ChainArg

func (vc *VarCallExpr) ChainArg() Expr

ChainArg returns chain arg expression of this call.

func (*VarCallExpr) ChainToken

func (vc *VarCallExpr) ChainToken() string

ChainToken returns chain string of this call.

func (*VarCallExpr) Source

func (vc *VarCallExpr) Source() *Source

Source returns stacktrace information used for error massages.

func (*VarCallExpr) String

func (vc *VarCallExpr) String() string

func (*VarCallExpr) TokenLiteral

func (vc *VarCallExpr) TokenLiteral() string

TokenLiteral returns token given by lexer.

Jump to

Keyboard shortcuts

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