Skip to content

Provide nested parser class for Zeitwerk compat#52

Merged
cjheath merged 1 commit intocjheath:masterfrom
eric1234:nested_class
Jan 22, 2025
Merged

Provide nested parser class for Zeitwerk compat#52
cjheath merged 1 commit intocjheath:masterfrom
eric1234:nested_class

Conversation

@eric1234
Copy link

Zeitwerk follows the general convention that the file name implies the constant the file will load. Since the compiled Treetop files define two constant one will not end up matching the filename, making it incompatible with reloaders such as Zeitwerk.

To maintain compatibility with existing uses of Treetop we want to maintain the <Grammar>Parser constant. But to enable compatibility with the convention that Zeitwerk follows we also want a <Grammar>::Parser constant.

Therefore, the compiled code now defines both. First, it defines the nested class within the grammar module. Then it aliases that constant to the existing constant.

This should provide the best of both worlds. Users already using the old constant can continue to do so. But users using auto-loaders like Zeitwerk can now assume the standard naming conventions.


In addition to changing the output, I also rebuilt the Treetop grammar so the new constant can be used on the included grammar. I also added a test to verify the new nested class can be used as a parser.


My editor auto-removed some unnecessary white-space.


This closes #51.

Zeitwerk follows the general convention that the file name implies the constant
the file will load. Since the compiled Treetop files define two constant one
will not end up matching the filename, making it incompatible with reloaders
such as Zeitwerk.

To maintain compatibility with existing uses of Treetop we want to maintain
the <Grammar>Parser constant. But to enable compatibility with the convention
that Zeitwerk follows we also want a <Grammar>::Parser constant.

Therefore, the compiled code now defines both. First, it defines the nested
class within the grammar module. Then it aliases that constant to the existing
constant.

This should provide the best of both worlds. Users already using the old
constant can continue to do so. But users using auto-loaders like Zeitwerk
can now assume the standard naming conventions.

---

In addition to changing the output, I also rebuilt the Treetop gramar so the
new constant can be used on the included grammar. I also added a test to verify
the new nested class can be used as a parser.

---

This closes cjheath#51.
@cjheath cjheath merged commit 7ec569b into cjheath:master Jan 22, 2025
6 of 8 checks passed
@cjheath
Copy link
Owner

cjheath commented Jan 22, 2025

Published to RubyGems as 1.6.14
Thank you for your contribution

@yaauie yaauie mentioned this pull request Jun 24, 2025
5 tasks
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.

Support Nested Parser Class

2 participants