Documentation ¶
Overview ¶
Package ir defines the Intermediate Representation (informally, in-memory representation) of smart records.
Index ¶
- Variables
- func AreSameNodes(x, y Nodes) bool
- func IsEqual(x, y Node) bool
- func IsEqualNumber(x, y Number) bool
- func Update(ctx UpdateContext, old, update Node) error
- type Assembler
- type AssemblerContext
- type Bool
- type BoolAssembler
- type Bytes
- type BytesAssembler
- type DefaultUpdateContext
- type Dict
- type DictAssembler
- type Float
- type FloatAssembler
- type Int
- type IntAssembler
- type List
- type ListAssembler
- type Node
- type Nodes
- type Number
- type Pair
- type Pairs
- type Predicate
- type PredicateAssembler
- type SequenceAssembler
- type String
- type StringAssembler
- type UpdateContext
Constants ¶
This section is empty.
Variables ¶
var SyntacticGrammar = SequenceAssembler{ StringAssembler{}, IntAssembler{}, FloatAssembler{}, BoolAssembler{}, BytesAssembler{}, DictAssembler{}, ListAssembler{}, PredicateAssembler{}, }
Functions ¶
func AreSameNodes ¶
AreSameNodes compairs to lists of key/values for set-wise equality (order independent).
func IsEqualNumber ¶
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 ¶
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.
type Bool ¶
type Bool struct { Value bool // contains filtered or unexported fields }
func (*Bool) Disassemble ¶
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 (*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) Disassemble ¶
func (*Dict) Metadata ¶
func (d *Dict) Metadata() meta.MetadataInfo
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 ¶
func (*Float) Disassemble ¶
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 ¶
func (*Int) Disassemble ¶
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) Disassemble ¶
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 ¶
MergeElements returns the union of the two Lists
type Pairs ¶
type Pairs []Pair
Pairs is a list of pairs.
func MergePairs ¶
MergePairs returns the union (wrt keys) of the two lists of pairs. Ties are broken in favor of y, the right argument.
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 (*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 (*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{}