parser

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OP_ADD       Operator = "+"
	OP_SUB                = "-"
	OP_DIV                = "/"
	OP_MUL                = "*"
	OP_REMAINDER          = "%"

	OP_BIT_AND   = "&"
	OP_BIT_OR    = "|"
	OP_BIT_XOR   = "^"
	OP_BIT_CLEAR = "&^" // AND NOT

	OP_LEFT_SHIFT  = "<<"
	OP_RIGHT_SHIFT = ">>"

	OP_GT   = ">"
	OP_GTEQ = ">="
	OP_LT   = "<"
	OP_LTEQ = "<="
	OP_EQ   = "=="
	OP_NEQ  = "!="

	OP_LOGICAL_AND = "&&"
	OP_LOGICAL_OR  = "||"
)

https://golang.org/ref/spec#Arithmetic_operators

Variables

This section is empty.

Functions

This section is empty.

Types

type AllocGroup

type AllocGroup struct {
	Allocs []*AllocNode
	// contains filtered or unexported fields
}

func (*AllocGroup) Node

func (n *AllocGroup) Node()

func (AllocGroup) String

func (an AllocGroup) String() string

type AllocNode

type AllocNode struct {
	Escapes bool

	Name []string
	Val  []Node

	Type TypeNode // Is set when allocating on the format "var ident int" and "var ident, ident int = expr, expr"

	IsConst bool // Is true when in a const expression.
	// contains filtered or unexported fields
}

AllocNode creates a new variable Name with the value Val

func (*AllocNode) Node

func (n *AllocNode) Node()

func (AllocNode) String

func (an AllocNode) String() string

type ArrayTypeNode

type ArrayTypeNode struct {
	SourceName string
	ItemType   TypeNode
	Len        int64
	IsVariadic bool
	// contains filtered or unexported fields
}

ArrayTypeNode refers to an array

func (ArrayTypeNode) GetName

func (atn ArrayTypeNode) GetName() string

func (*ArrayTypeNode) Node

func (n *ArrayTypeNode) Node()

func (ArrayTypeNode) SetName

func (atn ArrayTypeNode) SetName(name string)

func (ArrayTypeNode) String

func (atn ArrayTypeNode) String() string

func (ArrayTypeNode) Type

func (atn ArrayTypeNode) Type() string

func (ArrayTypeNode) Variadic

func (atn ArrayTypeNode) Variadic() bool

type AssignNode

type AssignNode struct {
	Target []Node
	Val    []Node
	// contains filtered or unexported fields
}

AssignNode assign Val to Target (or Name)

func (*AssignNode) Node

func (n *AssignNode) Node()

func (AssignNode) String

func (an AssignNode) String() string

type BreakNode

type BreakNode struct {
	// contains filtered or unexported fields
}

BreakNode breaks out of the current for loop

func (*BreakNode) Node

func (n *BreakNode) Node()

func (BreakNode) String

func (n BreakNode) String() string

type CallNode

type CallNode struct {
	Function  Node
	Arguments []Node
	// contains filtered or unexported fields
}

CallNode is a function call. Function is the name of the function to execute.

func (*CallNode) Node

func (n *CallNode) Node()

func (CallNode) String

func (cn CallNode) String() string

type ConditionNode

type ConditionNode struct {
	Cond  *OperatorNode
	True  []Node
	False []Node
	// contains filtered or unexported fields
}

ConditionNode creates a new if condition False is optional

func (*ConditionNode) Node

func (n *ConditionNode) Node()

func (ConditionNode) String

func (ConditionNode) String() string

type ConstantNode

type ConstantNode struct {
	Type       DataType
	TargetType TypeNode
	Value      int64
	ValueStr   string
	// contains filtered or unexported fields
}

ConstantNode is a raw string or number

func (*ConstantNode) Node

func (n *ConstantNode) Node()

func (ConstantNode) String

func (cn ConstantNode) String() string

type ContinueNode

type ContinueNode struct {
	// contains filtered or unexported fields
}

ContinueNode skips the current iteration of the current for loop

func (*ContinueNode) Node

func (n *ContinueNode) Node()

func (ContinueNode) String

func (n ContinueNode) String() string

type DataType

type DataType uint8
const (
	STRING DataType = iota
	BYTE
	NUMBER
	BOOL
)

type DeVariadicSliceNode

type DeVariadicSliceNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*DeVariadicSliceNode) Node

func (n *DeVariadicSliceNode) Node()

func (DeVariadicSliceNode) String

func (i DeVariadicSliceNode) String() string

type DeclarePackageNode

type DeclarePackageNode struct {
	PackageName string
	// contains filtered or unexported fields
}

DeclarePackageNode declares the package that we're in

func (*DeclarePackageNode) Node

func (n *DeclarePackageNode) Node()

func (DeclarePackageNode) String

func (d DeclarePackageNode) String() string

