igordejanovic / parglare

A pure Python LR/GLR parser - http://www.igordejanovic.net/parglare/
MIT License
135 stars 32 forks source link

ENHANCEMENT: new parameter for call_actions for not reversing #125

Open goodguy00 opened 3 years ago

goodguy00 commented 3 years ago

Description

for some uses, a non-reversing actions execution can be of good use. i propose to extend the definition:

      def call_actions(node, context=None, reverse=True):

...

        if (reverse):
            # Recursive right to left, bottom up. Simulate LR reductions.
            for n in reversed(node):
                subresults.append(inner_call_actions(n))
            subresults.reverse()
        else:
            for n in (node):
                subresults.append(inner_call_actions(n))

Usecase

text to be parsed (here a tikz example)

     \draw [line width=2pt,color=wwffqq,domain=-4:12.44] plot(\x,{(-1.4356438- -0.96*\x)/0.26});

in this case, definig the attributes (like "domain") in the same line and using them in the "plot" is only possible in a non-reversed execution. also, coincidentially, then the "draw" directive will be called last allowing for actually executing the completely assembled plot-code.

igordejanovic commented 3 years ago

@goodguy00 Thanks for the idea and sorry for the delay.

I guess this option might be useful if the language is naturally processed from left to right.