Skip to content

Conversation

@hukkin
Copy link
Contributor

@hukkin hukkin commented Feb 28, 2021

Based on #131

  • Always use __init__ as constructor, remove from_tokens
  • Allow constructing trees that don't have a document root, using an inline token or nested tokens as input.
@codecov
Copy link

codecov bot commented Feb 28, 2021

Codecov Report

Merging #132 (c44f026) into master (ab287be) will decrease coverage by 0.06%.
The diff coverage is 87.50%.

Impacted file tree graph

@@ 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 
Flag Coverage Δ
pytests 96.38% <87.50%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
markdown_it/tree.py 92.98% <87.50%> (-1.14%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab287be...c44f026. Read the comment docs.

@chrisjsewell
Copy link
Member

note this will aslo require a change to the documentation: https://markdown-it-py.readthedocs.io/en/latest/using.html#creating-a-syntax-tree

@hukkin
Copy link
Contributor Author

hukkin commented Mar 4, 2021

Fixed the from_tokens reference in docs.

@chrisjsewell
Copy link
Member

chrisjsewell commented Mar 10, 2021

@hukkinj1 can you resolve the conflicts cheers

@hukkin
Copy link
Contributor Author

hukkin commented Mar 10, 2021

👍 Merged master

Copy link
Member

@chrisjsewell chrisjsewell left a 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")
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

@chrisjsewell chrisjsewell Mar 12, 2021

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]}")
Copy link
Member

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

@chrisjsewell chrisjsewell merged commit 00a28a6 into executablebooks:master Mar 12, 2021
@hukkin hukkin deleted the tree-init branch March 16, 2021 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants