Coverage for src/renaissance/integrations/python/ast/kinds.py: 100%
3 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-15 10:34 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-15 10:34 +0000
1# Copyright (C) 2024-2026 TNO
2#
3# Licensed under the terms specified in the LICENSE file in the root directory
4# of this repository, also available at:
5# https://github.com/TNO/Renaissance.Py/blob/main/LICENSE
7"""AI: Mapping of Python `ast` node kinds and operators to the library's semantic kinds."""
9from renaissance.syntax_tree.semantic_kind import SemanticKind
11PYTHON_OPERATOR_MAP = {
12 "AnnAssign": "=",
13 "Assert": "assert",
14 "Assign": "=",
15 "AsyncFor": "for",
16 "AsyncFunctionDef": "function",
17 "AsyncWith": "with",
18 "AugAssignAdd": "+=",
19 "Break": "break",
20 "Call": "def",
21 "ClassDef": "class",
22 "Continue": "continue",
23 "For": "for",
24 "FunctionDef": "function",
25 "If": "if",
26 "Import": "import",
27 "ImportFrom": "import",
28 "Match": "match",
29 "Pass": "pass",
30 "Try": "try",
31 "TryStar": "try",
32 "While": "while",
33 "With": "with",
34}
36PYTHON_KIND_MAP = {
37 "Module": SemanticKind.TRANSLATION_UNIT,
38 "FunctionDef": SemanticKind.FUNCTION,
39 "AsyncFunctionDef": SemanticKind.FUNCTION,
40 "ClassDef": SemanticKind.CLASS,
41 "Call": SemanticKind.CALL,
42 "Name": SemanticKind.NAME,
43 "Attribute": SemanticKind.ATTRIBUTE,
44 "arg": SemanticKind.PARAMETER,
45 "Param": SemanticKind.PARAMETER,
46 "Constant": SemanticKind.LITERAL,
47 "Integer": SemanticKind.LITERAL,
48 "Float": SemanticKind.LITERAL,
49 "SimpleString": SemanticKind.LITERAL,
50 "FormattedString": SemanticKind.LITERAL,
51 "Assign": SemanticKind.ASSIGNMENT,
52 "AnnAssign": SemanticKind.ASSIGNMENT,
53 "AugAssign": SemanticKind.ASSIGNMENT,
54 "NamedExpr": SemanticKind.ASSIGNMENT,
55 "BinOp": SemanticKind.BINARY_OPERATION,
56 "BinaryOperation": SemanticKind.BINARY_OPERATION,
57 "BoolOp": SemanticKind.BINARY_OPERATION,
58 "Compare": SemanticKind.BINARY_OPERATION,
59 "UnaryOp": SemanticKind.UNARY_OPERATION,
60 "UnaryOperation": SemanticKind.UNARY_OPERATION,
61 "If": SemanticKind.CONDITIONAL,
62 "IfExp": SemanticKind.CONDITIONAL,
63 "For": SemanticKind.LOOP,
64 "AsyncFor": SemanticKind.LOOP,
65 "While": SemanticKind.LOOP,
66 "Return": SemanticKind.RETURN,
67 "Import": SemanticKind.IMPORT,
68 "ImportFrom": SemanticKind.IMPORT,
69 "Assert": SemanticKind.CONDITIONAL,
70 "With": SemanticKind.LOOP,
71 "AsyncWith": SemanticKind.LOOP,
72 "Raise": SemanticKind.RETURN,
73 "Break": SemanticKind.RETURN,
74 "Continue": SemanticKind.RETURN,
75 "Pass": SemanticKind.STATEMENT,
76 "Try": SemanticKind.STATEMENT,
77 "TryStar": SemanticKind.STATEMENT,
78 "Delete": SemanticKind.STATEMENT,
79 "TypeAlias": SemanticKind.STATEMENT,
80 "Expr": SemanticKind.EXPRESSION,
81 "Await": SemanticKind.EXPRESSION,
82 "Yield": SemanticKind.EXPRESSION,
83 "YieldFrom": SemanticKind.EXPRESSION,
84 "Global": SemanticKind.GLOBAL,
85 "Nonlocal": SemanticKind.NONLOCAL,
86 "Match": SemanticKind.STATEMENT,
87}