dbrownell-parserlib 0.10.0__tar.gz → 0.10.2__tar.gz
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.
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/PKG-INFO +1 -1
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/pyproject.toml +1 -1
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/expression.py +17 -23
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/multiline_strings.py +1 -1
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/visitors.py +6 -5
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/README.md +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/__init__.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/antlr/__init__.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/antlr/antlr_parser.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/antlr/antlr_visitor_mixins.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/antlr/build_antlr_grammar/__init__.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/antlr/build_antlr_grammar/antlr-4.13.2-complete.jar +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/errors.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/location.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/py.typed +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/region.py +0 -0
- {dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/terminal_expression.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "dbrownell-parserlib"
|
|
3
|
-
version = "0.10.
|
|
3
|
+
version = "0.10.2"
|
|
4
4
|
# ^^^^^
|
|
5
5
|
# Wheel names will be generated according to this value. Do not manually modify this value; instead
|
|
6
6
|
# update it according to committed changes by running this command from the root of the repository:
|
{dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/expression.py
RENAMED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
# noqa: D100
|
|
2
|
+
import weakref
|
|
3
|
+
|
|
2
4
|
from collections.abc import Generator, Iterable
|
|
3
5
|
from contextlib import contextmanager
|
|
4
6
|
from dataclasses import dataclass, field, fields, InitVar
|
|
@@ -9,8 +11,6 @@ from dbrownell_Common.Types import extension, override
|
|
|
9
11
|
from dbrownell_ParserLib.visitors import ExpressionVisitor, ExpressionVisitorHelper, VisitResult
|
|
10
12
|
|
|
11
13
|
if TYPE_CHECKING:
|
|
12
|
-
from collections.abc import Callable
|
|
13
|
-
|
|
14
14
|
from dbrownell_ParserLib.region import Region
|
|
15
15
|
|
|
16
16
|
|
|
@@ -27,13 +27,11 @@ class Expression:
|
|
|
27
27
|
region__: Region
|
|
28
28
|
finalize: InitVar[bool] = field(kw_only=True, default=True)
|
|
29
29
|
|
|
30
|
-
parent__: Expression | None = field(init=False)
|
|
30
|
+
parent__: weakref.ref[Expression] | None = field(init=False)
|
|
31
31
|
|
|
32
32
|
_unique_id: tuple[object, ...] | None = field(init=False)
|
|
33
33
|
_disabled: bool = field(init=False)
|
|
34
34
|
|
|
35
|
-
_finalize_func: Callable[[], None] = field(init=False)
|
|
36
|
-
|
|
37
35
|
# ----------------------------------------------------------------------
|
|
38
36
|
# |
|
|
39
37
|
# | Public Methods
|
|
@@ -48,18 +46,6 @@ class Expression:
|
|
|
48
46
|
self._unique_id = None
|
|
49
47
|
self._disabled = False
|
|
50
48
|
|
|
51
|
-
# ----------------------------------------------------------------------
|
|
52
|
-
def Finalize() -> None:
|
|
53
|
-
visitor = _UniqueIdVisitor(self)
|
|
54
|
-
|
|
55
|
-
self.Accept(visitor)
|
|
56
|
-
|
|
57
|
-
self._unique_id = visitor.unique_id
|
|
58
|
-
|
|
59
|
-
# ----------------------------------------------------------------------
|
|
60
|
-
|
|
61
|
-
self._finalize_func = Finalize
|
|
62
|
-
|
|
63
49
|
if finalize:
|
|
64
50
|
self._Finalize()
|
|
65
51
|
|
|
@@ -202,7 +188,7 @@ class Expression:
|
|
|
202
188
|
# | Protected Types
|
|
203
189
|
# |
|
|
204
190
|
# ----------------------------------------------------------------------
|
|
205
|
-
_GenerateAcceptDetailsResultType = Generator[tuple[str, Self]]
|
|
191
|
+
_GenerateAcceptDetailsResultType = Generator[tuple[str, Self | list[Self]]]
|
|
206
192
|
_GetAcceptChildrenResultType = tuple[str, Iterable[Self]] | None
|
|
207
193
|
|
|
208
194
|
# ----------------------------------------------------------------------
|
|
@@ -211,7 +197,11 @@ class Expression:
|
|
|
211
197
|
# |
|
|
212
198
|
# ----------------------------------------------------------------------
|
|
213
199
|
def _Finalize(self) -> None:
|
|
214
|
-
self
|
|
200
|
+
visitor = _FinalizeVisitor(self)
|
|
201
|
+
|
|
202
|
+
self.Accept(visitor)
|
|
203
|
+
|
|
204
|
+
self._unique_id = visitor.unique_id
|
|
215
205
|
|
|
216
206
|
# ----------------------------------------------------------------------
|
|
217
207
|
# |
|
|
@@ -222,7 +212,7 @@ class Expression:
|
|
|
222
212
|
def _GetTerminalUniqueId(self) -> tuple[object, ...]:
|
|
223
213
|
"""Get a unique identifier for this expression that doesn't include any of its children."""
|
|
224
214
|
|
|
225
|
-
msg = "This functionality should be implemented by a terminal expression (i.e. an expression that doesn't have any children)."
|
|
215
|
+
msg = f"This functionality should be implemented by a terminal expression (i.e. an expression that doesn't have any children or expression details) [{self.__class__.__name__}]"
|
|
226
216
|
raise Exception(msg)
|
|
227
217
|
|
|
228
218
|
# ----------------------------------------------------------------------
|
|
@@ -244,7 +234,9 @@ class Expression:
|
|
|
244
234
|
# | Private Types
|
|
245
235
|
# |
|
|
246
236
|
# ----------------------------------------------------------------------
|
|
247
|
-
class
|
|
237
|
+
class _FinalizeVisitor(ExpressionVisitorHelper):
|
|
238
|
+
"""Visitor that visits the children of an expression, but not anything below that; it sets the unique_id__ of the target expression and sets its children's parent attribute to the correct value."""
|
|
239
|
+
|
|
248
240
|
# ----------------------------------------------------------------------
|
|
249
241
|
def __init__(
|
|
250
242
|
self,
|
|
@@ -268,6 +260,7 @@ class _UniqueIdVisitor(ExpressionVisitorHelper):
|
|
|
268
260
|
self,
|
|
269
261
|
expression: Expression,
|
|
270
262
|
) -> Generator[VisitResult]:
|
|
263
|
+
# This code will visit the children of the target expression, but not anything below that.
|
|
271
264
|
if expression is self._target_expression:
|
|
272
265
|
yield VisitResult.Continue
|
|
273
266
|
|
|
@@ -281,8 +274,9 @@ class _UniqueIdVisitor(ExpressionVisitorHelper):
|
|
|
281
274
|
|
|
282
275
|
return
|
|
283
276
|
|
|
277
|
+
expression.parent__ = weakref.ref(self._target_expression)
|
|
278
|
+
|
|
284
279
|
self._child_unique_ids.append(expression.unique_id__)
|
|
285
280
|
|
|
286
|
-
# Do not parse the
|
|
287
|
-
# into account.
|
|
281
|
+
# Do not parse the grandchildren of the original target expression
|
|
288
282
|
yield VisitResult.SkipChildren
|
|
@@ -54,7 +54,7 @@ def ExtractMultilineString(
|
|
|
54
54
|
result = _CalcPrefixColumn(lines[-1], tab_size, None)
|
|
55
55
|
|
|
56
56
|
if result.column != opening_token_region.begin.column:
|
|
57
|
-
location = Location(opening_token_region.begin.line + len(lines)
|
|
57
|
+
location = Location(opening_token_region.begin.line + len(lines), result.column)
|
|
58
58
|
|
|
59
59
|
raise MisalignedMultilineStringError.CreateAsException(
|
|
60
60
|
Region(opening_token_region.filename, location, location)
|
{dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/visitors.py
RENAMED
|
@@ -122,12 +122,13 @@ class ExpressionVisitorHelper(ExpressionVisitor):
|
|
|
122
122
|
self,
|
|
123
123
|
method_name: str,
|
|
124
124
|
) -> object:
|
|
125
|
-
if method_name.
|
|
126
|
-
|
|
125
|
+
if method_name.startswith("On"):
|
|
126
|
+
index = method_name.find("__")
|
|
127
|
+
if index != -1 and not method_name.endswith("__"):
|
|
128
|
+
return types.MethodType(self.__class__._DefaultDetailMethod, self) # noqa: SLF001
|
|
127
129
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return types.MethodType(self.__class__._DefaultDetailMethod, self) # noqa: SLF001
|
|
130
|
+
if index == -1:
|
|
131
|
+
return self.__class__._DefaultExpressionMethod # noqa: SLF001
|
|
131
132
|
|
|
132
133
|
raise AttributeError(method_name)
|
|
133
134
|
|
|
File without changes
|
{dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/__init__.py
RENAMED
|
File without changes
|
{dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/antlr/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dbrownell_parserlib-0.10.0 → dbrownell_parserlib-0.10.2}/src/dbrownell_ParserLib/location.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|