ir

package
v0.0.0-...-49f93d6 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ir defines the Intermediate Representation (informally, in-memory representation) of smart records.

Index

Constants

This section is empty.

Variables

Functions

func AreSameNodes

func AreSameNodes(x, y Nodes) bool

AreSameNodes compairs to lists of key/values for set-wise equality (order independent).

func IsEqual

func IsEqual(x, y Node) bool

func IsEqualNumber

func IsEqualNumber(x, y Number) bool

func Update

func Update(ctx UpdateContext, old, update Node) error

Update updates the node in the first argument with the node in the second argument. NOTE: I don't think this top-level Update function is needed anymore. Consider removing it.

Types

type Assembler

type Assembler interface {
	Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)
}

Assembler is an object that can "parse" a syntactic tree (given as a dictionary) and produces a semantic representation of what is parsed. Usually what is produced will be a smart tag. However, an Assembler is not restricted to produce semantic nodes (like smart tags). It can also produce syntactic nodes (like dictionaries). In that sense, an Assembler can be used to implement any transformation or even just a verification operation that returns the input unchanged. Assemblers can add metadata to the generated semantic nodes.

type AssemblerContext

type AssemblerContext struct {
	Grammar Assembler
	Keys    map[string]interface{}
	Host    host.Host
}

AssemblerContext holds general contextual data for the stage of the assembly process. It provides a standard mechanism for assemblers to pass context to subordinate assemblers that are called recursively. NOTE: The right general long-term design for AssemblerContext is to make it an interface. This is currently not necassitated by our uses, so such improvements are deferred for when needed.

func (AssemblerContext) Assemble

func (ctx AssemblerContext) Assemble(src xr.Node, metadata ...meta.Metadata) (Node, error)

type Bool

type Bool struct {
	Value bool
	// contains filtered or unexported fields
}

func (*Bool) Disassemble

func (b *Bool) Disassemble() xr.Node

func (*Bool) Metadata

func (b *Bool) Metadata() meta.MetadataInfo

func (*Bool) UpdateWith

func (b *Bool) UpdateWith(ctx UpdateContext, with Node) error

type BoolAssembler

type BoolAssembler struct{}

func (BoolAssembler) Assemble

