-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
AST validation #425
AST validation #425
Conversation
I think there's quite a few places in the new |
After that, I think you'll find most checks raised by the tests are of the The |
Oh, right. I started with a recursive function but it blew the stack and there's a specific test case to avoid that, so I switched to an iterative version which introduced |
It seems that a few dozen remaining tests still don't pass. Most of them have a What do you think? Should we relax |
For the record, failing tests are:
|
Nice, thank you so much! Of the remaining, some of them are legit (like |
Sure! |
Thanks! The spoiler ones were particularly fun: half of the issues raised were legit, but half unearthed a weirdness in what gets added to the AST when a spoiler doesn't fully match. I've left a hack in |
This commit adds a `validate()` method to check that AST are well-formed. This can be useful when generating ASTs programmatically, where it's possible to violate the markdown specification, leading to invalid output if rendered. Additionally, this validation is done automatically when formatting an AST in debug mode.
17a0ca6
to
7460a2f
Compare
I did a bit of clean up, and simplified further the validation function: the first test that some nodes don't have children at all was superfluous, because it's also subsumed by It's good to go on my end 🙂 |
Really clean now. Thank you so much! |
This just unearthed some AST mistakes I was making! Thanks again! :) |
This draft PR implements a simple validation procedure for CommonMark ASTs, following the discussions in #371. The idea is to perform the additional checks that the nature of a block and the nature of its children (or the absence thereof) match, which isn't currently possible to enforce (or at least not in a agreable way) using static types.
@kivikakk The logic is pretty simple, but the tests seem to loop forever, so it sounds like there's an infinite loop somewhere. However the function is a pretty dumb tree traversal, so I wonder if I'm missing something (like
children()
is actually returning descendants, but given the API and the existence ofdescendants()
, this doesn't seem to be the case).