Documentation
¶
Index ¶
- Constants
- Variables
- func BuildLexicalGraph(source, code string) (*Graph, []Lexeme, error)
- func ClassifyStatement(vector Vector) (int, error)
- func FeatureIndex(feature string) (int, bool)
- func LanguageIndex(language string) (int, bool)
- func MustFeatureIndex(feature string) int
- type CanonicalEvent
- type CanonicalNode
- type CanonicalProgram
- type CapabilityModel
- type Graph
- func (g *Graph) AddNode(vector Vector, text, symbol string, sourceAt int) int
- func (g *Graph) AddNodes(nodes []Node) []int
- func (g *Graph) Connect(relation Relation, from, to int) error
- func (g *Graph) NodeMatrix() Matrix
- func (g *Graph) RelationCounts() Vector
- func (g *Graph) Requirements() Vector
- func (g *Graph) SemanticRequirements() Vector
- type Lexeme
- type Matrix
- func (m Matrix) At(row, col int) float64
- func (m Matrix) BooleanClosure() (Matrix, error)
- func (m Matrix) Hadamard(right Matrix) (Matrix, error)
- func (m Matrix) Multiply(right Matrix) (Matrix, error)
- func (m Matrix) Row(row int) Vector
- func (m Matrix) Set(row, col int, value float64)
- func (m Matrix) Threshold() Matrix
- func (m Matrix) Transpose() Matrix
- type Node
- type Relation
- type SparseMatrix
- func (m SparseMatrix) At(r, c int) float64
- func (m SparseMatrix) BooleanClosure() (SparseMatrix, error)
- func (m SparseMatrix) Dense() Matrix
- func (m SparseMatrix) Each(f func(int, int, float64))
- func (m *SparseMatrix) Grow(rows, cols int)
- func (m SparseMatrix) MarshalJSON() ([]byte, error)
- func (m SparseMatrix) Multiply(b SparseMatrix) (SparseMatrix, error)
- func (m SparseMatrix) NonZeros() int
- func (m SparseMatrix) Set(r, c int, v float64)
- func (m SparseMatrix) Sum() float64
- func (m SparseMatrix) Transpose() SparseMatrix
- func (m *SparseMatrix) UnmarshalJSON(data []byte) error
- type TargetPlan
- type TokenClass
- type TokenStructure
- type Vector
- func ActionSemantic(action Vector) (Vector, error)
- func AnalyzeExpression(source, text string) Vector
- func Basis(size, index int) Vector
- func FeatureRequirements(semantic Vector) (Vector, error)
- func GrammarProfile(language string) (Vector, error)
- func LexicalAxesFor(source string, class TokenClass, text string) Vector
- func MissingLowerings(target string, required Vector) (Vector, error)
- func StatementRequirements(vectors []Vector) (Vector, error)
Constants ¶
const ( StatementAssign = iota StatementPrint StatementReturn StatementExpression StatementClasses )
const ( GrammarBrace = iota GrammarIndent GrammarEnd GrammarSemicolon GrammarNewline GrammarTypedDeclaration GrammarMainWrapper GrammarOneBasedIndex GrammarIntegerSlashTruncates GrammarExclusiveRangeEnd GrammarDimensions )
const ( ActionSkip = iota ActionBlock ActionAssign ActionPrint ActionReturn ActionExpression ActionIf ActionElse ActionWhile ActionFor ActionFunction ActionCall ActionIndex ActionModule ActionObject ActionException ActionConcurrency ActionReflection ActionDimensions )
const ( LexIdentifier = iota LexNumber LexString LexStringComment LexStringKeyword LexBoolean LexReturn LexPrint LexIf LexWhile LexFor LexFunction LexObject LexException LexModule LexConcurrency LexReflection LexArithmetic LexDivision LexIntegerDivision LexComparison LexLogical LexShortCircuit LexBinding LexNamedArgument LexIndex LexGrouping LexCall LexBlock LexComment LexicalAxes )
const ( SemProgram = iota SemBlock SemAssign SemPrint SemReturn SemExpression SemIdentifier SemNumber SemString SemBoolean SemNull SemUnary SemBinary SemCall SemIndex SemIf SemWhile SemFor SemFunction SemArithmetic SemDivision SemIntegerDivision SemComparison SemLogical SemBinding SemReassignment SemScope SemClosure SemNamedArgument SemLazyEvaluation SemShortCircuit SemOverflow SemObject SemException SemGeneric SemOwnership SemModule SemConcurrency SemFFI SemReflection SemSerialization SemIO SemEffect SemStringComment SemStringKeyword SemMultiline SemGrouping SemUnknown SemanticDimensions )
Variables ¶
var ActionNames = [...]string{
"skip", "block", "assign", "print", "return", "expression", "if", "else", "while", "for", "function", "call", "index", "module", "object", "exception", "concurrency", "reflection",
}
var Features = [...]string{
"arithmetic", "binding", "reassignment", "division", "boolean", "string_comment", "string_keywords", "comparison",
"multiline", "grouping", "if_else", "while", "for", "function", "index", "integer_division",
"scope", "closure", "named_args", "lazy_eval", "short_circuit", "overflow", "null_na", "objects",
"exceptions", "generics", "ownership", "modules", "concurrency", "ffi", "reflection", "serialization",
}
var GrammarNames = [...]string{
"brace_blocks", "indent_blocks", "end_blocks", "semicolon", "newline", "typed_declaration", "main_wrapper", "one_based_index", "integer_slash_truncates", "exclusive_range_end",
}
var Languages = [...]string{"r", "go", "rust", "cpp", "c", "python", "zig", "julia", "nim", "csharp", "java", "kotlin", "swift"}
var RelationNames = [...]string{"syntax", "control", "data", "binding", "effect"}
var SemanticNames = [...]string{
"program", "block", "assign", "print", "return", "expression", "identifier", "number", "string", "boolean", "null",
"unary", "binary", "call", "index", "if", "while", "for", "function", "arithmetic", "division", "integer_division",
"comparison", "logical", "binding", "reassignment", "scope", "closure", "named_argument", "lazy_evaluation", "short_circuit",
"overflow", "object", "exception", "generic", "ownership", "module", "concurrency", "ffi", "reflection", "serialization",
"io", "effect", "string_comment", "string_keyword", "multiline", "grouping", "unknown",
}
Functions ¶
func ClassifyStatement ¶
func FeatureIndex ¶
func LanguageIndex ¶
func MustFeatureIndex ¶
Types ¶
type CanonicalEvent ¶
CanonicalEvent preserves structural action order for direct lowerers. It is not a source string field and is deliberately separate from the legacy R diagnostic view.
type CanonicalNode ¶
type CanonicalProgram ¶
type CanonicalProgram struct {
Source string
R string
Nodes []CanonicalNode
Graph *Graph
Actions Matrix
Grammar Vector
Roles Matrix
Lexemes []Lexeme
Events []CanonicalEvent
}
func Canonicalize ¶
func Canonicalize(source, code string) (CanonicalProgram, error)
Canonicalize lowers the supported common subset through token structure and action matrices into R-shaped syntax. It is not a full parser for all source languages; the R expression parser and some header recognizers remain.
type CapabilityModel ¶
type CapabilityModel struct {
Support Matrix // language x feature
Known Matrix // language x feature
}
CapabilityModel holds support and observation masks. A zero in Support is meaningful only when the corresponding Known cell is one.
func NewCapabilityModel ¶
func NewCapabilityModel(support, known Matrix) (CapabilityModel, error)
func (CapabilityModel) DeficitMatrices ¶
func (m CapabilityModel) DeficitMatrices(requirements Matrix) (missing Matrix, unknown Matrix, err error)
DeficitMatrices computes D=R*(K-S)^T and Q=R*(1-K)^T. R is a source/program x feature requirement matrix. D counts known missing contracts per target, Q counts unknown required contracts per target.
func (CapabilityModel) Plan ¶
func (m CapabilityModel) Plan(requirements Vector, target string) (TargetPlan, error)
type Graph ¶
type Graph struct {
Language string
Nodes []Node
Edges [RelationCount]SparseMatrix
}
func (*Graph) AddNodes ¶
AddNodes appends a batch with consecutive graph-owned IDs and copied semantic vectors. Relation matrices grow their dimensions without copying any edges. Invalid vectors are rejected before the graph is changed; incoming IDs are ignored because IDs are positions in this graph's relation matrices.
func (*Graph) NodeMatrix ¶
func (*Graph) RelationCounts ¶
func (*Graph) Requirements ¶
Requirements performs X*W, where X is the node matrix and W projects semantic dimensions onto the shared 32-feature contract. Counts are reduced to a binary program requirement vector after multiplication.
func (*Graph) SemanticRequirements ¶
type Lexeme ¶
type Matrix ¶
Matrix is a dense row-major matrix. The semantic graphs are sparse in meaning, but dense storage keeps dimensions and multiplication auditable at the current program sizes. Storage can later change without changing the IR.
func ActionSemanticProjection ¶
func ActionSemanticProjection() Matrix
ActionSemanticProjection converts an action vector into the shared semantic basis. It is the executable counterpart of the V9 structure-action matrix.
func GrammarProfileMatrix ¶
func GrammarProfileMatrix() Matrix
GrammarProfileMatrix is the V10 source-language grammar contract. Parser behavior is selected by multiplying a language basis vector by this matrix.
func LexicalRuleMatrix ¶
func LexicalRuleMatrix() Matrix
func LoweringMatrix ¶
func LoweringMatrix() Matrix
LoweringMatrix is target-language x semantic statement class. It is the shared structural rule table used before any target-specific renderer runs.
func MatrixFromRows ¶
func SemanticFeatureProjection ¶
func SemanticFeatureProjection() Matrix
func (Matrix) BooleanClosure ¶
BooleanClosure computes the transitive closure with boolean addition and multiplication. It deliberately does not add identity edges.
type SparseMatrix ¶
SparseMatrix stores only nonzero entries, indexed by row then column. Its coordinates do not depend on dimensions, so graph growth never copies edges. Small semantic/projection matrices deliberately retain the dense Matrix type.
func NewSparseMatrix ¶
func NewSparseMatrix(rows, cols int) SparseMatrix
func (SparseMatrix) At ¶
func (m SparseMatrix) At(r, c int) float64
func (SparseMatrix) BooleanClosure ¶
func (m SparseMatrix) BooleanClosure() (SparseMatrix, error)
BooleanClosure enumerates reachable coordinates, not an n*n temporary array. Dense reachability still requires quadratic output; sparsity is no guarantee that the mathematical result itself is sparse. No identity edges are added.
func (SparseMatrix) Dense ¶
func (m SparseMatrix) Dense() Matrix
func (SparseMatrix) Each ¶
func (m SparseMatrix) Each(f func(int, int, float64))
Each uses stable coordinate order, including in floating-point reductions.
func (*SparseMatrix) Grow ¶
func (m *SparseMatrix) Grow(rows, cols int)
func (SparseMatrix) MarshalJSON ¶
func (m SparseMatrix) MarshalJSON() ([]byte, error)
Sparse serialization is explicit; legacy dense audit fields call Dense at the boundary only. Encoding must never allocate rows*cols implicitly.
func (SparseMatrix) Multiply ¶
func (m SparseMatrix) Multiply(b SparseMatrix) (SparseMatrix, error)
func (SparseMatrix) NonZeros ¶
func (m SparseMatrix) NonZeros() int
func (SparseMatrix) Set ¶
func (m SparseMatrix) Set(r, c int, v float64)
func (SparseMatrix) Sum ¶
func (m SparseMatrix) Sum() float64
func (SparseMatrix) Transpose ¶
func (m SparseMatrix) Transpose() SparseMatrix
func (*SparseMatrix) UnmarshalJSON ¶
func (m *SparseMatrix) UnmarshalJSON(data []byte) error
UnmarshalJSON accepts only the explicit COO representation written above. It rejects duplicate or out-of-range coordinates so a serialized semantic graph cannot silently change meaning while it is loaded.
type TargetPlan ¶
type TokenClass ¶
type TokenClass int
const ( TokenIdentifier TokenClass = iota TokenNumber TokenString TokenOperator TokenDelimiter TokenNewline TokenComment TokenClassCount )
type TokenStructure ¶
type TokenStructure struct {
Classes Matrix
Pairs SparseMatrix
Code Vector
}
TokenStructure keeps class selection and delimiter incidence separate from semantic guesses. Strings/comments have zero weight in the code projection. Pairing is a syntax operation; multiplication alone cannot infer a grammar.
func AnalyzeTokenStructure ¶
func AnalyzeTokenStructure(tokens []Lexeme) (TokenStructure, error)
type Vector ¶
type Vector []float64
func ActionSemantic ¶
func AnalyzeExpression ¶
AnalyzeExpression creates a shared semantic vector without rewriting text. It is quote-aware and language-neutral; source-specific syntax is mapped to the same semantic axes. It is a structural scanner, not the translation engine and not a claim of full parsing.
func FeatureRequirements ¶
func GrammarProfile ¶
func LexicalAxesFor ¶
func LexicalAxesFor(source string, class TokenClass, text string) Vector