tree-sitter-analyzer 1.9.17.1__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.
Files changed (149) hide show
  1. tree_sitter_analyzer/__init__.py +132 -0
  2. tree_sitter_analyzer/__main__.py +11 -0
  3. tree_sitter_analyzer/api.py +853 -0
  4. tree_sitter_analyzer/cli/__init__.py +39 -0
  5. tree_sitter_analyzer/cli/__main__.py +12 -0
  6. tree_sitter_analyzer/cli/argument_validator.py +89 -0
  7. tree_sitter_analyzer/cli/commands/__init__.py +26 -0
  8. tree_sitter_analyzer/cli/commands/advanced_command.py +226 -0
  9. tree_sitter_analyzer/cli/commands/base_command.py +181 -0
  10. tree_sitter_analyzer/cli/commands/default_command.py +18 -0
  11. tree_sitter_analyzer/cli/commands/find_and_grep_cli.py +188 -0
  12. tree_sitter_analyzer/cli/commands/list_files_cli.py +133 -0
  13. tree_sitter_analyzer/cli/commands/partial_read_command.py +139 -0
  14. tree_sitter_analyzer/cli/commands/query_command.py +109 -0
  15. tree_sitter_analyzer/cli/commands/search_content_cli.py +161 -0
  16. tree_sitter_analyzer/cli/commands/structure_command.py +156 -0
  17. tree_sitter_analyzer/cli/commands/summary_command.py +116 -0
  18. tree_sitter_analyzer/cli/commands/table_command.py +414 -0
  19. tree_sitter_analyzer/cli/info_commands.py +124 -0
  20. tree_sitter_analyzer/cli_main.py +472 -0
  21. tree_sitter_analyzer/constants.py +85 -0
  22. tree_sitter_analyzer/core/__init__.py +15 -0
  23. tree_sitter_analyzer/core/analysis_engine.py +580 -0
  24. tree_sitter_analyzer/core/cache_service.py +333 -0
  25. tree_sitter_analyzer/core/engine.py +585 -0
  26. tree_sitter_analyzer/core/parser.py +293 -0
  27. tree_sitter_analyzer/core/query.py +605 -0
  28. tree_sitter_analyzer/core/query_filter.py +200 -0
  29. tree_sitter_analyzer/core/query_service.py +340 -0
  30. tree_sitter_analyzer/encoding_utils.py +530 -0
  31. tree_sitter_analyzer/exceptions.py +747 -0
  32. tree_sitter_analyzer/file_handler.py +246 -0
  33. tree_sitter_analyzer/formatters/__init__.py +1 -0
  34. tree_sitter_analyzer/formatters/base_formatter.py +201 -0
  35. tree_sitter_analyzer/formatters/csharp_formatter.py +367 -0
  36. tree_sitter_analyzer/formatters/formatter_config.py +197 -0
  37. tree_sitter_analyzer/formatters/formatter_factory.py +84 -0
  38. tree_sitter_analyzer/formatters/formatter_registry.py +377 -0
  39. tree_sitter_analyzer/formatters/formatter_selector.py +96 -0
  40. tree_sitter_analyzer/formatters/go_formatter.py +368 -0
  41. tree_sitter_analyzer/formatters/html_formatter.py +498 -0
  42. tree_sitter_analyzer/formatters/java_formatter.py +423 -0
  43. tree_sitter_analyzer/formatters/javascript_formatter.py +611 -0
  44. tree_sitter_analyzer/formatters/kotlin_formatter.py +268 -0
  45. tree_sitter_analyzer/formatters/language_formatter_factory.py +123 -0
  46. tree_sitter_analyzer/formatters/legacy_formatter_adapters.py +228 -0
  47. tree_sitter_analyzer/formatters/markdown_formatter.py +725 -0
  48. tree_sitter_analyzer/formatters/php_formatter.py +301 -0
  49. tree_sitter_analyzer/formatters/python_formatter.py +830 -0
  50. tree_sitter_analyzer/formatters/ruby_formatter.py +278 -0
  51. tree_sitter_analyzer/formatters/rust_formatter.py +233 -0
  52. tree_sitter_analyzer/formatters/sql_formatter_wrapper.py +689 -0
  53. tree_sitter_analyzer/formatters/sql_formatters.py +536 -0
  54. tree_sitter_analyzer/formatters/typescript_formatter.py +543 -0
  55. tree_sitter_analyzer/formatters/yaml_formatter.py +462 -0
  56. tree_sitter_analyzer/interfaces/__init__.py +9 -0
  57. tree_sitter_analyzer/interfaces/cli.py +535 -0
  58. tree_sitter_analyzer/interfaces/cli_adapter.py +359 -0
  59. tree_sitter_analyzer/interfaces/mcp_adapter.py +224 -0
  60. tree_sitter_analyzer/interfaces/mcp_server.py +428 -0
  61. tree_sitter_analyzer/language_detector.py +553 -0
  62. tree_sitter_analyzer/language_loader.py +271 -0
  63. tree_sitter_analyzer/languages/__init__.py +10 -0
  64. tree_sitter_analyzer/languages/csharp_plugin.py +1076 -0
  65. tree_sitter_analyzer/languages/css_plugin.py +449 -0
  66. tree_sitter_analyzer/languages/go_plugin.py +836 -0
  67. tree_sitter_analyzer/languages/html_plugin.py +496 -0
  68. tree_sitter_analyzer/languages/java_plugin.py +1299 -0
  69. tree_sitter_analyzer/languages/javascript_plugin.py +1622 -0
  70. tree_sitter_analyzer/languages/kotlin_plugin.py +656 -0
  71. tree_sitter_analyzer/languages/markdown_plugin.py +1928 -0
  72. tree_sitter_analyzer/languages/php_plugin.py +862 -0
  73. tree_sitter_analyzer/languages/python_plugin.py +1636 -0
  74. tree_sitter_analyzer/languages/ruby_plugin.py +757 -0
  75. tree_sitter_analyzer/languages/rust_plugin.py +673 -0
  76. tree_sitter_analyzer/languages/sql_plugin.py +2444 -0
  77. tree_sitter_analyzer/languages/typescript_plugin.py +1892 -0
  78. tree_sitter_analyzer/languages/yaml_plugin.py +695 -0
  79. tree_sitter_analyzer/legacy_table_formatter.py +860 -0
  80. tree_sitter_analyzer/mcp/__init__.py +34 -0
  81. tree_sitter_analyzer/mcp/resources/__init__.py +43 -0
  82. tree_sitter_analyzer/mcp/resources/code_file_resource.py +208 -0
  83. tree_sitter_analyzer/mcp/resources/project_stats_resource.py +586 -0
  84. tree_sitter_analyzer/mcp/server.py +869 -0
  85. tree_sitter_analyzer/mcp/tools/__init__.py +28 -0
  86. tree_sitter_analyzer/mcp/tools/analyze_scale_tool.py +779 -0
  87. tree_sitter_analyzer/mcp/tools/analyze_scale_tool_cli_compatible.py +291 -0
  88. tree_sitter_analyzer/mcp/tools/base_tool.py +139 -0
  89. tree_sitter_analyzer/mcp/tools/fd_rg_utils.py +816 -0
  90. tree_sitter_analyzer/mcp/tools/find_and_grep_tool.py +686 -0
  91. tree_sitter_analyzer/mcp/tools/list_files_tool.py +413 -0
  92. tree_sitter_analyzer/mcp/tools/output_format_validator.py +148 -0
  93. tree_sitter_analyzer/mcp/tools/query_tool.py +443 -0
  94. tree_sitter_analyzer/mcp/tools/read_partial_tool.py +464 -0
  95. tree_sitter_analyzer/mcp/tools/search_content_tool.py +836 -0
  96. tree_sitter_analyzer/mcp/tools/table_format_tool.py +572 -0
  97. tree_sitter_analyzer/mcp/tools/universal_analyze_tool.py +653 -0
  98. tree_sitter_analyzer/mcp/utils/__init__.py +113 -0
  99. tree_sitter_analyzer/mcp/utils/error_handler.py +569 -0
  100. tree_sitter_analyzer/mcp/utils/file_output_factory.py +217 -0
  101. tree_sitter_analyzer/mcp/utils/file_output_manager.py +322 -0
  102. tree_sitter_analyzer/mcp/utils/gitignore_detector.py +358 -0
  103. tree_sitter_analyzer/mcp/utils/path_resolver.py +414 -0
  104. tree_sitter_analyzer/mcp/utils/search_cache.py +343 -0
  105. tree_sitter_analyzer/models.py +840 -0
  106. tree_sitter_analyzer/mypy_current_errors.txt +2 -0
  107. tree_sitter_analyzer/output_manager.py +255 -0
  108. tree_sitter_analyzer/platform_compat/__init__.py +3 -0
  109. tree_sitter_analyzer/platform_compat/adapter.py +324 -0
  110. tree_sitter_analyzer/platform_compat/compare.py +224 -0
  111. tree_sitter_analyzer/platform_compat/detector.py +67 -0
  112. tree_sitter_analyzer/platform_compat/fixtures.py +228 -0
  113. tree_sitter_analyzer/platform_compat/profiles.py +217 -0
  114. tree_sitter_analyzer/platform_compat/record.py +55 -0
  115. tree_sitter_analyzer/platform_compat/recorder.py +155 -0
  116. tree_sitter_analyzer/platform_compat/report.py +92 -0
  117. tree_sitter_analyzer/plugins/__init__.py +280 -0
  118. tree_sitter_analyzer/plugins/base.py +647 -0
  119. tree_sitter_analyzer/plugins/manager.py +384 -0
  120. tree_sitter_analyzer/project_detector.py +328 -0
  121. tree_sitter_analyzer/queries/__init__.py +27 -0
  122. tree_sitter_analyzer/queries/csharp.py +216 -0
  123. tree_sitter_analyzer/queries/css.py +615 -0
  124. tree_sitter_analyzer/queries/go.py +275 -0
  125. tree_sitter_analyzer/queries/html.py +543 -0
  126. tree_sitter_analyzer/queries/java.py +402 -0
  127. tree_sitter_analyzer/queries/javascript.py +724 -0
  128. tree_sitter_analyzer/queries/kotlin.py +192 -0
  129. tree_sitter_analyzer/queries/markdown.py +258 -0
  130. tree_sitter_analyzer/queries/php.py +95 -0
  131. tree_sitter_analyzer/queries/python.py +859 -0
  132. tree_sitter_analyzer/queries/ruby.py +92 -0
  133. tree_sitter_analyzer/queries/rust.py +223 -0
  134. tree_sitter_analyzer/queries/sql.py +555 -0
  135. tree_sitter_analyzer/queries/typescript.py +871 -0
  136. tree_sitter_analyzer/queries/yaml.py +236 -0
  137. tree_sitter_analyzer/query_loader.py +272 -0
  138. tree_sitter_analyzer/security/__init__.py +22 -0
  139. tree_sitter_analyzer/security/boundary_manager.py +277 -0
  140. tree_sitter_analyzer/security/regex_checker.py +297 -0
  141. tree_sitter_analyzer/security/validator.py +599 -0
  142. tree_sitter_analyzer/table_formatter.py +782 -0
  143. tree_sitter_analyzer/utils/__init__.py +53 -0
  144. tree_sitter_analyzer/utils/logging.py +433 -0
  145. tree_sitter_analyzer/utils/tree_sitter_compat.py +289 -0
  146. tree_sitter_analyzer-1.9.17.1.dist-info/METADATA +485 -0
  147. tree_sitter_analyzer-1.9.17.1.dist-info/RECORD +149 -0
  148. tree_sitter_analyzer-1.9.17.1.dist-info/WHEEL +4 -0
  149. tree_sitter_analyzer-1.9.17.1.dist-info/entry_points.txt +25 -0
