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

Commit d43125e

Browse files
authored
Merge pull request #80 from abeaumont/fix/exception-handler-identifier
parser: Prevent duplicate tokens from happening and related tasks
2 parents e4c2db3 + 5e31ec7 commit d43125e

File tree

7 files changed

+142
-136
lines changed

7 files changed

+142
-136
lines changed

ANNOTATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Try'\]/\*\[@InternalType='Try\.orelse'\] | IfElse |
103103
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='TryExcept'\] | TryCatch, Statement |
104104
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='ExceptHandler'\] | TryCatch, Statement |
105+
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='ExceptHandler\.name'\] | SimpleIdentifier |
105106
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='TryFinally'\] | TryFinally, Statement |
106107
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='Raise'\] | Throw, Statement |
107108
| /self::\*\[@InternalType='Module'\]//\*\[@InternalType='With'\] | BlockScope, Statement |

driver/normalizer/annotation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ var AnnotationRules = On(Any).Self(
214214
),
215215
On(HasInternalType(pyast.TryExcept)).Roles(TryCatch, Statement), // py2
216216
On(HasInternalType(pyast.ExceptHandler)).Roles(TryCatch, Statement), // py3
217+
On(HasInternalType("ExceptHandler.name")).Roles(SimpleIdentifier),
217218
On(HasInternalType(pyast.TryFinally)).Roles(TryFinally, Statement),
218219
On(HasInternalType(pyast.Raise)).Roles(Throw, Statement),
219220
// FIXME: review, add path for the body and items childs

driver/normalizer/parser.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ var ToNoder = &native.ObjectToNoder{
6666
"FunctionDef": {"body": true, "decorator_list": true},
6767
"Lambda": {"body": true},
6868
"arguments": {"defaults": true},
69-
"Try": {"body": true, "orelse": true, "finalbody": true, "handlers": true},
69+
"Try": {"body": true, "orelse": true, "finalbody": true},
7070
"Raise": {"args": true},
7171
"ClassDef": {"body": true, "bases": true, "decorator_list": true, "keywords": true},
7272
},
7373
PromotedPropertyStrings: map[string]map[string]bool{
74-
"alias": {"asname": true},
75-
"ImportFrom": {"module": true},
74+
"alias": {"asname": true},
75+
"ImportFrom": {"module": true},
76+
"ExceptHandler": {"name": true},
7677
},
7778
// FIXME: test[ast_type=Compare].comparators is a list?? (should be "right")
7879
}

tests/except.py.uast

