[Python-porting] Fw: lib2to3 and matching of fixers

Vinay Sajip vinay_sajip at yahoo.co.uk
Wed Dec 14 12:43:10 CET 2011


>> What are you using exactly? I would expect "atom< STRING+>" to 

>> work.
>
>Thanks, that worked. I tried "atom" and "STRING+" separately - sorry, I'm unfamiliar with the pattern-matching
> language, but hopefully I'll get more familiar as I work with it!


I'm now trying to match a tuple using the following pattern:

PATTERN = "atom< '(' args=testlist_gexp< any+ > ')' >"


This is a subset of the pattern used in the isinstance fixer that Armin Ronacher wrote. However, the pattern fails to match the source

x = (int, long)


The parse tree for this source looks like this:

Node(file_input, [Node(simple_stmt, [Node(expr_stmt, [Leaf(1, 'x'), Leaf(22, '='), Node(atom, [Leaf(7, '('), Node(testlist_gexp, [Leaf(1, 'int'), Leaf(12, ','), Leaf(1, 'long')]), Leaf(8, ')')])]), Leaf(4, '\n')]), Leaf(0, '')])


Since it contains an "atom" node with children consisting of a parenthesised "testlist_gexp" node, I'm not sure why there is no match. What am I missing?

Thanks and regards,

Vinay Sajip



More information about the Python-porting mailing list