Skip to content

Comments

Rewrite Charset so that it uses Expression#2190

Draft
ehuss wants to merge 1 commit intorust-lang:masterfrom
ehuss:remove-characters
Draft

Rewrite Charset so that it uses Expression#2190
ehuss wants to merge 1 commit intorust-lang:masterfrom
ehuss:remove-characters

Conversation

@ehuss
Copy link
Contributor

@ehuss ehuss commented Feb 24, 2026

This removes the Characters type, and instead uses Expression. There was a lot of overlap with Expression, and this simplifies things a little bit and removes some duplication.

This also helps with some future changes I am working on that do coverage analysis, and this makes it easier to track coverage data for the different character values.

The downside is that without the enum it isn't clear from the code what limitations there are with ExpressionKind::Charset, or that ExpressionKind::CharacterRange should only be in a Charset. These are implicit based on how the parser works. I'm willing to make that tradeoff.

The Characters map as:

  • Characters::Named to ExpressionKind::Nt
  • Characters::Terminal to ExpressionKind::Terminal
  • Characters::Range to the NEW ExpressionKind::CharacterRange

This incidentally fixes a small oversight where Characters::Named was missing span with the grammar-text class.

This removes the `Characters` type, and instead uses `Expression`. There
was a lot of overlap with `Expression`, and this simplifies things a
little bit and removes some duplication.

This also helps with some future changes I am working on that do
coverage analysis, and this makes it easier to track coverage data for
the different character values.

The downside is that without the enum it isn't clear from the code what
limitations there are with `ExpressionKind::Charset`, or that
`ExpressionKind::CharacterRange` should only be in a `Charset`. These
are implicit based on how the parser works. I'm willing to make that
tradeoff.

The `Characters` map as:

- `Characters::Named` to `ExpressionKind::Nt`
- `Characters::Terminal` to `ExpressionKind::Terminal`
- `Characters::Range` to the NEW `ExpressionKind::CharacterRange`

This incidentally fixes a small oversight where `Characters::Named` was
missing span with the `grammar-text` class.
@ehuss
Copy link
Contributor Author

ehuss commented Feb 24, 2026

Opening as a draft as I'm not 100% confident that this is the right tradeoff to make. It would be nice if the type system could enforce the constraints, but I don't see an alternative way to do that which is any better than this.

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.

1 participant