lezer-parser / lezer

Dev utils and issues for the Lezer core packages
33 stars 1 forks source link

Getting the term names for static type checking #54

Open danielkleinert opened 1 month ago

danielkleinert commented 1 month ago

Is there a way to get the term names as TS string union type? This would allow me to ensure that I don't assign syntax highlighting for nodes that aren't in the grammar any more or when checking the types while traversing the tree and so on.

So basically this, but in working:

// @ts-expect-error can not find type declaration
import * as Terms from "./syntax.grammar.terms"
type TermNames = keyof typeof Terms
danielkleinert commented 1 month ago

Hm, I can make this work by generating the files without the rollup plug-in defining a .ts output file for the cli:

lezer-generator syntax.grammar -o syntax.ts

Maybe the rollup plug-in could provide the .d.ts files to make this work? (syntax.grammar.terms.d.ts and syntax.grammar.d.ts)

marijnh commented 1 month ago

If you can figure out how that would work in the Rollup plugin (and it's not too much of a mess to implement), I'd be open to adding support for this.