python-delphi-lsp 3.6.0__cp310-abi3-win_amd64.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 (56) hide show
  1. delphi_lsp/__init__.py +184 -0
  2. delphi_lsp/_version.py +1 -0
  3. delphi_lsp/agent_cache.py +1574 -0
  4. delphi_lsp/agent_cli.py +902 -0
  5. delphi_lsp/agent_context.py +3907 -0
  6. delphi_lsp/agent_cpg.py +349 -0
  7. delphi_lsp/agent_cpg_builder.py +666 -0
  8. delphi_lsp/agent_layers.py +1410 -0
  9. delphi_lsp/agent_metrics.py +526 -0
  10. delphi_lsp/agent_protocol.py +445 -0
  11. delphi_lsp/agent_relations.py +1881 -0
  12. delphi_lsp/agent_templates.py +614 -0
  13. delphi_lsp/agent_wiki.py +2853 -0
  14. delphi_lsp/agent_workspace.py +860 -0
  15. delphi_lsp/ast_serialize.py +126 -0
  16. delphi_lsp/binary.py +250 -0
  17. delphi_lsp/comment_builder.py +28 -0
  18. delphi_lsp/consts.py +345 -0
  19. delphi_lsp/delphi_lsp_native.pyd +0 -0
  20. delphi_lsp/delphiast_lexer.py +399 -0
  21. delphi_lsp/delphiast_parser.py +2189 -0
  22. delphi_lsp/delphiast_tokens.py +41 -0
  23. delphi_lsp/grammar.py +459 -0
  24. delphi_lsp/incremental.py +1139 -0
  25. delphi_lsp/lark_builder.py +2684 -0
  26. delphi_lsp/lark_tokens.py +236 -0
  27. delphi_lsp/lexical_scanner.py +30 -0
  28. delphi_lsp/lsp_server.py +6698 -0
  29. delphi_lsp/metrics.py +1452 -0
  30. delphi_lsp/native_bridge.py +300 -0
  31. delphi_lsp/navigation_cache.py +189 -0
  32. delphi_lsp/nodes.py +462 -0
  33. delphi_lsp/parallel_outline.py +662 -0
  34. delphi_lsp/parse_artifacts.py +969 -0
  35. delphi_lsp/parser.py +342 -0
  36. delphi_lsp/parser_backend.py +139 -0
  37. delphi_lsp/preprocessor.py +1122 -0
  38. delphi_lsp/progress.py +26 -0
  39. delphi_lsp/project_config.py +285 -0
  40. delphi_lsp/project_discovery.py +932 -0
  41. delphi_lsp/project_indexer.py +470 -0
  42. delphi_lsp/py.typed +1 -0
  43. delphi_lsp/response_cache.py +465 -0
  44. delphi_lsp/semantic.py +394 -0
  45. delphi_lsp/semantic_builder.py +2302 -0
  46. delphi_lsp/source_reader.py +17 -0
  47. delphi_lsp/wiki_external_sort.py +392 -0
  48. delphi_lsp/wiki_memory.py +548 -0
  49. delphi_lsp/workspace.py +83 -0
  50. delphi_lsp/writer.py +73 -0
  51. python_delphi_lsp-3.6.0.dist-info/METADATA +766 -0
  52. python_delphi_lsp-3.6.0.dist-info/RECORD +56 -0
  53. python_delphi_lsp-3.6.0.dist-info/WHEEL +4 -0
  54. python_delphi_lsp-3.6.0.dist-info/entry_points.txt +3 -0
  55. python_delphi_lsp-3.6.0.dist-info/licenses/LICENSE +373 -0
  56. python_delphi_lsp-3.6.0.dist-info/sboms/python-delphi-lsp.cyclonedx.json +770 -0
