nearley
nearley copied to clipboard
FYI: moo deprecated .has() and tweak to typescript output
First off: thanks for Nearley! :100: Great work.
When using moo as a lexer, Nearley's call to lexer.has()
in ParserRules
are going to behave unexpectedly: .has()
just always returns true now..
This update to moo was released Nov 2020, fwiw: https://github.com/no-context/moo/releases/tag/v0.5.0
Completely unrelated: would you want a PR that helps address modern typescript compilation? There are a couple issues that I currently fix with sed
:
"precompile": "printf '/* eslint-disable */\n\n' > grammar.ts",
"compile": "node_modules/.bin/nearleyc grammar.ne | sed 's/declare var/declare const/g' | sed 's/@ts-ignore//g' >> grammar.ts",
-
You probably don't want
@ts-ignore
. You may wanteslint-disable
instead? - The
declare var ...
could bedeclare const ...
(if they're building typescript, they're certainly on es6).
I ended up with the following to strip out the unused vars and deprecated calls to lexer.has() but still check the result with typescript:
In package.json my compile script is:
"grammar": "nearleyc src/grammar.ne | sed -f grammar.ts.sed | prettier --stdin-filepath src/grammar.ts > src/grammar.ts",
grammar.ts.sed:
/^declare var/d
s/(lexer.has("\([^"]*\)") ? {type: "\1"} : \1)/{type: "\1"}/g
s/^\(type NearleySymbol =\)/\1 { type: any }|/
Would you be open to a PR fixing use of moo's deprecated .has()
? I'd love to get rid of the deprecation warnings in my app.