Generator throws error on docs example

I installed the lezer packages, made a language.grammar file and pasted the example grammar given in the docs:

@top Program { expression }

expression { Name | Number | BinaryExpression }

BinaryExpression { "(" expression ("+" | "-") expression ")" }

@tokens {
  Name { @asciiLetter+ }
  Number { @digit+ }

Then I tried to generate it from the command line with npx @lezer/generator --names language.grammar. But I get the following error:

Unexpected token '@asciiLetter' (language.grammar 8:9)

I don’t understand this since I didn’t change the code at all and the docs clearly state that @asciiLetter is a built in character set. What am I missing? Thanks for your help!

Could it be you’re using an older version of lezer-generator? That syntax (@asciiLetter) was introduced in 1.1.0.

OK, I checked the versions. I had two packages installed via npm, @lezer/generator (1.1.1) and lezer-generator (0.13.4) both of which were up to date.

I tried uninstalling lezer-generator since I read that it’s an old version of @lezer/generator and maybe it was interfering. Afterwards, calling npx @lezer/generator results in the error lezer-generator: not found.

I guess I’m calling the tool incorrectly? Or is npm installing the wrong version?

@lezer/generator does provide the binary lezer-generator. It’s possible that npm messed up and, on deleting the old lezer-generator package, just removed the binary link. Reinstalling dependencies should help there.

That worked! Thanks so much for your help. Seems like the problem was just me being a npm noob.

Nah, this is more about npm being a buggy mess, I’d argue.