@@ -0,0 +1,543 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ HTML Language Queries
4
+
5
+ Comprehensive Tree-sitter queries for HTML language constructs.
6
+ Covers elements, attributes, text content, and document structure.
7
+ """
8
+
9
+ # HTML-specific query library
10
+ HTML_QUERIES: dict[str, str] = {
11
+ # --- Basic Elements ---
12
+ "element": """
13
+ (element) @element
14
+ """,
15
+ "start_tag": """
16
+ (start_tag
17
+ name: (tag_name) @tag_name) @start_tag
18
+ """,
19
+ "end_tag": """
20
+ (end_tag
21
+ name: (tag_name) @tag_name) @end_tag
22
+ """,
23
+ "self_closing_tag": """
24
+ (self_closing_tag
25
+ name: (tag_name) @tag_name) @self_closing_tag
26
+ """,
27
+ "void_element": """
28
+ (element
29
+ (start_tag
30
+ name: (tag_name) @tag_name
31
+ (#match? @tag_name "^(area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$"))) @void_element
32
+ """,
33
+ # --- Attributes ---
34
+ "attribute": """
35
+ (attribute
36
+ name: (attribute_name) @attribute_name
37
+ value: (quoted_attribute_value)? @attribute_value) @attribute
38
+ """,
39
+ "attribute_name": """
40
+ (attribute_name) @attribute_name
41
+ """,
42
+ "attribute_value": """
43
+ (quoted_attribute_value) @attribute_value
44
+ """,
45
+ "class_attribute": """
46
+ (attribute
47
+ name: (attribute_name) @attr_name
48
+ (#match? @attr_name "^class$")
49
+ value: (quoted_attribute_value) @class_value) @class_attribute
50
+ """,
51
+ "id_attribute": """
52
+ (attribute
53
+ name: (attribute_name) @attr_name
54
+ (#match? @attr_name "^id$")
55
+ value: (quoted_attribute_value) @id_value) @id_attribute
56
+ """,
57
+ "src_attribute": """
58
+ (attribute
59
+ name: (attribute_name) @attr_name
60
+ (#match? @attr_name "^src$")
61
+ value: (quoted_attribute_value) @src_value) @src_attribute
62
+ """,
63
+ "href_attribute": """
64
+ (attribute
65
+ name: (attribute_name) @attr_name
66
+ (#match? @attr_name "^href$")
67
+ value: (quoted_attribute_value) @href_value) @href_attribute
68
+ """,
69
+ # --- Text Content ---
70
+ "text": """
71
+ (text) @text
72
+ """,
73
+ "raw_text": """
74
+ (raw_text) @raw_text
75
+ """,
76
+ # --- Comments ---
77
+ "comment": """
78
+ (comment) @comment
79
+ """,
80
+ # --- Document Structure ---
81
+ "doctype": """
82
+ (doctype) @doctype
83
+ """,
84
+ "document": """
85
+ (document) @document
86
+ """,
87
+ # --- Semantic Elements ---
88
+ "heading": """
89
+ (element
90
+ (start_tag
91
+ name: (tag_name) @tag_name
92
+ (#match? @tag_name "^h[1-6]$"))) @heading
93
+ """,
94
+ "paragraph": """
95
+ (element
96
+ (start_tag
97
+ name: (tag_name) @tag_name
98
+ (#match? @tag_name "^p$"))) @paragraph
99
+ """,
100
+ "link": """
101
+ (element
102
+ (start_tag
103
+ name: (tag_name) @tag_name
104
+ (#match? @tag_name "^a$"))) @link
105
+ """,
106
+ "image": """
107
+ (element
108
+ (start_tag
109
+ name: (tag_name) @tag_name
110
+ (#match? @tag_name "^img$"))) @image
111
+ """,
112
+ "list": """
113
+ (element
114
+ (start_tag
115
+ name: (tag_name) @tag_name
116
+ (#match? @tag_name "^(ul|ol|dl)$"))) @list
117
+ """,
118
+ "list_item": """
119
+ (element
120
+ (start_tag
121
+ name: (tag_name) @tag_name
122
+ (#match? @tag_name "^(li|dt|dd)$"))) @list_item
123
+ """,
124
+ "table": """
125
+ (element
126
+ (start_tag
127
+ name: (tag_name) @tag_name
128
+ (#match? @tag_name "^table$"))) @table
129
+ """,
130
+ "table_row": """
131
+ (element
132
+ (start_tag
133
+ name: (tag_name) @tag_name
134
+ (#match? @tag_name "^tr$"))) @table_row
135
+ """,
136
+ "table_cell": """
137
+ (element
138
+ (start_tag
139
+ name: (tag_name) @tag_name
140
+ (#match? @tag_name "^(td|th)$"))) @table_cell
141
+ """,
142
+ # --- Structure Elements ---
143
+ "html": """
144
+ (element
145
+ (start_tag
146
+ name: (tag_name) @tag_name
147
+ (#match? @tag_name "^html$"))) @html
148
+ """,
149
+ "head": """
150
+ (element
151
+ (start_tag
152
+ name: (tag_name) @tag_name
153
+ (#match? @tag_name "^head$"))) @head
154
+ """,
155
+ "body": """
156
+ (element
157
+ (start_tag
158
+ name: (tag_name) @tag_name
159
+ (#match? @tag_name "^body$"))) @body
160
+ """,
161
+ "header": """
162
+ (element
163
+ (start_tag
164
+ name: (tag_name) @tag_name
165
+ (#match? @tag_name "^header$"))) @header
166
+ """,
167
+ "footer": """
168
+ (element
169
+ (start_tag
170
+ name: (tag_name) @tag_name
171
+ (#match? @tag_name "^footer$"))) @footer
172
+ """,
173
+ "main": """
174
+ (element
175
+ (start_tag
176
+ name: (tag_name) @tag_name
177
+ (#match? @tag_name "^main$"))) @main
178
+ """,
179
+ "section": """
180
+ (element
181
+ (start_tag
182
+ name: (tag_name) @tag_name
183
+ (#match? @tag_name "^section$"))) @section
184
+ """,
185
+ "article": """
186
+ (element
187
+ (start_tag
188
+ name: (tag_name) @tag_name
189
+ (#match? @tag_name "^article$"))) @article
190
+ """,
191
+ "aside": """
192
+ (element
193
+ (start_tag
194
+ name: (tag_name) @tag_name
195
+ (#match? @tag_name "^aside$"))) @aside
196
+ """,
197
+ "nav": """
198
+ (element
199
+ (start_tag
200
+ name: (tag_name) @tag_name
201
+ (#match? @tag_name "^nav$"))) @nav
202
+ """,
203
+ "div": """
204
+ (element
205
+ (start_tag
206
+ name: (tag_name) @tag_name
207
+ (#match? @tag_name "^div$"))) @div
208
+ """,
209
+ "span": """
210
+ (element
211
+ (start_tag
212
+ name: (tag_name) @tag_name
213
+ (#match? @tag_name "^span$"))) @span
214
+ """,
215
+ # --- Form Elements ---
216
+ "form": """
217
+ (element
218
+ (start_tag
219
+ name: (tag_name) @tag_name
220
+ (#match? @tag_name "^form$"))) @form
221
+ """,
222
+ "input": """
223
+ (element
224
+ (start_tag
225
+ name: (tag_name) @tag_name
226
+ (#match? @tag_name "^input$"))) @input
227
+ """,
228
+ "button": """
229
+ (element
230
+ (start_tag
231
+ name: (tag_name) @tag_name
232
+ (#match? @tag_name "^button$"))) @button
233
+ """,
234
+ "textarea": """
235
+ (element
236
+ (start_tag
237
+ name: (tag_name) @tag_name
238
+ (#match? @tag_name "^textarea$"))) @textarea
239
+ """,
240
+ "select": """
241
+ (element
242
+ (start_tag
243
+ name: (tag_name) @tag_name
244
+ (#match? @tag_name "^select$"))) @select
245
+ """,
246
+ "option": """
247
+ (element
248
+ (start_tag
249
+ name: (tag_name) @tag_name
250
+ (#match? @tag_name "^option$"))) @option
251
+ """,
252
+ "label": """
253
+ (element
254
+ (start_tag
255
+ name: (tag_name) @tag_name
256
+ (#match? @tag_name "^label$"))) @label
257
+ """,
258
+ "fieldset": """
259
+ (element
260
+ (start_tag
261
+ name: (tag_name) @tag_name
262
+ (#match? @tag_name "^fieldset$"))) @fieldset
263
+ """,
264
+ "legend": """
265
+ (element
266
+ (start_tag
267
+ name: (tag_name) @tag_name
268
+ (#match? @tag_name "^legend$"))) @legend
269
+ """,
270
+ # --- Media Elements ---
271
+ "video": """
272
+ (element
273
+ (start_tag
274
+ name: (tag_name) @tag_name
275
+ (#match? @tag_name "^video$"))) @video
276
+ """,
277
+ "audio": """
278
+ (element
279
+ (start_tag
280
+ name: (tag_name) @tag_name
281
+ (#match? @tag_name "^audio$"))) @audio
282
+ """,
283
+ "source": """
284
+ (element
285
+ (start_tag
286
+ name: (tag_name) @tag_name
287
+ (#match? @tag_name "^source$"))) @source
288
+ """,
289
+ "track": """
290
+ (element
291
+ (start_tag
292
+ name: (tag_name) @tag_name
293
+ (#match? @tag_name "^track$"))) @track
294
+ """,
295
+ "canvas": """
296
+ (element
297
+ (start_tag
298
+ name: (tag_name) @tag_name
299
+ (#match? @tag_name "^canvas$"))) @canvas
300
+ """,
301
+ "svg": """
302
+ (element
303
+ (start_tag
304
+ name: (tag_name) @tag_name
305
+ (#match? @tag_name "^svg$"))) @svg
306
+ """,
307
+ # --- Meta Elements ---
308
+ "meta": """
309
+ (element
310
+ (start_tag
311
+ name: (tag_name) @tag_name
312
+ (#match? @tag_name "^meta$"))) @meta
313
+ """,
314
+ "title": """
315
+ (element
316
+ (start_tag
317
+ name: (tag_name) @tag_name
318
+ (#match? @tag_name "^title$"))) @title
319
+ """,
320
+ "link_tag": """
321
+ (element
322
+ (start_tag
323
+ name: (tag_name) @tag_name
324
+ (#match? @tag_name "^link$"))) @link_tag
325
+ """,
326
+ "style": """
327
+ (element
328
+ (start_tag
329
+ name: (tag_name) @tag_name
330
+ (#match? @tag_name "^style$"))) @style
331
+ """,
332
+ "script": """
333
+ (element
334
+ (start_tag
335
+ name: (tag_name) @tag_name
336
+ (#match? @tag_name "^script$"))) @script
337
+ """,
338
+ "noscript": """
339
+ (element
340
+ (start_tag
341
+ name: (tag_name) @tag_name
342
+ (#match? @tag_name "^noscript$"))) @noscript
343
+ """,
344
+ "base": """
345
+ (element
346
+ (start_tag
347
+ name: (tag_name) @tag_name
348
+ (#match? @tag_name "^base$"))) @base
349
+ """,
350
+ # --- Script and Style Elements ---
351
+ "script_element": """
352
+ (script_element) @script_element
353
+ """,
354
+ "style_element": """
355
+ (style_element) @style_element
356
+ """,
357
+ # --- Name-only Extraction ---
358
+ "tag_name": """
359
+ (tag_name) @tag_name
360
+ """,
361
+ "element_name": """
362
+ (element
363
+ (start_tag
364
+ name: (tag_name) @element_name))
365
+ """,
366
+ }
367
+
368
+ # Query descriptions
369
+ HTML_QUERY_DESCRIPTIONS: dict[str, str] = {
370
+ "element": "Search all HTML elements",
371
+ "start_tag": "Search start tags",
372
+ "end_tag": "Search end tags",
373
+ "self_closing_tag": "Search self-closing tags",
374
+ "void_element": "Search void elements (br, img, input, etc.)",
375
+ "attribute": "Search all attributes",
376
+ "attribute_name": "Search attribute names",
377
+ "attribute_value": "Search attribute values",
378
+ "class_attribute": "Search class attributes",
379
+ "id_attribute": "Search id attributes",
380
+ "src_attribute": "Search src attributes",
381
+ "href_attribute": "Search href attributes",
382
+ "text": "Search text content",
383
+ "raw_text": "Search raw text content",
384
+ "comment": "Search HTML comments",
385
+ "doctype": "Search DOCTYPE declarations",
386
+ "document": "Search document root",
387
+ "heading": "Search heading elements (h1-h6)",
388
+ "paragraph": "Search paragraph elements",
389
+ "link": "Search anchor elements",
390
+ "image": "Search image elements",
391
+ "list": "Search list elements (ul, ol, dl)",
392
+ "list_item": "Search list item elements (li, dt, dd)",
393
+ "table": "Search table elements",
394
+ "table_row": "Search table row elements",
395
+ "table_cell": "Search table cell elements (td, th)",
396
+ "html": "Search html elements",
397
+ "head": "Search head elements",
398
+ "body": "Search body elements",
399
+ "header": "Search header elements",
400
+ "footer": "Search footer elements",
401
+ "main": "Search main elements",
402
+ "section": "Search section elements",
403
+ "article": "Search article elements",
404
+ "aside": "Search aside elements",
405
+ "nav": "Search nav elements",
406
+ "div": "Search div elements",
407
+ "span": "Search span elements",
408
+ "form": "Search form elements",
409
+ "input": "Search input elements",
410
+ "button": "Search button elements",
411
+ "textarea": "Search textarea elements",
412
+ "select": "Search select elements",
413
+ "option": "Search option elements",
414
+ "label": "Search label elements",
415
+ "fieldset": "Search fieldset elements",
416
+ "legend": "Search legend elements",
417
+ "video": "Search video elements",
418
+ "audio": "Search audio elements",
419
+ "source": "Search source elements",
420
+ "track": "Search track elements",
421
+ "canvas": "Search canvas elements",
422
+ "svg": "Search svg elements",
423
+ "meta": "Search meta elements",
424
+ "title": "Search title elements",
425
+ "link_tag": "Search link elements",
426
+ "style": "Search style elements",
427
+ "script": "Search script elements",
428
+ "noscript": "Search noscript elements",
429
+ "base": "Search base elements",
430
+ "script_element": "Search script elements with content",
431
+ "style_element": "Search style elements with content",
432
+ "tag_name": "Search tag names only",
433
+ "element_name": "Search element names only",
434
+ }
435
+
436
+ # Legacy query definitions for backward compatibility
437
+ ELEMENTS = """
438
+ (element
439
+ (start_tag
440
+ name: (tag_name) @element.name)
441
+ (text)? @element.text
442
+ (end_tag)?) @element.full
443
+ """
444
+
445
+ ATTRIBUTES = """
446
+ (attribute
447
+ name: (attribute_name) @attribute.name
448
+ value: (quoted_attribute_value)? @attribute.value) @attribute.full
449
+ """
450
+
451
+ COMMENTS = """
452
+ (comment) @comment
453
+ """
454
+
455
+ TEXT_CONTENT = """
456
+ (text) @text
457
+ """
458
+
459
+ # Convert to ALL_QUERIES format for dynamic loader compatibility
460
+ ALL_QUERIES = {}
461
+ for query_name, query_string in HTML_QUERIES.items():
462
+ description = HTML_QUERY_DESCRIPTIONS.get(query_name, "No description")
463
+ ALL_QUERIES[query_name] = {"query": query_string, "description": description}
464
+
465
+ # Add legacy queries for backward compatibility
466
+ ALL_QUERIES["elements"] = {
467
+ "query": ELEMENTS,
468
+ "description": "Search all HTML elements with names and text",
469
+ }
470
+ ALL_QUERIES["attributes"] = {
471
+ "query": ATTRIBUTES,
472
+ "description": "Search all HTML attributes",
473
+ }
474
+ ALL_QUERIES["comments"] = {
475
+ "query": COMMENTS,
476
+ "description": "Search all HTML comments",
477
+ }
478
+ ALL_QUERIES["text_content"] = {
479
+ "query": TEXT_CONTENT,
480
+ "description": "Search all text content",
481
+ }
482
+
483
+
484
+ def get_html_query(name: str) -> str:
485
+ """
486
+ Get the specified HTML query
487
+
488
+ Args:
489
+ name: Query name
490
+
491
+ Returns:
492
+ Query string
493
+
494
+ Raises:
495
+ ValueError: When query is not found
496
+ """
497
+ if name not in HTML_QUERIES:
498
+ available = list(HTML_QUERIES.keys())
499
+ raise ValueError(f"HTML query '{name}' does not exist. Available: {available}")
500
+
501
+ return HTML_QUERIES[name]
502
+
503
+
504
+ def get_html_query_description(name: str) -> str:
505
+ """
506
+ Get the description of the specified HTML query
507
+
508
+ Args:
509
+ name: Query name
510
+
511
+ Returns:
512
+ Query description
513
+ """
514
+ return HTML_QUERY_DESCRIPTIONS.get(name, "No description")
515
+
516
+
517
+ def get_query(name: str) -> str:
518
+ """Get a specific query by name."""
519
+ if name in ALL_QUERIES:
520
+ return ALL_QUERIES[name]["query"]
521
+ raise ValueError(
522
+ f"Query '{name}' not found. Available queries: {list(ALL_QUERIES.keys())}"
523
+ )
524
+
525
+
526
+ def get_all_queries() -> dict:
527
+ """Get all available queries."""
528
+ return ALL_QUERIES
529
+
530
+
531
+ def list_queries() -> list:
532
+ """List all available query names."""
533
+ return list(ALL_QUERIES.keys())
534
+
535
+
536
+ def get_available_html_queries() -> list[str]:
537
+ """
538
+ Get list of available HTML queries
539
+
540
+ Returns:
541
+ List of query names
542
+ """
543
+ return list(HTML_QUERIES.keys())