TOC Toolkit API - v0.1.0
    Preparing search index...

    toc-toolkit/grammars/rewriting

    Rewrites a context-free grammar to read better without changing the language of any variable. It holds the rewrite rules with their proofs, a cost model that ranks candidates, and a search over right-hand sides.

    • Readability rewriting. Applies inlining, folding and shared-context factoring in rounds, and accepts a rewrite only when the readability cost drops. It supports a traced run and a semantic variant. (readableGrammar, semanticReadability, traceReadability)
    • Readability search. Tries several option portfolios and keeps the cheapest grammar. (readableGrammarSearch, semanticReadabilitySearch)
    • Cartesian seeds. Expands a right-hand side into its finite set of words and factors complete rectangles by prefix or suffix. (cartesianRhsSeeds)
    • Right-hand side optimization. Saturates an e-graph under the language semiring and extracts the cheapest expression for each cost profile. (optimizeRhs)
    • Redundant production search. Looks for a production that another derivation already covers and returns a certificate that can be checked. (findRedundantProduction, verifyRedundancy)
    • Concatenation closure. Removes the productions A -> A A and A -> A of a variable that also has A -> ε and appends A to its other productions. (normalizeConcatenationClosure)
    • Right-hand side lowering. Turns an expression with unions and concatenations back into productions. (lowerGrammarRhs)
    • Grammar metrics. Measures the size of a grammar and its readability cost. (grammarMetrics, grammarReadabilityCost)
    • Expression construction. Builds right-hand side expressions and reads the expression of a grammar. (rhsEmpty, rhsEpsilon, rhsTerminal, rhsVariable, rhsUnion, rhsConcat, grammarRhsExpression)
    • Dumps. Print a right-hand side expression and a readability result as text. (dumpRhs, dumpReadability)
    • Right-hand side expression. A tree of empty, epsilon, terminal, variable, union and concatenation nodes. (RhsExpression)
    • Rewrite proof. The justification of a rewrite step. (RewriteProof)
    • Readability trace. The grammars and steps of a rewriting run. (ReadabilityTraceStep, traceReadability)
    • Redundancy certificate. The evidence that a production is covered by other derivations, and the limits of its search. (RedundancyCertificate, RedundancySearch, DEFAULT_REDUNDANCY_SEARCH)
    • Readability results. The options, the result and the notes of a readability run. (ReadableGrammarOptions, ReadableGrammarResult, ReadabilityNote, ReadabilityTraceStep)
    • Metrics and optimization reports. The size and cost of a grammar and the outcome of a right-hand side optimization, with its cost profiles. (GrammarMetrics, ReadabilityCost, RhsOptimization, RHS_ALTERNATIVE_COST_PROFILES)
    • Decoders. Read expressions, metrics, proofs, redundancy evidence, optimization reports, lowering results and readability results back from plain data. (rhsExpressionDecoder, grammarMetricsDecoder, rewriteProofDecoder, redundancyCertificateDecoder, rhsOptimizationDecoder, loweredGrammarDecoder, concatenationClosureResultDecoder, readableGrammarResultDecoder, cartesianSeedCandidateDecoder, cartesianSeedResultDecoder, concatenationClosureEvidenceDecoder, extendedClosureProductionDecoder, grammarReadabilityDecoder, readabilityCostDecoder, readabilityNoteDecoder, readabilityStepDecoder, readableGrammarOptionsDecoder, redundancySearchDecoder, redundancySearchOptionsDecoder, rewriteEvidenceDecoder, rhsCandidateDecoder, rhsCostProfileDecoder, rhsOperatorCostsDecoder)
    • Enumerations. Name the closed sets of strings that the types and the wire data of the package use. (GrammarRewriteKind, PreservedLanguages, ReadabilityBranch, ReadabilityNoteCode, RewriteProofKind, RewriteRuleId, RhsCostProfileId, RhsImprovement, RhsOperator, SemanticMatchKind)