macropy icon indicating copy to clipboard operation
macropy copied to clipboard

Use pattern matching internally

Open jnhnum1 opened this issue 11 years ago • 5 comments

A lot of our transformers could use pattern matching. It would make our code nicer.

jnhnum1 avatar May 13 '13 20:05 jnhnum1

Trying to pattern match on AST nodes causes the pattern matcher to barf because they don't have normal __init__ methods; is there a way to force keyword-only matching to bypass this?

lihaoyi avatar May 19 '13 01:05 lihaoyi

I just pushed a small change which makes positional matching as needed using generators. This should fix things.

jnhnum1 avatar May 19 '13 07:05 jnhnum1

and...tests

jnhnum1 avatar May 19 '13 08:05 jnhnum1

This:

with switch(tree):
        if Str(s=s):
            return q%Parser.Raw(ast%tree), stop
TypeError: <slot wrapper '__init__' of '_ast.AST' objects> is not a Python function

Is still blowing up on me. Do you want to try refactoring our macros to use pattern matching? I feel like you'll have a better shot at getting stuff working, since I suspect it will require substantial fixes to the pattern matcher to get it to work.

lihaoyi avatar May 19 '13 23:05 lihaoyi

ok. yeah ugh that's annoying.

jnhnum1 avatar May 19 '13 23:05 jnhnum1