nearley icon indicating copy to clipboard operation
nearley copied to clipboard

FYI: moo deprecated .has() and tweak to typescript output

Open mceachen opened this issue 3 years ago • 2 comments

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",
  1. You probably don't want @ts-ignore. You may want eslint-disable instead?
  2. The declare var ... could be declare const ... (if they're building typescript, they're certainly on es6).

mceachen avatar Apr 10 '21 23:04 mceachen

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 }|/

lrowe avatar Oct 07 '21 00:10 lrowe

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.

canac avatar Apr 06 '22 16:04 canac