Open tjvr opened 6 years ago
As to this:
try {
var result = grammar.parse(input)
} catch (err) {
// handle any SyntaxError, including EOF
}
It's unfortunate that parsing has to be wrapped in a try
/catch
at all, since that will de-optimize JavaScript JIT compiling. Ideally, the parser would never throw errors, but would return a callback (/ Promise?) with an Error object. I mean, unless the concern is that errors can be caused that aren't caused by Nearley, this will reduce JIT VM efficiency AFAIK.
since that will de-optimize JavaScript JIT compiling
That certainly used to be true for V8, but it's no longer the case for newer JITs I believe.
Regardless, we still haven't done any real planning toward a v3, so I wouldn't be concerned 🙂
Sent with GitHawk
That certainly used to be true for V8, but it's no longer the case for newer JITs I believe.
@tjvr is quite correct, See: https://www.nearform.com/blog/node-js-is-getting-a-new-v8-with-turbofan/
@bd82 Well bless my grits. I guess this is an issue no longer.
@matthew-dean Yeah it allowed me to remove some optimizations to mitigate performance loss due to try/catch usage and simplify the code in one of my projects 😄
As discussed in #305, we might like to have an alternative to
finish()
(which is undocumented), which throws an error if there are no results.Or, perhaps this could be part of lightweight parsing API? For users who don't want streaming, instead of writing:
It'd be neat if they could write:
...perhaps with a corresponding
allParses()
which returns all results, rather than the only result.This is quite possibly a v3 thing, since there are some other API changes I think would be good (for example, I'd like to have an "ordered choice / no ambiguity" mode).