Skip to content

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

Closed
Timmmm wants to merge 1 commit intolezer-parser:masterfrom
Timmmm:nodenames
Closed

Don't store node names as a joined string#6
Timmmm wants to merge 1 commit intolezer-parser:masterfrom
Timmmm:nodenames

Conversation

@Timmmm
Copy link

@Timmmm Timmmm commented Aug 1, 2021

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

@marijnh
Copy link
Collaborator

marijnh commented Aug 2, 2021

Hi, I'm not really that sure if I will ever do lezer-parser/lezer#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
Copy link
Author

Timmmm commented Aug 2, 2021

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
Copy link
Collaborator

marijnh commented Aug 3, 2021

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

@marijnh marijnh closed this Aug 3, 2021
@Timmmm
Copy link
Author

Timmmm commented Aug 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants