Getting the term names for static type checking #54

Open
opened 2024-06-03 16:57:12 +02:00 by danielkleinert · 2 comments
danielkleinert commented 2024-06-03 16:57:12 +02:00 (Migrated from github.com)

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
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: ```typescript // @ts-expect-error can not find type declaration import * as Terms from "./syntax.grammar.terms" type TermNames = keyof typeof Terms ```
danielkleinert commented 2024-06-03 17:35:01 +02:00 (Migrated from github.com)

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)

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 2024-06-03 17:54:11 +02:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lezer/lezer#54
No description provided.