isa

package
v0.0.0-...-7534ea8 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package isa provides types for all instructions in the GPeg virtual machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any struct {
	N byte
	// contains filtered or unexported fields
}

Any consumes the next N bytes and fails if that is not possible.

func (Any) String

func (i Any) String() string

String returns the string representation of this instruction.

type BackCommit

type BackCommit struct {
	Lbl Label
	// contains filtered or unexported fields
}

BackCommit pops a backtrack entry off the stack, goes to the subject position in the entry, and jumps to Lbl.

func (BackCommit) String

func (i BackCommit) String() string

String returns the string representation of this instruction.

type BackReference

type BackReference struct {
	Symbols map[int]string
}

func NewBackRef

func NewBackRef() *BackReference

func (*BackReference) Check

func (r *BackReference) Check(b []byte, src *input.Input, id, flag int) int

type Call

type Call struct {
	Lbl Label
	// contains filtered or unexported fields
}

Call pushes the next instruction to the stack as a return address and jumps to Lbl.

func (Call) String

func (i Call) String() string

String returns the string representation of this instruction.

type CaptureBegin

type CaptureBegin struct {
	Id int
	// contains filtered or unexported fields
}

CaptureBegin begins capturing the given ID.

func (CaptureBegin) String

func (i CaptureBegin) String() string

String returns the string representation of this instruction.

type CaptureEnd

type CaptureEnd struct {
	Id int
	// contains filtered or unexported fields
}

CaptureEnd completes an active capture.

func (CaptureEnd) String

func (i CaptureEnd) String() string

String returns the string representation of this instruction.

type CaptureFull

type CaptureFull struct {
	Back byte
	Id   int
	// contains filtered or unexported fields
}

CaptureFull begins a capture for the given ID at the current subject position minus Back, and immediately completes the capture. This is equivalent to CaptureLate Back ID; CaptureEnd.

func (CaptureFull) String

func (i CaptureFull) String() string

String returns the string representation of this instruction.

type CaptureLate

type CaptureLate struct {
	Back byte
	Id   int
	// contains filtered or unexported fields
}

CaptureLate begins capturing the given ID at the current subject position minus Back.

func (CaptureLate) String

func (i CaptureLate) String() string

String returns the string representation of this instruction.

type Char

type Char struct {
	Byte byte
	// contains filtered or unexported fields
}

Char consumes the next byte of the subject if it matches Byte and fails otherwise.

func (Char) String

func (i Char) String() string

String returns the string representation of this instruction.

type CheckBegin

type CheckBegin struct {
	Id   int
	Flag int
	// contains filtered or unexported fields
}

CheckBegin marks the beginning position for a checker.

func (CheckBegin) String

func (i CheckBegin) String() string

String returns the string representation of this instruction.

type CheckEnd

type CheckEnd struct {
	Checker Checker
	// contains filtered or unexported fields
}

CheckEnd records the end position of a checker and applies the checker to determine if the match should fail.

func (CheckEnd) String

func (i CheckEnd) String() string

String returns the string representation of this instruction.

type Checker

type Checker interface {
	Check(b []byte, src *input.Input, id, flag int) int
}

A Checker is used so the user can perform additional custom validation of parse results. For example, you might want to parse only 8-bit integers by matching [0-9]+ and then using a checker to ensure the matched integer is in the range 0-256.

type Choice

type Choice struct {
	Lbl Label
	// contains filtered or unexported fields
}

Choice pushes Lbl to the stack and if there is a failure the label will be popped from the stack and jumped to.

func (Choice) String

func (i Choice) String() string

String returns the string representation of this instruction.

type Commit

type Commit struct {
	Lbl Label
	// contains filtered or unexported fields
}

Commit jumps to Lbl and removes the top entry from the stack

func (Commit) String

func (i Commit) String() string

String returns the string representation of this instruction.

type Empty

type Empty struct {
	Op syntax.EmptyOp
	// contains filtered or unexported fields
}

Empty makes a zero-width assertion according to the Op option. We use the same zero-width assertions that are supported by Go's regexp package.

func (Empty) String

func (i Empty) String() string

String returns the string representation of this instruction.

type End

type End struct {
	Fail bool
	// contains filtered or unexported fields
}

End immediately completes the pattern as a match.

func (End) String

func (i End) String() string

String returns the string representation of this instruction.

type Error

type Error struct {
	Message string
	// contains filtered or unexported fields
}

Error logs an error message at the current position.

func (Error) String

func (i Error) String() string

String returns the string representation of this instruction.

type Fail

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

Fail causes the instruction pointer to go to the fail state.

func (Fail) String

func (i Fail) String() string

String returns the string representation of this instruction.

type FailTwice

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

FailTwice pops an entry off the stack and sets the instruction pointer to the fail state.

func (FailTwice) String

func (i FailTwice) String() string

String returns the string representation of this instruction.

type Insn

type Insn interface {
	// contains filtered or unexported methods
}

Insn represents the interface for an instruction in the ISA

type Jump

type Jump struct {
	Lbl Label
	// contains filtered or unexported fields
}

Jump jumps to Lbl.

func (Jump) String

func (i Jump) String() string

String returns the string representation of this instruction.

type JumpType

type JumpType interface {
	// contains filtered or unexported methods
}

A JumpType instruction is any instruction that refers to a Label.

type Label

type Label struct {
	Id int
	// contains filtered or unexported fields
}

