Package sxir/pkg/runtime/libgo
import "syntaxir.dev/sxir/pkg/runtime/libgo"
Generated from the source of this version. Also on pkg.go.dev.
Overview
Package libgo is the library of Go parsers generated by sxir gen.
A generated parser imports this package as rt, or carries a copy of its files in its internal/libgo directory, so that it depends only on the runtime packages (syntaxir.dev/sxir/pkg/runtime with its packages input, value, value/impl, instrument and schema) and the standard library. The code generated from a grammar sets up the rules and calls the exported names that are documented as for generated parsers; those are not a stable API. The file api.go of the generated parser re-exports the names its users need. Its behavior must match internal/runtime/engine exactly; the generator tests in internal/runtime/engine compare them.
Index
ConstantsVariablesfunc Allocfunc AllocSlicefunc BaseNodefunc DocumentParseConvertedfunc IterateNodesfunc KindOffunc NewGrammarfunc NewNodefunc NewNodeTypeKindsfunc RawFieldfunc ResolveOptionsfunc RunParsefunc RunParseConvertedfunc RunParseResolvedfunc RunParseStreamfunc RunParseStreamWithBudgetfunc SetMemoReportfunc SetNodeElemsfunc SetNodeFieldfunc SetNodeStartfunc SetNodeTextfunc TAsfunc TBackfunc TDereffunc TFreshNodefunc TKidfunc TListOffunc TMatchAsfunc TParsefunc TParseResolvedfunc TPtrfunc TPubfunc TPubInfunc TRegisterNodeTypefunc TSetNodeTypefunc TypedDocumentParsefunc UnboxNodefunc UnboxValuetype ActCtxfunc (*ActCtx) ActionCastFailedfunc (*ActCtx) ActionSetFieldfunc (*ActCtx) ActionStructfunc (*ActCtx) Capfunc (*ActCtx) NewListfunc (*ActCtx) NewListLogicalfunc (*ActCtx) Vartype BudgetClasstype BudgetControlfunc (*BudgetControl) Chargefunc (*BudgetControl) ChargeDocfunc (*BudgetControl) Checkfunc (*BudgetControl) FreeBeginfunc (*BudgetControl) FreeEndfunc (*BudgetControl) Pollfunc (*BudgetControl) Taketype BudgetRangetype CaptureFrametype Chunktype Classtype ClassSteptype Datatype Documentfunc MakeDocumentfunc (*Document) BeginParsefunc (*Document) CacheStatsfunc (*Document) Editfunc (*Document) EndParsefunc (*Document) Parsefunc (*Document) ResetHistoryfunc (*Document) ResolveParseOptionsfunc (*Document) Statsfunc (*Document) Textfunc (*Document) Unittype DocumentSliceKeytype Envtype ExpIDtype ExpMarktype FieldTypetype Marktype OperatorsRuletype OperatorsRuleLinetype OperatorsRuleOptype Parserfunc (*Parser) ActionBinaryfunc (*Parser) ActionConformsfunc (*Parser) ActionConvertfunc (*Parser) ActionCoverfunc (*Parser) ActionFilterKeepfunc (*Parser) ActionHullfunc (*Parser) ActionHullLogicalfunc (*Parser) ActionItemAtfunc (*Parser) ActionItemsfunc (*Parser) ActionLengthfunc (*Parser) ActionLogicfunc (*Parser) ActionMadefunc (*Parser) ActionMemberfunc (*Parser) ActionNodeTypefunc (*Parser) ActionPushfunc (*Parser) ActionPushItemsfunc (*Parser) ActionTextfunc (*Parser) ActionUnaryfunc (*Parser) Anchorfunc (*Parser) AtEndfunc (*Parser) AtEndBatchfunc (*Parser) AtEndBatchOrdinaryfunc (*Parser) AtEndOrdinaryfunc (*Parser) AtLineEndfunc (*Parser) AtLineEndOrdinaryfunc (*Parser) AtLineEndTracedfunc (*Parser) AtLineStartfunc (*Parser) AtLineStartBatchfunc (*Parser) AtLineStartBatchOrdinaryfunc (*Parser) AtLineStartOrdinaryfunc (*Parser) AttachCapturesfunc (*Parser) Bindfunc (*Parser) Callfunc (*Parser) CallLogicalfunc (*Parser) ChargeKeyfunc (*Parser) DiagnosticAttrfunc (*Parser) DropKidsfunc (*Parser) ElemsAbovefunc (*Parser) EmitStreamfunc (*Parser) Enterfunc (*Parser) ErrorAttrfunc (*Parser) ExaminedBeginfunc (*Parser) ExaminedEndfunc (*Parser) Expectfunc (*Parser) ExpectOrdinaryfunc (*Parser) Finishfunc (*Parser) FirstCallfunc (*Parser) HasCharfunc (*Parser) HasCharOrdinaryfunc (*Parser) HasCharTracedfunc (*Parser) InvokePlainfunc (*Parser) Isolatefunc (*Parser) Keepfunc (*Parser) KeyUnitsfunc (*Parser) Kidsfunc (*Parser) LiteralTextfunc (*Parser) LookBeginfunc (*Parser) LookEndfunc (*Parser) MakeErrorfunc (*Parser) Markfunc (*Parser) MatchAnyfunc (*Parser) MatchAnyLogicalfunc (*Parser) MatchAnyOrdinaryfunc (*Parser) MatchCharfunc (*Parser) MatchCharTracedfunc (*Parser) MatchLiteralfunc (*Parser) MatchLiteralFoldfunc (*Parser) MatchLiteralFoldLogicalfunc (*Parser) MatchLiteralFoldOrdinaryfunc (*Parser) MatchLiteralFoldTracedfunc (*Parser) MatchLiteralLogicalfunc (*Parser) MatchLiteralOrdinaryfunc (*Parser) MatchLiteralTracedfunc (*Parser) MergeExpectedfunc (*Parser) NewBranchfunc (*Parser) NewBranchOrdinaryfunc (*Parser) NewErrorNodefunc (*Parser) NewFramefunc (*Parser) NewNodefunc (*Parser) NewNodeOrdinaryfunc (*Parser) NewTerminalfunc (*Parser) NewTerminalOrdinaryfunc (*Parser) NextOrdinaryfunc (*Parser) Nodesfunc (*Parser) OperatorsRuleParsefunc (*Parser) Peekfunc (*Parser) PeekOrdinaryfunc (*Parser) PeekTracedfunc (*Parser) PollUnitsfunc (*Parser) Predicatefunc (*Parser) PushRecoveredfunc (*Parser) RecoverAttrfunc (*Parser) RecoveryErrorTextfunc (*Parser) RejectBudgetClassfunc (*Parser) Resetfunc (*Parser) Restorefunc (*Parser) ResumeBeginfunc (*Parser) ResumeEndfunc (*Parser) ResumeFinishfunc (*Parser) ResumeMorefunc (*Parser) ResumeNextfunc (*Parser) ResumeOnfunc (*Parser) ResumeStartfunc (*Parser) RunBeginfunc (*Parser) RunHotfunc (*Parser) RunWalkedfunc (*Parser) ScanEndfunc (*Parser) ScanKidsfunc (*Parser) ScanReachfunc (*Parser) ScopeValuefunc (*Parser) SetCapturefunc (*Parser) ShapeCapturefunc (*Parser) ShapeSinglefunc (*Parser) Singlefunc (*Parser) SkipBeginfunc (*Parser) SkipCallfunc (*Parser) SkipCallsfunc (*Parser) SkipEndfunc (*Parser) SkipHitfunc (*Parser) SkipKidsfunc (*Parser) SkipUnitsfunc (*Parser) SkipValuefunc (*Parser) SkipVisitfunc (*Parser) Spendfunc (*Parser) SpendReadfunc (*Parser) StreamStartfunc (*Parser) StreamsInfunc (*Parser) Textfunc (*Parser) TextEqualfunc (*Parser) TextEqualLogicalfunc (*Parser) TooDeepfunc (*Parser) Unisolatefunc (*Parser) UnitsOfItemsfunc (*Parser) UnitsSizedtype Ruletype RuleExtratype RuleSpectype RunKeytype RunStatetype Shapertype StreamPulltype TActCtxfunc (*TActCtx) ActionCastFailedfunc (*TActCtx) ActionComparefunc (*TActCtx) ActionFieldOperandfunc (*TActCtx) ActionRaisefunc (*TActCtx) Capfunc (*TActCtx) Finishfunc (*TActCtx) MadeOffunc (*TActCtx) NewListfunc (*TActCtx) NewListLogicalfunc (*TActCtx) Resultfunc (*TActCtx) Vartype TCaptureFrametype TErrorfunc NewTErrorfunc (*TError) TFieldfunc (*TError) TFreshfunc (*TError) TKidsfunc (*TError) TNamefunc (*TError) TSetFreshfunc (*TError) TStructfunc (*TError) TTexttype TErrorValuetype TMatchfunc (*TMatch) TFieldfunc (*TMatch) TFreshfunc (*TMatch) TKidsfunc (*TMatch) TNamefunc (*TMatch) TSetFreshfunc (*TMatch) TStructfunc (*TMatch) TTexttype TNodetype TOperandtype TOperatorsRuletype TOperatorsRuleLinetype TOperatorsRuleOptype TParserfunc (*TParser) ActionBinaryfunc (*TParser) ActionConformsfunc (*TParser) ActionConvertfunc (*TParser) ActionCoverfunc (*TParser) ActionFilterKeepfunc (*TParser) ActionHullfunc (*TParser) ActionHullLogicalfunc (*TParser) ActionItemAtfunc (*TParser) ActionItemsfunc (*TParser) ActionLengthfunc (*TParser) ActionLogicfunc (*TParser) ActionMadefunc (*TParser) ActionMemberfunc (*TParser) ActionPushfunc (*TParser) ActionPushItemsfunc (*TParser) ActionTextfunc (*TParser) ActionUnaryfunc (*TParser) Anchorfunc (*TParser) AttachCapturesfunc (*TParser) Bindfunc (*TParser) Callfunc (*TParser) CallMemofunc (*TParser) ClassFastfunc (*TParser) ClassFastLogicalfunc (*TParser) ClassSkipfunc (*TParser) ClassSkipLogicalfunc (*TParser) ClassesSkipfunc (*TParser) ClassesSkipLogicalfunc (*TParser) DiagnosticAttrfunc (*TParser) DocumentCallfunc (*TParser) DropCreatedfunc (*TParser) DropKidsfunc (*TParser) DropTrailfunc (*TParser) ElemsAbovefunc (*TParser) ErrorAttrfunc (*TParser) Finishfunc (*TParser) FreeFramefunc (*TParser) InvokePlainfunc (*TParser) Kidsfunc (*TParser) ListFieldfunc (*TParser) Markfunc (*TParser) MatchAnyfunc (*TParser) MatchAnyOrdinaryfunc (*TParser) MatchLiteralfunc (*TParser) MatchLiteralFoldfunc (*TParser) MatchLiteralOrdinaryfunc (*TParser) NewFramefunc (*TParser) NewMatchfunc (*TParser) NewMatchOrdinaryfunc (*TParser) NewNodefunc (*TParser) NewNodeOrdinaryfunc (*TParser) NewValsfunc (*TParser) OperatorsRuleParsefunc (*TParser) Predicatefunc (*TParser) PushKidfunc (*TParser) RecoverAttrfunc (*TParser) Resetfunc (*TParser) RunBeginfunc (*TParser) ScanKidsfunc (*TParser) ScopeValuefunc (*TParser) SetCapturefunc (*TParser) ShapeCapturefunc (*TParser) ShapeSinglefunc (*TParser) Singlefunc (*TParser) SkipCallfunc (*TParser) SkipCallsfunc (*TParser) SkipKidsfunc (*TParser) SkipTerminalfunc (*TParser) SkipTerminalLogicalfunc (*TParser) SkipValuefunc (*TParser) TConvertResultfunc (*TParser) TConvertResultOwnedfunc (*TParser) UnitsOfItemsfunc (*TParser) UseCtxtype TPubHookstype TRuletype TSeqfunc (*TSeq) TFieldfunc (*TSeq) TFreshfunc (*TSeq) TKidsfunc (*TSeq) TNamefunc (*TSeq) TSetFreshfunc (*TSeq) TSetSpanfunc (*TSeq) TSpanfunc (*TSeq) TStructfunc (*TSeq) TTexttype TValtype TerminalProgramtype TerminalTexttype TypedDocumentCloneBasefunc (*TypedDocumentCloneBase) Beginfunc (*TypedDocumentCloneBase) ReleaseBasefunc (*TypedDocumentCloneBase) Rememberfunc (*TypedDocumentCloneBase) Steptype TypedDocumentCloneTask
Constants
const (
OpAdd = 0 // +
OpSub = 1 // -
OpMul = 2 // *
OpQuo = 3 // /
OpRem = 4 // %
OpEq = 5 // ==
OpNe = 6 // !=
OpLt = 7 // <
OpLe = 8 // <=
OpGt = 9 // >
OpGe = 10 // >=
OpIndex = 11 // []
)
The codes of the binary operators, as the compositions of action expressions take them, for generated parsers; not a stable API.
const (
OpNeg = 0 // -
OpNot = 1 // !
)
The codes of the unary operators, for generated parsers; not a stable API.
const (
OpAnd = 0 // &&
OpOr = 1 // ||
)
The codes of the logical operators, for generated parsers; not a stable API.
const (
MemberField = 0
MemberStart = 1
MemberEnd = 2
MemberValue = 3
MemberCapture = 4
)
The codes of the kinds of member reads, for generated parsers; not a stable API.
const (
TypeTupleValue = valueimpl.TypeTupleValue
TypeListValue = valueimpl.TypeListValue
)
TypeTupleValue and TypeListValue are the type names of tuple and list values.
TypeTupleValue and TypeListValue are for generated parsers; not a stable API.
const (
// TerminalClass, class, id: consumes one character of Classes[class], or records the
// expectation id where it is expected.
TerminalClass uint16 = iota
// TerminalLiteral, literal, id: matches Literals[literal], or records id at its start.
TerminalLiteral
// TerminalSeq, operations...: matches the operations in turn.
TerminalSeq
// TerminalChoice, table, operations...: matches the first of the operations that matches.
// Unless table is TerminalNoTable, the choice begins with a run of guarded alternatives
// and Prepare builds the dispatch table number table for it if the table fits.
TerminalChoice
// TerminalOptional, operation: matches the operation or nothing.
TerminalOptional
// TerminalNot, operation: succeeds, consuming nothing, where the operation does not match.
TerminalNot
// TerminalGuard, class, id, operation: an alternative of a choice that is skipped where the
// next character is not a member of Classes[class], recording id at the position of the
// choice, as the generated code of a choice skips such an alternative; otherwise it is the
// operation.
TerminalGuard
// TerminalGuardClass, class, id, operations...: a TerminalGuard of an alternative that
// begins with the class Classes[class], whose operations are the rest of the alternative:
// where the guard admits the next character, the class matches it, so the character is
// consumed and the operations are matched in turn.
TerminalGuardClass
)
Operations of a TerminalProgram. Every operation starts with its code and its length in words, the operation included, so that a reader can step over it.
const (
RuleMemo uint8 = 1 << iota
RuleLeader
RuleNovalue
RuleDocMemo
RuleSplice
RuleRec
RulePositional
)
The flags of a RuleSpec set the fields of a Rule of the same names.
const BaseString = valueimpl.BaseString
BaseString is the base (valueimpl.Kind.Base) of string nodes.
BaseString is for generated parsers; not a stable API.
const Protocol30 = 30
Protocol30 is declared because the library implements protocol version 30.
const RunHotSpan = 64
RunHotSpan is the length of input that a walk of a run site may walk again, below the furthest point that the walks before it reached, before the site turns hot: the engine's, a constant of the charge model ("Run Sites" in spec/runtime/parsing.md). A walk shorter than that neither turns a site hot nor can walk that far again, so generated code passes only the longer ones to RunWalked. Tests that run the hot path on short inputs build their parsers against a copy of the library with a lower value.
const TerminalNoTable uint16 = 0xffff
TerminalNoTable marks a TerminalChoice without a dispatch table.
Variables
var (
MatchKind = valueimpl.MatchKind
SeqKind = valueimpl.SeqKind
ListKind = valueimpl.ListKind
)
The kinds of the reserved types without a rule that generated parsers name.
MatchKind, SeqKind and ListKind are for generated parsers; not a stable API.
var DocumentBusy = fmt.Errorf("document is already parsing")
DocumentBusy returned by a Parse, ParseValue or Edit of a Document that is already parsing. Only a trace callback of that parse can make one; parsers generated with observability export it as ErrDocumentBusy.
DocumentBusy is for generated parsers; not a stable API.
var EmptyFrame = &CaptureFrame{}
EmptyFrame is for generated parsers; not a stable API.
var EmptyTFrame = &TCaptureFrame{}
EmptyTFrame is for generated parsers; not a stable API.
Functions
func Alloc source
func Alloc[T any](s *Chunk[T]) *T
Alloc returns a new zero value from the chunk, which grows from 8 to 256 values. It allocates the first three values independently, so a later published value cannot retain discarded early siblings through a chunk.
Alloc is for generated parsers; not a stable API.
func AllocSlice source
func AllocSlice[T any](s *Chunk[T], n int) []T
AllocSlice returns n zero values with capacity n, so appending cannot overwrite another returned slice. Small-list chunks grow from 64 to 1,024 elements; a list of more than 256 elements is allocated on its own, and so is the first nonempty small list, to keep its backing values separate from later published lists of the same type. An empty list is not nil.
AllocSlice is for generated parsers; not a stable API.
func BaseNode source
func BaseNode(n *sxirvalue.Node) *sxirvalue.Node
BaseNode returns the node n of a named node type as the string, tuple or list node it was converted from: a copy with the kind of that node (n itself for other nodes).
BaseNode is for generated parsers; not a stable API.
func DocumentParseConverted source
func DocumentParseConverted[T any](d *documentState, o parseOptions, convert func(*sxirvalue.Node, *BudgetControl, error) T) (res T, err error)
DocumentParseConverted keeps Node parsing and final typed conversion inside the same limit-controlled invocation and memo cleanup boundary.
DocumentParseConverted is for generated parsers; not a stable API.
func IterateNodes source
func IterateNodes(g *grammar, opts []sxirruntime.ParseOption, run func(emit func(*sxirvalue.Node) error) error) (*sxirruntime.StreamIterator, error)
IterateNodes validates the options of a stream entry point of grammar g and returns a lazy iterator over the nodes that run passes to emit.
IterateNodes is for generated parsers; not a stable API.
func KindOf source
func KindOf(typ, rule string) *valueimpl.Kind
KindOf returns the interned kind of the type and rule names (rules and actions prepare theirs).
KindOf is for generated parsers; not a stable API.
func NewGrammar source
func NewGrammar(maxDepth int) *grammar
NewGrammar returns an empty grammar with the default limit MaxDepth on nested recursive rule calls.
NewGrammar is for generated parsers; not a stable API.
func NewNode source
func NewNode(k sxirvalue.NodeKind, start, end int, text string, elems []*sxirvalue.Node, typ string, fields valueimpl.Fields, value any) *sxirvalue.Node
NewNode returns a node of kind k with the range [start, end). text is the string of a KindString node, elems the elements of a tuple or list, typ the type name of a KindStruct node, fields its fields (or captures), and value the value of a KindValue node.
NewNode is for generated parsers and tests; not a stable API.
func NewNodeTypeKinds source
func NewNodeTypeKinds(typ string) *nodeTypeKinds
NewNodeTypeKinds returns the interned kinds of the named node type typ.
NewNodeTypeKinds is for generated parsers; not a stable API.
func RawField source
func RawField(n *sxirvalue.Node, name string) any
RawField returns the value of the field or capture name, whether or not it is public.
RawField is for generated parsers; not a stable API.
func ResolveOptions source
func ResolveOptions(g *grammar, opts []sxirruntime.ParseOption) (parseOptions, error)
ResolveOptions applies opts to the defaults of grammar g.
ResolveOptions is for generated parsers; not a stable API.
func RunParse source
func RunParse(r *Rule, input string, opts []sxirruntime.ParseOption) (n *sxirvalue.Node, err error)
RunParse parses the whole input with rule r.
RunParse is for generated parsers; not a stable API.
func RunParseConverted source
func RunParseConverted[T any](r *Rule, input string, o parseOptions, conv func(*sxirvalue.Node, *BudgetControl, error) T) (res T, err error)
RunParseConverted shares admission and counters with a Node-to-typed converter.
RunParseConverted is for generated parsers; not a stable API.
func RunParseResolved source
func RunParseResolved(r *Rule, input string, o parseOptions) (n *sxirvalue.Node, err error)
RunParseResolved is for generated parsers; not a stable API.
func RunParseStream source
func RunParseStream(r *Rule, reader io.Reader, emit func(*sxirvalue.Node) error, opts []sxirruntime.ParseOption) error
RunParseStream parses the input read from reader with rule r, passing each committed element of the rule's #stream repetition to emit.
RunParseStream is for generated parsers; not a stable API.
func RunParseStreamWithBudget source
func RunParseStreamWithBudget(r *Rule, reader io.Reader, emit func(*sxirvalue.Node, *BudgetControl) error, opts []sxirruntime.ParseOption) (err error)
RunParseStreamWithBudget is RunParseStream with emit also given the parse's budget control, so that converting elements to typed values is charged to it.
RunParseStreamWithBudget is for generated parsers; not a stable API.
func SetMemoReport source
func SetMemoReport(out *string)
SetMemoReport makes the parses that start after it, and that count logical units, store in *out, when they end without being stopped, the state of their memo that later calls read: the policy counts of each rule, the positions where each rule was called (the seen marks) and the stored entries, each chain in its order. A nil out stops the reports. It is a hook for the tests of logical units, which compare the memo between parsers that must leave the same state: it holds one destination for the whole process, so a test that uses it runs no parse beside it.
SetMemoReport is for generated parsers; not a stable API.
func SetNodeElems source
func SetNodeElems(n *sxirvalue.Node, elems []*sxirvalue.Node)
SetNodeElems replaces the elements of the tuple or list n, which can make a cycle.
SetNodeElems is for generated parsers and tests; not a stable API.
func SetNodeField source
func SetNodeField(n *sxirvalue.Node, name string, v any)
SetNodeField sets the field name of n to v, adding it if absent.
SetNodeField is for generated parsers and tests; not a stable API.
func SetNodeStart source
func SetNodeStart(n *sxirvalue.Node, start int)
SetNodeStart replaces the start of the range of n.
SetNodeStart is for generated parsers and tests; not a stable API.
func SetNodeText source
func SetNodeText(n *sxirvalue.Node, text string)
SetNodeText replaces the string of the KindString node n.
SetNodeText is for generated parsers and tests; not a stable API.
func TAs source
func TAs[T any](v any) T
TAs returns v as a T, or the zero T (nil) if it is not one.
TAs is for generated parsers; not a stable API.
func TBack source
func TBack(h *TPubHooks, v any) any
TBack returns the value of a field of an open type (a string node, a tuple or list node, an error value, a union, node or any) as a value of the typed library: the inverse of TPub, except that a tuple or list node becomes a tuple node and a []any a tuple value.
TBack is for generated parsers; not a stable API.
func TFreshNode source
func TFreshNode(v any) any
TFreshNode returns v if it is a fresh string, tuple or list node, and otherwise nil. Taken from the value of a rule's body before the rule finishes it, it is the node the body made and nothing else holds yet (see TConvertResultOwned).
TFreshNode is for generated parsers; not a stable API.
func TKid source
func TKid(kids []any, i int) any
TKid returns element i of a tuple's elements (nil if there is none).
TKid is for generated parsers; not a stable API.
func TListOf source
func TListOf(kids []any) any
TListOf returns a list value of kids, for reading a list field of a struct in an action.
TListOf is for generated parsers; not a stable API.
func TMatchAs source
func TMatchAs[N any](x *TMatch) *N
TMatchAs returns the public form of x, a string node of a named node type whose Go type N is struct{ TNode[string] }: N has the layout of TNode[string] (the types package declares it so, and the parser package refers to the schema constant of the types package it was generated with, so a parser and a types package of different schemas do not compile together), so the public value is x's own TNode seen as an N. A node so publishes as one value wherever it appears, as a plain string node does, without allocating or remembering it.
TMatchAs is for generated parsers; not a stable API.
func TParse source
func TParse[T any](r *TRule, input string, opts []sxirruntime.ParseOption, ext any, conv func(any) T) (T, error)
TParse parses the whole input with the typed rule r, and returns the result converted by conv (before the parser's scratch memory, which the result may be in, is cleared). ext holds the generated code's chunks.
TParse is for generated parsers; not a stable API.
func TParseResolved source
func TParseResolved[T any](r *TRule, input string, o parseOptions, ext any, conv func(any) T) (res T, err error)
TParseResolved consumes options already applied by the public entry point.
TParseResolved is for generated parsers; not a stable API.
func TPtr source
func TPtr[T any](p *T) any
TPtr and TDeref return the value of a field of a pointer type as a value of the typed library.
TPtr is for generated parsers; not a stable API.
func TPub source
func TPub(h *TPubHooks, v any) any
TPub returns the public form of a value: *TNode[string] and the types package's *Error for TMatch and TError, a *TNode[any] for a tuple or list node and a []any for a tuple or list value, with the public forms of their elements.
TPub is for generated parsers; not a stable API.
func TPubIn source
func TPubIn(h *TPubHooks, a any, v any) any
TPubIn is TPub with the generated code's chunks a (a *tslabs, or nil), which the public forms of values of named node types (tnodeType.pub) are made from and remembered in.
TPubIn is for generated parsers; not a stable API.
func TRegisterNodeType source
func TRegisterNodeType(name string, pub func(a any, x TVal) any) uint16
TRegisterNodeType registers a named node type of a grammar and returns its index. Types of different grammars have different indexes even when their names are the same.
TRegisterNodeType is for generated parsers; not a stable API.
func TSetNodeType source
func TSetNodeType(v any, nt uint16) any
TSetNodeType gives v, a string, tuple or list node that back made, the named node type nt.
TSetNodeType is for generated parsers; not a stable API.
func TypedDocumentParse source
func TypedDocumentParse[T any](d *Document, root *TRule, o parseOptions, a budgetControlSetter, publish func(any) T) (res T, err error)
TypedDocumentParse parses the Document d with the typed rule root and returns the value that publish makes of the parse result. The values of a typed Document parse are write-once: they are published as they are, and later parses reuse them, so publish must not write to them. a is the generated code's allocation chunks.
TypedDocumentParse is for generated parsers; not a stable API.
func UnboxNode source
func UnboxNode(n *sxirvalue.Node) any
UnboxNode returns the value that the carrier n stands for: the box's value for a box, nil for nil, and n otherwise.
UnboxNode is for generated parsers; not a stable API.
func UnboxValue source
func UnboxValue(v any) any
UnboxValue is UnboxNode for a value that may be a carrier.
UnboxValue is for generated parsers; not a stable API.
Types
type ActCtx source
type ActCtx struct {
P *Parser
Lhs, Rhs, Op any
Value any // the folded value of an Operators Rule, in its whole-rule action
// contains filtered or unexported fields
}
ActCtx is the context of evaluating an action or a predicate.
ActCtx is for generated parsers; not a stable API.
func (*ActCtx) ActionCastFailed source
func (c *ActCtx) ActionCastFailed(v any, t *FieldType, line, col int) any
ActionCastFailed returns the failure of a cast of v to t, a type that v does not fit. The failure names the input position where the action started and, when line is positive, the grammar position of the cast.
ActionCastFailed is for generated parsers; not a stable API.
func (*ActCtx) ActionSetField source
func (c *ActCtx) ActionSetField(n *sxirvalue.Node, name string, v any)
ActionSetField sets the field name of the struct n, which an action expression is making, to v: the operation action.setField.
ActionSetField is for generated parsers; not a stable API.
func (*ActCtx) ActionStruct source
func (c *ActCtx) ActionStruct(typ string, n int) *sxirvalue.Node
ActionStruct returns a new struct of the type typ with no field set and an empty range, with room for n fields: the operation action.struct of an action expression that makes a struct.
ActionStruct is for generated parsers; not a stable API.
func (*ActCtx) Cap source
func (c *ActCtx) Cap(slot int) any
func (*ActCtx) NewList source
func (c *ActCtx) NewList(items []*sxirvalue.Node) *sxirvalue.Node
func (*ActCtx) NewListLogical source
func (c *ActCtx) NewListLogical(items []*sxirvalue.Node) *sxirvalue.Node
NewListLogical is NewList for the list that map makes of a projection: it counts the elements that map visits and those of the list it builds.
NewListLogical is for generated parsers; not a stable API.
func (*ActCtx) Var source
func (c *ActCtx) Var(slot int) any
Var returns the value of the variable in slot i.
type BudgetClass source
type BudgetClass struct {
// contains filtered or unexported fields
}
BudgetClass is a character class with more ranges than a matcher tests inline. Testing a character charges one unit per range tried, up to the range that holds it.
BudgetClass is for generated parsers; not a stable API.
func NewBudgetClass source
func NewBudgetClass(ranges []BudgetRange, negated bool) *BudgetClass
NewBudgetClass returns the class of ranges, negated or not.
NewBudgetClass is for generated parsers; not a stable API.
type BudgetControl source
type BudgetControl struct {
// contains filtered or unexported fields
}
BudgetControl is private state for a single parser invocation. Callers must split long operations into bounded reservations so cancellation can be observed between chunks.
BudgetControl is for generated parsers; not a stable API.
func (*BudgetControl) Charge source
func (c *BudgetControl) Charge(n uint64)
Charge atomically reserves n compute units. Cancellation wins when it is observed at a poll or when the reservation would fail. A failed reservation leaves the counter unchanged. It is safe on a nil receiver.
func (*BudgetControl) ChargeDoc source
func (c *BudgetControl) ChargeDoc(n uint64)
ChargeDoc reserves n units of work that only a Document parse does, as Charge does, and leaves them out of the count against the limit, whichever limit it is: the limit rises by n first, so the units leave the room that counted work has. An unlimited control has no limit to raise. The units are in budgetUsed and advance sinceCheck, so cancellation and memory are polled as for any work, and are in doc, which LimitError leaves out. It is safe on a nil receiver.
func (*BudgetControl) Check source
func (c *BudgetControl) Check()
Check observes cancellation, then the memory limit, at an explicit engine checkpoint. It is safe on a nil receiver.
func (*BudgetControl) FreeBegin source
func (c *BudgetControl) FreeBegin(on bool) uint64
FreeBegin opens a region in which every reservation is work that only a Document parse does, as ChargeDoc reserves it, and returns the mark for FreeEnd, if on holds. The region ends the work it covers before any counted work starts. It lifts the limit until FreeEnd; with on false, or in a region, it opens none and returns noFree. It is safe on a nil receiver.
func (*BudgetControl) FreeEnd source
func (c *BudgetControl) FreeEnd(mark uint64)
FreeEnd ends the region that FreeBegin opened (mark is what it returned, noFree if it opened none): the units reserved since the region began are Document units, and the limit is what it was plus them, or none if it was none.
func (*BudgetControl) Poll source
func (c *BudgetControl) Poll()
Poll counts one step of work that reserves no unit, such as the reuse of an element of a run of a Document, toward the interval at which the parse observes cancellation and its memory limit, and observes them when the interval ends, as a reservation of one unit does (budget.poll). Work that reserves nothing then still lets a cancellation end the parse within an interval of steps. It is safe on a nil receiver.
func (*BudgetControl) Take source
func (c *BudgetControl) Take(n uint64) bool
Take reserves n compute units one at a time, as n one-unit reservations do, and returns true so that it can end a condition. A run that fits without reaching a poll boundary is reserved at once; otherwise takeSlow reserves it, so that a failed run reports the unit that does not fit: Used is the limit and Requested one. It does nothing on a nil receiver.
type BudgetRange source
type BudgetRange struct{ Lo, Hi rune }
BudgetRange is for generated parsers; not a stable API.
type CaptureFrame source
type CaptureFrame struct{ Vals []*sxirvalue.Node }
CaptureFrame is for generated parsers; not a stable API.
type Chunk source
type Chunk[T any] struct {
// contains filtered or unexported fields
}
Chunk owns unused values and the next allocation size for one type. Generated parsers keep one per type of a typed value and take the values from it (Alloc, AllocSlice). Handed-out values are never reused, even when a parse discards them.
Chunk is for generated parsers; not a stable API.
func (*Chunk[T]) MemoryBytes source
func (s *Chunk[T]) MemoryBytes() uint64
MemoryBytes returns the bytes of the values s has allocated.
MemoryBytes is for generated parsers; not a stable API.
type Class source
type Class struct {
ASCII [2]uint64
Wide []rune
Neg bool
}
Class is a character class for generated parsers; not a stable API. ASCII is the bitset of the characters below 128 that the class matches, Wide the inclusive [lo, hi] pairs of the members at or above 128, and Neg inverts the membership of the characters at or above 128 (the bitset already accounts for it below).
func (*Class) Has source
func (c *Class) Has(r rune) bool
Has reports whether r belongs to the class.
type ClassStep source
type ClassStep struct {
C *Class
ID ExpID
}
ClassStep is one character class of a sequence, with the expectation to record when it fails.
ClassStep is for generated parsers; not a stable API.
type Data source
type Data = valueimpl.Data[sxirvalue.Node]
Data is the representation of a value.Node, which the library builds and reads nodes through.
Data is for generated parsers; not a stable API.
func D source
func D(n *sxirvalue.Node) *Data
D returns the representation of the node n. A value.Node holds a Data as its only field, so the conversion is free.
D is for generated parsers; not a stable API.
type Document source
type Document struct {
State *documentState
// contains filtered or unexported fields
}
Document incrementally parses the configured start rule. It belongs to one goroutine; returned nodes may be shared with later parses.
Of its fields and methods, BeginParse, EndParse, ResolveParseOptions, State are for generated parsers; not a stable API.
func MakeDocument source
func MakeDocument(root *Rule, text string, opts []sxirruntime.ParseOption) (d *Document, err error)
MakeDocument is for generated parsers; not a stable API.
func (*Document) BeginParse source
func (d *Document) BeginParse() error
func (*Document) CacheStats source
func (d *Document) CacheStats() sxirruntime.CacheStats
CacheStats returns a point-in-time estimate of the memo and the repetition runs that the Document retains. It does not measure the process heap or bytes returned to the operating system.
func (*Document) Edit source
func (d *Document) Edit(start, end int, text string) error
Edit replaces [start,end) in the Document's position unit.
func (*Document) EndParse source
func (d *Document) EndParse()
func (*Document) Parse source
func (d *Document) Parse(opts ...sxirruntime.ParseOption) (*sxirvalue.Node, error)
Parse parses the current text, applying invocation options after the Document's construction defaults. An invocation cannot change its unit.
func (*Document) ResetHistory source
func (d *Document) ResetHistory()
ResetHistory releases the memo and the repetition runs, the incremental reuse history of a generated Document, without changing the text, the construction options or the statistics of the last parse. Trees returned earlier are detached from future node movement; this does not undo earlier movement.
func (*Document) ResolveParseOptions source
func (d *Document) ResolveParseOptions(opts []sxirruntime.ParseOption) (parseOptions, error)
func (*Document) Stats source
func (d *Document) Stats() sxirruntime.ParseStats
Stats returns the evaluation and reuse counts of the last Parse: Reused counts the memo hits and the elements of repetitions that the parse resumed.
func (*Document) Text source
func (d *Document) Text() string
Text returns the current text. In Bytes it holds the exact bytes, including invalid UTF-8; in CodePoints each invalid UTF-8 byte has been replaced by U+FFFD (normalizeCodePoints).
func (*Document) Unit source
func (d *Document) Unit() sxirinput.PositionUnit
Unit returns the position unit of the document, fixed at construction.
type DocumentSliceKey source
type DocumentSliceKey struct {
First any
Length int
Capacity int
}
A slice's first element, length and capacity identify an exact slice view. The element pointer keeps the backing array visible to the collector while cloning. Empty slices without capacity have no elements or mutable backing array to share.
DocumentSliceKey is for generated parsers; not a stable API.
type Env source
type Env struct {
// contains filtered or unexported fields
}
Env is for generated parsers; not a stable API. It is a persistent vector with one current value per declared variable, indexed by the variable's slot (its position in declaration order). A vector of at most envWidth variables is one node holding the values; a larger one is a trie of nodes with envWidth children, whose depth (the levels above the leaves) every holder knows from the variable count. Environments saved for rollback are never modified: a rebind copies the nodes on the path to its slot and shares the rest.
type ExpID source
type ExpID int32
ExpID is an expectation: an index into descs. With MsgBit set, it is an @error message.
ExpID is for generated parsers; not a stable API.
const (
IdAny ExpID = iota
IdBeginInput
IdEndInput
IdBeginLine
IdEndLine
)
Expectations at the start of every descs table. They are for generated parsers; not a stable API.
const ExpFar ExpID = 1 << 29
ExpFar is the only entry of an expectation record in a parse that does not record expectations. It stands for a failure at the position of the record and describes nothing.
const MsgBit ExpID = 1 << 30
MsgBit is for generated parsers; not a stable API.
func RenamedExpected source
func RenamedExpected(p *Parser, expected []ExpID, name ExpID) []ExpID
RenamedExpected is for generated parsers; not a stable API.
type ExpMark source
type ExpMark struct {
// contains filtered or unexported fields
}
ExpMark is the expectation record before isolate.
ExpMark is for generated parsers; not a stable API.
type FieldType source
type FieldType struct {
Kind byte // i int, s string, b bool, z nil, n node[_], S node[string], v node[elem], E error, N struct or named node type, l list, t tuple (alts), o optional, u union, _ top
Name string
Elem *FieldType
Alts []*FieldType
Text string
}
FieldType is a type that a cast checks a dynamically typed value against. Generated code declares one for each cast.
FieldType is for generated parsers; not a stable API.
type Mark source
type Mark struct {
Pos, Trail int
// contains filtered or unexported fields
}
Mark is for generated parsers; not a stable API.
type OperatorsRule source
type OperatorsRule struct {
Skip matcher
Operands []*OperatorsRuleLine
Prefix []*OperatorsRuleOp
Led []*OperatorsRuleOp
}
OperatorsRule is for generated parsers; not a stable API.
type OperatorsRuleLine source
type OperatorsRuleLine struct {
Scope []string
M matcher
Action func(*ActCtx) (any, any)
// Value makes the value of an operand line without an action, and of an operator line's
// operator, from the value of the line's expression.
Value Shaper
}
OperatorsRuleLine is for generated parsers; not a stable API.
type OperatorsRuleOp source
type OperatorsRuleOp struct {
Id int
Kind string
Assoc string
Level int
Line *OperatorsRuleLine
}
OperatorsRuleOp is for generated parsers; not a stable API.
type Parser source
type Parser struct {
Control *BudgetControl
// Units counts the logical compute units of a parser generated with them, and UnitsCheck is the
// count above which a check of the counter must look at the limit and the context (units.go).
Units, UnitsCheck uint64
// Observation observes the parse; it is nil unless the parse options select it.
Observation *observation
// Document is set only by the private incremental runner.
Document *documentState
In []rune // code points (CodePoints)
Pos int
MaxDepth int // invocation-local maximum nesting
Depth int // nesting of recursive rule calls
Env *Env
Frame *CaptureFrame
Trail []undo
Cut bool
// Silent is positive inside lookaheads, where expectations are not recorded.
Silent int
// Expectations makes Expect record expectations (grammar.Expectations). Without it a record
// holds at most the placeholder ExpFar, which stands for a failure at its position.
Expectations bool
KidStack []*sxirvalue.Node
// Stream is set only by ParseStream: positions then index its buffer.
Stream *streamInput
// contains filtered or unexported fields
}
Parser is for generated parsers; not a stable API.
func (*Parser) ActionBinary source
func (p *Parser) ActionBinary(op int, l any, r any) (any, any)
ActionBinary applies the binary operator that op indexes in exec.BinaryOps to l and r. Ints combine with + - * / % and compare with < <= > >=, with 64-bit wraparound; / and % truncate toward zero, and a division by zero fails. Strings concatenate with + and compare with < <= > >= by code point. == and != apply equal and fail where it has no equality. [] is index. Any other operands fail. ActionBinary is for generated parsers; not a stable API.
Printed from Exec IR function binary of internal/ir/code/exec/compose.
func (*Parser) ActionConforms source
func (p *Parser) ActionConforms(t *FieldType, v any) bool
ActionConforms returns whether v is a value of the type t of a cast in the value model, charging a step for each element of a list or a tuple it examines. A box counts as the value it holds. node[T] is a node whose value is of type T (node[_] any node with a value), and error an error value; a list or tuple type takes a list value or a tuple value, not the node of a repetition or a sequence. ActionConforms is for generated parsers; not a stable API.
Printed from Exec IR function conforms of internal/ir/code/exec/compose.
func (*Parser) ActionConvert source
func (p *Parser) ActionConvert(t *nodeTypeKinds, x any) (any, any)
ActionConvert is the conversion T{x} to the named node type t: a string, tuple or list node, of a named node type or not, becomes a node of t. Any other value fails. ActionConvert is for generated parsers; not a stable API.
Printed from Exec IR function convert of internal/ir/code/exec/compose.
func (*Parser) ActionCover source
func (p *Parser) ActionCover(n *sxirvalue.Node, v any, first bool) bool
ActionCover widens the range of the struct n, which an action expression is making, to cover the range of the field value v if v is a node, a list, a tuple or a struct, and returns whether n still has no node among its field values: first is whether it had none before, and the first node gives n its range. ActionCover is for generated parsers; not a stable API.
Printed from Exec IR function cover of internal/ir/code/exec/compose.
func (*Parser) ActionFilterKeep source
func (p *Parser) ActionFilterKeep(v any) (bool, any)
ActionFilterKeep returns whether filter keeps an element for which its function returned v. A v that is not a bool fails. ActionFilterKeep is for generated parsers; not a stable API.
Printed from Exec IR function filterKeep of internal/ir/code/exec/compose.
func (*Parser) ActionHull source
func (p *Parser) ActionHull(c *ActCtx, tuple bool, kids []*sxirvalue.Node) *sxirvalue.Node
ActionHull makes the tuple value, if tuple, or the list value of the elements kids in c, which it takes over, and gives it its range: the one that covers the ranges that the elements add (seq.span), and the empty range at the start of the rule if none adds one. It charges a step for each element. The value model does not show the range of a list or a tuple, but a struct that holds one covers it. ActionHull is for generated parsers; not a stable API.
Printed from Exec IR function hull of internal/ir/code/exec/compose.
func (*Parser) ActionHullLogical source
func (p *Parser) ActionHullLogical(c *ActCtx, tuple bool, kids []*sxirvalue.Node) *sxirvalue.Node
ActionHullLogical is ActionHull that counts one unit for each element of the list or tuple it builds.
ActionHullLogical is for generated parsers; not a stable API.
func (*Parser) ActionItemAt source
func (p *Parser) ActionItemAt(items []*sxirvalue.Node, i int, right bool) any
ActionItemAt returns the element that a built-in function iterating over items (map, filter, foldl, foldr) passes to its function at step i, with a box opened: element i, or element i from the end if right (foldr). It charges nothing; the loop charges the step (seq.step) before it, so that itemAt stays small enough for a target to inline. ActionItemAt is for generated parsers; not a stable API.
Printed from Exec IR function itemAt of internal/ir/code/exec/compose.
func (*Parser) ActionItems source
func (p *Parser) ActionItems(fn string, v any) ([]*sxirvalue.Node, any)
ActionItems returns the elements of v, an argument of the built-in function fn that takes a list: none for nil, and those of a list or a tuple. Any other value fails. ActionItems is for generated parsers; not a stable API.
Printed from Exec IR function items of internal/ir/code/exec/compose.
func (*Parser) ActionLength source
func (p *Parser) ActionLength(x any) (any, any)
ActionLength is the built-in function len: the length of a string in the position unit, of the range of a string node, and the number of elements of a list, a tuple or another node; nil and a recovered value have length 0. Any other value fails. ActionLength is for generated parsers; not a stable API.
Printed from Exec IR function length of internal/ir/code/exec/compose.
func (*Parser) ActionLogic source
func (p *Parser) ActionLogic(op int, x any) (bool, any)
ActionLogic checks the operand x of the logical operator that op indexes in exec.LogicalOps, and returns it. An operand that is not a bool fails. The caller short-circuits: it evaluates the right operand of && only if the left is true and of || only if it is false, and checks each operand it evaluates. ActionLogic is for generated parsers; not a stable API.
Printed from Exec IR function logic of internal/ir/code/exec/compose.
func (*Parser) ActionMade source
func (p *Parser) ActionMade(c *ActCtx, n *sxirvalue.Node, first bool)
ActionMade finishes the struct n that c made of field values that cover has gone over: n takes the range of the rule if no field value is a node, and c records n. ActionMade is for generated parsers; not a stable API.
Printed from Exec IR function made of internal/ir/code/exec/compose.
func (*Parser) ActionMember source
func (p *Parser) ActionMember(c *ActCtx, kind int, x any, name string, field string) (any, any)
ActionMember reads the member name of x, whose kind is kind (exec.MemberKinds) and which reads the field or capture field. Start, End and Value of a node read its range and value; a recovered value has a range and a nil value. A capture of a node reads it with a box opened, nil if it did not match; a field reads what the value holds, and of a struct the zero value of the declared type of a field that is not set. A value that has no members, a capture of a struct and a field that a struct does not declare fail. ActionMember is for generated parsers; not a stable API.
Printed from Exec IR function member of internal/ir/code/exec/compose.
func (*Parser) ActionNodeType source
func (p *Parser) ActionNodeType(typ string) *nodeTypeKinds
ActionNodeType returns the named node type typ, the operand of ActionConvert.
ActionNodeType is for generated parsers; not a stable API.
func (*Parser) ActionPush source
func (p *Parser) ActionPush(c *ActCtx, fn string, v any) any
ActionPush pushes v as the next element of the list or the tuple that the built-in function or literal fn makes in c: nil, a node, a list, a tuple or a struct as it is, and an int, a string or a bool as val.box makes it. Any other value, such as a function, fails and pushes nothing. ActionPush is for generated parsers; not a stable API.
Printed from Exec IR function push of internal/ir/code/exec/compose.
func (*Parser) ActionPushItems source
func (p *Parser) ActionPushItems(c *ActCtx, fn string, v any) any
ActionPushItems pushes the elements of v, an argument of the built-in function fn that concatenates lists, as the next elements of the list that fn makes in c: none for nil, and those of a list or a tuple as they are. Any other value fails and pushes nothing. ActionPushItems is for generated parsers; not a stable API.
Printed from Exec IR function pushItems of internal/ir/code/exec/compose.
func (*Parser) ActionText source
func (p *Parser) ActionText(x any) (string, any)
ActionText is the built-in function text: a string itself, the text that a string node holds, the input of the range of any other node, a recovered value among them, and the empty string for nil. Any other value fails. ActionText is for generated parsers; not a stable API.
Printed from Exec IR function text of internal/ir/code/exec/compose.
func (*Parser) ActionUnary source
func (p *Parser) ActionUnary(op int, x any) (any, any)
ActionUnary applies the unary operator that op indexes in exec.UnaryOps to x: - negates an int, with wraparound, and ! negates a bool. Any other operand fails. ActionUnary is for generated parsers; not a stable API.
Printed from Exec IR function unary of internal/ir/code/exec/compose.
func (*Parser) Anchor source
func (p *Parser) Anchor(ok bool, desc ExpID) (*sxirvalue.Node, bool)
func (*Parser) AtEnd source
func (p *Parser) AtEnd() bool
func (*Parser) AtEndBatch source
func (p *Parser) AtEndBatch() bool
AtEndBatch, AtLineStartBatch and their Ordinary forms are AtEnd and AtLineStart for the parsers that cannot stream (no ParseStream); small enough to inline.
func (*Parser) AtEndBatchOrdinary source
func (p *Parser) AtEndBatchOrdinary() bool
AtEndBatchOrdinary is AtEndBatch in an ordinary parse (ExpectOrdinary).
func (*Parser) AtEndOrdinary source
func (p *Parser) AtEndOrdinary() bool
AtEndOrdinary is AtEnd in an ordinary parse (ExpectOrdinary).
func (*Parser) AtLineEnd source
func (p *Parser) AtLineEnd() bool
AtLineEnd reports whether a line ends at the position (`$`): the input ends there or a line feed or a carriage return follows. It examines the slot at the position alone (spec/runtime/documents.md, Slots) and charges a unit for reading it.
func (*Parser) AtLineEndOrdinary source
func (p *Parser) AtLineEndOrdinary() bool
AtLineEndOrdinary is AtLineEnd in an ordinary parse (ExpectOrdinary).
func (*Parser) AtLineEndTraced source
func (p *Parser) AtLineEndTraced() bool
AtLineEndTraced is AtLineEnd in a traced rule body.
AtLineEndTraced is for generated parsers; not a stable API.
func (*Parser) AtLineStart source
func (p *Parser) AtLineStart() bool
func (*Parser) AtLineStartBatch source
func (p *Parser) AtLineStartBatch() bool
func (*Parser) AtLineStartBatchOrdinary source
func (p *Parser) AtLineStartBatchOrdinary() bool
AtLineStartBatchOrdinary is AtLineStartBatch in an ordinary parse (ExpectOrdinary).
func (*Parser) AtLineStartOrdinary source
func (p *Parser) AtLineStartOrdinary() bool
AtLineStartOrdinary is AtLineStart in an ordinary parse (ExpectOrdinary).
func (*Parser) AttachCaptures source
func (p *Parser) AttachCaptures(v *sxirvalue.Node, names []string, f *CaptureFrame, start, end int) *sxirvalue.Node
AttachCaptures attaches the non-nil captures as fields of the node. A node of another rule, or one that is itself captured, is first wrapped in a tuple node. It charges nothing: captures and the nodes that the parse builds are not an item of the cost (spec/runtime/parsing.md#cost), and the slots and names of a scope, and so the fields that it looks at, are a constant of the grammar.
func (*Parser) Bind source
func (p *Parser) Bind(slot int, t func(*ActCtx) (any, any)) bool
Bind binds the value of the action expression of a binding to the variable in slot. An action expression that fails fails the binding and binds nothing. The compiler has checked that the value fits the variable. The value of an action expression is never a function.
Printed from Exec IR function bind of internal/ir/code/exec/compose.
func (*Parser) Call source
func (p *Parser) Call(r *Rule, min int) (*sxirvalue.Node, bool)
Call calls rule r at binding level min: unmemoized while its memoization is deferred, and otherwise through the memo and the dependency memo of left-recursion contexts, growing the seed of a left-recursion leader. A call that is also the entry of Document parses first hands a Document parse to its tracked path (typedDocument for typed values), and for nodes an observed parse too (tracked).
Printed from Exec IR function call of internal/ir/code/exec/compose, specialized for document, observe, budget.
func (*Parser) CallLogical source
func (p *Parser) CallLogical(r *Rule, min int) (*sxirvalue.Node, bool)
CallLogical is Call that counts the unit of the call, and the key of a call of a memoized rule, and checks the counter.
CallLogical is for generated parsers; not a stable API.
func (*Parser) ChargeKey source
func (p *Parser) ChargeKey(r *Rule)
ChargeKey charges the lookup of the memo key of a call of r, a rule that a parse from scratch memoizes (budget.chargeKey): one unit for each variable r reads and one for each byte of each string value among them, whether or not the call looks the key up.
func (*Parser) DiagnosticAttr source
func (p *Parser) DiagnosticAttr(m matcher, name ExpID) (*sxirvalue.Node, bool)
func (*Parser) ElemsAbove source
func (p *Parser) ElemsAbove(base int) []*sxirvalue.Node
ElemsAbove is action.elemsAbove (spec/exec-ir/values.md): it returns the elements that an action expression gathered above base as Kids does and, under budget controls, reserves two units for each element, one for copying it and one for taking it off, in one reservation before it moves any.
func (*Parser) EmitStream source
func (p *Parser) EmitStream(v *sxirvalue.Node, end int)
EmitStream passes a committed element v of the start rule's #stream repetition to the caller and commits the input before end. The recovered errors committed so far are reported first, so that an error of the diagnostic callback ends the parse before the element is delivered. Elements are final once emitted: a caller error ends the parse unchanged.
Printed from Exec IR function streamEmit of internal/ir/code/exec/compose, specialized for stream.
func (*Parser) Enter source
func (p *Parser) Enter()
Enter counts one more nested entry of a recursive rule and fails the parse beyond the nesting limit.
func (*Parser) ErrorAttr source
func (p *Parser) ErrorAttr(m matcher, msg ExpID) (*sxirvalue.Node, bool)
ErrorAttr replaces the expectations of a failing m with the message msg (an ID with MsgBit), reported at the farthest position m reached.
func (*Parser) ExaminedBegin source
func (p *Parser) ExaminedBegin() int
ExaminedBegin starts measuring the examined end of an observed call, returning that of the enclosing call for ExaminedEnd. The call itself, and any memo entry it reads or records, extends the end as in an unobserved parse, so observation does not change reuse.
ExaminedBegin is for generated parsers; not a stable API.
func (*Parser) ExaminedEnd source
func (p *Parser) ExaminedEnd(enclosing int) int
ExaminedEnd returns the examined end of the call that ExaminedBegin began and merges it into the enclosing one.
ExaminedEnd is for generated parsers; not a stable API.
func (*Parser) Expect source
func (p *Parser) Expect(pos int, id ExpID)
Expect records that id was expected at pos: an expectation before the farthest failure or in a lookahead is dropped, one past it starts the record anew, and one at it joins the entries. It records no examined input: the read that failed at pos recorded what it examined. It is for parser code and not a stable API.
Printed from Exec IR function expect of internal/ir/code/exec/compose, specialized for budget.
func (*Parser) ExpectOrdinary source
func (p *Parser) ExpectOrdinary(pos int, id ExpID)
ExpectOrdinary is the form of an ordinary parse: one without limit controls and outside a Document. The generated rule bodies have a branch for such parses that calls the Ordinary forms of the runtime helpers, which leave out the budget charges and the Document's record of the examined input. It is for generated parsers and not a stable API.
Printed from Exec IR function expect of internal/ir/code/exec/compose.
func (*Parser) Finish source
func (p *Parser) Finish(r *Rule, f *CaptureFrame, v *sxirvalue.Node, start int) *sxirvalue.Node
Finish makes the rule's value from the value of its body.
func (*Parser) FirstCall source
func (p *Parser) FirstCall(r *Rule) bool
FirstCall records a call of the memoized rule r at the position and reports whether its memoization is deferred, in which case the call is not memoized. A result is reused only when the rule is called again at the same position, which in practice is rare, so memoizing every first call would cost a memo entry per call for nothing. Deferring memoization to the second call evaluates the body of a rule at most twice per position, binding level and combination of variable values. That bounds how often a rule body runs, not the time of a parse: loops inside a body, left-recursion growth and variable environments do work that the memo does not share. A parse that memoizes on the first call, a rule without a seen index and an eager rule are memoized at once.
Printed from Exec IR function firstCall of internal/ir/code/exec/compose.
func (*Parser) HasChar source
func (p *Parser) HasChar(want rune, fold bool) bool
HasChar reports whether the input at the position begins with the character want, compared as a literal compares each of its characters (MatchChar); it is the guard of an alternative that begins with a literal whose first character is want (the Flow operation guardLitFails).
HasChar is for generated parsers; not a stable API.
func (*Parser) HasCharOrdinary source
func (p *Parser) HasCharOrdinary(want rune, fold bool) bool
HasCharOrdinary is HasChar in an ordinary parse (ExpectOrdinary), with the common case, a code-point input, written so that the compiler inlines it.
HasCharOrdinary is for generated parsers; not a stable API.
func (*Parser) HasCharTraced source
func (p *Parser) HasCharTraced(want rune, fold bool) bool
HasCharTraced is HasChar in a traced rule body.
HasCharTraced is for generated parsers; not a stable API.
func (*Parser) InvokePlain source
func (p *Parser) InvokePlain(r *Rule, min int) (*sxirvalue.Node, bool)
InvokePlain is an unmemoized call of a rule without captures: invoke without the capture frame (the body never writes one, so the caller's stays current), with the failure handling of call.
func (*Parser) Isolate source
func (p *Parser) Isolate(pos int) ExpMark
Isolate starts a separate expectation record whose farthest position is pos.
func (*Parser) Keep source
func (p *Parser) Keep(s []ExpID) []ExpID
Keep returns the expectations of s as a set that outlives the record, for a memo entry, a context or a recovery to keep: the empty set for none, the set kept last when it has the same entries in the same order, and otherwise a copy, which becomes the set kept last. It is for parser code and not a stable API.
Printed from Exec IR function keep of internal/ir/code/exec/compose, specialized for budget.
func (*Parser) KeyUnits source
func (p *Parser) KeyUnits(r *Rule)
KeyUnits counts the key of a call of the memoized rule r, and checks the counter if it counts any.
KeyUnits is for generated parsers; not a stable API.
func (*Parser) Kids source
func (p *Parser) Kids(base int) []*sxirvalue.Node
Kids returns p.KidStack[base:] as a child list and pops it. It charges nothing: the values that the parse gathers are not an item of the cost, and taking each off is constant work for the evaluation that gathered it (spec/runtime/parsing.md#cost).
func (*Parser) LiteralText source
func (p *Parser) LiteralText(start int, text string) string
LiteralText returns source bytes if replacement decoding accepted a shorter spelling than the literal, retaining the usual constant-text success path.
func (*Parser) LookBegin source
func (p *Parser) LookBegin(site int)
LookBegin starts a lookahead of the given site. In a context at the current position, the lookahead records what it reads, so that a result that depends on it records its outcome instead of the seeds it read (LookEnd). Where no frame records dependencies, a lookahead records nothing, and the frames are the same at its end.
LookBegin is for generated parsers; not a stable API.
func (*Parser) LookEnd source
func (p *Parser) LookEnd(ok bool)
LookEnd ends the innermost lookahead, whose expression matched if ok.
LookEnd is for generated parsers; not a stable API.
func (*Parser) MakeError source
func (p *Parser) MakeError(pos int, expected []ExpID) *sxirvalue.SyntaxError
func (*Parser) Mark source
func (p *Parser) Mark() Mark
func (*Parser) MatchAny source
func (p *Parser) MatchAny(build bool) (*sxirvalue.Node, bool)
func (*Parser) MatchAnyLogical source
func (p *Parser) MatchAnyLogical(build bool) (*sxirvalue.Node, bool)
MatchAnyLogical is MatchAnyOrdinary that counts the input it advances over.
MatchAnyLogical is for generated parsers; not a stable API.
func (*Parser) MatchAnyOrdinary source
func (p *Parser) MatchAnyOrdinary(build bool) (*sxirvalue.Node, bool)
MatchAnyOrdinary is MatchAny in an ordinary parse (ExpectOrdinary).
func (*Parser) MatchChar source
func (p *Parser) MatchChar(want rune, fold bool) (int, bool)
MatchChar compares the character want of a literal with the input at the position, as a literal compares each of its characters (spec/runtime/documents.md#reuse-model, Slots), and returns its size in units if it matches. In code points it reads the character at the position. In bytes it compares the UTF-8 encoding of want with the input byte by byte and stops at the first byte that differs: no character that begins with other bytes can be want, so the bytes after it are not examined, and a stream reads none of them. U+FFFD also matches one invalid byte, which only decoding tells, so it decodes the character. With fold, want is folded (foldASCIIRune) and an ASCII letter of the input matches it in either case.
It records the input it examined, as Peek does, and consumes nothing. It charges a unit for reading the character, as Peek does, and what decoding charges when it decodes; comparing bytes charges nothing more.
func (*Parser) MatchCharTraced source
func (p *Parser) MatchCharTraced(want rune, fold bool) (int, bool)
MatchCharTraced is MatchChar in a traced rule body, which records the examined end of a stream read too.
func (*Parser) MatchLiteral source
func (p *Parser) MatchLiteral(rs []rune, text string, desc ExpID, build bool) (*sxirvalue.Node, bool)
func (*Parser) MatchLiteralFold source
func (p *Parser) MatchLiteralFold(rs []rune, desc ExpID, build bool) (*sxirvalue.Node, bool)
MatchLiteralFold is MatchLiteral for a case-insensitive literal. rs is the literal with each ASCII letter lowercased, and each character is compared as MatchChar compares it, with an ASCII letter of the input folded the same way, so only ASCII letters ignore case. The node text is the consumed input. MatchChar records the examined input and the work of each character, so the loop needs no bookkeeping of its own.
func (*Parser) MatchLiteralFoldLogical source
func (p *Parser) MatchLiteralFoldLogical(rs []rune, desc ExpID, build bool) (*sxirvalue.Node, bool)
MatchLiteralFoldLogical is MatchLiteralFoldOrdinary that counts the input it advances over.
MatchLiteralFoldLogical is for generated parsers; not a stable API.
func (*Parser) MatchLiteralFoldOrdinary source
func (p *Parser) MatchLiteralFoldOrdinary(rs []rune, desc ExpID, build bool) (*sxirvalue.Node, bool)
MatchLiteralFoldOrdinary is MatchLiteralFold in an ordinary parse (ExpectOrdinary).
func (*Parser) MatchLiteralFoldTraced source
func (p *Parser) MatchLiteralFoldTraced(rs []rune, desc ExpID, build bool) (*sxirvalue.Node, bool)
MatchLiteralFoldTraced is MatchLiteralFold in a traced rule body.
MatchLiteralFoldTraced is for generated parsers; not a stable API.
func (*Parser) MatchLiteralLogical source
func (p *Parser) MatchLiteralLogical(rs []rune, text string, desc ExpID, build bool) (*sxirvalue.Node, bool)
MatchLiteralLogical is MatchLiteralOrdinary that counts the input it advances over.
MatchLiteralLogical is for generated parsers; not a stable API.
func (*Parser) MatchLiteralOrdinary source
func (p *Parser) MatchLiteralOrdinary(rs []rune, text string, desc ExpID, build bool) (*sxirvalue.Node, bool)
MatchLiteralOrdinary is MatchLiteral in an ordinary parse (ExpectOrdinary).
func (*Parser) MatchLiteralTraced source
func (p *Parser) MatchLiteralTraced(rs []rune, text string, desc ExpID, build bool) (*sxirvalue.Node, bool)
MatchLiteralTraced is MatchLiteral in a traced rule body.
MatchLiteralTraced is for generated parsers; not a stable API.
func (*Parser) MergeExpected source
func (p *Parser) MergeExpected(far int, s []ExpID)
MergeExpected records the expectations of s at far, as expect does for each of them, so that the expectations of a call that a memo entry or a finished isolation kept become those of the enclosing record. s may alias the stack above the current record: writes only happen below the read position. It is for parser code and not a stable API.
Printed from Exec IR function mergeExpected of internal/ir/code/exec/compose, specialized for budget.
func (*Parser) NewBranch source
func (p *Parser) NewBranch(kind *valueimpl.Kind, start int, children []*sxirvalue.Node) *sxirvalue.Node
NewBranch returns the node of kind (valueimpl.SeqKind or valueimpl.ListKind) with children from start to the current position, allocated like buildNode(Data{Kind: kind, ...}). It charges nothing, as buildNode.
func (*Parser) NewBranchOrdinary source
func (p *Parser) NewBranchOrdinary(kind *valueimpl.Kind, start int, children []*sxirvalue.Node) *sxirvalue.Node
NewBranchOrdinary is NewBranch in an ordinary parse (ExpectOrdinary).
func (*Parser) NewErrorNode source
func (p *Parser) NewErrorNode(start int, e *sxirvalue.SyntaxError) *sxirvalue.Node
NewErrorNode returns the node that stands for the input from start to the current position, which a recovery (#recover) skipped after the syntax error e: an error node with the message of e, allocated like NewNode.
NewErrorNode is for generated parsers; not a stable API.
func (*Parser) NewFrame source
func (p *Parser) NewFrame(n int) *CaptureFrame
NewFrame returns a capture frame with n slots.
func (*Parser) NewNode source
func (p *Parser) NewNode(v Data) *sxirvalue.Node
NewNode returns a copy of v allocated from the node slab, charging a unit for a value that an action expression or a Document makes. A slab stays alive while any of its nodes is referenced.
func (*Parser) NewNodeOrdinary source
func (p *Parser) NewNodeOrdinary(v Data) *sxirvalue.Node
NewNodeOrdinary is NewNode in an ordinary parse (ExpectOrdinary).
func (*Parser) NewTerminal source
func (p *Parser) NewTerminal(start int, text string) *sxirvalue.Node
NewTerminal returns the node of text matched from start to the current position, allocated like buildNode(Data{Kind: valueimpl.MatchKind, ...}). It charges nothing, as buildNode.
func (*Parser) NewTerminalOrdinary source
func (p *Parser) NewTerminalOrdinary(start int, text string) *sxirvalue.Node
NewTerminalOrdinary is NewTerminal in an ordinary parse (ExpectOrdinary).
func (*Parser) NextOrdinary source
func (p *Parser) NextOrdinary() (r rune, size int, ok bool)
NextOrdinary is PeekOrdinary with the common case, a code-point input, written so that the compiler inlines it (the named results keep it within the inlining budget).
func (*Parser) Nodes source
func (p *Parser) Nodes(n int) []*sxirvalue.Node
Nodes returns a child list of length and capacity n from the pointer slab.
func (*Parser) OperatorsRuleParse source
func (p *Parser) OperatorsRuleParse(r *Rule, min int) (*sxirvalue.Node, bool)
OperatorsRuleParse parses an expression of the Operators Rule r with operators that bind tighter than min. Each level of its recursion (the operand of a prefix operator, the right operand of an infix operator) counts against the nesting limit, like the entry of a recursive rule.
Printed from Exec IR function operatorsParse of internal/ir/code/exec/compose, specialized for budget.
func (*Parser) Peek source
func (p *Parser) Peek() (rune, int, bool)
Peek returns the character at the current position and its size in units.
func (*Parser) PeekOrdinary source
func (p *Parser) PeekOrdinary() (rune, int, bool)
PeekOrdinary is peek in an ordinary parse (ExpectOrdinary).
func (*Parser) PeekTraced source
func (p *Parser) PeekTraced() (rune, int, bool)
PeekTraced is Peek in a traced rule body.
PeekTraced is for generated parsers; not a stable API.
func (*Parser) PollUnits source
func (p *Parser) PollUnits()
PollUnits is the slow path of a check of the counter, which the generated code makes when the count passes UnitsCheck: it observes the context once every budgetCheckInterval units, then stops the parse if the count exceeds the limit. A context error wins over the limit.
PollUnits is for generated parsers; not a stable API.
func (*Parser) Predicate source
func (p *Parser) Predicate(t func(*ActCtx) (any, any)) bool
Predicate applies the action expression of a predicate to the context that action.ctx makes. It fails on the boolean false and on an action expression that fails, and holds on every other value. The value of an action expression is never a function.
Printed from Exec IR function predicate of internal/ir/code/exec/compose.
func (*Parser) PushRecovered source
func (p *Parser) PushRecovered(e *sxirvalue.SyntaxError)
PushRecovered records the error e that a recovery made (rec.push). Generated parsers call it.
func (*Parser) RecoverAttr source
func (p *Parser) RecoverAttr(m, skip matcher, build bool) (*sxirvalue.Node, bool)
RecoverAttr records the error of a failing m, skips what skip matches and returns an Error node. It fails without recovering when skip fails or skips nothing.
func (*Parser) RecoveryErrorText source
func (p *Parser) RecoveryErrorText(e *sxirvalue.SyntaxError) string
RecoveryErrorText is only for engine-owned Error-node materialization. Public post-return Error/Message calls remain caller spend. The local builder owns its immutable output and is never pooled or written after return.
func (*Parser) RejectBudgetClass source
func (p *Parser) RejectBudgetClass(ch rune, c *BudgetClass) bool
Reject charges the test of ch and reports whether the class rejects it.
func (*Parser) Reset source
func (p *Parser) Reset(m Mark)
Reset returns to the backtracking point m: the position, the variable environment, the recovered errors and the captures (undoing the trail) become what they were when m was taken.
Printed from Exec IR function reset of internal/ir/code/exec/compose.
func (*Parser) Restore source
func (p *Parser) Restore(pos, rec int)
Restore goes back to the position pos and to the recovered errors of the first rec, as a failed alternative does.
func (*Parser) ResumeBegin source
func (p *Parser) ResumeBegin(r *RunState)
ResumeBegin starts evaluating an element of the run r: its examined input and its expectations are recorded apart from those of the enclosing call, so that the run can record them with the element.
Printed from Exec IR function runBegin of internal/ir/code/exec/compose, specialized for document, budget.
func (*Parser) ResumeEnd source
func (p *Parser) ResumeEnd(r *RunState, ok bool, v *sxirvalue.Node)
ResumeEnd ends evaluating an element of the run r, with its success ok and value v, before the parse resets its state if it failed: it adds the element's examined input and expectations to those of the enclosing call, and records the element if it matched.
Printed from Exec IR function runEnd of internal/ir/code/exec/compose, specialized for document, budget.
func (*Parser) ResumeFinish source
func (p *Parser) ResumeFinish(r *RunState)
ResumeFinish records the run r of a repetition that matched (flow.resumeFinish), and keeps r for the next run that starts.
ResumeFinish is for generated parsers; not a stable API.
func (*Parser) ResumeMore source
func (p *Parser) ResumeMore(r *RunState) bool
ResumeMore reports whether the run r may take another element: no reused element ended it, and it has fewer than its maximum.
Printed from Exec IR function runMore of internal/ir/code/exec/compose, specialized for document, budget.
func (*Parser) ResumeNext source
func (p *Parser) ResumeNext(r *RunState) (*sxirvalue.Node, bool)
ResumeNext reuses the next element of the run r that the old run supplies, when runMore(r) holds, and returns its value and true: first the reused prefix (runPrefix), then, once the run is back in step with the old run after the edit (runResync), the old elements after it (runTail). It returns false when the repetition evaluates its next element instead.
Printed from Exec IR function runNext of internal/ir/code/exec/compose, specialized for document, budget.
func (*Parser) ResumeOn source
func (p *Parser) ResumeOn() bool
ResumeOn reports whether a repetition resumes its run (flow.resumeOn): in a Document parse, outside a lookahead.
ResumeOn is for generated parsers; not a stable API.
func (*Parser) ResumeStart source
func (p *Parser) ResumeStart(site, min, max int, shiftable bool) *RunState
ResumeStart starts the run of the repetition site at the position, with at least min and at most max elements (max -1 for no bound) (flow.resumeStart). shiftable tells whether the values of its elements hold no position values.
ResumeStart is for generated parsers; not a stable API.
func (*Parser) RunBegin source
func (p *Parser) RunBegin(site int, build, keyEnv bool)
RunBegin starts a walk of the hot run site at the current position. build reports that its iterations have values (SkipValue), which SkipKids gathers in a list, and keyEnv that its records are keyed by the values of the variables of the site's run key (Grammar.SetRunKey).
func (*Parser) RunHot source
func (p *Parser) RunHot(site int) bool
RunHot reports whether the walks of the run site keep records. A walk of a site that is not hot is an ordinary repetition, whose end the generated code passes to RunWalked.
func (*Parser) RunWalked source
func (p *Parser) RunWalked(site, start int)
RunWalked ends the walk of a run site that was not hot, which began at start and ended at the current position. A walk that began below the furthest position that the walks of the site passed walks input again, and the site turns hot when it walks RunHotSpan of it below that position.
func (*Parser) ScanEnd source
func (p *Parser) ScanEnd(site, start, count int)
ScanEnd ends a value-free walk of the scan site that began at start, matched count characters (at least scanHotSpan) and ended at the position: unless it took the rest from a record, it records itself if the site is hot and notes that it walked if not.
func (*Parser) ScanKids source
func (p *Parser) ScanKids(site, start, base, count int) []*sxirvalue.Node
ScanKids returns the elements of a walk of the scan site that builds a value, which began at start, gathered its elements on the stack from base and matched count characters: for a walk of scanHotSpan characters or more that took the rest from a record, the elements of the record, which it shares (the gathered ones are dropped); otherwise the gathered elements, which a walk of that length records at a hot site.
func (*Parser) ScanReach source
func (p *Parser) ScanReach(site, start, count int) int
ScanReach is called by a walk of the scan site that began at start when it has matched scanHotSpan characters, count of them. At a hot site with a record of start it moves to the recorded end and returns the recorded count, charging one step for the lookup and one for the record; otherwise it returns count, charging one step for the lookup at a hot site.
func (*Parser) ScopeValue source
func (p *Parser) ScopeValue(s Shaper, v *sxirvalue.Node, start int) *sxirvalue.Node
ScopeValue returns the value of a scope whose body matched [start, p.Pos) with the result v.
func (*Parser) SetCapture source
func (p *Parser) SetCapture(slot int, v *sxirvalue.Node)
func (*Parser) ShapeCapture source
func (p *Parser) ShapeCapture(s Shaper, v *sxirvalue.Node, start int) *sxirvalue.Node
ShapeCapture is ShapeSingle for a capture or a recovered expression, whose value is the unit node of the range matched when the expression has no value.
func (*Parser) ShapeSingle source
func (p *Parser) ShapeSingle(s Shaper, v *sxirvalue.Node, start int) (*sxirvalue.Node, bool)
ShapeSingle returns the value of the result v where the expression takes one element; ok is false when it has no value.
func (*Parser) Single source
func (p *Parser) Single(size int, build bool) (*sxirvalue.Node, bool)
Single consumes one character of size units.
func (*Parser) SkipBegin source
func (p *Parser) SkipBegin(site int)
SkipBegin starts a walk of the skip-run site at the current position.
func (*Parser) SkipCall source
func (p *Parser) SkipCall(r *Rule, exp ExpID)
SkipCall makes the effects of a call of the memoized rule r that a skipped alternative would have made at the position: the call is the alternative's only call, and fails at r's first terminal, whose expectation is exp (skipCalls).
SkipCall is for generated parsers; not a stable API.
func (*Parser) SkipCalls source
func (p *Parser) SkipCalls(exp ExpID, rules ...*Rule)
SkipCalls makes the effects of the calls of rules that a skipped alternative would have made at the position: each rule calls the next before its first terminal, and the last fails at its first terminal, whose expectation is exp (skipCalls).
SkipCalls is for generated parsers; not a stable API.
func (*Parser) SkipEnd source
func (p *Parser) SkipEnd()
SkipEnd ends the walk and records the rest of it from each position it visited recording. A walk that builds values drops them, uncharged.
func (*Parser) SkipHit source
func (p *Parser) SkipHit() bool
SkipHit is called before an iteration after the minimum. It ends the iteration before and, in a recording walk, reports whether the current position has a record, which it then reuses. The walk then stops.
func (*Parser) SkipKids source
func (p *Parser) SkipKids() []*sxirvalue.Node
SkipKids ends a walk begun with build as SkipEnd does, and returns the values of its iterations, then those of the record it took, as a child list. The list may share its elements with the lists of other walks. Like Kids it charges nothing: the values that the parse gathers, takes off, places in records and drops are not an item of the cost (spec/runtime/parsing.md#cost); each is moved a constant number of times for the iteration that gathered it or the record that holds it.
func (*Parser) SkipUnits source
func (p *Parser) SkipUnits(n uint64)
SkipUnits counts the n calls that a skipped alternative would have made, none of them of a memoized rule, each failing at the alternative's first terminal, and checks the counter.
SkipUnits is for generated parsers; not a stable API.
func (*Parser) SkipValue source
func (p *Parser) SkipValue(v *sxirvalue.Node)
SkipValue adds the value of the iteration that matched. Nodes in records are shared by the lists that reuse them, so a node that the rule that made it may still change is final from here.
func (*Parser) SkipVisit source
func (p *Parser) SkipVisit()
SkipVisit begins an iteration at the current position: in a plain walk it marks the position of the iteration before, which matched, visited; in a recording walk it ends the iteration before and isolates this one.
func (*Parser) Spend source
func (p *Parser) Spend()
func (*Parser) SpendRead source
func (p *Parser) SpendRead(n uint64)
Spend helpers keep long engine-owned scans between bounded reservations.
SpendRead charges the read of n units. It records no input: in a Document parse each matcher records the exact end of what it read itself (documentTouch).
func (*Parser) StreamStart source
func (p *Parser) StreamStart()
StreamStart is called when the start rule's #stream repetition starts. The capture frames allocated so far, including the start rule's, stay in use; elements allocate their nodes from chunks of their own.
func (*Parser) StreamsIn source
func (p *Parser) StreamsIn(id int, rec bool) bool
StreamsIn reports whether the #stream repetition of the rule id streams: the parse delivers elements, the rule is its start rule, and the rule runs at the top (a recursive rule counts its entries, so its outermost entry is the first; any other rule is entered once). It is not a stable API.
Printed from Exec IR function streamsIn of internal/ir/code/exec/compose, specialized for stream.
func (*Parser) Text source
func (p *Parser) Text(start, end int) string
func (*Parser) TextEqual source
func (p *Parser) TextEqual(l, r string) bool
TextEqual reports whether two strings are equal (the operation str.eq). Under a budget it charges the comparison of their bytes, which strings of different lengths skip.
func (*Parser) TextEqualLogical source
func (p *Parser) TextEqualLogical(l, r string) bool
TextEqualLogical is TextEqual that counts the length of the shorter string.
TextEqualLogical is for generated parsers; not a stable API.
func (*Parser) TooDeep source
func (p *Parser) TooDeep()
TooDeep fails the parse for exceeding the nesting limit.
func (*Parser) Unisolate source
func (p *Parser) Unisolate(m ExpMark) (far int, inner []ExpID)
Unisolate ends the separate record and returns its farthest position and expectations. The expectations alias the stack and are valid only until the next record (passing them to MergeExpected is fine; keep copies them).
func (*Parser) UnitsOfItems source
func (p *Parser) UnitsOfItems(v any, k int)
UnitsOfItems counts k units for each element of the list or tuple v, and checks the counter.
UnitsOfItems is for generated parsers; not a stable API.
func (*Parser) UnitsSized source
func (p *Parser) UnitsSized(n int)
UnitsSized counts a sized event of n units and checks the counter.
UnitsSized is for generated parsers; not a stable API.
type Rule source
type Rule struct {
Id int
Name string
Scope []string // capture names of the rule body, in slot order
Body func(p *Parser, min int) (*sxirvalue.Node, bool)
// Action returns the value of the rule's action and the failure that ends its evaluation, nil if
// it does not fail.
Action func(c *ActCtx) (any, any)
Value Shaper // makes the rule's value from the value of its body, without an action
// NodeType, if not "", is the named node type the rule's value is converted to, whose kinds
// are nodeKinds.
NodeType string
// OpNodeType, if not "", is the named node type every operator node of an Operators Rule is
// converted to, whose kinds are opKinds.
OpNodeType string
// Memo means the rule's results are memoized. It is false for transient rules, whose entries
// could never be reused.
Memo bool
// Leader is the leader of a left-recursive cycle; its results are always memoized.
Leader bool
// Rec means the rule is on a cycle of calls: its entries count against the nesting limit.
Rec bool
// Cycle numbers the left-recursion cycle of a leader or a member of one from 1, and is 0 for
// any other rule: a call of a rule of a cycle can read the seeds of the cycle's leaders that grow
// at its position (context_memo.go).
Cycle int32
// DocMemo means Documents memoize the rule, transient or not, as the engine does for a leader
// and for a rule marked for memoization.
DocMemo bool
// Positional means the rule's results may depend on positions (.Start, .End), not only on the
// input they examine: an edit of a Document before them removes them instead of moving them.
Positional bool
// Seen is the rule's index among the memoized rules whose memoization is deferred to the
// second call at a position (FirstCall), or -1.
Seen int
OperatorsRule *OperatorsRule
Novalue bool // value-free twin, called where the value is discarded
// Splice means the rule makes no node of its own: its value is the result of its body as it is,
// and the captures of its body end with it. Its callers take the elements of the value.
Splice bool
// Where, if not "", names the rule in the message of a failed action, instead of Name: the
// hidden rule of an inline action is named by the rule that holds the action.
Where string
// Vars are the variables the rule or its callees read, sorted. Memo entries are keyed by their
// values at the call, since definitions inside the rule are undone when it returns.
Vars []string
// contains filtered or unexported fields
}
Rule is for generated parsers; not a stable API.
func NewRules source
func NewRules[S ~struct {
Name string
Value *Shaper
Flags uint8
Seen int32
Scope uint16
Vars uint16
}, E ~struct {
Id int
Where string
NodeType string
OpNodeType string
Cycle int32
}](specs []S, strs [][]string, extras []E) []*Rule
NewRules builds the rule table of the specs, with the string lists their Scope and Vars index and the rare fields in extras. The entries have the fields of RuleSpec and RuleExtra in their order, in types of the caller, so that generated code can write them without field names (go vet accepts unkeyed fields only for a type of the same package).
For generated parsers; not a stable API.
func TraceRule source
func TraceRule(r *Rule) *Rule
TraceRule returns the traced copy of the rule r, as TraceRules does for a table.
TraceRule is for generated parsers; not a stable API.
func TraceRules source
func TraceRules(rules []*Rule) []*Rule
TraceRules returns the traced copies of rules, one for one: a copy of each rule, recorded as its traced copy (forParse), whose Body and OperatorsRule the generated code sets to forms that report their calls to the observation and track the examined input. A copy starts without them, so that a form the generated code leaves out fails instead of running untraced.
TraceRules is for generated parsers; not a stable API.
type RuleExtra source
type RuleExtra struct {
Id int
Where string
NodeType string
OpNodeType string
Cycle int32
}
RuleExtra holds the fields of the Rule with the Id that are rarely set.
For generated parsers; not a stable API.
type RuleSpec source
type RuleSpec struct {
Name string
Value *Shaper
Flags uint8
Seen int32
Scope uint16
Vars uint16
}
RuleSpec is the compact form of the analysis results of a rule, which generated parsers keep as static data. Its Id is its position in the table. Scope and Vars index the string lists given to NewRules, 0 for none; a nil Value is the zero Shaper. Seen is the Seen field of the Rule plus one, so that the zero value is the -1 of a rule whose memoization is not deferred.
For generated parsers; not a stable API.
type RunKey source
type RunKey struct {
Vars, Bind []int
}
RunKey holds the slots of the variables that key the records of a run site that is not free of the environment: Vars, those that its element reads or binds and those that the rules it calls read, and Bind, those that it binds, which a walk that takes a record sets to the values the walk of the record left in them.
RunKey is for generated parsers; not a stable API.
type RunState source
type RunState struct {
Min, Max int
Shiftable, Done, Moved bool
Prefixed bool
Count int
EditStart, EditEnd, EditDelta int
// The run is old[:K], then the new elements mid, then old[J:J+T] (the elements after the edit,
// moved), then the new elements post.
K, J, T int
// The search for the old element to resync at resumes at Seek; the run resyncs at none before
// Barred (runResync).
Seek, Barred int
ElemStart int
OuterExamined, OuterLow int
Mark ExpMark
// contains filtered or unexported fields
}
RunState is a run of a repetition in progress in a Document parse. Its exported fields are the fields of the Run record of the Exec IR (exec.RunFields), which the printed compositions read and write; the rest is the library's own.
RunState is for generated parsers; not a stable API.
type Shaper source
type Shaper struct {
Elems bool // the method returns the tuple node of its elements
K int // the number of valued elements
Mode singleMode // how the expression takes one element
Tuple bool // the value of a scope is the node of its tuple, rather than its one element
// Shared means the tuple node the method returns (Elems) is the result of a splice rule, shared
// through its memo entry: a node that takes it as its own takes a copy.
Shared bool
}
Shaper converts the result of an expression's method to the value where the expression takes one element or is a scope (a rule body, a repetition element or an Operators Rule line). The generator fills it from the expression's static shape, as the engine does.
Shaper is for generated parsers; not a stable API.
type StreamPull source
type StreamPull[T any] struct {
// contains filtered or unexported fields
}
StreamPull advances a stream parse synchronously to one committed element at a time. The standard library pull coroutine has no independently scheduled producer.
StreamPull is for generated parsers; not a stable API.
func IterateStream source
func IterateStream[T any](g *grammar, opts []sxirruntime.ParseOption, run func(emit func(T) error) error) (*StreamPull[T], error)
IterateStream validates the options of a stream entry point of grammar g and returns a lazy iterator over the elements that run passes to emit.
IterateStream is for generated parsers; not a stable API.
func (*StreamPull[T]) Close source
func (it *StreamPull[T]) Close()
func (*StreamPull[T]) Next source
func (it *StreamPull[T]) Next() (v T, ok bool, err error)
type TActCtx source
type TActCtx struct {
P *TParser
F *TCaptureFrame
Start, End int
Cbase int
Lhs, Rhs, Op any
Value any // the folded value of an Operators Rule, in its whole-rule action
}
TActCtx is the context of evaluating an action or a predicate (ActCtx in the typed library).
TActCtx is for generated parsers; not a stable API.
func (*TActCtx) ActionCastFailed source
func (c *TActCtx) ActionCastFailed(v any, t *FieldType, line, col int) any
ActionCastFailed is ActCtx.ActionCastFailed for the values of the typed library.
ActionCastFailed is for generated parsers; not a stable API.
func (*TActCtx) ActionCompare source
func (c *TActCtx) ActionCompare(op int, l, r TOperand) (any, any)
ActionCompare applies a comparison operator as ActionBinary does, comparing two strings directly, and returns the failure of the comparison.
ActionCompare is for generated parsers; not a stable API.
func (*TActCtx) ActionFieldOperand source
func (c *TActCtx) ActionFieldOperand(x any, name string) (TOperand, any)
ActionFieldOperand reads x.name as ActionMember does, keeping a string field of a struct unboxed, and returns the failure of the read.
ActionFieldOperand is for generated parsers; not a stable API.
func (*TActCtx) ActionRaise source
func (c *TActCtx) ActionRaise(f any)
ActionRaise ends the parse with the failure f of the action that the generated rule evaluates in place, as Result does for an action that fails.
ActionRaise is for generated parsers; not a stable API.
func (*TActCtx) Cap source
func (c *TActCtx) Cap(slot int) any
func (*TActCtx) Finish source
func (c *TActCtx) Finish(v any) any
Finish checks and finishes the value v of an action (see result; v is never a function value, see SetCapture): a struct the action made takes the rule's range, and the value is no longer fresh. A value other than a node needs no carrier here.
func (*TActCtx) MadeOf source
func (c *TActCtx) MadeOf(n TVal, fields ...any) any
MadeOf finishes a struct value n made by an action from the field values it was made of: n takes the range that covers the field values that are nodes, or the range of the rule if there is none (see NewStruct). The variadic list stays on the stack of the generated constructor.
MadeOf is for generated parsers; not a stable API.
func (*TActCtx) NewList source
func (c *TActCtx) NewList(items []any) any
func (*TActCtx) NewListLogical source
func (c *TActCtx) NewListLogical(items []any) any
NewListLogical is the typed NewList that counts as ActCtx.NewListLogical does.
func (*TActCtx) Result source
func (c *TActCtx) Result(action func(*TActCtx) (any, any), where string) (n any)
Result evaluates an action, whose result is a value of the grammar's value model and never a function value; the library does not check it (see SetCapture). Its errors fail the parse: tparse reports them with the rule name, which result records in p.Where instead of deferring a recovery for each action.
func (*TActCtx) Var source
func (c *TActCtx) Var(slot int) any
Var returns the value of the variable in slot i.
type TCaptureFrame source
type TCaptureFrame struct{ Vals []any }
TCaptureFrame is for generated parsers; not a stable API.
type TError source
type TError struct {
TErrorValue
// contains filtered or unexported fields
}
TError is for generated parsers; not a stable API.
func NewTError source
func NewTError(start, end int, message string) *TError
NewTError returns a fresh error value for the input range [start, end) that recovery skipped.
NewTError is for generated parsers; not a stable API.
func (*TError) TField source
func (e *TError) TField(name string) (any, bool)
func (*TError) TFresh source
func (e *TError) TFresh() bool
func (*TError) TKids source
func (e *TError) TKids() []any
func (*TError) TName source
func (e *TError) TName() string
func (*TError) TSetFresh source
func (e *TError) TSetFresh(f bool)
func (*TError) TStruct source
func (e *TError) TStruct() bool
func (*TError) TText source
func (e *TError) TText() (string, bool)
type TErrorValue source
type TErrorValue struct {
sxirinput.Span
Message string
}
TErrorValue is the data of the input that error recovery (#recover) skipped: its range and the message. The types package of a parser declares the type of the same fields that users see (Error), so TPub hands out a TErrorValue as that type.
TErrorValue is for generated parsers; not a stable API.
func TPubError source
func TPubError(v any) *TErrorValue
TPubError is for generated parsers; not a stable API.
func (*TErrorValue) TSetSpan source
func (e *TErrorValue) TSetSpan(start, end int)
func (*TErrorValue) TSpan source
func (e *TErrorValue) TSpan() (int, int)
type TMatch source
type TMatch struct {
TNode[string]
Nt uint16
// contains filtered or unexported fields
}
TMatch and TError are a string node and an Error while the typed library handles them: whether the value is fresh (see Data.Fresh) is part of the state of the parse, not of the result. The result holds pointers to the embedded TNode[string] and Error (TPub). A string node of a named node type has nt, the type's registered index (TRegisterNodeType; 0 for a plain string node).
TMatch is for generated parsers; not a stable API.
func (*TMatch) TField source
func (m *TMatch) TField(string) (any, bool)
func (*TMatch) TFresh source
func (m *TMatch) TFresh() bool
func (*TMatch) TKids source
func (m *TMatch) TKids() []any
func (*TMatch) TName source
func (m *TMatch) TName() string
func (*TMatch) TSetFresh source
func (m *TMatch) TSetFresh(f bool)
func (*TMatch) TStruct source
func (m *TMatch) TStruct() bool
func (*TMatch) TText source
func (m *TMatch) TText() (string, bool)
type TNode source
type TNode[T any] struct {
sxirinput.Span
Value T
}
TNode is a node whose Value has type T: a string node (TNode[string]) holds the text a literal, a character class, ., a #atomic or _ matched, and a tuple or list node holds its elements. A node of a statically unknown value is a TNode[any] whose Value is a string, or a []any of the elements of a tuple or list.
TNode is for generated parsers; not a stable API.
func TPubMatch source
func TPubMatch(v any) *TNode[string]
TPubMatch is for generated parsers; not a stable API.
func TPubNode source
func TPubNode(h *TPubHooks, v any) *TNode[any]
TPubNode returns the public form of a node of a statically unknown value: a TNode[any], also for a node of a named node type, as the node it was converted from.
TPubNode is for generated parsers; not a stable API.
func TPubNodeIn source
func TPubNodeIn(h *TPubHooks, a any, v any) *TNode[any]
TPubNodeIn is TPubNode with the chunks a (see TPubIn).
TPubNodeIn is for generated parsers; not a stable API.
func (*TNode[T]) TSetSpan source
func (n *TNode[T]) TSetSpan(start, end int)
func (*TNode[T]) TSpan source
func (n *TNode[T]) TSpan() (int, int)
type TOperand source
type TOperand struct {
V any
Str string
IsStr bool
}
TOperand is an operand of a comparison: a string field read without boxing it (Str, with IsStr), or any other value (V).
TOperand is for generated parsers; not a stable API.
type TOperatorsRule source
type TOperatorsRule struct {
Skip tmatcher
Operands []*TOperatorsRuleLine
Prefix []*TOperatorsRuleOp
Led []*TOperatorsRuleOp
}
TOperatorsRule is for generated parsers; not a stable API.
type TOperatorsRuleLine source
type TOperatorsRuleLine struct {
Scope []string
M tmatcher
Action func(*TActCtx) (any, any)
// Value makes the value of an operand line without an action, and of an operator line's
// operator, from the value of the line's expression.
Value Shaper
}
TOperatorsRuleLine is for generated parsers; not a stable API.
type TOperatorsRuleOp source
type TOperatorsRuleOp struct {
Id int
Kind string
Assoc string
Level int
Line *TOperatorsRuleLine
}
TOperatorsRuleOp is for generated parsers; not a stable API.
type TParser source
type TParser struct {
*Parser
Ext any // the generated code's allocation chunks
Where string // the rule whose action is being evaluated
Frame *TCaptureFrame
Trail []tundo
Created []TVal // struct values made by the action being evaluated
KidStack []any
// TypedDocument is set only by typed Document parses (TypedDocumentParse).
TypedDocument *typedDocumentState
// contains filtered or unexported fields
}
TParser is the parser state of the typed library.
TParser is for generated parsers; not a stable API.
func (*TParser) ActionBinary source
func (p *TParser) ActionBinary(op int, l any, r any) (any, any)
ActionBinary applies the binary operator that op indexes in exec.BinaryOps to l and r. Ints combine with + - * / % and compare with < <= > >=, with 64-bit wraparound; / and % truncate toward zero, and a division by zero fails. Strings concatenate with + and compare with < <= > >= by code point. == and != apply equal and fail where it has no equality. [] is index. Any other operands fail. ActionBinary is for generated parsers; not a stable API.
Printed from Exec IR function binary of internal/ir/code/exec/compose.
func (*TParser) ActionConforms source
func (p *TParser) ActionConforms(t *FieldType, v any) bool
ActionConforms returns whether v is a value of the type t of a cast in the value model, charging a step for each element of a list or a tuple it examines. A box counts as the value it holds. node[T] is a node whose value is of type T (node[_] any node with a value), and error an error value; a list or tuple type takes a list value or a tuple value, not the node of a repetition or a sequence. ActionConforms is for generated parsers; not a stable API.
Printed from Exec IR function conforms of internal/ir/code/exec/compose.
func (*TParser) ActionConvert source
func (p *TParser) ActionConvert(t uint16, x any) (any, any)
ActionConvert is the conversion T{x} to the named node type t: a string, tuple or list node, of a named node type or not, becomes a node of t. Any other value fails. ActionConvert is for generated parsers; not a stable API.
Printed from Exec IR function convert of internal/ir/code/exec/compose.
func (*TParser) ActionCover source
func (p *TParser) ActionCover(n TVal, v any, first bool) bool
ActionCover widens the range of the struct n, which an action expression is making, to cover the range of the field value v if v is a node, a list, a tuple or a struct, and returns whether n still has no node among its field values: first is whether it had none before, and the first node gives n its range. ActionCover is for generated parsers; not a stable API.
Printed from Exec IR function cover of internal/ir/code/exec/compose.
func (*TParser) ActionFilterKeep source
func (p *TParser) ActionFilterKeep(v any) (bool, any)
ActionFilterKeep returns whether filter keeps an element for which its function returned v. A v that is not a bool fails. ActionFilterKeep is for generated parsers; not a stable API.
Printed from Exec IR function filterKeep of internal/ir/code/exec/compose.
func (*TParser) ActionHull source
func (p *TParser) ActionHull(c *TActCtx, tuple bool, kids []any) TVal
ActionHull makes the tuple value, if tuple, or the list value of the elements kids in c, which it takes over, and gives it its range: the one that covers the ranges that the elements add (seq.span), and the empty range at the start of the rule if none adds one. It charges a step for each element. The value model does not show the range of a list or a tuple, but a struct that holds one covers it. ActionHull is for generated parsers; not a stable API.
Printed from Exec IR function hull of internal/ir/code/exec/compose.
func (*TParser) ActionHullLogical source
func (p *TParser) ActionHullLogical(c *TActCtx, tuple bool, kids []any) TVal
ActionHullLogical is the typed ActionHull that counts one unit for each element it builds.
func (*TParser) ActionItemAt source
func (p *TParser) ActionItemAt(items []any, i int, right bool) any
ActionItemAt returns the element that a built-in function iterating over items (map, filter, foldl, foldr) passes to its function at step i, with a box opened: element i, or element i from the end if right (foldr). It charges nothing; the loop charges the step (seq.step) before it, so that itemAt stays small enough for a target to inline. ActionItemAt is for generated parsers; not a stable API.
Printed from Exec IR function itemAt of internal/ir/code/exec/compose.
func (*TParser) ActionItems source
func (p *TParser) ActionItems(fn string, v any) ([]any, any)
ActionItems returns the elements of v, an argument of the built-in function fn that takes a list: none for nil, and those of a list or a tuple. Any other value fails. ActionItems is for generated parsers; not a stable API.
Printed from Exec IR function items of internal/ir/code/exec/compose.
func (*TParser) ActionLength source
func (p *TParser) ActionLength(x any) (any, any)
ActionLength is the built-in function len: the length of a string in the position unit, of the range of a string node, and the number of elements of a list, a tuple or another node; nil and a recovered value have length 0. Any other value fails. ActionLength is for generated parsers; not a stable API.
Printed from Exec IR function length of internal/ir/code/exec/compose.
func (*TParser) ActionLogic source
func (p *TParser) ActionLogic(op int, x any) (bool, any)
ActionLogic checks the operand x of the logical operator that op indexes in exec.LogicalOps, and returns it. An operand that is not a bool fails. The caller short-circuits: it evaluates the right operand of && only if the left is true and of || only if it is false, and checks each operand it evaluates. ActionLogic is for generated parsers; not a stable API.
Printed from Exec IR function logic of internal/ir/code/exec/compose.
func (*TParser) ActionMade source
func (p *TParser) ActionMade(c *TActCtx, n TVal, first bool)
ActionMade finishes the struct n that c made of field values that cover has gone over: n takes the range of the rule if no field value is a node, and c records n. ActionMade is for generated parsers; not a stable API.
Printed from Exec IR function made of internal/ir/code/exec/compose.
func (*TParser) ActionMember source
func (p *TParser) ActionMember(c *TActCtx, kind int, x any, name string, field string) (any, any)
ActionMember reads the member name of x, whose kind is kind (exec.MemberKinds) and which reads the field or capture field. Start, End and Value of a node read its range and value; a recovered value has a range and a nil value. A capture of a node reads it with a box opened, nil if it did not match; a field reads what the value holds, and of a struct the zero value of the declared type of a field that is not set. A value that has no members, a capture of a struct and a field that a struct does not declare fail. ActionMember is for generated parsers; not a stable API.
Printed from Exec IR function member of internal/ir/code/exec/compose.
func (*TParser) ActionPush source
func (p *TParser) ActionPush(c *TActCtx, fn string, v any) any
ActionPush pushes v as the next element of the list or the tuple that the built-in function or literal fn makes in c: nil, a node, a list, a tuple or a struct as it is, and an int, a string or a bool as val.box makes it. Any other value, such as a function, fails and pushes nothing. ActionPush is for generated parsers; not a stable API.
Printed from Exec IR function push of internal/ir/code/exec/compose.
func (*TParser) ActionPushItems source
func (p *TParser) ActionPushItems(c *TActCtx, fn string, v any) any
ActionPushItems pushes the elements of v, an argument of the built-in function fn that concatenates lists, as the next elements of the list that fn makes in c: none for nil, and those of a list or a tuple as they are. Any other value fails and pushes nothing. ActionPushItems is for generated parsers; not a stable API.
Printed from Exec IR function pushItems of internal/ir/code/exec/compose.
func (*TParser) ActionText source
func (p *TParser) ActionText(x any) (string, any)
ActionText is the built-in function text: a string itself, the text that a string node holds, the input of the range of any other node, a recovered value among them, and the empty string for nil. Any other value fails. ActionText is for generated parsers; not a stable API.
Printed from Exec IR function text of internal/ir/code/exec/compose.
func (*TParser) ActionUnary source
func (p *TParser) ActionUnary(op int, x any) (any, any)
ActionUnary applies the unary operator that op indexes in exec.UnaryOps to x: - negates an int, with wraparound, and ! negates a bool. Any other operand fails. ActionUnary is for generated parsers; not a stable API.
Printed from Exec IR function unary of internal/ir/code/exec/compose.
func (*TParser) Anchor source
func (p *TParser) Anchor(ok bool, desc ExpID) (any, bool)
func (*TParser) AttachCaptures source
func (p *TParser) AttachCaptures(v any, names []string, vals []any, start, end int) any
AttachCaptures attaches the non-nil captures vals (named names) as fields of the value (a CST node), first wrapping it in a tuple node unless it is a fresh one that is not itself captured.
func (*TParser) Bind source
func (p *TParser) Bind(slot int, t func(*TActCtx) (any, any)) bool
Bind binds the value of the action expression of a binding to the variable in slot. An action expression that fails fails the binding and binds nothing. The compiler has checked that the value fits the variable. The value of an action expression is never a function.
Printed from Exec IR function bind of internal/ir/code/exec/compose.
func (*TParser) Call source
func (p *TParser) Call(r *TRule, min int) (any, bool)
func (*TParser) CallMemo source
func (p *TParser) CallMemo(r *TRule, inv func(*TParser) (any, bool)) (any, bool)
CallMemo is the memoized part of a rule call, for the rule r at binding level 0 invoked by inv: the rule is called at the position again, or its memoization is no longer deferred.
Printed from Exec IR function callMemo of internal/ir/code/exec/compose, specialized for document, observe, typed.
func (*TParser) ClassFast source
func (p *TParser) ClassFast(c *Class) bool
ClassFast consumes one ASCII character of c and reports whether it did. It changes nothing otherwise, and the caller then runs ClassSkip for the other characters and the expectation. It is small enough for the compiler to inline into the generated parser.
func (*TParser) ClassFastLogical source
func (p *TParser) ClassFastLogical(c *Class) bool
ClassFastLogical is ClassFast that counts the character it consumes.
ClassFastLogical is for generated parsers; not a stable API.
func (*TParser) ClassSkip source
func (p *TParser) ClassSkip(c *Class, id ExpID) bool
ClassSkip consumes one character of c in an ordinary parse and reports whether there was one; otherwise it records the expectation id at the position.
func (*TParser) ClassSkipLogical source
func (p *TParser) ClassSkipLogical(c *Class, id ExpID) bool
ClassSkipLogical is ClassSkip that counts the character it consumes.
ClassSkipLogical is for generated parsers; not a stable API.
func (*TParser) ClassesSkip source
func (p *TParser) ClassesSkip(steps []ClassStep) bool
ClassesSkip consumes one character of each step's class in turn in an ordinary parse and reports whether all matched; at the first that does not it records that step's expectation.
func (*TParser) ClassesSkipLogical source
func (p *TParser) ClassesSkipLogical(steps []ClassStep) bool
ClassesSkipLogical is ClassesSkip that counts the characters it consumes, also those of the classes that match before one fails.
ClassesSkipLogical is for generated parsers; not a stable API.
func (*TParser) DiagnosticAttr source
func (p *TParser) DiagnosticAttr(m tmatcher, name ExpID) (any, bool)
func (*TParser) DocumentCall source
func (p *TParser) DocumentCall(r *TRule, min int, inv func(*TParser) (any, bool)) (any, bool)
DocumentCall is a typed rule call in a Document parse, for the rule r at binding level min, invoked by inv when a generated call passes it: unmemoized for a rule that the Document does not memoize, and otherwise through the memo, with the Document record of each entry kept beside it. As in document, the enclosing call's examined input is restored however the call ends.
Printed from Exec IR function typedDocument of internal/ir/code/exec/compose, specialized for document, observe, typed, budget.
func (*TParser) DropCreated source
func (p *TParser) DropCreated(base int)
func (*TParser) DropKids source
func (p *TParser) DropKids(base int)
func (*TParser) DropTrail source
func (p *TParser) DropTrail(base int)
DropTrail discards undo history whose effects are already restored or whose frame is returning. Clear its references before truncating the backing slice.
func (*TParser) ElemsAbove source
func (p *TParser) ElemsAbove(base int) []any
ElemsAbove is Parser.ElemsAbove in a typed parse: action.elemsAbove, which charges two units for each element in one reservation before it moves any.
func (*TParser) ErrorAttr source
func (p *TParser) ErrorAttr(m tmatcher, msg ExpID) (any, bool)
func (*TParser) Finish source
func (p *TParser) Finish(r *TRule, f *TCaptureFrame, v any, start int) any
Finish makes the rule's value from the value of its body, and checks it against the rule's declared type if needed.
func (*TParser) FreeFrame source
func (p *TParser) FreeFrame(f *TCaptureFrame)
FreeFrame makes the frame f, which nothing refers to any more, available to NewFrame. A rule's frame is dead when the rule returns: the values have been copied into its result, and the trail entries that refer to it are gone.
func (*TParser) InvokePlain source
func (p *TParser) InvokePlain(r *TRule, min int) (any, bool)
func (*TParser) Kids source
func (p *TParser) Kids(base int) []any
Kids returns p.KidStack[base:] as a value list and pops it. It charges nothing, as Parser.Kids.
func (*TParser) ListField source
func (p *TParser) ListField(kids []any) any
ListField materializes a typed struct's list field during an action read. The ordinary TField path remains independent of a parser or budget controller.
func (*TParser) Mark source
func (p *TParser) Mark() Mark
func (*TParser) MatchAny source
func (p *TParser) MatchAny(build bool) (any, bool)
func (*TParser) MatchAnyOrdinary source
func (p *TParser) MatchAnyOrdinary(build bool) (any, bool)
MatchAnyOrdinary is MatchAny in an ordinary parse (parser.ExpectOrdinary).
func (*TParser) MatchLiteral source
func (p *TParser) MatchLiteral(rs []rune, text string, desc ExpID, build bool) (any, bool)
func (*TParser) MatchLiteralFold source
func (p *TParser) MatchLiteralFold(rs []rune, desc ExpID, build bool) (any, bool)
MatchLiteralFold is MatchLiteral for a case-insensitive literal (see Parser.MatchLiteralFold).
func (*TParser) MatchLiteralOrdinary source
func (p *TParser) MatchLiteralOrdinary(rs []rune, text string, desc ExpID, build bool) (any, bool)
MatchLiteralOrdinary is MatchLiteral in an ordinary parse (parser.ExpectOrdinary).
func (*TParser) NewFrame source
func (p *TParser) NewFrame(n int) *TCaptureFrame
func (*TParser) NewMatch source
func (p *TParser) NewMatch(start, end int, text string, fresh bool) *TMatch
NewMatch returns a match that the parse builds. It charges nothing, as NewNode.
func (*TParser) NewMatchOrdinary source
func (p *TParser) NewMatchOrdinary(start, end int, text string, fresh bool) *TMatch
func (*TParser) NewNode source
func (p *TParser) NewNode(typ string, start, end int, kids []any) *TSeq
NewNode returns a node that the parse builds. It charges nothing: the values that the parse builds are not an item of the cost (spec/runtime/parsing.md#cost).
func (*TParser) NewNodeOrdinary source
func (p *TParser) NewNodeOrdinary(typ string, start, end int, kids []any) *TSeq
func (*TParser) NewVals source
func (p *TParser) NewVals(n int) []any
NewVals returns a value list of length and capacity n.
func (*TParser) OperatorsRuleParse source
func (p *TParser) OperatorsRuleParse(r *TRule, min int) (any, bool)
OperatorsRuleParse parses an expression of the Operators Rule r with operators that bind tighter than min. Each level of its recursion (the operand of a prefix operator, the right operand of an infix operator) counts against the nesting limit, like the entry of a recursive rule.
Printed from Exec IR function operatorsParseTyped of internal/ir/code/exec/compose, specialized for budget, typed.
func (*TParser) Predicate source
func (p *TParser) Predicate(t func(*TActCtx) (any, any)) bool
Predicate applies the action expression of a predicate to the context that action.ctx makes. It fails on the boolean false and on an action expression that fails, and holds on every other value. The value of an action expression is never a function.
Printed from Exec IR function predicate of internal/ir/code/exec/compose.
func (*TParser) PushKid source
func (p *TParser) PushKid(v any)
PushKid gathers v. It charges nothing: the values that the parse gathers are not an item of the cost.
func (*TParser) RecoverAttr source
func (p *TParser) RecoverAttr(m, skip tmatcher, build bool) (any, bool)
func (*TParser) Reset source
func (p *TParser) Reset(m Mark)
Reset returns to the backtracking point m: the position, the variable environment, the recovered errors and the captures (undoing the trail) become what they were when m was taken.
Printed from Exec IR function reset of internal/ir/code/exec/compose.
func (*TParser) RunBegin source
func (p *TParser) RunBegin(site int, build, keyEnv bool)
RunBegin is the Parser's RunBegin in a typed parse, whose values SkipValue and SkipKids take.
func (*TParser) ScanKids source
func (p *TParser) ScanKids(site, start, base, count int) []any
ScanKids is Parser.ScanKids for a typed parse.
func (*TParser) ScopeValue source
func (p *TParser) ScopeValue(s Shaper, v any, start int) any
ScopeValue returns the value of a scope whose body matched [start, p.Pos) with the result v.
func (*TParser) SetCapture source
func (p *TParser) SetCapture(slot int, v any)
SetCapture stores v in the capture slot. v is a value of the grammar's value model, never a function value: the library does not check it, because the code of a generated parser makes values only by lowered action expressions, and a lowered action expression never yields a function. Like every exported symbol of this package it is not a stable API.
func (*TParser) ShapeCapture source
func (p *TParser) ShapeCapture(s Shaper, v any, start int) any
ShapeCapture is ShapeSingle for a capture or a recovered expression, whose value is the unit node of the range matched when the expression has no value.
func (*TParser) ShapeSingle source
func (p *TParser) ShapeSingle(s Shaper, v any, start int) (any, bool)
ShapeSingle returns the value of the result v where the expression takes one element; ok is false when it has no value.
func (*TParser) Single source
func (p *TParser) Single(size int, build bool) (any, bool)
func (*TParser) SkipCall source
func (p *TParser) SkipCall(r *Rule, exp ExpID)
SkipCall is Parser.SkipCall for the typed library, whose memo it stores in.
func (*TParser) SkipCalls source
func (p *TParser) SkipCalls(exp ExpID, rules ...*Rule)
SkipCalls is Parser.SkipCalls for the typed library, whose memo it stores in.
func (*TParser) SkipKids source
func (p *TParser) SkipKids() []any
SkipKids is the Parser's SkipKids in a typed parse.
func (*TParser) SkipTerminal source
func (p *TParser) SkipTerminal(t *TerminalProgram) bool
SkipTerminal matches t in an ordinary parse and reports whether it matched. It consumes the same input as the generated code of the expression and records the same expectations at the same positions. On failure the position is unspecified, as after the generated code; the caller restores it.
func (*TParser) SkipTerminalLogical source
func (p *TParser) SkipTerminalLogical(t *TerminalProgram) bool
SkipTerminalLogical is SkipTerminal that counts the input that each of its terminals advances over, again after the program backtracks.
SkipTerminalLogical is for generated parsers; not a stable API.
func (*TParser) SkipValue source
func (p *TParser) SkipValue(v any)
SkipValue is the Parser's SkipValue for a typed value.
func (*TParser) TConvertResult source
func (p *TParser) TConvertResult(r *TRule, v any) any
TConvertResult converts v, the value of rule r, to the rule's named node type.
func (*TParser) TConvertResultOwned source
func (p *TParser) TConvertResultOwned(r *TRule, v, body any) any
TConvertResultOwned converts v, the value of rule r, to the rule's named node type, like TConvertResult. If v is body, the fresh node of the rule's body (TFreshNode), the rule returns the node it made itself, which nothing else holds, so it gets the type in place instead of being copied: the copy tconvert makes keeps a node that others hold as it is.
func (*TParser) UnitsOfItems source
func (p *TParser) UnitsOfItems(v any, k int)
UnitsOfItems is the typed Parser.UnitsOfItems.
func (*TParser) UseCtx source
func (p *TParser) UseCtx(c TActCtx) *TActCtx
type TPubHooks source
type TPubHooks struct {
Match func(*TNode[string]) any
Error func(*TErrorValue) any
Node func(*TNode[any]) any
Back func(any) any
}
TPubHooks makes the public forms of the values the typed library builds that the generated package defines types for: a string node, an error value and a node of a statically unknown value are public values of the package's own types, which implement the package's unions. Back is the inverse: it returns the library's form of such a public value, and any other value unchanged.
TPubHooks is for generated parsers; not a stable API.
type TRule source
type TRule struct {
*Rule
Body func(p *TParser, min int) (any, bool)
Action func(c *TActCtx) (any, any) // as Rule.Action
OperatorsRule *TOperatorsRule
// Entry is the generated method that calls the rule as call(r, 0) does (u<id> or s<id>). The
// generated parser sets it only for the start rules, which TParse runs through it; every other
// rule is called through the generated methods that name it. A flat rule (one the generator prints
// as one function) has no body or action and is called only through it.
Entry func(p *TParser) (any, bool)
// Nt is the registered index of the named node type the rule's value is converted to
// (rule.NodeType), or 0.
Nt uint16
// OpNt is the registered index of the named node type every operator node of an Operators
// Rule is converted to (rule.OpNodeType), or 0.
OpNt uint16
}
TRule is a rule of the typed library: the rule's analysis results and its typed body.
TRule is for generated parsers; not a stable API.
func NewTRules source
func NewTRules(rules []*Rule) []*TRule
NewTRules returns the typed rules that share the analysis results of rules, one for one.
For generated parsers; not a stable API.
func TraceTRules source
func TraceTRules(trules []*TRule) []*TRule
TraceTRules returns the traced copies of the typed rules, one for one, as TraceRules does for rules: the generated code sets their Body, OperatorsRule and Entry. A copy shares the analysis results of its rule (Rule).
TraceTRules is for generated parsers; not a stable API.
type TSeq source
type TSeq struct {
sxirinput.Span
Typ string
Kids []any
// contains filtered or unexported fields
}
TSeq is a tuple node, a list node, a tuple value (TypeTupleValue) or a list value (TypeListValue) of the typed library. A tuple node's fields are its captures. A tuple or list node of a named node type has nt, as TMatch does; typ stays "tuple" or "list".
TSeq is for generated parsers; not a stable API.
func (*TSeq) TField source
func (n *TSeq) TField(name string) (any, bool)
func (*TSeq) TFresh source
func (n *TSeq) TFresh() bool
func (*TSeq) TKids source
func (n *TSeq) TKids() []any
func (*TSeq) TName source
func (n *TSeq) TName() string
func (*TSeq) TSetFresh source
func (n *TSeq) TSetFresh(f bool)
func (*TSeq) TSetSpan source
func (n *TSeq) TSetSpan(start, end int)
func (*TSeq) TSpan source
func (n *TSeq) TSpan() (int, int)
func (*TSeq) TStruct source
func (n *TSeq) TStruct() bool
func (*TSeq) TText source
func (n *TSeq) TText() (string, bool)
type TVal source
type TVal interface {
TSpan() (int, int)
TSetSpan(start, end int)
TName() string // type name
TText() (string, bool) // text of a string node or an error value
TKids() []any // children of a CST node
TField(name string) (any, bool) // field value, and whether the type has the field (structs)
TStruct() bool // a struct type
TFresh() bool
TSetFresh(bool)
}
TVal is a node value of the typed library: a value of a struct type, *TMatch, *TError or *TSeq.
TVal is for generated parsers; not a stable API.
func AsTval source
func AsTval(v any) TVal
AsTval returns v as a node value, or nil. Values never hold nil pointers: nil is always the untyped nil.
AsTval is for generated parsers; not a stable API.
type TerminalProgram source
type TerminalProgram struct {
Code []uint16
Classes []*Class
Literals []TerminalText
// contains filtered or unexported fields
}
TerminalProgram is a value-free expression made only of literals, character classes, sequences, choices, options and negative lookaheads, which generated parsers match through this table instead of straight-line code; not a stable API.
func (*TerminalProgram) Prepare source
func (t *TerminalProgram) Prepare() *TerminalProgram
Prepare builds the dispatch tables of the choices of t from the classes of their guards and returns t. Generated parsers declare a program as static data and prepare it once.
type TerminalText source
type TerminalText struct {
Runes []rune
Text string
}
TerminalText is a literal of a TerminalProgram, as the generated code passes it to MatchLiteral.
TerminalText is for generated parsers; not a stable API.
type TypedDocumentCloneBase source
type TypedDocumentCloneBase struct {
Control *BudgetControl
Values map[any]any
Slices map[DocumentSliceKey]any
Tasks []TypedDocumentCloneTask
}
TypedDocumentCloneBase is the state of a CloneValue copy of a published typed Document value. The generated typedDocumentClone embeds it and adds the copies of the grammar's types.
TypedDocumentCloneBase is for generated parsers; not a stable API.
func (*TypedDocumentCloneBase) Begin source
func (c *TypedDocumentCloneBase) Begin(control *BudgetControl)
func (*TypedDocumentCloneBase) ReleaseBase source
func (c *TypedDocumentCloneBase) ReleaseBase()
func (*TypedDocumentCloneBase) Remember source
func (c *TypedDocumentCloneBase) Remember(from, to any)
func (*TypedDocumentCloneBase) Step source
func (c *TypedDocumentCloneBase) Step(n uint64)
type TypedDocumentCloneTask source
type TypedDocumentCloneTask struct{ Source, Target any }
TypedDocumentCloneTask is a value whose copy (target) has yet to be filled from source.
TypedDocumentCloneTask is for generated parsers; not a stable API.