type DecrementNode

type DecrementNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*DecrementNode) Node

func (n *DecrementNode) Node()

func (DecrementNode) String

func (i DecrementNode) String() string

type DefineFuncNode

type DefineFuncNode struct {
	Name    string
	IsNamed bool

	IsMethod bool
	IsExtern bool

	MethodOnType      *SingleTypeNode
	IsPointerReceiver bool
	InstanceName      string

	Arguments    []*NameNode
	ReturnValues []*NameNode
	Body         []Node
	// contains filtered or unexported fields
}

DefineFuncNode creates a new named function

func (*DefineFuncNode) Node

func (n *DefineFuncNode) Node()

func (DefineFuncNode) String

func (dfn DefineFuncNode) String() string

type DefineTypeNode

type DefineTypeNode struct {
	Name string
	Type TypeNode
	// contains filtered or unexported fields
}

DefineTypeNode creates a new named type

func (*DefineTypeNode) Node

func (n *DefineTypeNode) Node()

func (DefineTypeNode) String

func (dtn DefineTypeNode) String() string

type DereferenceNode

type DereferenceNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*DereferenceNode) Node

func (n *DereferenceNode) Node()

func (DereferenceNode) String

func (dn DereferenceNode) String() string

type ExternNode added in v0.2.0

type ExternNode struct {
	FuncNodes []*DefineFuncNode
	// contains filtered or unexported fields
}

func (*ExternNode) Node added in v0.2.0

func (n *ExternNode) Node()

func (ExternNode) String added in v0.2.0

func (en ExternNode) String() string

type FileNode

type FileNode struct {
	Instructions []Node
	// contains filtered or unexported fields
}

FileNode is a list of other nodes Indicates the root of one source file

func Parse

func Parse(input []lexer.Item, options *option.Options) *FileNode

func (*FileNode) Node

func (n *FileNode) Node()

func (FileNode) String

func (fn FileNode) String() string

type ForNode

type ForNode struct {
	BeforeLoop     Node
	Condition      *OperatorNode
	AfterIteration Node
	Block          []Node

	IsThreeTypeFor bool
	// contains filtered or unexported fields
}

ForNode creates a new for-loop

func (*ForNode) Node

func (n *ForNode) Node()

func (ForNode) String

func (f ForNode) String() string

type FuncTypeNode

type FuncTypeNode struct {
	ArgTypes []TypeNode
	RetTypes []TypeNode

	SourceName string
	IsVariadic bool
	// contains filtered or unexported fields
}

func (FuncTypeNode) GetName

func (ftn FuncTypeNode) GetName() string

func (*FuncTypeNode) Node

func (n *FuncTypeNode) Node()

func (FuncTypeNode) SetName

func (ftn FuncTypeNode) SetName(name string)

func (FuncTypeNode) String

func (ftn FuncTypeNode) String() string

func (FuncTypeNode) Type

func (ftn FuncTypeNode) Type() string

func (FuncTypeNode) Variadic

func (ftn FuncTypeNode) Variadic() bool

type GetReferenceNode

type GetReferenceNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*GetReferenceNode) Node

func (n *GetReferenceNode) Node()

func (GetReferenceNode) String

func (grn GetReferenceNode) String() string

type GroupNode

type GroupNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*GroupNode) Node

func (n *GroupNode) Node()

func (GroupNode) String

func (i GroupNode) String() string

type ImportNode

type ImportNode struct {
	PackagePaths []string
	// contains filtered or unexported fields
}

func (*ImportNode) Node

func (n *ImportNode) Node()

func (ImportNode) String

func (in ImportNode) String() string

type IncrementNode

type IncrementNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*IncrementNode) Node

func (n *IncrementNode) Node()

func (IncrementNode) String

func (i IncrementNode) String() string

type InitializeArrayNode

type InitializeArrayNode struct {
	Type  TypeNode
	Size  int
	Items []Node
	// contains filtered or unexported fields
}

func (*InitializeArrayNode) Node

func (n *InitializeArrayNode) Node()

func (InitializeArrayNode) String

func (i InitializeArrayNode) String() string

type InitializeSliceNode

type InitializeSliceNode struct {
	Type  TypeNode
	Len   Node
	Cap   Node
	Items []Node
	// contains filtered or unexported fields
}

func (*InitializeSliceNode) Node

func (n *InitializeSliceNode) Node()

func (InitializeSliceNode) String

func (i InitializeSliceNode) String() string

type InitializeStringWithSliceNode added in v0.2.0

type InitializeStringWithSliceNode struct {
	Items []Node
	// contains filtered or unexported fields
}

func (*InitializeStringWithSliceNode) Node added in v0.2.0

func (n *InitializeStringWithSliceNode) Node()

func (InitializeStringWithSliceNode) String added in v0.2.0

type InitializeStructNode

