- Notifications
You must be signed in to change notification settings - Fork 84
👌 IMPROVE: Use regular __init__ to create SyntaxTreeNodes #132
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
Codecov Report
@@ Coverage Diff @@ ## master #132 +/- ## ========================================== - Coverage 96.44% 96.38% -0.07% ========================================== Files 72 72 Lines 3204 3205 +1 ========================================== - Hits 3090 3089 -1 - Misses 114 116 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| note this will aslo require a change to the documentation: https://markdown-it-py.readthedocs.io/en/latest/using.html#creating-a-syntax-tree |
| Fixed the |
| @hukkinj1 can you resolve the conflicts cheers |
| 👍 Merged master |
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.
just a few minor suggestions
| | ||
| assert token.nesting == 1 | ||
| if token.nesting != 1: | ||
| raise ValueError("Invalid token nesting") |
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.
it would be nice here to identify where in the token stream the issue is.
Maybe at the start of this function set length = len(tokens), then here do index = length - len(reversed_tokens) and add this to the exception message
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.
Note that due to the nested nature of the tree, there's a very good chance tokens won't be the same stream that the programmer input to SyntaxTreeNode init but rather a nested sub-stream. In this case showing the index could potentially be more confusing than helpful. I'm also a bit hesitant to add logic just for the sake of an exception message that, in software working expectedly, should never be raised.
Can add this if you still think its a good idea.
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.
ah yeh fair I think, if only for myst-parser, I want to have a new exception (i.e. that inherits from ValueError) that stores the token, so I can report maybe the line number (from token.map) or whole token, but I can add that in a separate PR
| nesting += token.nesting | ||
| if nesting != 0: | ||
| if nesting: | ||
| raise ValueError(f"unclosed tokens starting {nested_tokens[0]}") |
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.
maybe same here as above for noting the index of the problematic token in the token stream
Based on #131
__init__as constructor, removefrom_tokens