@@ -35,6 +35,9 @@ Missing nodes or nodes needing new features from the SDK:
3535 Yield
3636 YieldFrom
3737
38+ = PR 57:
39+ Starred
40+
3841 = PR 58:
3942 withitem
4043
@@ -44,6 +47,11 @@ Missing nodes or nodes needing new features from the SDK:
4447 Slice
4548 ExtSlice
4649
50+ = PR 63:
51+ Lambda
52+ kwarg
53+ FunctionDef.decorator_list
54+
4755 = PR 81:
4856 ListComp
4957 SetComp
@@ -52,35 +60,37 @@ Missing nodes or nodes needing new features from the SDK:
5260 = PR 79:
5361 arguments
5462
55- === No PR:
63+ = PR 111:
64+ FormattedValue (InterpolatedValue)
5665
57- JoinedStr
58- FormattedValue
66+ = PR 112:
67+ AnnAssign
68+ annotation
5969
60- Starred
70+ = PR 113:
71+ AsyncFunctionDef (FunctionDef + async)
72+ Await
73+ AsyncFor (For + async)
74+ AsyncWith (With + async)
75+
76+ = PR 114:
77+ Global
78+ Nonlocal
79+
80+ === No PR:
6181
6282 BoolOp collapsing: needs SDK features
6383 arguments.defaults: needs SDK features
6484 arguments.keywords: same
6585
66- GeneratorExp: check
67-
68- AnnAssign (currently as assign, needs Annotation UAST)
69-
70- Lambda
71-
72- Global
73- Nonlocal
74-
75- AsyncFunctionDef (FunctionDef + async)
76- Await
77- AsyncFor (For + async)
78- AsyncWith (With + async)
79-
86+ These also need SDK list-mix features:
87+ Compare.comparators
88+ Compare.ops
89+ IfCondition.left
90+ (see: https://greentreesnakes.readthedocs.io/en/latest/nodes.html#Compare)
8091
8192*/
8293
83- // TODO: add the "stride", third element of slices in some way once we've the index/slice roles
8494var AnnotationRules = On (Any ).Self (
8595 On (Not (HasInternalType (pyast .Module ))).Error (errors .New ("root must be Module" )),
8696 On (HasInternalType (pyast .Module )).Roles (File ).Descendants (
@@ -138,9 +148,10 @@ var AnnotationRules = On(Any).Self(
138148 On (HasInternalType (pyast .NumLiteral )).Roles (NumberLiteral ),
139149 On (HasInternalType (pyast .Str )).Roles (StringLiteral ),
140150 On (HasInternalType (pyast .BoolLiteral )).Roles (BooleanLiteral ),
141- // FIXME: JoinedStr are the fstrings (f"my name is {name}"), they have a composite AST
142- // with a body that is a list of StringLiteral + FormattedValue(value, conversion, format_spec)
143- On (HasInternalType (pyast .JoinedStr )).Roles (StringLiteral ),
151+ On (HasInternalType (pyast .JoinedStr )).Roles (StringLiteral ).Children (
152+ // FIXME: should be StringInterpolatedExpression or something like that
153+ On (HasInternalType (pyast .FormattedValue )).Roles (Expression ),
154+ ),
144155 On (HasInternalType (pyast .NoneLiteral )).Roles (NullLiteral ),
145156 On (HasInternalType (pyast .Set )).Roles (SetLiteral ),
146157 On (HasInternalType (pyast .List )).Roles (ListLiteral ),
@@ -225,7 +236,7 @@ var AnnotationRules = On(Any).Self(
225236 On (HasInternalRole ("handlers" )).Roles (TryCatch ),
226237 On (HasInternalRole ("orelse" )).Roles (IfElse ),
227238 ),
228- On (HasInternalType (pyast .TryExcept )).Roles (TryCatch ), // py2
239+ On (HasInternalType (pyast .TryExcept )).Roles (TryCatch ), // py2
229240 On (HasInternalType (pyast .ExceptHandler )).Roles (TryCatch ), // py3
230241 On (HasInternalType (pyast .TryFinally )).Roles (TryFinally ),
231242 On (HasInternalType (pyast .Raise )).Roles (Throw ),
@@ -236,10 +247,27 @@ var AnnotationRules = On(Any).Self(
236247 On (HasInternalType (pyast .Return )).Roles (Return ),
237248 On (HasInternalType (pyast .Break )).Roles (Break ),
238249 On (HasInternalType (pyast .Continue )).Roles (Continue ),
250+ // FIXME: IfCondition bodies in Python take the form:
251+ // 1 < a < 10
252+ // - left (internalRole): 1 (first element)
253+ // - Compare.ops (internalType): [LessThan, LessThan]
254+ // - Compare.comparators (internalType): ['a', 10]
255+ // The current mapping is:
256+ // - left: BinaryExpressionLeft
257+ // - Compare.ops: BinaryExpressionOp
258+ // - Compare.comparators: BinaryExpressionRight
259+ // But this is obviously not correct. To fix this properly we would need
260+ // and SDK feature to mix lists (also needed for default and keyword arguments and
261+ // boolean operators).
262+ // "If that sounds awkward is because it is" (their words)
239263 On (HasInternalType (pyast .If )).Roles (If ).Children (
240264 On (HasInternalType ("If.body" )).Roles (IfBody ),
241- On (HasInternalType (pyast .Compare )).Roles (IfCondition ),
242265 On (HasInternalType ("If.orelse" )).Roles (IfElse ),
266+ On (HasInternalType (pyast .Compare )).Roles (IfCondition , BinaryExpression ).Children (
267+ On (HasInternalType ("Compare.ops" )).Roles (BinaryExpressionOp ),
268+ On (HasInternalType ("Compare.comparators" )).Roles (BinaryExpressionRight ),
269+ On (HasInternalRole ("left" )).Roles (BinaryExpressionLeft ),
270+ ),
243271 ),
244272 On (HasInternalType (pyast .IfExp )).Roles (If , Expression ).Children (
245273 // These are used on ifexpressions (a = 1 if x else 2)
@@ -296,11 +324,27 @@ var AnnotationRules = On(Any).Self(
296324 // information by themselves and this we consider it comments (some preprocessors or linters can use
297325 // them, the runtimes ignore them). The TOKEN will take the annotation in the UAST node so
298326 // the information is keept in any case.
327+ // FIXME: change to Annotation when PR 112 is merged
299328 On (HasInternalRole ("annotation" )).Roles (Comment ),
300329 On (HasInternalRole ("returns" )).Roles (Comment ),
301330
302331 // Python very odd ellipsis operator. Has a special rule in tonoder synthetic tokens
303332 // map to load it with the token "PythonEllipsisOperator" and gets the role SimpleIdentifier
304333 On (HasInternalType (pyast .Ellipsis )).Roles (SimpleIdentifier ),
334+
335+ // List/Map/Set comprehensions. We map the "for x in y" to ForEach roles and the
336+ // "if something" to If* roles. FIXME: missing the top comprehension roles in the UAST, change
337+ // once they've been merged
338+ On (HasInternalType (pyast .Comprehension )).Roles (ForEach ).Children (
339+ On (HasInternalRole ("iter" )).Roles (ForUpdate ),
340+ On (HasInternalRole ("target" )).Roles (ForExpression ),
341+ // FIXME: see the comment on IfCondition above
342+ On (HasInternalType (pyast .Compare )).Roles (IfCondition , BinaryExpression ).Children (
343+ On (HasInternalType ("Compare.ops" )).Roles (BinaryExpressionOp ),
344+ On (HasInternalType ("Compare.comparators" )).Roles (BinaryExpressionRight ),
345+ On (HasInternalRole ("left" )).Roles (BinaryExpressionLeft ),
346+ ),
347+ ),
348+
305349 ),
306350)
0 commit comments