Label is used for marking a location in the instruction code with a unique ID

func NewLabel

func NewLabel() Label

NewLabel returns a new label with a unique ID

func (Label) String

func (i Label) String() string

String returns the string representation of this instruction.

type MapChecker

type MapChecker map[string]struct{}

func NewMapChecker

func NewMapChecker(strs []string) MapChecker

func (MapChecker) Check

func (m MapChecker) Check(b []byte, src *input.Input, id, flag int) int

type MemoClose

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

MemoClose completes a memoization entry and adds the entry into the memo table if it meets certain conditions (size, or other heuristics).

func (MemoClose) String

func (i MemoClose) String() string

String returns the string representation of this instruction.

type MemoOpen

type MemoOpen struct {
	Lbl Label
	Id  int
	// contains filtered or unexported fields
}

MemoOpen begins a memo entry at this position. It marks the pattern that is being memoized with a unique ID for that pattern, and stores a label to jump to if the pattern is found in the memoization table.

func (MemoOpen) String

func (i MemoOpen) String() string

String returns the string representation of this instruction.

type MemoTree

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

MemoTree "tree-ifies" the current memoization entries on the stack.

func (MemoTree) String

func (i MemoTree) String() string

String returns the string representation of this instruction.

type MemoTreeClose

type MemoTreeClose struct {
	Id int
	// contains filtered or unexported fields
}

MemoTreeClose completes the tree memoization routine.

func (MemoTreeClose) String

func (i MemoTreeClose) String() string

String returns the string representation of this instruction.

type MemoTreeInsert

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

MemoTreeInsert performs insertion into the memoization table for the tree memoization strategy.

func (MemoTreeInsert) String

func (i MemoTreeInsert) String() string

String returns the string representation of this instruction.

type MemoTreeOpen

type MemoTreeOpen struct {
	Lbl Label
	Id  int
	// contains filtered or unexported fields
}

MemoTreeOpen starts a memoization tree repetition routine.

func (MemoTreeOpen) String

func (i MemoTreeOpen) String() string

String returns the string representation of this instruction.

type Nop

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

Nop does nothing.

func (Nop) String

func (i Nop) String() string

String returns the string representation of this instruction.

type PartialCommit

type PartialCommit struct {
	Lbl Label
	// contains filtered or unexported fields
}

PartialCommit modifies the backtrack entry on the top of the stack to point to the current subject offset, and jumps to Lbl.

func (PartialCommit) String

func (i PartialCommit) String() string

String returns the string representation of this instruction.

type Program

type Program []Insn

A Program is a sequence of instructions

func (Program) Size

func (p Program) Size() int

Size returns the number of instructions in a program ignoring labels and nops.

func (Program) String

func (p Program) String() string

String returns the string representation of the program.

type RefKind

type RefKind uint8
const (
	RefDef RefKind = iota
	RefUse
	RefBlock
)

type Return

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

Return pops a return address off the stack and jumps to it.

func (Return) String

func (i Return) String() string

String returns the string representation of this instruction.

type Set

type Set struct {
	Chars charset.Set
	// contains filtered or unexported fields
}

Set consumes the next byte of input if it is in the set of chars defined by Chars.

func (Set) String

func (i Set) String() string

String returns the string representation of this instruction.

type Span

type Span struct {
	Chars charset.Set
	// contains filtered or unexported fields
}

Span consumes zero or more bytes in the set Chars. This instruction never fails.

func (Span) String

func (i Span) String() string

String returns the string representation of this instruction.

type TestAny

type TestAny struct {
	N   byte
	Lbl Label
	// contains filtered or unexported fields
}

TestAny consumes the next N bytes and jumps to Lbl if that is not possible. If the consumption is possible, a backtrack entry referring to Lbl and the subject position from before consumption is pushed to the stack.

func (TestAny) String

func (i TestAny) String() string

String returns the string representation of this instruction.

type TestChar

type TestChar struct {
	Byte byte
	Lbl  Label
	// contains filtered or unexported fields
}

TestChar consumes the next byte if it matches Byte and jumps to Lbl otherwise. If the consumption is possible, a backtrack entry referring to Lbl and the subject position from before consumption is pushed to the stack.

func (TestChar) String

func (i TestChar) String() string

String returns the string representation of this instruction.

type TestCharNoChoice

type TestCharNoChoice struct {
	Byte byte
	Lbl  Label
	// contains filtered or unexported fields
}

TestCharNoChoice consumes the next byte if it matches Byte and jumps to Lbl otherwise. No backtrack entry is pushed to the stack.

func (TestCharNoChoice) String

func (i TestCharNoChoice) String() string

String returns the string representation of this instruction.

type TestSet

type TestSet struct {
	Chars charset.Set
	Lbl   Label
	// contains filtered or unexported fields
}

TestSet consumes the next byte if it is in the set Chars and jumps to Lbl otherwise. If the consumption is possible, a backtrack entry referring to Lbl and the subject position from before consumption is pushed to the stack.

func (TestSet) String

func (i TestSet) String() string

String returns the string representation of this instruction.

type TestSetNoChoice

type TestSetNoChoice struct {
	Chars charset.Set
	Lbl   Label
	// contains filtered or unexported fields
}

TestSetNoChoice is the same as TestSet but no backtrack entry is pushed to the stack.

func (TestSetNoChoice) String

func (i TestSetNoChoice) String() string

String returns the string representation of this instruction.

Jump to

Keyboard shortcuts

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