BenjaminSchaaf / sbnf

A BNF-style language for writing sublime-syntax files
MIT License
58 stars 6 forks source link

NYI panic in some recursive patterns #10

Closed mitranim closed 3 years ago

mitranim commented 3 years ago

Ran into NYI when implementing a recursive rule for nestable comments. The following abbreviated versions don't compile:

main = (~comment)*;
comment = `[` (~comment)* `]`;
main = `[` (~main)* `]`;

The backtrace for the latter looks like this:

thread 'main' panicked at 'not yet implemented', src/compiler/codegen.rs:516:32
stack backtrace:
   0:        0x108f1d165 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h487f444342133877
   1:        0x108f36670 - core::fmt::write::h5660fecfc358cbad
   2:        0x108f1b01b - std::io::Write::write_fmt::heffa1329234601f9
   3:        0x108f1ed93 - std::panicking::default_hook::{{closure}}::h4c626b183da25edf
   4:        0x108f1ea9a - std::panicking::default_hook::h4e4369f7da993efa
   5:        0x108f1f3db - std::panicking::rust_panic_with_hook::ha90a0fcd081f2912
   6:        0x108f3f245 - std::panicking::begin_panic::h75e4da29b1c40589
   7:        0x108e80512 - sbnf::compiler::codegen::gen_contexts::h13f80b1b37d9969d
   8:        0x108e83d0b - sbnf::compiler::codegen::gen_simple_match_contexts::h2f3d4d6554e49c84
   9:        0x108e827ba - sbnf::compiler::codegen::gen_simple_match::h558366c06a1cc205
  10:        0x108e7d751 - sbnf::compiler::codegen::gen_contexts::h13f80b1b37d9969d
  11:        0x108e7c21c - sbnf::compiler::codegen::codegen::h5afdd46de8d28447
  12:        0x108e66b73 - sbnf::compiler::compile::h9c53b9e44cf67fb3
  13:        0x108e59a02 - sbnf::main::h5ac4d1751626d18a
  14:        0x108e551a6 - std::rt::lang_start::{{closure}}::he2e0f2ed6c3747d9
  15:        0x108f1ee58 - std::panicking::try::do_call::hb5f9c52a170af65b
  16:        0x108f2095f - __rust_maybe_catch_panic
  17:        0x108f1f76e - std::rt::lang_start_internal::h032b1be013493933
  18:        0x108e5aff9 - main

Prepending ~ to the closing element seems to make it work:

main = (~comment)*;
comment = `[` (~comment)* ~`]`;
main = `[` (~main)* ~`]`;

I say seems because the resulting code has unexpected redundancies; opened issue #11.

mitranim commented 3 years ago

Found another NYI case.

The following doesn't compile:

main = `[` main* ~`]`;

Meanwhile, the following happily compiles but has redundancies, see #11:

main = `[` main* `]`;