vm

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: 12 Imported by: 6

Documentation

Overview

Package vm implements the GPeg virtual machine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Code

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

Code is the representation of VM bytecode.

func Encode

func Encode(insns isa.Program) Code

Encode transforms a program into VM bytecode.

func FromBytes

func FromBytes(b []byte) (Code, error)

FromBytes loads a Code from a compressed and serialized object.

func FromJson

func FromJson(b []byte) (Code, error)

FromJson returns a Code loaded from JSON form.

func (*Code) Exec

func (vm *Code) Exec(r io.ReaderAt, memtbl memo.Table) (bool, int, *memo.Capture, []ParseError)

Exec executes the parsing program this virtual machine was created with. It returns whether the parse was a match, the last position in the subject string that was matched, and any captures that were created.

func (*Code) ExecInterval

func (vm *Code) ExecInterval(r io.ReaderAt, memtbl memo.Table, intrvl *Interval) (bool, int, *memo.Capture, []ParseError)

func (*Code) Size

func (c *Code) Size() int

Size returns the size of the encoded instructions.

func (*Code) ToBytes

func (c *Code) ToBytes() ([]byte, error)

ToBytes serializes and compresses this Code.

func (*Code) ToJson

func (c *Code) ToJson() ([]byte, error)

ToJson returns this Code serialized to JSON form.

type Interval

type Interval struct {
	Low, High int
}

type ParseError

type ParseError struct {
	Message string
	Pos     int
}

func (ParseError) Error

func (e ParseError) Error() string

Jump to

Keyboard shortcuts

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