bobzhang/peg/compiler does not have a README file

    CompilerError

    pub(all) suberror CompilerError {
    CompilerError(String)
    } derive(
    Debug
    )

    A compiler error without a source location (a plain Error in PEG.js).

    GrammarError

    pub(all) suberror GrammarError {
    GrammarError(message~ : String, location~ :
    Location
    )
    } derive(
    Debug
    )

    A semantic error in the grammar, reported at location (PEG.js' GrammarError).

    Compiled

    pub(all) enum Compiled[T] {
    Parser(
    Parser
    [T])
    Source(String)
    }

    Result of compile: a parser or generated source, per Options::output.

    Optimize

    pub(all) enum Optimize {
    Speed
    Size
    } derive(Eq,
    Debug
    )

    Options

    pub(all) struct Options[T] {
    allowed_start_rules : Array[String]?
    cache : Bool
    optimize : Optimize
    output : Output
    trace : Bool
    features : Map[String, Bool]
    header : Array[String]
    parser : ParserOptions
    actions : Map[String, (
    ActionContext
    [T]) ->
    Value
    [T] raise]
    initializer : (
    ActionContext
    [T]) -> Map[String, (
    ActionContext
    [T]) ->
    Value
    [T] raise] raise?
    value_type : String
    name_prefix : String
    extra : Map[String, Json]
    }

    Options of compile / generate. Plugins may modify them.

    Options::copy

    fn[T] Options::copy(self : Options[T]) -> Options[T]

    A copy that can be modified without affecting self (like PEG.js' processOptions, which builds a fresh options object).

    Options::new

    fn[T] Options::new(allowed_start_rules? : Array[String], cache? : Bool, optimize? : Optimize, output? : Output, trace? : Bool, features? : Map[String, Bool], header? : Array[String], parser? : ParserOptions, actions? : Map[String, (
    ActionContext
    [T]) ->
    Value
    [T] raise], initializer? : (
    ActionContext
    [T]) -> Map[String, (
    ActionContext
    [T]) ->
    Value
    [T] raise] raise, value_type? : String, name_prefix? : String, extra? : Map[String, Json]) -> Options[T]

    Options::runtime_features

    fn[T] Options::runtime_features(self : Options[T]) ->
    Features

    The resolved features record used by generated parsers.

    Options::start_rules

    fn[T] Options::start_rules(self : Options[T], grammar :
    Grammar
    ) -> Array[String]

    Allowed start rules, defaulting to the grammar's first rule.

    Options::use_feature

    fn[T] Options::use_feature(self : Options[T], feature : String) -> Bool

    The use(feature) test of generateJS: enabled unless set to false.

    Output

    pub(all) enum Output {
    Parser
    Source
    } derive(Eq,
    Debug
    )

    ParserOptions

    pub(all) struct ParserOptions {
    reserved_words : Array[String]?
    extract_comments : Bool
    filename : String?
    } derive(
    Debug
    )

    Options of the grammar parser (peg.parser.parse).

    ParserOptions::copy

    ParserOptions::new

    fn ParserOptions::new(reserved_words? : Array[String], extract_comments? : Bool, filename? : String) -> ParserOptions

    Pass

    pub(all) struct Pass[T] {
    name : String
    run : (
    Grammar
    , Session[T], Options[T]) -> Unit raise
    }

    A compiler pass: inspects or rewrites the grammar, reporting problems through the session. name identifies built-in passes (e.g. "reportUndefinedRules"), which lets plugins find and replace them.

    Passes

    pub(all) struct Passes[T] {
    check : Array[Pass[T]]
    transform : Array[Pass[T]]
    generate : Array[Pass[T]]
    }

    The ordered pass stages compile runs.

    Session

    pub(all) struct Session[T] {
    parser : (String, ParserOptions) ->
    Grammar
    raise
    passes : Passes[T]
    opcodes :
    Opcodes

    warn : (String,
    Location
    ?) -> Unit
    error : (String,
    Location
    ?) -> Unit raise
    backend : (
    Grammar
    , Session[T], Options[T]) ->
    Parser
    [T] raise
    }

    Compiler configuration handed to plugins (peg.compiler.Session).

    Every component can be replaced: the grammar parser, the passes, the opcodes numbering used by bytecode generation, the warn / error reporters, and the backend that turns a compiled grammar into a parser (the counterpart of PEG.js' vm).

    Session::new

    fn[T] Session::new(parser~ : (String, ParserOptions) ->
    Grammar
    raise, passes? : Passes[T], opcodes? :
    Opcodes
    , warn? : (String,
    Location
    ?) -> Unit, error? : (String,
    Location
    ?) -> Unit raise, backend? : (
    Grammar
    , Session[T], Options[T]) ->
    Parser
    [T] raise) -> Session[T]

    Session::parse

    fn[T] Session::parse(self : Session[T], input : String, options : ParserOptions) ->
    Grammar
    raise

    Session::report_error

    fn[T] Session::report_error(self : Session[T], message : String, location? :
    Location
    ) -> Unit raise

    Session::report_warning

    fn[T] Session::report_warning(self : Session[T], message : String, location? :
    Location
    ) -> Unit

    calc_report_failures

    fn[T] calc_report_failures(grammar :
    Grammar
    , _session : Session[T], options : Options[T]) -> Unit raise

    Marks the rules whose failures can be visible (calc-report-failures.js): start rules, and rules reachable from them outside named rules.

    compile

    fn[T] compile(grammar :
    Grammar
    , session : Session[T], options : Options[T]) -> Compiled[T] raise

    Runs the session's passes over grammar and produces the output selected by options.output (peg.compiler.compile).

    Raises GrammarError / CompilerError for semantic errors.

    default_passes

    fn[T] default_passes() -> Passes[T]

    The standard passes, in PEG.js order.

    fatal

    fn fatal(message : String, location? :
    Location
    ) -> Unit raise

    Raises GrammarError when a location is given, CompilerError otherwise (session.fatal).

    generate_bytecode

    fn[T] generate_bytecode(grammar :
    Grammar
    , session : Session[T], _options : Options[T]) -> Unit raise

    Generates bytecode for every rule and stores the constant tables on the grammar.

    inference_match_result

    fn[T] inference_match_result(grammar :
    Grammar
    , session : Session[T], _options : Options[T]) -> Unit raise

    Infers whether each node always (1), sometimes (0) or never (-1) matches (inference-match-result.js).

    interpreter_backend

    fn[T] interpreter_backend(grammar :
    Grammar
    , session : Session[T], options : Options[T]) ->
    Parser
    [T] raise

    The default backend: interprets the grammar's bytecode, implementing code blocks with Options::actions / Options::initializer.

    program_of

    fn[T] program_of(grammar :
    Grammar
    , session : Session[T], options : Options[T]) ->
    Program
    raise

    Collects the bytecode program produced by the generate passes.

    remove_proxy_rules

    fn[T] remove_proxy_rules(grammar :
    Grammar
    , _session : Session[T], options : Options[T]) -> Unit raise

    Removes rules that only delegate to another rule, redirecting references (remove-proxy-rules.js). Proxies listed as start rules are kept.

    report_duplicate_labels

    fn[T] report_duplicate_labels(grammar :
    Grammar
    , session : Session[T], _options : Options[T]) -> Unit raise

    Checks that each label is defined only once within each scope (report-duplicate-labels.js).

    report_duplicate_rules

    fn[T] report_duplicate_rules(grammar :
    Grammar
    , session : Session[T], _options : Options[T]) -> Unit raise

    Checks that each rule is defined only once (report-duplicate-rules.js).

    report_incorrect_plucking

    fn[T] report_incorrect_plucking(grammar :
    Grammar
    , session : Session[T], _options : Options[T]) -> Unit raise

    Ensures @ is not combined with an action block or used on a semantic predicate (report-incorrect-plucking.js).

    report_infinite_recursion

    fn[T] report_infinite_recursion(grammar :
    Grammar
    , session : Session[T], _options : Options[T]) -> Unit raise

    Reports left recursion (report-infinite-recursion.js).

    If a rule reference can be reached without consuming any input, it can lead to infinite recursion.

    report_infinite_repetition

    fn[T] report_infinite_repetition(grammar :
    Grammar
    , session : Session[T], _options : Options[T]) -> Unit raise

    Reports repetitions of expressions that may not consume input (report-infinite-repetition.js). Like PEG.js, a checked repetition's operand is not searched further.

    report_undefined_rules

    fn[T] report_undefined_rules(grammar :
    Grammar
    , session : Session[T], options : Options[T]) -> Unit raise

    Checks that all referenced rules exist (report-undefined-rules.js).

    report_unused_rules

    fn[T] report_unused_rules(grammar :
    Grammar
    , session : Session[T], options : Options[T]) -> Unit raise

    Warns about rules that are never referenced (report-unused-rules.js).

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io