Don't store node names as a joined string #6

Closed
Timmmm wants to merge 1 commit from nodenames into master
Timmmm commented 2021-08-01 15:27:15 +02:00 (Migrated from github.com)

This stores the node names as an array of strings instead of a joined string. It is preparatory work for fixing https://github.com/lezer-parser/lezer/issues/35 (and depends on the corresponding change in lezer.

This stores the node names as an array of strings instead of a joined string. It is preparatory work for fixing https://github.com/lezer-parser/lezer/issues/35 (and depends on the corresponding change in `lezer`.
marijnh commented 2021-08-02 21:14:21 +02:00 (Migrated from github.com)

Hi, I'm not really that sure if I will ever do https://github.com/lezer-parser/lezer/issues/35 anymore (since it has a bunch of other tricky implications around interface complexity for parser packages). Also, I don't really see how this PR helps with that.

Hi, I'm not really that sure if I will ever do https://github.com/lezer-parser/lezer/issues/35 anymore (since it has a bunch of other tricky implications around interface complexity for parser packages). Also, I don't really see how this PR helps with that.
Timmmm commented 2021-08-02 22:30:25 +02:00 (Migrated from github.com)

This doesn't help directly, but I have a future change that lets you export Typescript instead of Javascript, and then you can do:

const nodeNames = ["foo", "bar", "baz"] as const;
type NodeName = typeof nodeNames[number];

This change is a precursor to that.

I think that would be worth doing even if it isn't integrated into the parser type, since user code still might want to do things like iterate over all of the node names, or use NodeName in their code.

This doesn't help directly, but I have a future change that lets you export Typescript instead of Javascript, and then you can do: ``` const nodeNames = ["foo", "bar", "baz"] as const; type NodeName = typeof nodeNames[number]; ``` This change is a precursor to that. I think that would be worth doing even if it isn't integrated into the parser type, since user code still might want to do things like iterate over all of the node names, or use `NodeName` in their code.
marijnh commented 2021-08-03 15:58:55 +02:00 (Migrated from github.com)

Iterating over node types can be done with nodeSet.types. This string is purely internal and only intended for deserialize.

Iterating over node types can be done with `nodeSet.types`. This string is purely internal and only intended for `deserialize`.
Timmmm commented 2021-08-03 18:56:59 +02:00 (Migrated from github.com)

Right, but you can't get a static type of all the node names from nodeSet.types because they need to be written down as a const array in the source code in order for Typescript to understand them statically.

Right, but you can't get a static type of all the node names from `nodeSet.types` because they need to be written down as a const array in the source code in order for Typescript to understand them statically.

Pull request closed

Sign in to join this conversation.
No reviewers
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/generator!6
No description provided.