Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 308049c

Browse files
author
Juanjo Alvarez
committed
Compare node and children fixes
1 parent 48cafaf commit 308049c

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

driver/normalizer/annotation.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -217,21 +217,19 @@ var AnnotationRules = On(Any).Self(
217217
On(pyast.Break).Roles(uast.Break, uast.Statement),
218218
On(pyast.Continue).Roles(uast.Continue, uast.Statement),
219219

220-
// - Compare.ops (internaluast.Type): [uast.LessThan, uast.LessThan]
221-
// - Compare.comparators (internaluast.Type): ['a', 10]
222-
// The current mapping is:
223-
// - left: uast.Expression, uast.Binary, uast.Left
224-
// - Compare.ops: uast.Expression, uast.Binary, uast.Operator
225-
// - Compare.comparators: uast.Expression, uast.Binary, uast.Right
226-
// But this is obviously not correct. To fix this properly we would need
227-
// and SDK feature to mix lists (also needed for default and keyword arguments and
228-
// boolean operators).
229-
// "uast.If that sounds awkward is because it is" (their words)
220+
// Comparison nodes in Python are oddly structured. Probably one if the first
221+
// things that could be changed once we can normalize tree structures. Check:
222+
// https://greentreesnakes.readthedocs.io/en/latest/nodes.html#Compare
223+
224+
// Parent of all comparisons
230225
On(pyast.Compare).Roles(uast.Expression, uast.Binary).Children(
231-
On(pyast.CompareOps).Roles(uast.Expression, uast.Binary, uast.Operator),
232-
On(HasInternalRole("left")).Roles(uast.Expression, uast.Binary, uast.Left),
226+
// Operators
227+
On(pyast.CompareOps).Roles(uast.Expression, uast.Operator, uast.Incomplete),
228+
// Leftmost element (the others are the comparators below)
229+
On(HasInternalRole("left")).Roles(uast.Expression, uast.Left),
230+
// These hold the members of the comparison (not the operators)
231+
On(pyast.CompareComparators).Roles(uast.Expression, uast.Right),
233232
),
234-
On(pyast.CompareComparators).Roles(uast.Expression, uast.Binary, uast.Right),
235233
On(pyast.If).Roles(uast.If, uast.Statement).Children(
236234
On(pyast.IfBody).Roles(uast.If, uast.Body, uast.Then),
237235
On(HasInternalRole("test")).Roles(uast.If, uast.Condition),

0 commit comments

Comments
 (0)