type InitializeStructNode struct {
	Type  TypeNode
	Items map[string]Node
	// contains filtered or unexported fields
}

func (*InitializeStructNode) Node

func (n *InitializeStructNode) Node()

func (InitializeStructNode) String

func (i InitializeStructNode) String() string

type InterfaceMethod

type InterfaceMethod struct {
	ArgumentTypes []TypeNode
	ReturnTypes   []TypeNode
}

type InterfaceTypeNode

type InterfaceTypeNode struct {
	SourceName string
	Methods    map[string]InterfaceMethod
	IsVariadic bool
	// contains filtered or unexported fields
}

func (InterfaceTypeNode) GetName

func (itn InterfaceTypeNode) GetName() string

func (*InterfaceTypeNode) Node

func (n *InterfaceTypeNode) Node()

func (InterfaceTypeNode) SetName

func (itn InterfaceTypeNode) SetName(name string)

func (InterfaceTypeNode) String

func (itn InterfaceTypeNode) String() string

func (InterfaceTypeNode) Type

func (itn InterfaceTypeNode) Type() string

func (InterfaceTypeNode) Variadic

func (itn InterfaceTypeNode) Variadic() bool

type LoadArrayElement

type LoadArrayElement struct {
	Array Node
	Pos   Node
	// contains filtered or unexported fields
}

LoadArrayElement loads a single element from an array On the form arr[1]

func (*LoadArrayElement) Node

func (n *LoadArrayElement) Node()

func (LoadArrayElement) String

func (l LoadArrayElement) String() string

type MultiNameNode

type MultiNameNode struct {
	Names []*NameNode
	// contains filtered or unexported fields
}

func (*MultiNameNode) Node

func (n *MultiNameNode) Node()

func (MultiNameNode) String

func (n MultiNameNode) String() string

type NameNode

type NameNode struct {
	Package string
	Name    string
	Type    TypeNode
	// contains filtered or unexported fields
}

NameNode retreives a named variable

func (*NameNode) Node

func (n *NameNode) Node()

func (NameNode) String

func (nn NameNode) String() string

type NegateNode

type NegateNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*NegateNode) Node

func (n *NegateNode) Node()

func (NegateNode) String

func (nn NegateNode) String() string

type Node

type Node interface {
	Node()
	String() string
}

Node is the base node. A node consists of something that the compiler or language can do

func Walk

func Walk(v Visitor, node Node) (r Node)

type Operator

type Operator string

type OperatorNode

type OperatorNode struct {
	Operator Operator
	Left     Node
	Right    Node
	// contains filtered or unexported fields
}

OperatorNode is mathematical operations and comparisons

func (*OperatorNode) Node

func (n *OperatorNode) Node()

func (OperatorNode) String

func (on OperatorNode) String() string

type PackageNode

type PackageNode struct {
	Files []FileNode
	Name  string
	// contains filtered or unexported fields
}

func (*PackageNode) Node

func (n *PackageNode) Node()

type PointerTypeNode

type PointerTypeNode struct {
	SourceName string
	IsVariadic bool
	ValueType  TypeNode
	// contains filtered or unexported fields
}

func (PointerTypeNode) GetName

func (ptn PointerTypeNode) GetName() string

func (*PointerTypeNode) Node

func (n *PointerTypeNode) Node()

func (PointerTypeNode) SetName

func (ptn PointerTypeNode) SetName(name string)

func (PointerTypeNode) String

func (ptn PointerTypeNode) String() string

func (PointerTypeNode) Type

func (ptn PointerTypeNode) Type() string

func (PointerTypeNode) Variadic

func (ptn PointerTypeNode) Variadic() bool

type PragmaNode

type PragmaNode struct {
	Version VersionScheme
	// contains filtered or unexported fields
}

PragmaNode implements the Node interface, to tell compiler how to compile

func (*PragmaNode) Node

func (n *PragmaNode) Node()

func (PragmaNode) String

func (p PragmaNode) String() string

type RangeNode

type RangeNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*RangeNode) Node

func (n *RangeNode) Node()

func (RangeNode) String

func (r RangeNode) String() string

type ReturnNode

type ReturnNode struct {
	Vals []Node
	// contains filtered or unexported fields
}

ReturnNode returns Val from within the current function

func (*ReturnNode) Node

func (n *ReturnNode) Node()

func (ReturnNode) String

func (rn ReturnNode) String() string

type SingleTypeNode

type SingleTypeNode struct {
	PackageName string
	SourceName  string
	TypeName    string
	IsVariadic  bool
	// contains filtered or unexported fields
}

SingleTypeNode refers to an existing type. Such as "string".

func (SingleTypeNode) GetName

func (stn SingleTypeNode) GetName() string

func (*SingleTypeNode) Node

func (n *SingleTypeNode) Node()

func (SingleTypeNode) SetName

