softdevteam / grmtools

Rust grammar tool libraries and binaries
Other
494 stars 32 forks source link

Make generated parsers usable on the web #461

Open stephanemagnenat opened 1 month ago

stephanemagnenat commented 1 month ago

As discussed in #145, currently the generated parsers are not available on WebAssembly in browsers, due to Instant::now() panicking. I have an application (https://cand.li) which requires me to run the generated parser on the browser, so I would like to solve this compatibility problem. I see two ways forward:

I do not have a strong opinion either way.

Alternatively (or in addition, also mentioned in #145, but never done), we could also slightly refactor parser.rs:371 to not call Instant::now() when recovery is not used. That might be the cheapest way, in term of changes, but of course only brings us half way (works on the web without error recovery, but at least it would allow the traditional lex/yacc use case there). As an additional benefit, it would enable using the parser without error recovery even when Instant::now() is unsupported, for example in worklets, which I would say is strictly a good thing.

ltratt commented 1 month ago

modify grmtools to disable timeout, for example by creating an abstraction around the notion of "enough work has been done", and allow other conditions such as number of trials.

There's definitely potential to do this. One simple way of doing this might be to take a hard example (e.g. the "((((((" problem), see how many repairs are done in 0.5s on a normal machine, and use that number as a proxy for timeouts on platforms (e.g. WASM) which lack timing facilities.