1
- # mypy: disable-error-code="attr-defined,no-untyped-call,no-untyped-def, union-attr"
1
+ # mypy: disable-error-code="attr-defined,union-attr"
2
2
from typing import Optional , Union
3
3
4
4
from textx import TextXSyntaxError
30
30
)
31
31
32
32
33
- def get_textx_syntax_error_message (exception : TextXSyntaxError ):
33
+ def get_textx_syntax_error_message (exception : TextXSyntaxError ) -> str :
34
34
return f"SDoc markup error: { exception .context } ."
35
35
36
36
@@ -43,7 +43,7 @@ def __init__(
43
43
line : Optional [int ] = None ,
44
44
col : Optional [int ] = None ,
45
45
filename : Optional [str ] = None ,
46
- ):
46
+ ) -> None :
47
47
super ().__init__ (title , hint , line , col , filename )
48
48
self .title = title
49
49
self .hint = hint
@@ -53,7 +53,9 @@ def __init__(
53
53
self .file_path = filename
54
54
55
55
@staticmethod
56
- def unknown_node_type (node : SDocNode , path_to_sdoc_file : str ):
56
+ def unknown_node_type (
57
+ node : SDocNode , path_to_sdoc_file : str
58
+ ) -> "StrictDocSemanticError" :
57
59
return StrictDocSemanticError (
58
60
title = f"Invalid node type: { node .node_type } ." ,
59
61
hint = None ,
@@ -63,14 +65,63 @@ def unknown_node_type(node: SDocNode, path_to_sdoc_file: str):
63
65
filename = path_to_sdoc_file ,
64
66
)
65
67
68
+ @staticmethod
69
+ def composite_node_and_non_composite_element_mismatch (
70
+ node : SDocNode , path_to_sdoc_file : str
71
+ ) -> "StrictDocSemanticError" :
72
+ return StrictDocSemanticError (
73
+ title = f"The composite node's grammar element is declared as non-composite: [[{ node .node_type } ]]." ,
74
+ hint = (
75
+ "The composite node grammar element declaration must "
76
+ "have a 'PROPERTIES/IS_COMPOSITE: True' declaration."
77
+ ),
78
+ example = """\
79
+ [GRAMMAR]
80
+ ELEMENTS:
81
+ - TAG: NODE
82
+ PROPERTIES:
83
+ IS_COMPOSITE: True
84
+ FIELDS:
85
+ ...
86
+ """ ,
87
+ line = node .ng_line_start ,
88
+ col = node .ng_col_start ,
89
+ filename = path_to_sdoc_file ,
90
+ )
91
+
92
+ @staticmethod
93
+ def non_composite_node_and_composite_element_composite (
94
+ node : SDocNode , path_to_sdoc_file : str
95
+ ) -> "StrictDocSemanticError" :
96
+ return StrictDocSemanticError (
97
+ title = f"The non-composite node's grammar element is declared as composite: [[{ node .node_type } ]]." ,
98
+ hint = (
99
+ "The composite node grammar element declaration must "
100
+ "have a 'PROPERTIES/IS_COMPOSITE: False' declaration or the "
101
+ "PROPERTIES/IS_COMPOSITE can be simply omitted."
102
+ ),
103
+ example = """\
104
+ [GRAMMAR]
105
+ ELEMENTS:
106
+ - TAG: NODE
107
+ PROPERTIES:
108
+ IS_COMPOSITE: False
109
+ FIELDS:
110
+ ...
111
+ """ ,
112
+ line = node .ng_line_start ,
113
+ col = node .ng_col_start ,
114
+ filename = path_to_sdoc_file ,
115
+ )
116
+
66
117
@staticmethod
67
118
def unregistered_field (
68
119
* ,
69
120
field_name : str ,
70
121
requirement : SDocNode ,
71
122
document_grammar : DocumentGrammar ,
72
123
path_to_sdoc_file : str ,
73
- ):
124
+ ) -> "StrictDocSemanticError" :
74
125
grammar_dump = document_grammar .dump_fields (requirement .node_type )
75
126
return StrictDocSemanticError (
76
127
title = f"Invalid requirement field: { field_name } " ,
@@ -90,7 +141,7 @@ def missing_required_field(
90
141
grammar_field : GrammarElementField ,
91
142
document_grammar : DocumentGrammar ,
92
143
path_to_sdoc_file : str ,
93
- ):
144
+ ) -> "StrictDocSemanticError" :
94
145
grammar_fields = document_grammar .dump_fields (node .node_type )
95
146
return StrictDocSemanticError (
96
147
title = (
@@ -113,7 +164,7 @@ def unexpected_field_outside_grammar(
113
164
requirement_field : SDocNodeField ,
114
165
document_grammar : DocumentGrammar ,
115
166
path_to_sdoc_file : str ,
116
- ):
167
+ ) -> "StrictDocSemanticError" :
117
168
grammar_fields = document_grammar .dump_fields (node .node_type )
118
169
return StrictDocSemanticError (
119
170
title = (
@@ -136,7 +187,7 @@ def wrong_field_order(
136
187
document_grammar : DocumentGrammar ,
137
188
problematic_field : SDocNodeField ,
138
189
path_to_sdoc_file : str ,
139
- ):
190
+ ) -> "StrictDocSemanticError" :
140
191
assert isinstance (problematic_field , SDocNodeField ), (
141
192
f"{ problematic_field } "
142
193
)
@@ -161,7 +212,7 @@ def invalid_choice_field(
161
212
document_grammar : DocumentGrammar ,
162
213
requirement_field : SDocNodeField ,
163
214
path_to_sdoc_file : str ,
164
- ):
215
+ ) -> "StrictDocSemanticError" :
165
216
return StrictDocSemanticError (
166
217
title = (
167
218
f"Requirement field has an invalid SingleChoice value: "
@@ -187,7 +238,7 @@ def invalid_multiple_choice_field(
187
238
document_grammar : DocumentGrammar ,
188
239
requirement_field : SDocNodeField ,
189
240
path_to_sdoc_file : str ,
190
- ):
241
+ ) -> "StrictDocSemanticError" :
191
242
return StrictDocSemanticError (
192
243
title = (
193
244
f"Requirement field has an invalid MultipleChoice value: "
@@ -211,8 +262,8 @@ def invalid_multiple_choice_field(
211
262
def not_comma_separated_choices (
212
263
node : SDocNode ,
213
264
requirement_field : SDocNodeField ,
214
- path_to_sdoc_file ,
215
- ):
265
+ path_to_sdoc_file : str ,
266
+ ) -> "StrictDocSemanticError" :
216
267
return StrictDocSemanticError (
217
268
title = (
218
269
f"Requirement field of type MultipleChoice is invalid: "
@@ -230,7 +281,7 @@ def not_comma_separated_tag_field(
230
281
node : SDocNode ,
231
282
requirement_field : SDocNodeField ,
232
283
path_to_sdoc_file : str ,
233
- ):
284
+ ) -> "StrictDocSemanticError" :
234
285
return StrictDocSemanticError (
235
286
title = (
236
287
f"Requirement field of type Tag is invalid: "
@@ -248,7 +299,7 @@ def invalid_reference_type_item(
248
299
node : SDocNode ,
249
300
reference_item : Reference ,
250
301
path_to_sdoc_file : str ,
251
- ):
302
+ ) -> "StrictDocSemanticError" :
252
303
role_and_type = (
253
304
f"{ reference_item .ref_type } / { reference_item .role } "
254
305
if reference_item .role is not None
@@ -277,7 +328,7 @@ def invalid_marker_role(
277
328
ForwardRangeMarker ,
278
329
],
279
330
path_to_src_file : str ,
280
- ):
331
+ ) -> "StrictDocSemanticError" :
281
332
role_and_type = marker .role if marker .role is not None else "Any"
282
333
return StrictDocSemanticError (
283
334
title = (f"File marker role is not registered: { role_and_type } ." ),
@@ -294,7 +345,7 @@ def grammar_missing_reserved_statement(
294
345
path_to_sdoc_file : str ,
295
346
line : int ,
296
347
column : int ,
297
- ):
348
+ ) -> "StrictDocSemanticError" :
298
349
return StrictDocSemanticError (
299
350
title = (
300
351
f"Grammar element '{ grammar_element .tag } ' is missing a reserved"
@@ -318,7 +369,7 @@ def grammar_reserved_statement_must_be_required(
318
369
path_to_sdoc_file : str ,
319
370
line : int ,
320
371
column : int ,
321
- ):
372
+ ) -> "StrictDocSemanticError" :
322
373
return StrictDocSemanticError (
323
374
title = (
324
375
f"Grammar element '{ grammar_element .tag } 's { field_title } field "
@@ -339,7 +390,7 @@ def grammar_reserved_statement_must_be_required(
339
390
def grammar_element_has_no_mid_field (
340
391
grammar_element : GrammarElement ,
341
392
path_to_sdoc_file : str ,
342
- ):
393
+ ) -> "StrictDocSemanticError" :
343
394
return StrictDocSemanticError (
344
395
title = (
345
396
f"Grammar element '{ grammar_element .tag } ' is missing the MID field "
@@ -360,7 +411,7 @@ def view_references_nonexisting_grammar_element(
360
411
document_view : DocumentView ,
361
412
view_element : ViewElement ,
362
413
object_type : str ,
363
- ):
414
+ ) -> "StrictDocSemanticError" :
364
415
return StrictDocSemanticError (
365
416
title = (
366
417
f"View element '{ view_element .view_id } ' references a non-existing"
@@ -383,7 +434,7 @@ def view_references_nonexisting_field(
383
434
view_element : ViewElement ,
384
435
object_type : str ,
385
436
field_name : str ,
386
- ):
437
+ ) -> "StrictDocSemanticError" :
387
438
return StrictDocSemanticError (
388
439
title = (
389
440
f"View element '{ view_element .view_id } ' references a non-existing"
@@ -404,7 +455,7 @@ def default_view_doesnt_exist(
404
455
document : SDocDocument ,
405
456
document_config : DocumentConfig ,
406
457
default_view : str ,
407
- ):
458
+ ) -> "StrictDocSemanticError" :
408
459
filename = document .meta .input_doc_full_path
409
460
410
461
return StrictDocSemanticError (
0 commit comments