node

package
v0.0.0-...-2c802aa Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package node implements some AST nodes.

Index

Constants

View Source
const (
	TypeCharacter = "Character"
	TypeUnion     = "Union"
	TypeConcat    = "Concat"
	TypeStar      = "Star"
	TypePlus      = "Plus"
	TypeQuestion  = "Question"
	TypeAny       = "Any"
	TypeEpsilon   = "Epsilon" // Empty character
)

String to identify the type of Node.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any struct {
	Ty string
}

Any represents the Any node.

func NewAny

func NewAny() *Any

NewAny returns a new Any node.

func (*Any) Compile

func (a *Any) Compile() *bytecode.BC

Compile returns a BC compiled from Any node which VM can execute. The BC compiled from an expression '.' will be like below:

|00| Any

Note: The bytecode is just a fragment, so when finally give VM it, you need to add the instruction of Match to the last of BC.

func (*Any) String

func (a *Any) String() string

func (*Any) SubtreeString

func (a *Any) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Any node at the top.

type Character

type Character struct {
	Ty string
	V  rune
}

Character represents the Character node.

func NewCharacter

func NewCharacter(r rune) *Character

NewCharacter returns a new Character node.

func (*Character) Compile

func (c *Character) Compile() *bytecode.BC

Compile returns a BC compiled from Character node which VM can execute. The BC compiled from an expression 'a' will be like below:

|0| Char 'a'

Note: The bytecode is just a fragment, so when finally give VM it, you need to add the instruction of Match to the last of BC.

func (*Character) String

func (c *Character) String() string

func (*Character) SubtreeString

func (c *Character) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Character node at the top.

type Concat

type Concat struct {
	Ty   string
	Ope1 Node
	Ope2 Node
}

Concat represents the Concat node.

func NewConcat

func NewConcat(ope1, ope2 Node) *Concat

NewConcat returns a new Concat node.

func (*Concat) Compile

func (c *Concat) Compile() *bytecode.BC

Compile returns a BC compiled from Concat node which VM can execute. The BC compiled from an expression 'abc' will be like below:

|0| Char 'a'
|1| Char 'b'
|2| Char 'c'

Note: The bytecode is just a fragment, so when finally give VM it, you need to add the instruction of Match to the last of BC.

func (*Concat) String

func (c *Concat) String() string

func (*Concat) SubtreeString

func (c *Concat) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Concat node at the top.

type Epsilon

type Epsilon struct {
	Ty string
}

Epsilon represents the Epsilon node.

func NewEpsilon

func NewEpsilon() *Epsilon

NewEpsilon returns a new Star node.

func (*Epsilon) Compile

func (*Epsilon) Compile() *bytecode.BC

Compile returns a BC compiled from Epsilon node which VM can execute.

func (*Epsilon) String

func (e *Epsilon) String() string

func (*Epsilon) SubtreeString

func (e *Epsilon) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Epsilon node at the top.

type Node

type Node interface {
	// SubtreeString returns a string to which converts
	// a subtree with Node at the top.
	SubtreeString() string

	// Compile returns a byte code fragment for VM.
	Compile() *bytecode.BC
}

Node is the interface Node implements.

type Plus

type Plus struct {
	Ty  string
	Ope Node
}

Plus represents the Plus node.

func NewPlus

func NewPlus(ope Node) *Plus

NewPlus returns a new Plus node.

func (*Plus) Compile

func (p *Plus) Compile() *bytecode.BC

Compile returns a BC compiled from Plus node which VM can execute. The BC compiled from an expression 'a' will be like below:

|00| Char 'a'
|01| Split 0, 2
|02| <nop>

Note: The bytecode is just a fragment, so when finally give VM it, you need to add the instruction of Match to the last of BC.

func (*Plus) String

func (p *Plus) String() string

func (*Plus) SubtreeString

func (p *Plus) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Star node at the top.

type Question

type Question struct {
	Ty  string
	Ope Node
}

Question represents the Question node.

func NewQuestion

func NewQuestion(ope Node) *Question

NewQuestion returns a new Question node.

func (*Question) Compile

func (q *Question) Compile() *bytecode.BC

Compile returns a BC compiled from Question node which VM can execute. The BC compiled from an expression 'a' will be like below:

|00| Split 1, 2
|01| Char 'a'
|02| <nop>

Note: The bytecode is just a fragment, so when finally give VM it, you need to add the instruction of Match to the last of BC.

func (*Question) String

func (q *Question) String() string

func (*Question) SubtreeString

func (q *Question) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Star node at the top.

type Star

type Star struct {
	Ty  string
	Ope Node
}

Star represents the Star node.

func NewStar

func NewStar(ope Node) *Star

NewStar returns a new Star node.

func (*Star) Compile

func (s *Star) Compile() *bytecode.BC

Compile returns a BC compiled from Star node which VM can execute. The BC compiled from an expression 'abc' will be like below:

|00| Split 1, 3
|01| Char 'a'
|02| Jmp 0
|03| <nop>

Note: The bytecode is just a fragment, so when finally give VM it, you need to add the instruction of Match to the last of BC.

func (*Star) String

func (s *Star) String() string

func (*Star) SubtreeString

func (s *Star) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Star node at the top.

type Union

type Union struct {
	Ty   string
	Ope1 Node
	Ope2 Node
}

Union represents the Union node.

func NewUnion

func NewUnion(ope1, ope2 Node) *Union

NewUnion returns a new Union node.

func (*Union) Compile

func (u *Union) Compile() *bytecode.BC

Compile returns a BC compiled from Union node which VM can execute. The BC compiled from an expression 'a|b' will be like below:

|0| Split 1, 3
|1| Char 'a'
|2| Jmp 4
|3| Char 'b'
|4| <nop>

Note: The bytecode is just a fragment, so when finally give VM it, you need to add the instruction of Match to the last of BC.

func (*Union) String

func (u *Union) String() string

func (*Union) SubtreeString

func (u *Union) SubtreeString() string

SubtreeString returns a string to which converts a subtree with the Union node at the top.

Jump to

Keyboard shortcuts

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