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

Separate imports of the same file result in multiple "instances" #151

Open
Tiger-Tom opened this issue Apr 29, 2024 · 3 comments
Open

Separate imports of the same file result in multiple "instances" #151

Tiger-Tom opened this issue Apr 29, 2024 · 3 comments

Comments

@Tiger-Tom
Copy link

  • parglare version: 0.18.0
  • Python version: 3.12.3
  • Operating System: Linux 6.8.7-arch1-2 x86_64

Description

When two grammar files import the same file (lets say root imports a and b, and a imports b), one file (root) will have a different "version" (root.b) of the imported file (b) from the other file (a, root.a.b)

When the first file overrides a terminal in the imported file, the second terminal should, in theory, use that override (a.b.B), however it does not (b.B)

What I Did

root.pg

import './a.pg' ;
import './b.pg' ;

start: a.a ;

terminals
b.B: 'C' ;

a.pg

import './b.pg' ;

a: b.B ;

b.pg

terminals
B: 'B' ;

Given the above examples, upon constructing the grammar (parglare.Grammar.from_file('./root.pg')), the terminals are as such:

  • b.B
  • a.b.B

I would expect there to be only one, a.b.B, as having each import potentially separate makes overriding complex multi-file grammars much more difficult.

@Tiger-Tom
Copy link
Author

I created a pull request with a small, somewhat untested simple fix at #152 for a starting point. If you approve of the base concept, I will add tests and update anything else as necessary.

@igordejanovic
Copy link
Owner

@Tiger-Tom Thanks for the contributions! I expect to find time for the review during the next week.

@igordejanovic
Copy link
Owner

Looks good as a starting point. Watch out for file_path which is relative to the importing file. That should probably be normalized to be e.g. relative to the root file to be sure that we always get the same file back no matter where we are importing it from.

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

No branches or pull requests

2 participants