node

package
v0.0.0-...-d9f2893 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package node implements some AST nodes.

Index

Constants

View Source
const (
	TypeCharacter = "Character"
	TypeUnion     = "Union"
	TypeConcat    = "Concat"
	TypeStar      = "Star"
	TypePlus      = "Plus"
)

String to identify the type of Node.

Variables

This section is empty.

Functions

This section is empty.

Types

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

func (c *Character) Assemble(ctx *utils.Context) *nfabuilder.Fragment

Assemble returns a NFA fragment assembled with Character node. The fragment assembled from a Character node is like below:

q1(Initial State) -- [Character.V] --> q2(Accept state)

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

func (c *Concat) Assemble(ctx *utils.Context) *nfabuilder.Fragment

Assemble returns a NFA fragment assembled with Concat node. The fragment assembled from a Concat node is like below:

frg1 -- ['ε'] --> frg2

+ frg1(fragment assembled with Concat.Ope1): I1 -- [???] --> F1
+ frg2(fragment assembled with Concat.Ope2): I2 -- [???] --> F2

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 Node

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

	// Assemble returns a NFA fragment assembled with a Node.
	Assemble(*utils.Context) *nfabuilder.Fragment
}

Node is the interface Node implements.

type Plus

type Plus struct {
	Ty  string
	Ope Node
}

Plus represents the Star node.

func NewPlus

func NewPlus(ope Node) *Plus

NewPlus returns a new Star node.

func (*Plus) Assemble

func (p *Plus) Assemble(ctx *utils.Context) *nfabuilder.Fragment

Assemble returns a NFA fragment assembled with Plus node.

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 Plus 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) Assemble

func (s *Star) Assemble(ctx *utils.Context) *nfabuilder.Fragment

Assemble returns a NFA fragment assembled with Star node. The fragment assembled from a Star node is like below:

(new state1) -- ['ε'] --> I1 -----> F1 -- ['ε'] --> (new state2)
   \					  ↑--['ε']-´						 ↑
	\														 /
	 `-------------------------['ε']------------------------´

+ frg1(fragment assembled with Ope): I1 -- [???] --> F1

Note: Accept states of new fragment is "(new state2)" and "I1".

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

func (u *Union) Assemble(ctx *utils.Context) *nfabuilder.Fragment

Assemble returns a NFA fragment assembled with Union node. The fragment assembled from a Union node is like below:

	I'(new initial state) -- ['ε'] --> frg1
    	              	 `- ['ε'] --> frg2

	+ frg1(fragment assembled with Union.Ope1): I1 -- [???] --> F1
	+ frg2(fragment assembled with Union.Ope2): I2 -- [???] --> F2

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