func (asm BoolAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type Bytes

type Bytes struct {
	Bytes []byte
	// contains filtered or unexported fields
}

func (*Bytes) Disassemble

func (b *Bytes) Disassemble() xr.Node

func (*Bytes) Metadata

func (b *Bytes) Metadata() meta.MetadataInfo

func (*Bytes) UpdateWith

func (b *Bytes) UpdateWith(ctx UpdateContext, with Node) error

type BytesAssembler

type BytesAssembler struct{}

func (BytesAssembler) Assemble

func (asm BytesAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type DefaultUpdateContext

type DefaultUpdateContext struct{}

type Dict

type Dict struct {
	Pairs Pairs // keys must be unique wrt IsEqual
	// contains filtered or unexported fields
}

Dict is a set of uniquely-keyed values.

func (Dict) Copy

func (d Dict) Copy() Dict

func (*Dict) Disassemble

func (d *Dict) Disassemble() xr.Node

func (Dict) Get

func (d Dict) Get(key Node) Node

func (Dict) Len

func (d Dict) Len() int

func (*Dict) Metadata

func (d *Dict) Metadata() meta.MetadataInfo

func (*Dict) Remove

func (d *Dict) Remove(key Node) Node

func (*Dict) UpdateWith

func (d *Dict) UpdateWith(ctx UpdateContext, with Node) error

type DictAssembler

type DictAssembler struct{}

func (DictAssembler) Assemble

func (asm DictAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type Float

type Float struct {
	*big.Float
	// contains filtered or unexported fields
}

func (*Float) Disassemble

func (n *Float) Disassemble() xr.Node

func (*Float) Metadata

func (n *Float) Metadata() meta.MetadataInfo

func (*Float) TypeIsNumber

func (n *Float) TypeIsNumber()

func (*Float) UpdateWith

func (n *Float) UpdateWith(ctx UpdateContext, with Node) error

type FloatAssembler

type FloatAssembler struct{}

func (FloatAssembler) Assemble

func (asm FloatAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type Int

type Int struct {
	*big.Int
	// contains filtered or unexported fields
}

func NewInt64

func NewInt64(v int64, metadata ...meta.Metadata) *Int

func (*Int) Disassemble

func (n *Int) Disassemble() xr.Node

func (*Int) Metadata

func (n *Int) Metadata() meta.MetadataInfo

func (*Int) TypeIsNumber

func (n *Int) TypeIsNumber()

func (*Int) UpdateWith

func (n *Int) UpdateWith(ctx UpdateContext, with Node) error

type IntAssembler

type IntAssembler struct{}

func (IntAssembler) Assemble

func (asm IntAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type List

type List struct {
	Elements Nodes
	// contains filtered or unexported fields
}

List is a List of (uniquely) elements.

func (List) Copy

func (s List) Copy() List

func (*List) Disassemble

func (s *List) Disassemble() xr.Node

func (List) Len

func (s List) Len() int

func (*List) Metadata

func (s *List) Metadata() meta.MetadataInfo

func (*List) UpdateWith

func (s *List) UpdateWith(ctx UpdateContext, with Node) error

type ListAssembler

type ListAssembler struct{}

func (ListAssembler) Assemble

func (asm ListAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type Node

type Node interface {
	Disassemble() xr.Node // returns only syntactic nodes
	UpdateWith(ctx UpdateContext, with Node) error
	Metadata() meta.MetadataInfo
}

type Nodes

type Nodes []Node

func MergeElements

func MergeElements(x, y Nodes) Nodes

MergeElements returns the union of the two Lists

func (Nodes) IndexOf

func (ns Nodes) IndexOf(element Node) int

type Number

type Number interface {
	TypeIsNumber()
}

type Pair

type Pair struct {
	Key   Node `json:"key"`
	Value Node `json:"value"`
}

Pair holds a key/value pair.

type Pairs

type Pairs []Pair

Pairs is a list of pairs.

func MergePairs

func MergePairs(x, y Pairs) Pairs

MergePairs returns the union (wrt keys) of the two lists of pairs. Ties are broken in favor of y, the right argument.

func (Pairs) IndexOf

func (ps Pairs) IndexOf(key Node) int

type Predicate

type Predicate struct {
	Tag        string
	Positional Nodes
	Named      Pairs // the keys in each pair must be unique wrt IsEqual
	// contains filtered or unexported fields
}

Predicate models a function invocation with named and positional arguments, corresponding to the syntax:

tag(a1, a2, ...; n1=v1, n2=v2, ...)

func (*Predicate) Disassemble

func (p *Predicate) Disassemble() xr.Node

func (*Predicate) GetNamed

func (p *Predicate) GetNamed(key Node) Node

func (*Predicate) Metadata

func (p *Predicate) Metadata() meta.MetadataInfo

func (*Predicate) UpdateWith

func (p *Predicate) UpdateWith(ctx UpdateContext, with Node) error

type PredicateAssembler

type PredicateAssembler struct{}

func (PredicateAssembler) Assemble

func (asm PredicateAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type SequenceAssembler

type SequenceAssembler []Assembler

SequenceAssembler is, in common parlance, a parser combinator. Or, in our nomenclature, an "assembler combinator". SequenceAssembler tries to assemble the input, using each of its subordinate assemblers in turn until one of them succeeds. NOTE: With the current implementation all assembled nodes are updated with the same metadata. In the future additional tags could be specified so nodes can be assembled with different metadata each.

func (SequenceAssembler) Assemble

func (asm SequenceAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type String

type String struct {
	Value string
	// contains filtered or unexported fields
}

String is a node representing a string literal.

func (*String) Disassemble

func (s *String) Disassemble() xr.Node

func (*String) Metadata

func (s *String) Metadata() meta.MetadataInfo

func (*String) UpdateWith

func (s *String) UpdateWith(ctx UpdateContext, with Node) error

type StringAssembler

type StringAssembler struct{}

func (StringAssembler) Assemble

func (asm StringAssembler) Assemble(ctx AssemblerContext, src xr.Node, metadata ...meta.Metadata) (Node, error)

type UpdateContext

type UpdateContext interface{}

Directories

Path Synopsis
Package base implements the basic set of smart tags supported by a smart record.
Package base implements the basic set of smart tags supported by a smart record.

Jump to

Keyboard shortcuts

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