dbrownell-parserlib 0.8.0__tar.gz → 0.8.1__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.
Files changed (16) hide show
  1. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/PKG-INFO +1 -1
  2. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/pyproject.toml +1 -1
  3. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/antlr/antlr_parser.py +5 -0
  4. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/antlr/antlr_visitor_mixins.py +35 -8
  5. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/expression.py +1 -1
  6. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/README.md +0 -0
  7. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/__init__.py +0 -0
  8. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/antlr/__init__.py +0 -0
  9. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/antlr/build_antlr_grammar/__init__.py +0 -0
  10. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/antlr/build_antlr_grammar/antlr-4.13.2-complete.jar +0 -0
  11. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/errors.py +0 -0
  12. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/location.py +0 -0
  13. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/py.typed +0 -0
  14. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/region.py +0 -0
  15. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/terminal_expression.py +0 -0
  16. {dbrownell_parserlib-0.8.0 → dbrownell_parserlib-0.8.1}/src/dbrownell_ParserLib/visitors.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dbrownell-parserlib
3
- Version: 0.8.0
3
+ Version: 0.8.1
4
4
  Summary: Functionality useful when creating parsers.
5
5
  Author: Dave Brownell
6
6
  Author-email: Dave Brownell <github@DavidBrownell.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dbrownell-parserlib"
3
- version = "0.8.0"
3
+ version = "0.8.1"
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:
@@ -479,6 +479,11 @@ class _ErrorListener(antlr4.DiagnosticErrorListener):
479
479
  msg: str,
480
480
  e: antlr4.RecognitionException | None,
481
481
  ) -> None:
482
+ if msg.startswith("report"):
483
+ # I don't think that these should be errors
484
+ assert e is None, e
485
+ return
486
+
482
487
  location = Location(line, column + 1)
483
488
  error = Error(msg, Region(self._source, location, location))
484
489
  ex = AntlrParserException(error)
@@ -73,21 +73,48 @@ class InsignificantWhitespaceAntlrVisitorMixin(AntlrVisitorMixinBase):
73
73
  @override
74
74
  def CreateRegion(
75
75
  self,
76
- ctx: antlr4.ParserRuleContext,
76
+ ctx: antlr4.ParserRuleContext | antlr4.TerminalNode,
77
77
  ) -> Region:
78
78
  """Create a `Region` from the given context."""
79
79
 
80
- start_token = ctx.start
81
- stop_token = ctx.stop
80
+ if isinstance(ctx, antlr4.ParserRuleContext):
81
+ start_token = ctx.start
82
+ stop_token = ctx.stop
83
+
84
+ if start_token is None or stop_token is None:
85
+ msg = "Context does not have start or stop token"
86
+ raise ValueError(msg)
87
+
88
+ start_line = start_token.line
89
+ start_col = start_token.column + 1
90
+ end_line = stop_token.line
91
+ end_col = stop_token.column + 1
92
+
93
+ if start_line == end_line:
94
+ end_col += len(stop_token.text)
95
+ else:
96
+ end_col += 1
97
+
98
+ elif isinstance(ctx, antlr4.TerminalNode):
99
+ token = cast(antlr4.Token, ctx.symbol) # ty: ignore[unresolved-attribute]
100
+
101
+ assert token.column is not None
102
+
103
+ start_line = token.line
104
+ start_col = token.column + 1
105
+ end_line = token.line
106
+ end_col = token.column + 1 + len(token.text)
107
+
108
+ else:
109
+ assert False, ctx # noqa: B011, PT015 # pragma: no cover
82
110
 
83
- if start_token is None or stop_token is None:
84
- msg = "Context does not have start or stop token"
85
- raise ValueError(msg)
111
+ assert start_line is not None
112
+ assert end_line is not None
86
113
 
87
114
  return Region(
88
115
  self.filename,
89
- Location(start_token.line, start_token.column),
90
- Location(stop_token.line, stop_token.column + len(stop_token.text)),
116
+ Location(start_line, start_col),
117
+ Location(end_line, end_col),
91
118
  )
92
119
 
93
120
 
@@ -202,7 +202,7 @@ class Expression:
202
202
  # | Protected Types
203
203
  # |
204
204
  # ----------------------------------------------------------------------
205
- _GenerateAcceptDetailsResultType = Generator[tuple[str, list[Self]]]
205
+ _GenerateAcceptDetailsResultType = Generator[tuple[str, Self]]
206
206
  _GetAcceptChildrenResultType = tuple[str, Iterable[Self]] | None
207
207
 
208
208
  # ----------------------------------------------------------------------