Lines changed: 129 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -236,201 +236,204 @@ Module {
236236
. . . . . . }
237237
. . . . . }
238238
. . . . }
239-
. . . . 2: Try.handlers {
240-
. . . . . Roles: TryCatch
239+
. . . . 2: ExceptHandler {
240+
. . . . . Roles: TryCatch,Statement
241+
. . . . . StartPosition: {
242+
. . . . . . Offset: 69
243+
. . . . . . Line: 4
244+
. . . . . . Col: 25
245+
. . . . . }
246+
. . . . . EndPosition: {
247+
. . . . . . Offset: 104
248+
. . . . . . Line: 5
249+
. . . . . . Col: 33
250+
. . . . . }
241251
. . . . . Properties: {
242-
. . . . . . promotedPropertyList: true
252+
. . . . . . ExceptHandler.name: e
253+
. . . . . . internalRole: handlers
243254
. . . . . }
244255
. . . . . Children: {
245-
. . . . . . 0: ExceptHandler {
246-
. . . . . . . Roles: TryCatch,Statement
247-
. . . . . . . TOKEN "e"
256+
. . . . . . 0: Expr {
257+
. . . . . . . Roles: Expression
248258
. . . . . . . StartPosition: {
249-
. . . . . . . . Offset: 69
250-
. . . . . . . . Line: 4
251-
. . . . . . . . Col: 25
259+
. . . . . . . . Offset: 76
260+
. . . . . . . . Line: 5
261+
. . . . . . . . Col: 5
252262
. . . . . . . }
253263
. . . . . . . EndPosition: {
254264
. . . . . . . . Offset: 104
255265
. . . . . . . . Line: 5
256266
. . . . . . . . Col: 33
257267
. . . . . . . }
268+
. . . . . . . Properties: {
269+
. . . . . . . . internalRole: body
270+
. . . . . . . }
258271
. . . . . . . Children: {
259-
. . . . . . . . 0: Expr {
260-
. . . . . . . . . Roles: Expression
272+
. . . . . . . . 0: Call {
273+
. . . . . . . . . Roles: Call,Expression
261274
. . . . . . . . . StartPosition: {
262-
. . . . . . . . . . Offset: 76
275+
. . . . . . . . . . Offset: 77
263276
. . . . . . . . . . Line: 5
264-
. . . . . . . . . . Col: 5
277+
. . . . . . . . . . Col: 6
265278
. . . . . . . . . }
266279
. . . . . . . . . EndPosition: {
267280
. . . . . . . . . . Offset: 104
268281
. . . . . . . . . . Line: 5
269282
. . . . . . . . . . Col: 33
270283
. . . . . . . . . }
271284
. . . . . . . . . Properties: {
272-
. . . . . . . . . . internalRole: body
285+
. . . . . . . . . . internalRole: value
273286
. . . . . . . . . }
274287
. . . . . . . . . Children: {
275-
. . . . . . . . . . 0: Call {
276-
. . . . . . . . . . . Roles: Call,Expression
288+
. . . . . . . . . . 0: StringLiteral {
289+
. . . . . . . . . . . Roles: StringLiteral,Expression,CallPositionalArgument
290+
. . . . . . . . . . . TOKEN "someexception catched"
277291
. . . . . . . . . . . StartPosition: {
278-
. . . . . . . . . . . . Offset: 77
292+
. . . . . . . . . . . . Offset: 82
279293
. . . . . . . . . . . . Line: 5
280-
. . . . . . . . . . . . Col: 6
294+
. . . . . . . . . . . . Col: 11
281295
. . . . . . . . . . . }
282296
. . . . . . . . . . . EndPosition: {
283297
. . . . . . . . . . . . Offset: 104
284298
. . . . . . . . . . . . Line: 5
285299
. . . . . . . . . . . . Col: 33
286300
. . . . . . . . . . . }
287301
. . . . . . . . . . . Properties: {
288-
. . . . . . . . . . . . internalRole: value
302+
. . . . . . . . . . . . internalRole: args
289303
. . . . . . . . . . . }
290-
. . . . . . . . . . . Children: {
291-
. . . . . . . . . . . . 0: StringLiteral {
292-
. . . . . . . . . . . . . Roles: StringLiteral,Expression,CallPositionalArgument
293-
. . . . . . . . . . . . . TOKEN "someexception catched"
294-
. . . . . . . . . . . . . StartPosition: {
295-
. . . . . . . . . . . . . . Offset: 82
296-
. . . . . . . . . . . . . . Line: 5
297-
. . . . . . . . . . . . . . Col: 11
298-
. . . . . . . . . . . . . }
299-
. . . . . . . . . . . . . EndPosition: {
300-
. . . . . . . . . . . . . . Offset: 104
301-
. . . . . . . . . . . . . . Line: 5
302-
. . . . . . . . . . . . . . Col: 33
303-
. . . . . . . . . . . . . }
304-
. . . . . . . . . . . . . Properties: {
305-
. . . . . . . . . . . . . . internalRole: args
306-
. . . . . . . . . . . . . }
307-
. . . . . . . . . . . . }
308-
. . . . . . . . . . . . 1: Name {
309-
. . . . . . . . . . . . . Roles: CallCallee,SimpleIdentifier,Expression
310-
. . . . . . . . . . . . . TOKEN "print"
311-
. . . . . . . . . . . . . StartPosition: {
312-
. . . . . . . . . . . . . . Offset: 76
313-
. . . . . . . . . . . . . . Line: 5
314-
. . . . . . . . . . . . . . Col: 5
315-
. . . . . . . . . . . . . }
316-
. . . . . . . . . . . . . EndPosition: {
317-
. . . . . . . . . . . . . . Offset: 80
318-
. . . . . . . . . . . . . . Line: 5
319-
. . . . . . . . . . . . . . Col: 9
320-
. . . . . . . . . . . . . }
321-
. . . . . . . . . . . . . Properties: {
322-
. . . . . . . . . . . . . . ctx: Load
323-
. . . . . . . . . . . . . . internalRole: func
324-
. . . . . . . . . . . . . }
325-
. . . . . . . . . . . . }
304+
. . . . . . . . . . }
305+
. . . . . . . . . . 1: Name {
306+
. . . . . . . . . . . Roles: CallCallee,SimpleIdentifier,Expression
307+
. . . . . . . . . . . TOKEN "print"
308+
. . . . . . . . . . . StartPosition: {
309+
. . . . . . . . . . . . Offset: 76
310+
. . . . . . . . . . . . Line: 5
311+
. . . . . . . . . . . . Col: 5
312+
. . . . . . . . . . . }
313+
. . . . . . . . . . . EndPosition: {
314+
. . . . . . . . . . . . Offset: 80
315+
. . . . . . . . . . . . Line: 5
316+
. . . . . . . . . . . . Col: 9
317+
. . . . . . . . . . . }
318+
. . . . . . . . . . . Properties: {
319+
. . . . . . . . . . . . ctx: Load
320+
. . . . . . . . . . . . internalRole: func
326321
. . . . . . . . . . . }
327322
. . . . . . . . . . }
328323
. . . . . . . . . }
329324
. . . . . . . . }
330-
. . . . . . . . 1: Name {
331-
. . . . . . . . . Roles: SimpleIdentifier,Expression
332-
. . . . . . . . . TOKEN "SomeException"
333-
. . . . . . . . . StartPosition: {
334-
. . . . . . . . . . Offset: 52
335-
. . . . . . . . . . Line: 4
336-
. . . . . . . . . . Col: 8
337-
. . . . . . . . . }
338-
. . . . . . . . . EndPosition: {
339-
. . . . . . . . . . Offset: 64
340-
. . . . . . . . . . Line: 4
341-
. . . . . . . . . . Col: 20
342-
. . . . . . . . . }
343-
. . . . . . . . . Properties: {
344-
. . . . . . . . . . ctx: Load
345-
. . . . . . . . . . internalRole: type
346-
. . . . . . . . . }
347-
. . . . . . . . }
348325
. . . . . . . }
349326
. . . . . . }
350-
. . . . . . 1: ExceptHandler {
351-
. . . . . . . Roles: TryCatch,Statement
352-
. . . . . . . TOKEN "<nil>"
327+
. . . . . . 1: Name {
328+
. . . . . . . Roles: SimpleIdentifier,Expression
329+
. . . . . . . TOKEN "SomeException"
330+
. . . . . . . StartPosition: {
331+
. . . . . . . . Offset: 52
332+
. . . . . . . . Line: 4
333+
. . . . . . . . Col: 8
334+
. . . . . . . }
335+
. . . . . . . EndPosition: {
336+
. . . . . . . . Offset: 64
337+
. . . . . . . . Line: 4
338+
. . . . . . . . Col: 20
339+
. . . . . . . }
340+
. . . . . . . Properties: {
341+
. . . . . . . . ctx: Load
342+
. . . . . . . . internalRole: type
343+
. . . . . . . }
344+
. . . . . . }
345+
. . . . . . 2: ExceptHandler.name {
346+
. . . . . . . Roles: SimpleIdentifier
347+
. . . . . . . TOKEN "e"
348+
. . . . . . . Properties: {
349+
. . . . . . . . promotedPropertyString: true
350+
. . . . . . . }
351+
. . . . . . }
352+
. . . . . }
353+
. . . . }
354+
. . . . 3: ExceptHandler {
355+
. . . . . Roles: TryCatch,Statement
356+
. . . . . TOKEN "<nil>"
357+
. . . . . StartPosition: {
358+
. . . . . . Offset: 107
359+
. . . . . . Line: 6
360+
. . . . . . Col: 1
361+
. . . . . }
362+
. . . . . EndPosition: {
363+
. . . . . . Offset: 131
364+
. . . . . . Line: 7
365+
. . . . . . Col: 17
366+
. . . . . }
367+
. . . . . Properties: {
368+
. . . . . . internalRole: handlers
369+
. . . . . . type: <nil>
370+
. . . . . }
371+
. . . . . Children: {
372+
. . . . . . 0: Expr {
373+
. . . . . . . Roles: Expression
353374
. . . . . . . StartPosition: {
354-
. . . . . . . . Offset: 107
355-
. . . . . . . . Line: 6
356-
. . . . . . . . Col: 1
375+
. . . . . . . . Offset: 119
376+
. . . . . . . . Line: 7
377+
. . . . . . . . Col: 5
357378
. . . . . . . }
358379
. . . . . . . EndPosition: {
359380
. . . . . . . . Offset: 131
360381
. . . . . . . . Line: 7
361382
. . . . . . . . Col: 17
362383
. . . . . . . }
363384
. . . . . . . Properties: {
364-
. . . . . . . . type: <nil>
385+
. . . . . . . . internalRole: body
365386
. . . . . . . }
366387
. . . . . . . Children: {
367-
. . . . . . . . 0: Expr {
368-
. . . . . . . . . Roles: Expression
388+
. . . . . . . . 0: Call {
389+
. . . . . . . . . Roles: Call,Expression
369390
. . . . . . . . . StartPosition: {
370-
. . . . . . . . . . Offset: 119
391+
. . . . . . . . . . Offset: 120
371392
. . . . . . . . . . Line: 7
372-
. . . . . . . . . . Col: 5
393+
. . . . . . . . . . Col: 6
373394
. . . . . . . . . }
374395
. . . . . . . . . EndPosition: {
375396
. . . . . . . . . . Offset: 131
376397
. . . . . . . . . . Line: 7
377398
. . . . . . . . . . Col: 17
378399
. . . . . . . . . }
379400
. . . . . . . . . Properties: {
380-
. . . . . . . . . . internalRole: body
401+
. . . . . . . . . . internalRole: value
381402
. . . . . . . . . }
382403
. . . . . . . . . Children: {
383-
. . . . . . . . . . 0: Call {
384-
. . . . . . . . . . . Roles: Call,Expression
404+
. . . . . . . . . . 0: StringLiteral {
405+
. . . . . . . . . . . Roles: StringLiteral,Expression,CallPositionalArgument
406+
. . . . . . . . . . . TOKEN "ayyyy"
385407
. . . . . . . . . . . StartPosition: {
386-
. . . . . . . . . . . . Offset: 120
408+
. . . . . . . . . . . . Offset: 125
387409
. . . . . . . . . . . . Line: 7
388-
. . . . . . . . . . . . Col: 6
410+
. . . . . . . . . . . . Col: 11
389411
. . . . . . . . . . . }
390412
. . . . . . . . . . . EndPosition: {
391413
. . . . . . . . . . . . Offset: 131
392414
. . . . . . . . . . . . Line: 7
393415
. . . . . . . . . . . . Col: 17
394416
. . . . . . . . . . . }
395417
. . . . . . . . . . . Properties: {
396-
. . . . . . . . . . . . internalRole: value
418+
. . . . . . . . . . . . internalRole: args
419+
. . . . . . . . . . . }
420+
. . . . . . . . . . }
421+
. . . . . . . . . . 1: Name {
422+
. . . . . . . . . . . Roles: CallCallee,SimpleIdentifier,Expression
423+
. . . . . . . . . . . TOKEN "print"
424+
. . . . . . . . . . . StartPosition: {
425+
. . . . . . . . . . . . Offset: 119
426+
. . . . . . . . . . . . Line: 7
427+
. . . . . . . . . . . . Col: 5
397428
. . . . . . . . . . . }
398-
. . . . . . . . . . . Children: {
399-
. . . . . . . . . . . . 0: StringLiteral {
400-
. . . . . . . . . . . . . Roles: StringLiteral,Expression,CallPositionalArgument
401-
. . . . . . . . . . . . . TOKEN "ayyyy"
402-
. . . . . . . . . . . . . StartPosition: {
403-
. . . . . . . . . . . . . . Offset: 125
404-
. . . . . . . . . . . . . . Line: 7
405-
. . . . . . . . . . . . . . Col: 11
406-
. . . . . . . . . . . . . }
407-
. . . . . . . . . . . . . EndPosition: {
408-
. . . . . . . . . . . . . . Offset: 131
409-
. . . . . . . . . . . . . . Line: 7
410-
. . . . . . . . . . . . . . Col: 17
411-
. . . . . . . . . . . . . }
412-
. . . . . . . . . . . . . Properties: {
413-
. . . . . . . . . . . . . . internalRole: args
414-
. . . . . . . . . . . . . }
415-
. . . . . . . . . . . . }
416-
. . . . . . . . . . . . 1: Name {
417-
. . . . . . . . . . . . . Roles: CallCallee,SimpleIdentifier,Expression
418-
. . . . . . . . . . . . . TOKEN "print"
419-
. . . . . . . . . . . . . StartPosition: {
420-
. . . . . . . . . . . . . . Offset: 119
421-
. . . . . . . . . . . . . . Line: 7
422-
. . . . . . . . . . . . . . Col: 5
423-
. . . . . . . . . . . . . }
424-
. . . . . . . . . . . . . EndPosition: {
425-
. . . . . . . . . . . . . . Offset: 123
426-
. . . . . . . . . . . . . . Line: 7
427-
. . . . . . . . . . . . . . Col: 9
428-
. . . . . . . . . . . . . }
429-
. . . . . . . . . . . . . Properties: {
430-
. . . . . . . . . . . . . . ctx: Load
431-
. . . . . . . . . . . . . . internalRole: func
432-
. . . . . . . . . . . . . }
433-
. . . . . . . . . . . . }
429+
. . . . . . . . . . . EndPosition: {
430+
. . . . . . . . . . . . Offset: 123
431+
. . . . . . . . . . . . Line: 7
432+
. . . . . . . . . . . . Col: 9
433+
. . . . . . . . . . . }
434+
. . . . . . . . . . . Properties: {
435+
. . . . . . . . . . . . ctx: Load
436+
. . . . . . . . . . . . internalRole: func
434437
. . . . . . . . . . . }
435438
. . . . . . . . . . }
436439
. . . . . . . . . }

tests/import.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ Module {
117117
. . . . Col: 19
118118
. . . }
119119
. . . Properties: {
120+
. . . . ImportFrom.module: os
120121
. . . . internalRole: body
121122
. . . . level: 0
122-
. . . . module: os
123123
. . . }
124124
. . . Children: {
125125
. . . . 0: alias {
@@ -162,9 +162,9 @@ Module {
162162
. . . . Col: 32
163163
. . . }
164164
. . . Properties: {
165+
. . . . ImportFrom.module: os.path
165166
. . . . internalRole: body
166167
. . . . level: 0
167-
. . . . module: os.path
168168
. . . }
169169
. . . Children: {
170170
. . . . 0: alias {

0 commit comments

Comments
 (0)