Skip to content

Commit e89e99d

Browse files
authored
Merge pull request #4461 from erik-krogh/pyPrint
Python: implement printAst for Python
2 parents 9ff5142 + e18cf08 commit e89e99d

File tree

4 files changed

+4845
-0
lines changed

4 files changed

+4845
-0
lines changed

python/ql/src/printAst.ql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @name Print AST
3+
* @description Outputs a representation of a file's Abstract Syntax Tree. This
4+
* query is used by the VS Code extension.
5+
* @id py/print-ast
6+
* @kind graph
7+
* @tags ide-contextual-queries/print-ast
8+
*/
9+
10+
import python
11+
import semmle.python.PrintAst
12+
import analysis.DefinitionTracking
13+
14+
/**
15+
* The source file to generate an AST from.
16+
*/
17+
external string selectedSourceFile();
18+
19+
class PrintAstConfigurationOverride extends PrintAstConfiguration {
20+
/**
21+
* Holds if the location matches the selected file in the VS Code extension and
22+
* the element is not a synthetic constructor.
23+
*/
24+
override predicate shouldPrint(AstNode e, Location l) {
25+
super.shouldPrint(e, l) and
26+
l.getFile() = getEncodedFile(selectedSourceFile())
27+
}
28+
}

0 commit comments

Comments
 (0)