@@ -0,0 +1,41 @@
1
+ """Token model for the pure-Python DelphiAST parser.
2
+
3
+ This file is a Python port inspired by DelphiAST/SimpleParser, licensed under
4
+ MPL-2.0: https://github.com/RomanYankovsky/DelphiAST
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ from dataclasses import dataclass, field
10
+ from enum import Enum
11
+
12
+
13
+ class TokenKind(str, Enum):
14
+ IDENTIFIER = "identifier"
15
+ KEYWORD = "keyword"
16
+ NUMBER = "number"
17
+ STRING = "string"
18
+ CHAR_CODE = "char_code"
19
+ SYMBOL = "symbol"
20
+ COMMENT = "comment"
21
+ DIRECTIVE = "directive"
22
+ UNKNOWN = "unknown"
23
+ EOF = "eof"
24
+
25
+
26
+ @dataclass(frozen=True, slots=True)
27
+ class Token:
28
+ kind: TokenKind
29
+ value: str
30
+ line: int
31
+ column: int
32
+ start: int
33
+ end: int
34
+ file_name: str
35
+ normalized: str = field(init=False)
36
+
37
+ def __post_init__(self) -> None:
38
+ object.__setattr__(self, "normalized", self.value.casefold())
39
+
40
+
41
+ __all__ = ["Token", "TokenKind"]
delphi_lsp/grammar.py ADDED
@@ -0,0 +1,459 @@
1
+ from __future__ import annotations
2
+
3
+ from .lark_tokens import build_grammar_snippet
4
+
5
+ GRAMMAR_RULES = r'''
6
+ ?start: unit_file
7
+ | program_file
8
+ | library_file
9
+ | package_file
10
+ | include_file
11
+
12
+ unit_file: unit_header interface_section implementation_section? initialization_section? finalization_section? END "."
13
+ | unit_header interface_section implementation_section? bare_initialization_section "."
14
+ program_file: program_header program_body "."
15
+ library_file: library_header program_body "."
16
+ package_file: package_header package_body END "."
17
+ include_file: uses_clause? implementation_decl_sections
18
+ | literal
19
+
20
+ unit_header: UNIT qualified_name unit_directive_list? ";" uses_clause?
21
+ program_header: PROGRAM qualified_name program_params? ";" uses_clause?
22
+ library_header: LIBRARY qualified_name ";" uses_clause?
23
+ package_header: PACKAGE qualified_name ";"
24
+
25
+ unit_directive_list: unit_directive+
26
+ unit_directive: DEPRECATED (STRING_LITERAL)?
27
+ | PLATFORM
28
+ | EXPERIMENTAL
29
+ | LIBRARY
30
+
31
+ program_params: "(" name_list ")"
32
+ program_body: block
33
+ package_body: requires_clause? contains_clause?
34
+
35
+ interface_section: INTERFACE interface_preamble? uses_clause? interface_decl_sections
36
+ implementation_section: IMPLEMENTATION uses_clause? implementation_decl_sections
37
+ initialization_section: INITIALIZATION statement_list?
38
+ finalization_section: FINALIZATION statement_list?
39
+ bare_initialization_section: compound_statement
40
+
41
+ interface_preamble: ignored_compiler_error_line+
42
+
43
+ interface_decl_sections: (label_section | const_section | resourcestring_section | type_section | var_section
44
+ | threadvar_section | routine_decl | property_decl | exports_section)*
45
+ implementation_decl_sections: (label_section | const_section | resourcestring_section | type_section | var_section
46
+ | threadvar_section | routine_impl | property_decl | exports_section
47
+ | ignored_proc_type_directive | ignored_compiler_error_line)*
48
+ ignored_proc_type_directive: proc_type_decl_directive ";"?
49
+ ignored_compiler_error_line: COMPILER_ERROR_TEXT
50
+
51
+ uses_clause: EMPTY_USES_BEFORE_IMPLEMENTATION
52
+ | USES uses_item ("," uses_item)* ";"
53
+ uses_item: qualified_name (IN STRING_LITERAL)?
54
+
55
+ label_section: LABEL label_list ";"
56
+ label_list: label ("," label)*
57
+ label: NAME | INT | EXIT
58
+
59
+ const_section: CONST const_decl+
60
+ resourcestring_section: RESOURCESTRING const_decl+
61
+ const_decl: attribute_sections? NAME (":" type_spec)? "=" const_value? decl_directive_list? ";"
62
+
63
+ type_section: TYPE type_decl+
64
+ type_decl: attribute_sections? type_decl_name type_params? "=" forward_type_decl decl_directive_list? ";"
65
+ | attribute_sections? type_decl_name type_params? "=" type_spec proc_type_decl_directive? decl_directive_list? ";"
66
+ | attribute_sections? type_decl_name type_params? "=" -> incomplete_type_decl
67
+ type_decl_name: NAME | GENERIC_NAME
68
+ forward_type_decl: CLASS class_modifiers? type_heritage? -> forward_class_decl
69
+ | INTERFACE type_heritage? -> forward_interface_decl
70
+ | DISPINTERFACE type_heritage? -> forward_dispinterface_decl
71
+
72
+ decl_directive_list: decl_directive+
73
+ decl_directive: DEPRECATED (STRING_LITERAL)?
74
+ | PLATFORM
75
+ | EXPERIMENTAL
76
+ | LIBRARY
77
+
78
+ var_section: VAR var_decl+
79
+ threadvar_section: THREADVAR var_decl+
80
+ var_decl: attribute_sections? name_list ":" type_spec proc_type_decl_directive? absolute_spec? ("=" const_value)? ";"
81
+ absolute_spec: ABSOLUTE expr
82
+
83
+ exports_section: EXPORTS exports_item ("," exports_item)* ";"
84
+ exports_item: qualified_name formal_parameters? exports_specifier*
85
+ exports_specifier: NAME expr | INDEX expr | RESIDENT
86
+
87
+ requires_clause: REQUIRES qualified_name ("," qualified_name)* ";"
88
+ contains_clause: CONTAINS contains_item ("," contains_item)* ";"
89
+ contains_item: qualified_name (IN STRING_LITERAL)?
90
+
91
+ property_decl: attribute_sections? CLASS? PROPERTY NAME property_params? (":" type_spec)? property_specifier* property_directive* property_directive_block* ";"
92
+ property_params: "[" param_list? "]"
93
+ property_specifier: INDEX expr | READONLY | WRITEONLY
94
+ property_directive_block: ";" property_directive+
95
+ property_directive: READ expr
96
+ | WRITE expr
97
+ | ADD expr
98
+ | REMOVE expr
99
+ | DEFAULT expr?
100
+ | STORED expr?
101
+ | NODEFAULT
102
+ | IMPLEMENTS qualified_name
103
+ | DISPID expr
104
+
105
+ routine_decl: resolution_decl
106
+ | routine_heading proc_type_decl_directive ";" directive_list?
107
+ | routine_heading ";" directive_list?
108
+
109
+ resolution_decl: (procedure_decl | function_decl | operator_decl | qualified_name) "=" qualified_name ";"
110
+
111
+ routine_impl: routine_heading proc_type_decl_directive ";" body_directive_list? routine_body ";"?
112
+ | routine_heading ";" body_directive_list? routine_body ";"?
113
+ | routine_heading proc_type_decl_directive ";" body_directive_list EXTERNAL external_spec? (";" directive)* ";"?
114
+ | routine_heading proc_type_decl_directive EXTERNAL external_spec? (";" directive)* ";"?
115
+ | routine_heading ";" body_directive_list EXTERNAL external_spec? (";" directive)* ";"?
116
+ | routine_heading proc_type_decl_directive proc_type_decl_directive ";" EXTERNAL external_spec? (";" directive)* ";"?
117
+ | routine_heading proc_type_decl_directive ";" body_directive_list FORWARD (";" directive)* ";"?
118
+ | routine_heading ";" body_directive_list FORWARD (";" directive)* ";"?
119
+ | routine_heading proc_type_decl_directive ";" FORWARD (";" directive)* ";"?
120
+ | routine_heading ";" FORWARD (";" directive)* ";"?
121
+ | routine_heading proc_type_decl_directive ";" EXTERNAL external_spec? (";" directive)* ";"?
122
+ | routine_heading ";" EXTERNAL external_spec? (";" directive)* ";"?
123
+
124
+ routine_heading: procedure_decl
125
+ | function_decl
126
+ | constructor_decl
127
+ | destructor_decl
128
+ | operator_decl
129
+
130
+ procedure_decl: attribute_sections? CLASS? PROCEDURE qualified_name type_params? formal_parameters? routine_heading_directive_list?
131
+ function_decl: attribute_sections? CLASS? FUNCTION qualified_name type_params? formal_parameters? (":" type_spec)? routine_heading_directive_list?
132
+ constructor_decl: attribute_sections? CLASS? CONSTRUCTOR qualified_name type_params? formal_parameters? routine_heading_directive_list?
133
+ destructor_decl: attribute_sections? CLASS? DESTRUCTOR qualified_name type_params? formal_parameters? routine_heading_directive_list?
134
+ operator_decl: attribute_sections? CLASS? OPERATOR operator_target type_params? formal_parameters? (":" type_spec)? routine_heading_directive_list?
135
+ operator_target: operator_name | qualified_name
136
+ routine_heading_directive_list: routine_heading_directive+
137
+ routine_heading_directive: VARARGS
138
+
139
+ operator_name: "+" | "-" | "*" | "/" | "=" | "<" | ">" | "<=" | ">=" | "<>" | IN | IS | AS
140
+
141
+ routine_body: block
142
+ | asm_block
143
+ asm_block: block_decl_sections? asm_statement
144
+ block: block_decl_sections? compound_statement
145
+ block_decl_sections: (label_section | const_section | resourcestring_section | type_section | var_section
146
+ | threadvar_section | routine_impl | exports_section)*
147
+
148
+ formal_parameters: "(" param_list? ")"
149
+ param_list: param (";" param)*
150
+ param: attribute_sections? param_modifier? attribute_sections? name_list (":" type_spec)? param_default?
151
+ param_modifier: CONST | VAR | OUT
152
+ param_default: "=" expr
153
+
154
+ name_list: (NAME | STRICT_NAME) ("," (NAME | STRICT_NAME))*
155
+
156
+ ?type_spec: simple_type
157
+ | distinct_type
158
+ | pointer_type
159
+ | array_type
160
+ | array_of_const_type
161
+ | set_type
162
+ | structured_type
163
+ | proc_type
164
+ | subrange_type
165
+ | enum_type
166
+ | string_type
167
+ | file_type
168
+ | class_of_type
169
+ | reference_type
170
+ | packed_type
171
+
172
+ packed_type: PACKED type_spec
173
+ distinct_type: TYPE type_spec
174
+ simple_type: type_name
175
+ type_name: qualified_name type_args? codepage_spec?
176
+ codepage_spec: "(" expr ")"
177
+ pointer_type: "^" type_spec
178
+ | POINTER_CHAR
179
+ array_type: ARRAY ("[" array_bounds "]")? OF type_spec
180
+ array_of_const_type: ARRAY OF CONST
181
+ array_bounds: array_bound ("," array_bound)*
182
+ array_bound: range_expr (".." range_expr)?
183
+ set_type: SET OF type_spec
184
+ subrange_type: range_expr ".." range_expr
185
+ enum_type: "(" enum_item ("," enum_item)* ")"
186
+ enum_item.2: NAME ("=" expr)?
187
+ string_type: STRING ("[" expr "]")?
188
+ file_type: FILE (OF type_spec)?
189
+ class_of_type: CLASS OF type_spec
190
+ reference_type: REFERENCE TO proc_type
191
+
192
+ structured_type: class_type | record_type | interface_type | object_type | helper_type
193
+ class_type: CLASS class_modifiers? type_params? type_heritage? class_body? END
194
+ record_type: RECORD record_body? END record_align?
195
+ record_align: ALIGN expr
196
+ object_type: OBJECT type_heritage? class_body? END
197
+ interface_type: (INTERFACE | DISPINTERFACE) type_heritage? interface_guid? interface_body? END
198
+ helper_type: (CLASS | RECORD) HELPER FOR type_spec class_body? END
199
+
200
+ class_modifiers: (SEALED | ABSTRACT) (SEALED | ABSTRACT)?
201
+ interface_guid: "[" STRING_LITERAL "]"
202
+
203
+ class_body: class_member*
204
+ record_body: class_member*
205
+ interface_body: interface_member*
206
+
207
+ class_member: visibility_spec
208
+ | visibility_spec? class_member_item
209
+ class_member_item: field_decl ";"?
210
+ | routine_decl
211
+ | property_decl
212
+ | class_var_section
213
+ | class_threadvar_section
214
+ | class_const_section
215
+ | class_type_section
216
+ | var_section
217
+ | const_section
218
+ | type_section
219
+ | threadvar_section
220
+ | variant_part
221
+
222
+ class_var_section: CLASS VAR var_decl+
223
+ class_threadvar_section: CLASS THREADVAR var_decl+
224
+ class_const_section: CLASS CONST const_decl+
225
+ class_type_section: CLASS TYPE type_decl+
226
+
227
+ interface_member: routine_decl | property_decl
228
+
229
+ visibility_spec: STRICT? PRIVATE
230
+ | STRICT? PROTECTED
231
+ | PUBLIC
232
+ | PUBLISHED
233
+ | AUTOMATED
234
+
235
+ variant_part: CASE variant_selector? OF variant_section (";" variant_section)* ";"?
236
+ variant_selector: NAME ":" type_spec
237
+ | type_spec
238
+ variant_section: case_label_list ":" "(" field_list? ")"
239
+ field_list: record_field (";" record_field)* ";"?
240
+ record_field: field_decl | variant_part
241
+ field_decl: attribute_sections? name_list ":" type_spec proc_type_decl_directive?
242
+
243
+ proc_type: (PROCEDURE | FUNCTION) formal_parameters? (":" type_spec)? of_object?
244
+ proc_type_decl_directive: PROC_TYPE_DIRECTIVE
245
+ of_object: OF OBJECT
246
+
247
+ type_heritage: "(" type_name ("," type_name)* ")"
248
+
249
+ type_params: "<" type_param ((","|";") type_param)* ">"
250
+ type_param: NAME (":" type_constraints)?
251
+ type_constraints: type_constraint ((","|";") type_constraint)*
252
+ type_constraint: type_spec | CLASS | RECORD | CONSTRUCTOR | INTERFACE | UNMANAGED
253
+
254
+ type_args: "<" type_spec ("," type_spec)* ">"
255
+
256
+ attribute_sections: attribute_section+
257
+ attribute_section: "[" attribute ("," attribute)* "]"
258
+ attribute: attribute_name attribute_arguments?
259
+ attribute_name: qualified_name | attribute_keyword
260
+ attribute_keyword: IN | OUT | CONST | VAR | UNSAFE
261
+ attribute_arguments: "(" arg_list? ")"
262
+
263
+ directive_list: directive ((";" directive) | proc_type_decl_directive)* ";"?
264
+ body_directive_list: body_directive ((";" body_directive) | proc_type_decl_directive)* ";"?
265
+ body_directive: OVERLOAD | OVERRIDE | VIRTUAL | DYNAMIC | ABSTRACT | INLINE | REINTRODUCE | STATIC | FINAL | SEALED
266
+ | STDCALL | CDECL | PASCAL | REGISTER | SAFECALL | WINAPI | MESSAGE expr
267
+ | DEPRECATED (STRING_LITERAL)?
268
+ | PLATFORM
269
+ | EXPERIMENTAL
270
+ | NORETURN
271
+ | VARARGS
272
+ | LOCAL
273
+ | LIBRARY
274
+ | DELAYED
275
+ | EXPORT
276
+ | FAR
277
+ | NEAR
278
+ | ASSEMBLER
279
+ | UNSAFE
280
+ | DISPID expr
281
+ directive: OVERLOAD | OVERRIDE | VIRTUAL | DYNAMIC | ABSTRACT | INLINE | REINTRODUCE | STATIC | FINAL | SEALED
282
+ | STDCALL | CDECL | PASCAL | REGISTER | SAFECALL | WINAPI | MESSAGE expr | EXTERNAL external_spec? | FORWARD
283
+ | DEPRECATED (STRING_LITERAL)?
284
+ | PLATFORM
285
+ | EXPERIMENTAL
286
+ | NORETURN
287
+ | VARARGS
288
+ | LOCAL
289
+ | LIBRARY
290
+ | DELAYED
291
+ | EXPORT
292
+ | FAR
293
+ | NEAR
294
+ | ASSEMBLER
295
+ | UNSAFE
296
+ | DISPID expr
297
+ external_spec: external_item+
298
+ external_item: INDEX expr | DELAYED | expr
299
+
300
+ const_value: expr | array_const | record_const
301
+ array_const: "(" const_value_list? ")"
302
+ const_value_list: const_value ("," const_value)*
303
+ record_const: "(" record_const_item ((","|";") record_const_item)* ";"? ")"
304
+ record_const_item: NAME ":" const_value
305
+ set_const: "[" set_element_list? "]"
306
+ set_element_list: set_element ("," set_element)*
307
+ set_element: expr (".." expr)?
308
+
309
+ ?statement_list: ";"* statement (";"+ statement)* ";"*
310
+ | ";"+
311
+
312
+ ?statement: compound_statement
313
+ | if_statement
314
+ | while_statement
315
+ | for_statement
316
+ | repeat_statement
317
+ | try_statement
318
+ | raise_statement
319
+ | case_statement
320
+ | with_statement
321
+ | asm_statement
322
+ | inline_statement
323
+ | inline_var_section
324
+ | inline_const_section
325
+ | goto_statement
326
+ | label_statement
327
+ | address_assignment
328
+ | assignment
329
+ | comparison_statement
330
+ | call_statement
331
+ | break_statement
332
+ | continue_statement
333
+ | exit_statement
334
+
335
+ compound_statement: BEGIN statement_list? END
336
+ if_statement: IF expr THEN statement? (ELSE statement?)?
337
+ while_statement: WHILE expr DO statement?
338
+ for_statement: FOR for_init (TO|DOWNTO) expr DO statement
339
+ | FOR for_in DO statement
340
+ for_init: NAME ASSIGN expr
341
+ | VAR NAME ASSIGN expr
342
+ | VAR NAME ":" type_spec ASSIGN expr
343
+ for_in: NAME IN expr
344
+ | VAR NAME IN expr
345
+ | VAR NAME ":" type_spec IN expr
346
+ repeat_statement: REPEAT statement_list? UNTIL expr
347
+ case_statement: CASE expr OF case_selector_list case_else? END
348
+ case_selector_list: case_selector (";" case_selector)* ";"?
349
+ case_selector: case_label_list ":" statement?
350
+ case_label_list: case_label ("," case_label)*
351
+ case_label: expr (".." expr)?
352
+ case_else: ELSE statement_list?
353
+ with_statement: WITH expr_list DO statement
354
+ try_statement: TRY statement_list (except_block | finally_block) END
355
+ except_block: EXCEPT statement_list
356
+ | EXCEPT exception_handler+ (ELSE statement_list)?
357
+ | EXCEPT
358
+ exception_handler: ON qualified_name (":" qualified_name)? DO statement_list?
359
+ finally_block: FINALLY statement_list?
360
+ raise_statement: RAISE expr? (AT expr)?
361
+ goto_statement: GOTO label
362
+ label_statement: label ":" statement?
363
+ inherited_statement: INHERITED call_statement?
364
+ break_statement: BREAK
365
+ continue_statement: CONTINUE
366
+ exit_statement: EXIT
367
+ | EXIT "(" ")"
368
+ | EXIT expr
369
+ asm_statement: ASM asm_item* END
370
+ asm_item: NAME | INT | HEX_INT | BIN_INT | FLOAT | STRING_LITERAL | CHAR_CODE | "." | "," | ":" | ";" | "+" | "-" | "*" | "/" | "[" | "]" | "(" | ")" | "@" | "^" | "="
371
+ inline_statement: INLINE "(" inline_number ("/" inline_number)* ")"
372
+ inline_number: INT | HEX_INT
373
+ inline_const_section: CONST inline_const_decl
374
+ inline_const_decl: attribute_sections? NAME (":" type_spec)? "=" const_value
375
+ inline_var_section: VAR inline_var_decl
376
+ inline_var_decl: attribute_sections? name_list (":" type_spec)? (ASSIGN expr)?
377
+
378
+ address_assignment: "@" postfix_expr ASSIGN expr
379
+ assignment: postfix_expr ASSIGN expr
380
+ comparison_statement: postfix_expr rel_op expr
381
+ call_statement: postfix_expr
382
+
383
+ ?expr_list: expr ("," expr)*
384
+
385
+ ?expr: if_expr
386
+ | or_expr
387
+ if_expr: IF expr THEN expr ELSE expr
388
+ ?or_expr: xor_expr (OR xor_expr)*
389
+ ?xor_expr: and_expr (XOR and_expr)*
390
+ ?and_expr: rel_expr (AND rel_expr)*
391
+ ?rel_expr: add_expr (rel_op add_expr)*
392
+ rel_op: "=" | "<>" | "<" | "<=" | ">" | ">=" | IN | IS | AS | not_in_op | is_not_op
393
+ not_in_op: NOT IN
394
+ is_not_op: IS NOT
395
+ ?add_expr: mul_expr (("+"|"-") mul_expr)*
396
+ ?mul_expr: unary_expr (("*"|"/"|DIV|MOD|SHL|SHR) unary_expr)*
397
+ ?unary_expr: (NOT|"+"|"-"|"@"|"^") unary_expr
398
+ | postfix_expr
399
+
400
+ ?postfix_expr: primary (call_suffix | index_suffix | field_suffix | deref_suffix)*
401
+ call_suffix: "(" arg_list? ")"
402
+ index_suffix: "[" expr_list "]"
403
+ field_suffix: "." (NAME | GENERIC_NAME | ADD | REMOVE | READ | WRITE | DEFAULT | STORED | INDEX | MESSAGE | DISPID | ABSOLUTE)
404
+ deref_suffix: "^"
405
+ arg_list: argument ("," argument)*
406
+ argument: named_formatted_argument | formatted_argument | NAME ":" expr | NAME ASSIGN expr | expr
407
+ named_formatted_argument: NAME ":" expr ":" expr
408
+ formatted_argument: expr ":" expr (":" expr)?
409
+
410
+ ?primary: literal
411
+ | expr_qualified_name
412
+ | set_const
413
+ | anonymous_method
414
+ | inherited_expr
415
+ | "(" expr ")"
416
+ | NIL
417
+ | TRUE
418
+ | FALSE
419
+ | SELF
420
+
421
+ inherited_expr: INHERITED postfix_expr?
422
+ anonymous_method: (PROCEDURE formal_parameters? | FUNCTION formal_parameters? ":" type_spec) block
423
+
424
+ literal: string_literal_sequence | numeric_literal
425
+ string_literal_sequence: string_literal_part+
426
+ string_literal_part: STRING_BLOCK5 | STRING_BLOCK3 | STRING_LITERAL | CHAR_CODE | POINTER_CHAR
427
+ numeric_literal: FLOAT | HEX_INT | BIN_INT | INT
428
+
429
+ expr_qualified_name: expr_identifier ("." expr_identifier)*
430
+ expr_identifier: NAME | GENERIC_NAME | SPACED_GENERIC_NAME
431
+ | ADD | REMOVE | READ | WRITE | DEFAULT | STORED | INDEX | MESSAGE | DISPID | ABSOLUTE
432
+
433
+ qualified_name: qualified_name_part ("." qualified_name_part)*
434
+ qualified_name_part: NAME | GENERIC_NAME
435
+
436
+ ?range_expr: range_add
437
+ ?range_add: range_mul (range_add_op range_mul)* -> add_expr
438
+ range_add_op: "+" -> op_add
439
+ | "-" -> op_sub
440
+ ?range_mul: range_unary (range_mul_op range_unary)* -> mul_expr
441
+ range_mul_op: "*" -> op_mul
442
+ | "/" -> op_fdiv
443
+ | DIV -> op_div
444
+ | MOD -> op_mod
445
+ | SHL -> op_shl
446
+ | SHR -> op_shr
447
+ ?range_unary: ("+"|"-") range_unary -> unary_expr
448
+ | range_postfix
449
+ range_postfix: range_primary range_call_suffix*
450
+ range_call_suffix: "(" range_arg_list? ")"
451
+ range_arg_list: range_expr ("," range_expr)*
452
+ range_primary: literal | qualified_name | "(" range_expr ")"
453
+
454
+ ASSIGN: ":="
455
+ '''
456
+
457
+
458
+ def build_grammar() -> str:
459
+ return build_grammar_snippet() + '\n' + GRAMMAR_RULES