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

Do not suppress rules with one child sequences #24

Open
igordejanovic opened this issue Nov 1, 2015 · 3 comments
Open

Do not suppress rules with one child sequences #24

igordejanovic opened this issue Nov 1, 2015 · 3 comments

Comments

@igordejanovic
Copy link
Member

For grammars that have rules with one-child sequence (i.e. delegating to other rules) an optimisation measure will suppress those node from the parser model.
This causes problems in semantic analysis as the visitors will not get called.

def qfile():             return ZeroOrMore(entry), EOF
def entry():            return header, data
def header():           return "Min. 1st Qu.  Median    Mean 3rd Qu.    Max."
def data():             return _min, q1, med, mean, q3, _max
def number():           return _(r'\d*\.\d*|\d+')
def _min():             return number
def q1():               return number
def med():              return number
def mean():             return number
def q3():               return number
def _max():             return number

Here _min, q1, med... rules are delegating to number rule.
If we now write visitor method:

    def visit_number(self, node, children):
        return float(node.value)

If will not get called as the number node from the parser model is suppressed.

This optimisation measure should be controlled with a parser param.

@igordejanovic
Copy link
Member Author

Current workaround is to do visitor job in some of the calling rules.
For example:

    def visit_data(self, node, children):
        return [float(x) for x in children]

@timothy-shields
Copy link

@igordejanovic This is also causing problems for me. Do you plan on fixing it?

@igordejanovic
Copy link
Member Author

Of course. But can't tell when I'll have time to do it. if you have time and this issue is hurting you maybe you could try? It shouldn't be very hard. I'll be glad to review PR.

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