code-explore-by-sql 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,215 @@
1
+ """JavaScript / TypeScript language configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from ..configs import LanguageConfig
8
+
9
+ _NEVER_MATCH = re.compile(r"(?!x)x")
10
+
11
+
12
+ def make_javascript_language() -> LanguageConfig:
13
+ """JavaScript language configuration."""
14
+ return LanguageConfig(
15
+ name="javascript",
16
+ class_re=re.compile(
17
+ r"(?:^|\s)(?:export\s+)?(?:default\s+)?(?:abstract\s+)?(class)\s+(\w+)"
18
+ r"(?:\s+extends\s+(\w+))?"
19
+ ),
20
+ enum_re=_NEVER_MATCH,
21
+ namespace_re=_NEVER_MATCH,
22
+ func_name_re=re.compile(
23
+ r"(?:async\s+)?(?:function\s+)?"
24
+ r"(?:get\s+|set\s+|static\s+|async\s+)*"
25
+ r"(\w+)\s*\("
26
+ ),
27
+ export_macro_re=_NEVER_MATCH,
28
+ calling_conv_re=_NEVER_MATCH,
29
+ attribute_re=_NEVER_MATCH,
30
+ template_re=_NEVER_MATCH,
31
+ dtor_re=_NEVER_MATCH,
32
+ control_flow_re=re.compile(
33
+ r"\b(if|else\s+if|else|while|for|do|switch|catch|try|finally)\b"
34
+ ),
35
+ control_flow_names=frozenset({
36
+ "if", "else", "while", "for", "do", "switch", "catch", "try", "finally",
37
+ "return", "break", "continue", "throw", "yield", "await", "new",
38
+ "delete", "typeof", "instanceof",
39
+ }),
40
+ trailing_mods_re=_NEVER_MATCH,
41
+ access_spec_re=_NEVER_MATCH,
42
+ macro_like_re=_NEVER_MATCH,
43
+ define_re=_NEVER_MATCH,
44
+ extern_c_re=_NEVER_MATCH,
45
+ operator_re=None,
46
+ uses_braces=True,
47
+ uses_namespaces=False,
48
+ uses_colon_inheritance=True,
49
+ scope_operator=".",
50
+ base_keyword="super",
51
+ static_call_re=re.compile(
52
+ r"\b([A-Z][A-Za-z0-9_]+)\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
53
+ ),
54
+ super_call_re=re.compile(
55
+ r"\bsuper\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
56
+ ),
57
+ type_re=re.compile(r"\b([A-Z][A-Za-z0-9_]+)\b"),
58
+ param_type_re=_NEVER_MATCH,
59
+ basic_skip_types=frozenset({
60
+ "Object", "Array", "String", "Number", "Boolean", "Symbol", "BigInt",
61
+ "Promise", "Map", "Set", "WeakMap", "WeakSet", "Date", "RegExp",
62
+ "Error", "Math", "JSON", "console", "undefined", "null", "NaN",
63
+ "Infinity",
64
+ }),
65
+ block_keyword_re=re.compile(r"\b(?:class|function)\b"),
66
+ lambda_re=re.compile(r"=>"),
67
+ namespace_sig_re=None,
68
+ init_list_re=None,
69
+ access_spec_names=frozenset(),
70
+ view_structural_kws=("class ", "function "),
71
+ view_modifier_kws=("async ", "static ", "get ", "set "),
72
+ local_var_modifiers="const|let|var",
73
+ verbatim_string_prefix=None,
74
+ raw_string_char=None,
75
+ range_for_re=re.compile(
76
+ r"for\s*\(\s*(?:const|let|var)?\s*(\w+)\s+of\s+(\w+)"
77
+ ),
78
+ # Comment syntax
79
+ line_comment="//",
80
+ block_comment_pair=("/*", "*/"),
81
+ # String syntax
82
+ string_delimiters=frozenset({'"', "'"}),
83
+ string_escape_char="\\",
84
+ triple_quote_strings=(),
85
+ # Block style
86
+ uses_indent_blocks=False,
87
+ # Preprocessor
88
+ preprocessor_prefix="",
89
+ has_preprocessor_macros=False,
90
+ # Statement / block close
91
+ statement_terminator=";",
92
+ block_close_suffix="}",
93
+ summary_comment_prefix="//",
94
+ # Config-driven control flow
95
+ control_flow_patterns=(
96
+ ("for", re.compile(r"^\s*for\s+\((.{1,80})\)\s*\{?\s*$")),
97
+ ("while", re.compile(r"^\s*while\s+\((.{1,80})\)\s*\{?\s*$")),
98
+ ("if", re.compile(r"^\s*(?:else\s+)?if\s+\((.{1,80})\)\s*\{?\s*$")),
99
+ ("switch", re.compile(r"^\s*switch\s+\((.{1,40})\)\s*\{?\s*$")),
100
+ ),
101
+ return_re=re.compile(r"^\s*return\s+(.{1,60});"),
102
+ # Extra syntax hints
103
+ type_indicator_chars="",
104
+ define_line_re=None,
105
+ has_template_strings=True,
106
+ raw_string_style="cpp",
107
+ )
108
+
109
+
110
+ def make_typescript_language() -> LanguageConfig:
111
+ """TypeScript language configuration."""
112
+ return LanguageConfig(
113
+ name="typescript",
114
+ class_re=re.compile(
115
+ r"(?:^|\s)(?:export\s+)?(?:default\s+)?(?:abstract\s+)?(class)\s+(\w+)"
116
+ r"(?:\s+extends\s+(\w+))?"
117
+ ),
118
+ enum_re=re.compile(r"\benum\s+(\w+)"),
119
+ namespace_re=re.compile(r"\bnamespace\s+(\w+)"),
120
+ func_name_re=re.compile(
121
+ r"(?:async\s+)?(?:function\s+)?"
122
+ r"(?:get\s+|set\s+|static\s+|async\s+|abstract\s+)*"
123
+ r"(\w+)\s*[(<]"
124
+ ),
125
+ export_macro_re=_NEVER_MATCH,
126
+ calling_conv_re=_NEVER_MATCH,
127
+ attribute_re=re.compile(r"@\w+(?:\.\w+)*(?:\([^)]*\))?"),
128
+ template_re=re.compile(r"<[^<>]*>"),
129
+ dtor_re=_NEVER_MATCH,
130
+ control_flow_re=re.compile(
131
+ r"\b(if|else\s+if|else|while|for|do|switch|catch|try|finally)\b"
132
+ ),
133
+ control_flow_names=frozenset({
134
+ "if", "else", "while", "for", "do", "switch", "catch", "try", "finally",
135
+ "return", "break", "continue", "throw", "yield", "await", "new",
136
+ "delete", "typeof", "instanceof",
137
+ }),
138
+ trailing_mods_re=_NEVER_MATCH,
139
+ access_spec_re=_NEVER_MATCH,
140
+ macro_like_re=_NEVER_MATCH,
141
+ define_re=_NEVER_MATCH,
142
+ extern_c_re=_NEVER_MATCH,
143
+ operator_re=None,
144
+ uses_braces=True,
145
+ uses_namespaces=False,
146
+ uses_colon_inheritance=True,
147
+ scope_operator=".",
148
+ base_keyword="super",
149
+ static_call_re=re.compile(
150
+ r"\b([A-Z][A-Za-z0-9_]+)\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
151
+ ),
152
+ super_call_re=re.compile(
153
+ r"\bsuper\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
154
+ ),
155
+ type_re=re.compile(r"\b([A-Z][A-Za-z0-9_]+)\b"),
156
+ param_type_re=re.compile(r"(\w+)\s*:\s*([A-Z][A-Za-z0-9_]+)"),
157
+ basic_skip_types=frozenset({
158
+ "Object", "Array", "String", "Number", "Boolean", "Symbol", "BigInt",
159
+ "Promise", "Map", "Set", "WeakMap", "WeakSet", "Date", "RegExp",
160
+ "Error", "Math", "JSON", "console", "undefined", "null", "NaN",
161
+ "Infinity",
162
+ # TypeScript-specific
163
+ "string", "number", "boolean", "void", "never", "unknown", "any",
164
+ "object", "symbol", "bigint",
165
+ "Record", "Partial", "Required", "Readonly", "Pick", "Omit",
166
+ "Exclude", "Extract",
167
+ }),
168
+ block_keyword_re=re.compile(
169
+ r"\b(?:class|function|interface|enum|namespace|type)\b"
170
+ ),
171
+ lambda_re=re.compile(r"=>"),
172
+ func_sig_end_re=re.compile(r"\)\s*(?::\s*\w[\w<>\[\]| ]*)?\s*\{?\s*$"),
173
+ namespace_sig_re=None,
174
+ init_list_re=None,
175
+ access_spec_names=frozenset(),
176
+ view_structural_kws=(
177
+ "class ", "function ", "interface ", "enum ", "namespace ", "type ",
178
+ ),
179
+ view_modifier_kws=("async ", "static ", "get ", "set "),
180
+ local_var_modifiers="const|let|var",
181
+ verbatim_string_prefix=None,
182
+ raw_string_char=None,
183
+ range_for_re=re.compile(
184
+ r"for\s*\(\s*(?:const|let|var)?\s*(\w+)\s+of\s+(\w+)"
185
+ ),
186
+ # Comment syntax
187
+ line_comment="//",
188
+ block_comment_pair=("/*", "*/"),
189
+ # String syntax
190
+ string_delimiters=frozenset({'"', "'"}),
191
+ string_escape_char="\\",
192
+ triple_quote_strings=(),
193
+ # Block style
194
+ uses_indent_blocks=False,
195
+ # Preprocessor
196
+ preprocessor_prefix="",
197
+ has_preprocessor_macros=False,
198
+ # Statement / block close
199
+ statement_terminator=";",
200
+ block_close_suffix="}",
201
+ summary_comment_prefix="//",
202
+ # Config-driven control flow
203
+ control_flow_patterns=(
204
+ ("for", re.compile(r"^\s*for\s+\((.{1,80})\)\s*\{?\s*$")),
205
+ ("while", re.compile(r"^\s*while\s+\((.{1,80})\)\s*\{?\s*$")),
206
+ ("if", re.compile(r"^\s*(?:else\s+)?if\s+\((.{1,80})\)\s*\{?\s*$")),
207
+ ("switch", re.compile(r"^\s*switch\s+\((.{1,40})\)\s*\{?\s*$")),
208
+ ),
209
+ return_re=re.compile(r"^\s*return\s+(.{1,60});"),
210
+ # Extra syntax hints
211
+ type_indicator_chars="",
212
+ define_line_re=None,
213
+ has_template_strings=True,
214
+ raw_string_style="cpp",
215
+ )
@@ -0,0 +1,108 @@
1
+ """Kotlin language configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from ..configs import LanguageConfig
8
+
9
+ _NEVER_MATCH = re.compile(r"(?!x)x")
10
+
11
+
12
+ def make_kotlin_language() -> LanguageConfig:
13
+ """Kotlin language configuration."""
14
+ return LanguageConfig(
15
+ name="kotlin",
16
+ class_re=re.compile(
17
+ r"(?:(?:public|private|protected|internal|abstract|final|open|sealed|data|inner|companion)\s+)*"
18
+ r"(class|interface|object)\s+(\w+)"
19
+ r"(?:\s*:\s*(\w+))?"
20
+ ),
21
+ enum_re=re.compile(r"\benum\s+class\s+(\w+)"),
22
+ namespace_re=re.compile(r"\bpackage\s+([\w.]+)"),
23
+ func_name_re=re.compile(
24
+ r"(?:(?:public|private|protected|internal)\s+)?"
25
+ r"(?:suspend\s+)?"
26
+ r"fun\s+(?:<[^>]*>\s+)?(?:\w+\.)?(\w+)\s*\("
27
+ ),
28
+ export_macro_re=_NEVER_MATCH,
29
+ calling_conv_re=_NEVER_MATCH,
30
+ attribute_re=re.compile(r"@\w+(?:\.\w+)*(?:\([^)]*\))?"),
31
+ template_re=re.compile(r"<[^<>]*>"),
32
+ dtor_re=_NEVER_MATCH,
33
+ control_flow_re=re.compile(
34
+ r"\b(if|else\s+if|else|while|for|do|when|try|catch|finally)\b"
35
+ ),
36
+ control_flow_names=frozenset({
37
+ "if", "else", "while", "for", "do", "when", "try", "catch", "finally",
38
+ "return", "break", "continue", "throw", "yield", "suspend",
39
+ }),
40
+ trailing_mods_re=_NEVER_MATCH,
41
+ access_spec_re=_NEVER_MATCH,
42
+ macro_like_re=_NEVER_MATCH,
43
+ define_re=_NEVER_MATCH,
44
+ extern_c_re=_NEVER_MATCH,
45
+ operator_re=None,
46
+ uses_braces=True,
47
+ uses_namespaces=False,
48
+ uses_colon_inheritance=True,
49
+ scope_operator=".",
50
+ base_keyword="super",
51
+ static_call_re=re.compile(
52
+ r"\b([A-Z][A-Za-z0-9_]+)\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
53
+ ),
54
+ super_call_re=re.compile(
55
+ r"\bsuper\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
56
+ ),
57
+ type_re=re.compile(r"\b([A-Z][A-Za-z0-9_]+)\b"),
58
+ param_type_re=re.compile(r"(\w+)\s*:\s*([A-Z][A-Za-z0-9_]+)"),
59
+ basic_skip_types=frozenset({
60
+ "Int", "Long", "Short", "Byte", "Float", "Double", "Boolean", "Char",
61
+ "String", "Unit", "Nothing", "Any", "Array", "List", "Set", "Map",
62
+ "MutableList", "MutableSet", "MutableMap",
63
+ }),
64
+ block_keyword_re=re.compile(r"\b(?:class|interface|object|fun|enum)\b"),
65
+ lambda_re=re.compile(r"\{"),
66
+ namespace_sig_re=None,
67
+ init_list_re=None,
68
+ access_spec_names=frozenset(),
69
+ view_structural_kws=(
70
+ "class ", "interface ", "object ", "fun ", "enum class ",
71
+ ),
72
+ view_modifier_kws=(
73
+ "suspend ", "inline ", "abstract ", "open ", "data ", "sealed ",
74
+ ),
75
+ local_var_modifiers="val|var|const|lateinit",
76
+ verbatim_string_prefix=None,
77
+ raw_string_char=None,
78
+ range_for_re=re.compile(r"for\s*\(\s*(\w+)\s+in\s+(\w+)"),
79
+ # Comment syntax
80
+ line_comment="//",
81
+ block_comment_pair=("/*", "*/"),
82
+ # String syntax
83
+ string_delimiters=frozenset({'"'}),
84
+ string_escape_char="\\",
85
+ triple_quote_strings=(),
86
+ # Block style
87
+ uses_indent_blocks=False,
88
+ # Preprocessor
89
+ preprocessor_prefix="",
90
+ has_preprocessor_macros=False,
91
+ # Statement / block close
92
+ statement_terminator="",
93
+ block_close_suffix="}",
94
+ summary_comment_prefix="//",
95
+ # Config-driven control flow
96
+ control_flow_patterns=(
97
+ ("for", re.compile(r"^\s*for\s+\((.{1,80})\)\s*\{?\s*$")),
98
+ ("while", re.compile(r"^\s*while\s+\((.{1,80})\)\s*\{?\s*$")),
99
+ ("if", re.compile(r"^\s*(?:else\s+)?if\s+\((.{1,80})\)\s*\{?\s*$")),
100
+ ("when", re.compile(r"^\s*when\s+(?:\((.{1,40})\)\s*)?\{?\s*$")),
101
+ ),
102
+ return_re=re.compile(r"^\s*return\s+(.{1,60})"),
103
+ # Extra syntax hints
104
+ type_indicator_chars="",
105
+ define_line_re=None,
106
+ has_template_strings=False,
107
+ raw_string_style="cpp",
108
+ )
@@ -0,0 +1,105 @@
1
+ """Python language configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from ..configs import LanguageConfig
8
+
9
+ _NEVER_MATCH = re.compile(r"(?!x)x")
10
+
11
+
12
+ def make_python_language() -> LanguageConfig:
13
+ """Python language configuration."""
14
+ return LanguageConfig(
15
+ name="python",
16
+ class_re=re.compile(
17
+ r"^\s*(class)\s+(\w+)(?:\s*\(\s*(\w+))?[^:]*:"
18
+ ),
19
+ enum_re=_NEVER_MATCH,
20
+ namespace_re=_NEVER_MATCH,
21
+ func_name_re=re.compile(r"(\w+)\s*\([^)]*\)\s*(?:\s*->.*?)?\s*:\s*$"),
22
+ export_macro_re=_NEVER_MATCH,
23
+ calling_conv_re=_NEVER_MATCH,
24
+ attribute_re=re.compile(r"@\w+(?:\.\w+)*(?:\([^)]*\))?"),
25
+ template_re=_NEVER_MATCH,
26
+ dtor_re=_NEVER_MATCH,
27
+ control_flow_re=re.compile(
28
+ r"^\s*(?:if|elif|else|while|for|try|except|finally|with|match|case)\b"
29
+ ),
30
+ control_flow_names=frozenset({
31
+ "if", "elif", "else", "while", "for", "try", "except", "finally",
32
+ "with", "match", "case", "return", "yield", "break", "continue",
33
+ "raise", "pass", "del", "global", "nonlocal", "assert", "import",
34
+ "from",
35
+ }),
36
+ trailing_mods_re=_NEVER_MATCH,
37
+ access_spec_re=_NEVER_MATCH,
38
+ macro_like_re=_NEVER_MATCH,
39
+ define_re=_NEVER_MATCH,
40
+ extern_c_re=_NEVER_MATCH,
41
+ operator_re=None,
42
+ uses_braces=False,
43
+ uses_namespaces=False,
44
+ uses_colon_inheritance=True,
45
+ scope_operator=".",
46
+ base_keyword="super()",
47
+ static_call_re=re.compile(
48
+ r"\b([A-Z][A-Za-z0-9_]+)\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
49
+ ),
50
+ super_call_re=re.compile(
51
+ r"\bsuper\(\)\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
52
+ ),
53
+ type_re=re.compile(r"\b([A-Z][A-Za-z0-9_]+)\b"),
54
+ param_type_re=re.compile(r"(\w+)\s*:\s*([A-Z][A-Za-z0-9_]+)"),
55
+ basic_skip_types=frozenset({
56
+ "int", "float", "str", "bool", "list", "dict", "set", "tuple",
57
+ "bytes", "bytearray", "memoryview", "range", "enumerate", "type",
58
+ "object", "complex", "frozenset",
59
+ "None", "Any", "Optional", "Union", "Callable", "Type",
60
+ "List", "Dict", "Set", "Tuple",
61
+ }),
62
+ block_keyword_re=re.compile(r"\b(?:class|def|async\s+def)\b"),
63
+ lambda_re=re.compile(r"\blambda\b"),
64
+ func_sig_end_re=re.compile(r"\)\s*(?:->.*?)?\s*:\s*$"),
65
+ namespace_sig_re=None,
66
+ init_list_re=None,
67
+ access_spec_names=frozenset(),
68
+ view_structural_kws=("class ", "def ", "async def "),
69
+ view_modifier_kws=(
70
+ "@staticmethod ", "@classmethod ", "@property ", "@abstractmethod ",
71
+ ),
72
+ local_var_modifiers="global|nonlocal",
73
+ verbatim_string_prefix=None,
74
+ raw_string_char="r",
75
+ range_for_re=re.compile(r"^\s*for\s+(\w+)\s+in\s+(\w+)"),
76
+ # Comment syntax
77
+ line_comment="#",
78
+ block_comment_pair=None,
79
+ # String syntax
80
+ string_delimiters=frozenset({'"', "'"}),
81
+ string_escape_char="\\",
82
+ triple_quote_strings=('"""', "'''"),
83
+ # Block style
84
+ uses_indent_blocks=True,
85
+ # Preprocessor
86
+ preprocessor_prefix="",
87
+ has_preprocessor_macros=False,
88
+ # Statement / block close
89
+ statement_terminator="",
90
+ block_close_suffix="",
91
+ summary_comment_prefix="#",
92
+ # Config-driven control flow
93
+ control_flow_patterns=(
94
+ ("for", re.compile(r"^\s*for\s+(.{1,80})\s*:\s*$")),
95
+ ("while", re.compile(r"^\s*while\s+(.{1,80})\s*:\s*$")),
96
+ ("if", re.compile(r"^\s*(?:elif\s+)?if\s+(.{1,80})\s*:\s*$")),
97
+ ("match", re.compile(r"^\s*match\s+(.{1,40})\s*:\s*$")),
98
+ ),
99
+ return_re=re.compile(r"^\s*return\s+(.{1,60})\s*$"),
100
+ # Extra syntax hints
101
+ type_indicator_chars="",
102
+ define_line_re=None,
103
+ has_template_strings=False,
104
+ raw_string_style="cpp",
105
+ )
@@ -0,0 +1,91 @@
1
+ """Rust language configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from ..configs import LanguageConfig
8
+
9
+
10
+ def make_rust_language() -> LanguageConfig:
11
+ """Rust language configuration."""
12
+ return LanguageConfig(
13
+ name="rust",
14
+ class_re=re.compile(r"(?:pub\s+)?(struct|enum|trait)\s+(\w+)"),
15
+ enum_re=re.compile(r"(?:pub\s+)?enum\s+(\w+)"),
16
+ namespace_re=re.compile(r"\bmod\s+(\w+)"),
17
+ func_name_re=re.compile(r"(?:pub\s+)?(?:async\s+)?fn\s+(\w+)"),
18
+ export_macro_re=re.compile(r"(?!x)x"),
19
+ calling_conv_re=re.compile(r"(?!x)x"),
20
+ attribute_re=re.compile(r"#!?\[[^\]]*\]"), # inner/outer attributes
21
+ template_re=re.compile(r"<[^<>]*>"), # generics
22
+ dtor_re=re.compile(r"(?!x)x"), # Rust uses Drop trait
23
+ control_flow_re=re.compile(r"\b(if|else\s+if|else|while|for|loop|match|return|break|continue)\b"),
24
+ control_flow_names=frozenset({
25
+ "if", "else", "while", "for", "loop", "match",
26
+ "return", "break", "continue", "yield", "await", "unsafe",
27
+ }),
28
+ trailing_mods_re=re.compile(r"(?!x)x"),
29
+ access_spec_re=re.compile(r"(?!x)x"), # Rust uses pub
30
+ macro_like_re=re.compile(r"^[a-z_]+!\s"), # Rust macros end with !
31
+ define_re=re.compile(r"(?!x)x"), # Rust has macro_rules!, not #define
32
+ extern_c_re=re.compile(r"\bextern\s+"),
33
+ operator_re=None,
34
+ uses_braces=True,
35
+ uses_namespaces=True,
36
+ uses_colon_inheritance=False,
37
+ scope_operator="::",
38
+ base_keyword="", # Rust has no super; uses Deref or explicit paths
39
+ static_call_re=re.compile(r"\b([A-Z][A-Za-z0-9_]+)::([A-Za-z_][A-Za-z0-9_]*)\s*\("),
40
+ super_call_re=None,
41
+ type_re=re.compile(r"\b([A-Z][A-Za-z0-9_]+)\b"),
42
+ param_type_re=re.compile(r":\s*(?:&)?(?:mut\s+)?([A-Z][A-Za-z0-9_]+)"), # name: Type syntax
43
+ basic_skip_types=frozenset({
44
+ "i8", "i16", "i32", "i64", "i128",
45
+ "u8", "u16", "u32", "u64", "u128",
46
+ "f32", "f64", "bool", "char", "str", "String",
47
+ "Vec", "Box", "Rc", "Arc", "Option", "Result",
48
+ "Cow", "Cell", "RefCell",
49
+ }),
50
+ block_keyword_re=re.compile(r"\b(?:struct|enum|trait|impl|mod|fn|type)\b"),
51
+ lambda_re=re.compile(r"\|[^|]*\|\s*"), # Rust closures
52
+ namespace_sig_re=re.compile(r"\bmod\s+(\w+)\s*\{?\s*$"),
53
+ init_list_re=None,
54
+ access_spec_names=frozenset(),
55
+ view_structural_kws=("struct ", "enum ", "trait ", "impl ", "fn "),
56
+ view_modifier_kws=("pub ", "async ", "unsafe ", "const "),
57
+ local_var_modifiers="let|mut|const|static|ref",
58
+ verbatim_string_prefix=None,
59
+ raw_string_char="r",
60
+ range_for_re=re.compile(r"for\s+(\w+)\s+in\s+(\w+)"),
61
+ # Comment syntax
62
+ line_comment="//",
63
+ block_comment_pair=("/*", "*/"),
64
+ # String syntax
65
+ string_delimiters=frozenset({'"'}),
66
+ string_escape_char="\\",
67
+ triple_quote_strings=(),
68
+ # Block style
69
+ uses_indent_blocks=False,
70
+ # Preprocessor
71
+ preprocessor_prefix="", # Rust # is for attributes, not preprocessor
72
+ has_preprocessor_macros=False,
73
+ # Statement / block close
74
+ statement_terminator=";",
75
+ block_close_suffix="}",
76
+ summary_comment_prefix="//",
77
+ # Config-driven control flow
78
+ control_flow_patterns=(
79
+ ("for", re.compile(r"^\s*for\s+(.{1,80})\s*\{?\s*$")),
80
+ ("while", re.compile(r"^\s*while\s+(.{1,80})\s*\{?\s*$")),
81
+ ("if", re.compile(r"^\s*(?:else\s+)?if\s+(.{1,80})\s*\{?\s*$")),
82
+ ("match", re.compile(r"^\s*match\s+(.{1,40})\s*\{?\s*$")),
83
+ ("loop", re.compile(r"^\s*loop\s*\{?\s*$")),
84
+ ),
85
+ return_re=re.compile(r"^\s*return\s+(.{1,60});"),
86
+ # Extra syntax hints
87
+ type_indicator_chars="&", # Rust references use &
88
+ define_line_re=None,
89
+ has_template_strings=False,
90
+ raw_string_style="rust", # Rust uses r#"..."# raw strings
91
+ )
@@ -0,0 +1,116 @@
1
+ """Swift language configuration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from ..configs import LanguageConfig
8
+
9
+ _NEVER_MATCH = re.compile(r"(?!x)x")
10
+
11
+
12
+ def make_swift_language() -> LanguageConfig:
13
+ """Swift language configuration."""
14
+ return LanguageConfig(
15
+ name="swift",
16
+ class_re=re.compile(
17
+ r"(?:(?:public|private|internal|open|fileprivate|final|static|override)\s+)*"
18
+ r"(class|struct|protocol|enum|actor)\s+(\w+)"
19
+ r"(?:\s*<[^>]*>)?"
20
+ r"(?:\s*:\s*(\w+))?"
21
+ ),
22
+ enum_re=re.compile(r"(?:indirect\s+)?enum\s+(\w+)"),
23
+ namespace_re=_NEVER_MATCH,
24
+ func_name_re=re.compile(
25
+ r"(?:(?:public|private|internal|open|fileprivate|static|override|mutating|nonmutating)\s+)*"
26
+ r"(?:async\s+)?(?:throws\s+)?"
27
+ r"func\s+(\w+)\s*\("
28
+ ),
29
+ export_macro_re=_NEVER_MATCH,
30
+ calling_conv_re=_NEVER_MATCH,
31
+ attribute_re=re.compile(r"@\w+(?:\([^)]*\))?"),
32
+ template_re=re.compile(r"<[^<>]*>"),
33
+ dtor_re=re.compile(r"deinit"),
34
+ control_flow_re=re.compile(
35
+ r"\b(if|else\s+if|else|while|for|switch|catch|try|guard|repeat)\b"
36
+ ),
37
+ control_flow_names=frozenset({
38
+ "if", "else", "while", "for", "switch", "catch", "try",
39
+ "return", "break", "continue", "throw", "guard", "repeat",
40
+ "defer", "yield", "await",
41
+ }),
42
+ trailing_mods_re=_NEVER_MATCH,
43
+ access_spec_re=_NEVER_MATCH,
44
+ macro_like_re=_NEVER_MATCH,
45
+ define_re=_NEVER_MATCH,
46
+ extern_c_re=_NEVER_MATCH,
47
+ operator_re=None,
48
+ uses_braces=True,
49
+ uses_namespaces=False,
50
+ uses_colon_inheritance=True,
51
+ scope_operator=".",
52
+ base_keyword="super",
53
+ static_call_re=re.compile(
54
+ r"\b([A-Z][A-Za-z0-9_]+)\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
55
+ ),
56
+ super_call_re=re.compile(
57
+ r"\bsuper\.([A-Za-z_][A-Za-z0-9_]*)\s*\("
58
+ ),
59
+ type_re=re.compile(r"\b([A-Z][A-Za-z0-9_]+)\b"),
60
+ param_type_re=re.compile(r"(\w+)\s*:\s*([A-Z][A-Za-z0-9_]+)"),
61
+ basic_skip_types=frozenset({
62
+ "Int", "Int8", "Int16", "Int32", "Int64",
63
+ "UInt", "UInt8", "UInt16", "UInt32", "UInt64",
64
+ "Float", "Double", "Bool", "String", "Character",
65
+ "Void", "Any", "AnyObject", "Optional", "Array",
66
+ "Dictionary", "Set", "Result", "URL", "Data", "Date",
67
+ }),
68
+ block_keyword_re=re.compile(
69
+ r"\b(?:class|struct|protocol|enum|actor|func|extension|typealias)\b"
70
+ ),
71
+ lambda_re=re.compile(r"\{"),
72
+ namespace_sig_re=None,
73
+ init_list_re=None,
74
+ access_spec_names=frozenset(),
75
+ view_structural_kws=(
76
+ "class ", "struct ", "protocol ", "enum ", "actor ",
77
+ "func ", "extension ",
78
+ ),
79
+ view_modifier_kws=(
80
+ "public ", "private ", "internal ", "open ", "static ",
81
+ "override ", "mutating ", "async ",
82
+ ),
83
+ local_var_modifiers="let|var|guard",
84
+ verbatim_string_prefix=None,
85
+ raw_string_char=None,
86
+ range_for_re=re.compile(r"for\s+(\w+)\s+in\s+(\w+)"),
87
+ # Comment syntax
88
+ line_comment="//",
89
+ block_comment_pair=("/*", "*/"),
90
+ # String syntax
91
+ string_delimiters=frozenset({'"'}),
92
+ string_escape_char="\\",
93
+ triple_quote_strings=(),
94
+ # Block style
95
+ uses_indent_blocks=False,
96
+ # Preprocessor
97
+ preprocessor_prefix="",
98
+ has_preprocessor_macros=False,
99
+ # Statement / block close
100
+ statement_terminator=";",
101
+ block_close_suffix="}",
102
+ summary_comment_prefix="//",
103
+ # Config-driven control flow
104
+ control_flow_patterns=(
105
+ ("for", re.compile(r"^\s*for\s+(.{1,80})\s*\{?\s*$")),
106
+ ("while", re.compile(r"^\s*while\s+(.{1,80})\s*\{?\s*$")),
107
+ ("if", re.compile(r"^\s*(?:else\s+)?if\s+(.{1,80})\s*\{?\s*$")),
108
+ ("switch", re.compile(r"^\s*switch\s+(.{1,40})\s*\{?\s*$")),
109
+ ),
110
+ return_re=re.compile(r"^\s*return\s+(.{1,60})"),
111
+ # Extra syntax hints
112
+ type_indicator_chars="",
113
+ define_line_re=None,
114
+ has_template_strings=False,
115
+ raw_string_style="cpp",
116
+ )