Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use symbol for rest property in grammars #3420

Closed
RunDevelopment opened this issue Mar 31, 2022 · 1 comment
Closed

Use symbol for rest property in grammars #3420

RunDevelopment opened this issue Mar 31, 2022 · 1 comment

Comments

@RunDevelopment
Copy link
Member

Motivation
Prism supports a rest property in grammars that essentially functions as an object spread replacement. The behavior of rest and object spread is subtly different, so we can't remove support for rest, unfortunately. However, we may as well fix the worst aspect of rest: it gets in the way of token iteration.

Everything that processes or analyses grammars has to take rest into account, because rest is the only property of a grammar that isn't a token (this also creates problems with TS).

Description
Replace the rest property with a symbol, let's call it Prism.rest.

This will solve the iteration problem, because symbols are non-enumerable by default.

This will also make it possible to finally define a proper type for Prism grammars, which simply wasn't possible before.

interface Grammar {
  [key: string]: RegExp | GrammarToken | Array<RegExp | GrammarToken>;
  [Prism.rest]?: Grammar;
}
@RunDevelopment
Copy link
Member Author

Implemented in v2. The only difference is that the rest symbol is exported using module exports and not as a property of Prism instances.

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

No branches or pull requests

1 participant