func (stn SingleTypeNode) SetName(name string)

func (SingleTypeNode) String

func (stn SingleTypeNode) String() string

func (SingleTypeNode) Type

func (stn SingleTypeNode) Type() string

func (SingleTypeNode) Variadic

func (stn SingleTypeNode) Variadic() bool

type SliceArrayNode

type SliceArrayNode struct {
	Val    Node
	Start  Node
	HasEnd bool
	End    Node
	// contains filtered or unexported fields
}

SliceArrayNode slices an array or string Can be on the forms arr[1], arr[1:], or arr[1:3]

func (*SliceArrayNode) Node

func (n *SliceArrayNode) Node()

func (SliceArrayNode) String

func (san SliceArrayNode) String() string

type SliceTypeNode

type SliceTypeNode struct {
	SourceName string
	ItemType   TypeNode
	IsVariadic bool
	// contains filtered or unexported fields
}

func (SliceTypeNode) GetName

func (stn SliceTypeNode) GetName() string

func (*SliceTypeNode) Node

func (n *SliceTypeNode) Node()

func (SliceTypeNode) SetName

func (stn SliceTypeNode) SetName(name string)

func (SliceTypeNode) String

func (stn SliceTypeNode) String() string

func (SliceTypeNode) Type

func (stn SliceTypeNode) Type() string

func (SliceTypeNode) Variadic

func (stn SliceTypeNode) Variadic() bool

type StructLoadElementNode

type StructLoadElementNode struct {
	Struct      Node
	ElementName string
	// contains filtered or unexported fields
}

StructLoadElementNode retrieves a value by key from a struct

func (*StructLoadElementNode) Node

func (n *StructLoadElementNode) Node()

func (StructLoadElementNode) String

func (slen StructLoadElementNode) String() string

type StructTypeNode

type StructTypeNode struct {
	SourceName string
	Types      []TypeNode
	Names      map[string]int
	IsVariadic bool
	// contains filtered or unexported fields
}

StructTypeNode refers to a struct type

func (StructTypeNode) GetName

func (stn StructTypeNode) GetName() string

func (*StructTypeNode) Node

func (n *StructTypeNode) Node()

func (StructTypeNode) SetName

func (stn StructTypeNode) SetName(name string)

func (StructTypeNode) String

func (stn StructTypeNode) String() string

func (StructTypeNode) Type

func (stn StructTypeNode) Type() string

func (StructTypeNode) Variadic

func (stn StructTypeNode) Variadic() bool

type SubNode

type SubNode struct {
	Item Node
	// contains filtered or unexported fields
}

func (*SubNode) Node

func (n *SubNode) Node()

func (SubNode) String

func (sn SubNode) String() string

type SwitchCaseNode added in v0.2.0

type SwitchCaseNode struct {
	Conditions  []Node
	Body        []Node
	Fallthrough bool
	// contains filtered or unexported fields
}

func (*SwitchCaseNode) Node added in v0.2.0

func (n *SwitchCaseNode) Node()

func (SwitchCaseNode) String added in v0.2.0

func (s SwitchCaseNode) String() string

type SwitchNode added in v0.2.0

type SwitchNode struct {
	Item        Node
	Cases       []*SwitchCaseNode
	DefaultBody []Node // can be null
	// contains filtered or unexported fields
}

func (*SwitchNode) Node added in v0.2.0

func (n *SwitchNode) Node()

func (SwitchNode) String added in v0.2.0

func (s SwitchNode) String() string

type TypeCastInterfaceNode

type TypeCastInterfaceNode struct {
	Item Node
	Type TypeNode
	// contains filtered or unexported fields
}

func (*TypeCastInterfaceNode) Node

func (n *TypeCastInterfaceNode) Node()

func (TypeCastInterfaceNode) String

func (i TypeCastInterfaceNode) String() string

type TypeCastNode

type TypeCastNode struct {
	Type TypeNode
	Val  Node
	// contains filtered or unexported fields
}

TypeCastNode tries to cast Val to Type

func (*TypeCastNode) Node

func (n *TypeCastNode) Node()

func (TypeCastNode) String

func (tcn TypeCastNode) String() string

type TypeNode

type TypeNode interface {
	Node() // must also implement the Node interface
	Type() string
	String() string
	Variadic() bool
	SetName(string)
	GetName() string
}

TypeNode is an interface for different ways of creating new types or referring to existing ones

type VersionScheme

type VersionScheme struct {
	Major int
	Minor int
	Patch int
	// contains filtered or unexported fields
}

VersionScheme implements the Node interface, to specify the compiler version

func (*VersionScheme) Node

func (n *VersionScheme) Node()

func (VersionScheme) String

func (v VersionScheme) String() string

type Visitor

type Visitor interface {
	Visit(node Node) (n Node, w Visitor)
}

Jump to

Keyboard shortcuts

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