-
-
Notifications
You must be signed in to change notification settings - Fork 290
Meaningful repr for ParserElements #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
A couple of notes: - Populated instances of Forward are represented only as "Forward(...)" to prevent infinite recursion. - Helper classes like _PendingSkip and _ErrorStop are not yet handled.
Codecov Report
@@ Coverage Diff @@
## master #423 +/- ##
==========================================
+ Coverage 89.67% 89.72% +0.05%
==========================================
Files 11 11
Lines 4028 4157 +129
Branches 1013 1043 +30
==========================================
+ Hits 3612 3730 +118
- Misses 217 223 +6
- Partials 199 204 +5
Continue to review full report at Codecov.
|
@@ -2299,7 +2301,7 @@ def must_skip(t): | |||
def show_skip(t): | |||
if t._skipped.as_list()[-1:] == [""]: | |||
t.pop("_skipped") | |||
t["_skipped"] = "missing <" + repr(self.anchor) + ">" | |||
t["_skipped"] = f"missing <{self.anchor}>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used to show repr(self.anchor)
- should change to {self.anchor!r}
"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was so that an existing unit test would pass. I'm still hazy on the what/why of SkipTo
in this context - should the test be changed instead?
Does this make the railroad diagrams better? worse? |
If you are using features (such as typing annotations) not yet available until Py 3.7, I'll be dropping Py3.6 support in pyparsing 3.1, but this won't be for a few months yet. |
Looks like railroad diagrams must use IIRC everything worked fine with |
Introduces a _make_repr() method with parameters to account for the different contexts in which an element may need to be represented (top level or as a term in an expression, as a potential string literal or not). In order to make the code a little easier to read, the __format__() method is implemented as well, with conversion specifiers used to indicate the context.
This function determines how to represent a set of characters using srange(), then returns either the original set or the srange expression, whichever is shorter. To be used in repr() implementations in elements, such as Word, which are based on sets of characters.
Let's close this PR, and start fresh from the current state of things if you are still interested. Thanks a bunch for your contributions so far!!! |
See #416 for discussion.
Populated instances of
Forward
are represented only as"Forward(...)"
to prevent infinite recursion. I don't imagine this changing.Helper classes like
_PendingSkip
and_ErrorStop
are not yet handled, and there is no special handling forLiteral
. I'll ask about these in the issue.I held off on creating unit tests for the new implementations to let the devs decide whether
__repr__()
actually belongs in the test suite or not.