Skip to main content

Module parser_runtime

Module parser_runtime 

Source
Expand description

Parser combinator interpreter (#221).

Lives in lex-bytecode rather than lex-runtime because it needs to invoke Value::Closure values from Map / AndThen nodes, which requires VM-level access. The structural primitives are constructed by lex-runtime::builtins; only the recursive interpretation step (parser.run) is here.

Calling convention:

  • The Vm intercepts ("parser", "run") effect dispatch before invoking the handler and routes the args to run_parser, passing itself as the ClosureCaller.
  • Map(p, f) and AndThen(p, f) AST nodes carry a closure value f; the interpreter calls back via caller.call_closure to invoke it on the parsed result.

Traits§

ClosureCaller
Trait the parser interpreter uses to invoke captured closures during the recursive walk. The Vm implements it via Vm::invoke_closure_value, but the interpreter is generic over the implementation so lex-bytecode doesn’t need to depend on any higher-level runtime concepts.

Functions§

run_parser
Walk a parser AST. Returns (value, end_pos) on success or (failure_pos, message) on failure. The interpreter is the same shape as the original (in lex-runtime::builtins) plus the Map and AndThen cases that need closure invocation.