Arpeggio
Arpeggio copied to clipboard
Do not suppress rules with one child sequences
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.
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]
@igordejanovic This is also causing problems for me. Do you plan on fixing it?
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.