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

Reference class not accessible anymore #102

Closed
spironato opened this issue Mar 23, 2021 · 7 comments
Closed

Reference class not accessible anymore #102

spironato opened this issue Mar 23, 2021 · 7 comments

Comments

@spironato
Copy link

spironato commented Mar 23, 2021

We are building a Domain-Specific Language(let call for simplicity xDSL) for our product.
We needed to handle different xDSL versions so in a new xDSL version can be added new grammar or existing grammar can be deprecated. We need to be able to parse different versions of our xDSL and provide errors if f.ex new grammar has been added parsing a source code meant for a older version.
We implemented this with dart-petitparser 2.4.0.
Not sure if is the best approach but we solve the xDSL versioning extending GrammarDefinition adding a new RefVersion on top of the existing Ref.
RefVersion return as the Ref a Reference.
Now after updating to the version 3.1.0 (we are preparing to move to the null safety version) the Reference class is not accessible anymore as was with 2.4.0:

import 'package:petitparser/src/core/definition/reference.dart';

Any advice hint best approach how this could be solved with the 3.1.0?

Thanks in advance for the help!

@renggli
Copy link
Member

renggli commented Mar 23, 2021

AFAIK, the Reference class is package private and was never exposed externally: https://dart-lang.github.io/linter/lints/implementation_imports.html

That said, it has moved to petitparser/src/definition/reference.dart.

@spironato
Copy link
Author

spironato commented Mar 23, 2021

Thanks for the message @renggli.
Yep checked in 2.4.0 and just realised that was not exposed.

thanks a lot for the suggestion!
i can proceed now.

@renggli
Copy link
Member

renggli commented Mar 23, 2021

Are you sure you have the correct import statement? I can import it, I get an appropriate linter warning that I should not import package private files, but it works for me.

Yes, I would prefer not to expose it externally. It is an internal implementation detail. At some point, we might be able to get rid of it with code generation.

I do not understand why you needed to create your own Reference implementation. Maybe you can elaborate a bit and post a minimal example?

@spironato
Copy link
Author

spironato commented Mar 23, 2021

Sorry i cross checked and i had a wrong import now is working.

In our implementation we use RefVersion instead of Ref and with RefVersion we add extra parameters versionFrom and depreactedVersion; otherwise RefVersion behave as the Ref.

When we parse a source code we know the version that the source code is assigned. If the source code has some unexpected Statement for that version we throw and exception of invalid code.

Thanks again for the prompt answer @renggli and the support!

@spironato
Copy link
Author

Anyway thanks to your input @renggli this make clear a missing lint rule in our side and we need to change our implementation we can't use private implementation.

@renggli
Copy link
Member

renggli commented Mar 23, 2021

The built in Reference parser can be parametrized:

    Parser start() => ref(other, Version.v1);

    Parser other(Version version) {
      switch (version) {
        case v1:
           return ...;
        case v2:
           return ...;
      }
    }

Not sure if this is what you are trying to do, or something else?

@spironato
Copy link
Author

Thanks for the suggestion, i will think about it in the next weeks since at this point we must get rid of the use of Reference. We need before upgrade to latest version.

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