GithubHelp home page GithubHelp logo

`a_opt: a?;` is not equivalent to `a_opt: a | EMPTY;` and causes an error `First set empty for grammar symbol "a_opt". An infinite recursion on the grammar symbol.` when `a` is a sequence. about parglare HOT 4 CLOSED

KOLANICH avatar KOLANICH commented on August 17, 2024
`a_opt: a?;` is not equivalent to `a_opt: a | EMPTY;` and causes an error `First set empty for grammar symbol "a_opt". An infinite recursion on the grammar symbol.` when `a` is a sequence.

from parglare.

Comments (4)

igordejanovic avatar igordejanovic commented on August 17, 2024

? is syntax sugar which unrolls to rules with _opt suffix. Please see here.

Using rule gyro_specifier_opt: gyro_specifier?; you end-up with gyro_specifier_opt: gyro_specifier_opt | EMPTY;. The first alternative is invalid self-reference. A workaround is to use different name for gyro_specifier_opt, or gyro_specifier? directly in other rules RHSs (which is IMHO better for readability as it makes apparent that something is optional).

While this is not a bug, i.e. it works as designed, I think it would be nice to have better error report in this case where user rules clashes with rules produced by syntax sugar unroll.

from parglare.

KOLANICH avatar KOLANICH commented on August 17, 2024

Thank you.

A workaround is to use different name for gyro_specifier_opt, or gyro_specifier? directly in other rules RHSs (which is IMHO better for readability as it makes apparent that something is optional).

I just resorted to doing desugaring in this case myself. It may be better for readability to have a? than a_opt: a | EMPTY; ... a_opt, but for me it is not an option (for now) because for some parser generators one has to have each thing being captured in a separate rule and having the same tree structure for all the grammars for all the backends allows me use the same code for postprocessing.

While this is not a bug, i.e. it works as designed, I think it would be nice to have better error report in this case where user rules clashes with rules produced by syntax sugar unroll.

Could we detect the cases when a: b; and optimize them out by renaming b everywhere into a, when b is a generated name?

from parglare.

igordejanovic avatar igordejanovic commented on August 17, 2024

Manual desugaring is perfectly fine as the desugaring process will introduce new rules only if they don't already exist.

Could we detect the cases when a: b; and optimize them out by renaming b everywhere into a, when b is a generated name?

I don't think that such transformation should be implemented in parglare.

from parglare.

KOLANICH avatar KOLANICH commented on August 17, 2024

Thanks for making it clear.

from parglare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.