jcmsuite-data-tree 1.0.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.
- jcmsuite_data_tree/__init__.py +91 -0
- jcmsuite_data_tree/_build_info.py +4 -0
- jcmsuite_data_tree/compat_runtime/__init__.py +10 -0
- jcmsuite_data_tree/compat_runtime/tree_writer.py +53 -0
- jcmsuite_data_tree/data_branch.py +366 -0
- jcmsuite_data_tree/data_primitives.py +1060 -0
- jcmsuite_data_tree/data_tree_exceptions.py +196 -0
- jcmsuite_data_tree/decorators.py +40 -0
- jcmsuite_data_tree/facade.py +91 -0
- jcmsuite_data_tree/parser.py +1045 -0
- jcmsuite_data_tree/py.typed +0 -0
- jcmsuite_data_tree/schema_primitives.py +989 -0
- jcmsuite_data_tree/schema_tree.py +369 -0
- jcmsuite_data_tree/system.py +102 -0
- jcmsuite_data_tree/toolbox.py +322 -0
- jcmsuite_data_tree-1.0.0.dist-info/METADATA +61 -0
- jcmsuite_data_tree-1.0.0.dist-info/RECORD +18 -0
- jcmsuite_data_tree-1.0.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Exceptions raised while parsing and validating data-tree files."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from typing import Protocol
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ReaderWithPosition(Protocol):
|
|
12
|
+
"""Reader interface required to report file and line information."""
|
|
13
|
+
|
|
14
|
+
def FileName(self) -> str: ...
|
|
15
|
+
def ReportPosition(self) -> tuple[str, int, int]: ...
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class ParseTreeError(RuntimeError):
|
|
19
|
+
"""Base exception carrying source-position details for parse failures."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, s: str, reader: ReaderWithPosition | None) -> None:
|
|
22
|
+
"""Capture parser context and format a diagnostic message."""
|
|
23
|
+
|
|
24
|
+
if reader is None:
|
|
25
|
+
self.filename = "NULL"
|
|
26
|
+
self.lineContent = "NULL"
|
|
27
|
+
self.lineNumber = 0
|
|
28
|
+
self.columnNumber = 0
|
|
29
|
+
else:
|
|
30
|
+
self.filename = reader.FileName()
|
|
31
|
+
self.lineContent, self.lineNumber, self.columnNumber = (
|
|
32
|
+
reader.ReportPosition()
|
|
33
|
+
)
|
|
34
|
+
self.errmessage = s
|
|
35
|
+
self.message = 'File "%s", line: %d, column: %d\n>>> %s\n' % (
|
|
36
|
+
self.filename,
|
|
37
|
+
self.lineNumber,
|
|
38
|
+
self.columnNumber,
|
|
39
|
+
self.lineContent,
|
|
40
|
+
)
|
|
41
|
+
self.message += s
|
|
42
|
+
|
|
43
|
+
def __str__(self) -> str:
|
|
44
|
+
"""Return the formatted parse error message."""
|
|
45
|
+
|
|
46
|
+
return self.message
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class InvalidObjectName(ParseTreeError):
|
|
50
|
+
"""Raised when a parsed object name differs from the expected name."""
|
|
51
|
+
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
reader: ReaderWithPosition | None,
|
|
55
|
+
readObjectName: str,
|
|
56
|
+
expectedObjectName: str,
|
|
57
|
+
) -> None:
|
|
58
|
+
"""Build an error that reports the mismatched object names."""
|
|
59
|
+
|
|
60
|
+
additional_info = 'expected: "%s", read: "%s".' % (
|
|
61
|
+
expectedObjectName,
|
|
62
|
+
readObjectName,
|
|
63
|
+
)
|
|
64
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class MissingDirOpenBracket(ParseTreeError):
|
|
68
|
+
"""Raised when a directory section is missing its opening brace."""
|
|
69
|
+
|
|
70
|
+
def __init__(self, reader: ReaderWithPosition | None) -> None:
|
|
71
|
+
"""Build an error for a missing directory opening brace."""
|
|
72
|
+
|
|
73
|
+
additional_info = 'Missing "}".'
|
|
74
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class MissingStringOpenQuotMark(ParseTreeError):
|
|
78
|
+
"""Raised when a quoted string is missing its opening quote."""
|
|
79
|
+
|
|
80
|
+
def __init__(self, reader: ReaderWithPosition | None) -> None:
|
|
81
|
+
"""Build an error for a missing opening quote mark."""
|
|
82
|
+
|
|
83
|
+
additional_info = "Missing opening '\"'."
|
|
84
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class MissingStringCloseQuotMark(ParseTreeError):
|
|
88
|
+
"""Raised when a quoted string is missing its closing quote."""
|
|
89
|
+
|
|
90
|
+
def __init__(self, reader: ReaderWithPosition | None) -> None:
|
|
91
|
+
"""Build an error for a missing closing quote mark."""
|
|
92
|
+
|
|
93
|
+
additional_info = "Missing closing '\"'."
|
|
94
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class MissingEqualSign(ParseTreeError):
|
|
98
|
+
"""Raised when a key/value assignment is missing an equals sign."""
|
|
99
|
+
|
|
100
|
+
def __init__(self, reader: ReaderWithPosition | None) -> None:
|
|
101
|
+
"""Build an error for a missing assignment operator."""
|
|
102
|
+
|
|
103
|
+
additional_info = 'Missing "=".'
|
|
104
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
class InvalidPrimitive(ParseTreeError):
|
|
108
|
+
"""Raised when primitive data cannot be parsed for its declared type."""
|
|
109
|
+
|
|
110
|
+
def __init__(
|
|
111
|
+
self, reader: ReaderWithPosition | None, primitiveTypeName: str
|
|
112
|
+
) -> None:
|
|
113
|
+
"""Build an error for an invalid primitive payload."""
|
|
114
|
+
|
|
115
|
+
additional_info = 'Invalid data of type "%s".' % (primitiveTypeName)
|
|
116
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
class PrimitiveOutOfRange(ParseTreeError):
|
|
120
|
+
"""Raised when primitive data violates its schema range."""
|
|
121
|
+
|
|
122
|
+
def __init__(self, reader: ReaderWithPosition | None) -> None:
|
|
123
|
+
"""Build an error for an out-of-range primitive value."""
|
|
124
|
+
|
|
125
|
+
additional_info = "Data out of range."
|
|
126
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class DataRedefinition(ParseTreeError):
|
|
130
|
+
"""Raised when the same data keyword is defined more than once."""
|
|
131
|
+
|
|
132
|
+
def __init__(self, reader: ReaderWithPosition | None, tokenName: str) -> None:
|
|
133
|
+
"""Build an error for duplicate keyword definitions."""
|
|
134
|
+
|
|
135
|
+
additional_info = 'Wrong keyword: "%s".' % (tokenName)
|
|
136
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class UnknownKeyword(ParseTreeError):
|
|
140
|
+
"""Raised when input contains a keyword unknown to the schema."""
|
|
141
|
+
|
|
142
|
+
def __init__(self, reader: ReaderWithPosition | None, tokenName: str) -> None:
|
|
143
|
+
"""Build an error for an unknown keyword token."""
|
|
144
|
+
|
|
145
|
+
additional_info = 'Wrong keyword: "%s".' % (tokenName)
|
|
146
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class MissingDefault(ParseTreeError):
|
|
150
|
+
"""Raised when a required default value is not available."""
|
|
151
|
+
|
|
152
|
+
def __init__(self, reader: ReaderWithPosition | None, tokenName: str) -> None:
|
|
153
|
+
"""Build an error for a missing default value."""
|
|
154
|
+
|
|
155
|
+
additional_info = 'No default value set for "%s".' % (tokenName)
|
|
156
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class MissingDefaultSonDir(ParseTreeError):
|
|
160
|
+
"""Raised when no default choice directory is defined."""
|
|
161
|
+
|
|
162
|
+
def __init__(self, reader: ReaderWithPosition | None) -> None:
|
|
163
|
+
"""Build an error for a missing default child directory."""
|
|
164
|
+
|
|
165
|
+
additional_info = "No default son set."
|
|
166
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
class ExclusionError(ParseTreeError):
|
|
170
|
+
"""Raised when two mutually exclusive schema items are both present."""
|
|
171
|
+
|
|
172
|
+
def __init__(
|
|
173
|
+
self,
|
|
174
|
+
reader: ReaderWithPosition | None,
|
|
175
|
+
tokenName: str,
|
|
176
|
+
presentTokenName: str,
|
|
177
|
+
) -> None:
|
|
178
|
+
"""Build an error for an exclusion-rule violation."""
|
|
179
|
+
|
|
180
|
+
additional_info = '"%s" excludes "%s".' % (tokenName, presentTokenName)
|
|
181
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class InclusionError(ParseTreeError):
|
|
185
|
+
"""Raised when a required companion schema item is missing."""
|
|
186
|
+
|
|
187
|
+
def __init__(
|
|
188
|
+
self,
|
|
189
|
+
reader: ReaderWithPosition | None,
|
|
190
|
+
tokenName: str,
|
|
191
|
+
presentTokenName: str,
|
|
192
|
+
) -> None:
|
|
193
|
+
"""Build an error for an inclusion-rule violation."""
|
|
194
|
+
|
|
195
|
+
additional_info = '"%s" requires "%s".' % (tokenName, presentTokenName)
|
|
196
|
+
ParseTreeError.__init__(self, additional_info, reader)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Decorator helpers used by the data-tree modules."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from functools import wraps
|
|
10
|
+
from typing import Any, TypeVar, cast
|
|
11
|
+
|
|
12
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def accepts(*args: object, **kwargs: object) -> Callable[[F], F]:
|
|
16
|
+
"""Return a no-op compatibility decorator."""
|
|
17
|
+
|
|
18
|
+
def decorator(function: F) -> F:
|
|
19
|
+
return function
|
|
20
|
+
|
|
21
|
+
return decorator
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def returns(*args: object, **kwargs: object) -> Callable[[F], F]:
|
|
25
|
+
"""Return a no-op compatibility decorator."""
|
|
26
|
+
|
|
27
|
+
def decorator(function: F) -> F:
|
|
28
|
+
return function
|
|
29
|
+
|
|
30
|
+
return decorator
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def cached(function: F) -> F:
|
|
34
|
+
"""Return a no-op cache decorator wrapper."""
|
|
35
|
+
|
|
36
|
+
@wraps(function)
|
|
37
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
38
|
+
return function(*args, **kwargs)
|
|
39
|
+
|
|
40
|
+
return cast(F, wrapper)
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT
|
|
2
|
+
# Copyright (c) 2001-2026 JCMwave GmbH
|
|
3
|
+
|
|
4
|
+
"""Typed facade helpers over the data-tree modules."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from collections.abc import Iterable
|
|
9
|
+
|
|
10
|
+
from . import data_branch, schema_tree
|
|
11
|
+
from .compat_runtime import write_tree_dir
|
|
12
|
+
|
|
13
|
+
DirSchema = schema_tree.DirSchema
|
|
14
|
+
TreeDir = data_branch.TreeDir
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def create_dir_schema(
|
|
18
|
+
name: str,
|
|
19
|
+
*,
|
|
20
|
+
father: DirSchema | None = None,
|
|
21
|
+
alias_names: Iterable[str] = (),
|
|
22
|
+
) -> DirSchema:
|
|
23
|
+
"""Create a schema directory.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
name : str
|
|
28
|
+
Schema node name.
|
|
29
|
+
father : DirSchema | None, optional
|
|
30
|
+
Optional parent schema node.
|
|
31
|
+
alias_names : Iterable[str], optional
|
|
32
|
+
Alias names for compatibility lookups.
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
-------
|
|
36
|
+
DirSchema
|
|
37
|
+
Newly created schema directory.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
alias_name_set: set[str] = set(alias_names)
|
|
41
|
+
created = schema_tree.DirSchema.Create(
|
|
42
|
+
father=father, name=name, aliasNames=alias_name_set
|
|
43
|
+
)
|
|
44
|
+
return created
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def create_tree_dir(
|
|
48
|
+
name: str = "",
|
|
49
|
+
*,
|
|
50
|
+
father: TreeDir | None = None,
|
|
51
|
+
branch_dir: TreeDir | None = None,
|
|
52
|
+
) -> TreeDir:
|
|
53
|
+
"""Create a runtime tree directory.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
name : str, optional
|
|
58
|
+
Directory name.
|
|
59
|
+
father : TreeDir | None, optional
|
|
60
|
+
Optional parent runtime tree node.
|
|
61
|
+
branch_dir : TreeDir | None, optional
|
|
62
|
+
Optional branch template copied by compatibility constructor.
|
|
63
|
+
|
|
64
|
+
Returns
|
|
65
|
+
-------
|
|
66
|
+
TreeDir
|
|
67
|
+
Newly created runtime tree directory.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
created = data_branch.TreeDir.Create(name, father, branch_dir)
|
|
71
|
+
return created
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def serialize_tree_dir(tree_dir: TreeDir, *, indentation: int = 0) -> str:
|
|
75
|
+
"""Serialize a runtime tree directory to text.
|
|
76
|
+
|
|
77
|
+
Parameters
|
|
78
|
+
----------
|
|
79
|
+
tree_dir : TreeDir
|
|
80
|
+
Runtime tree node to serialize.
|
|
81
|
+
indentation : int, optional
|
|
82
|
+
Initial indentation level.
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
str
|
|
87
|
+
Serialized tree representation.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
serialized = write_tree_dir(tree_dir, indentation=indentation)
|
|
91
|
+
return serialized
|