-
Notifications
You must be signed in to change notification settings - Fork 52
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
Allow the visitor to abort or cease recursion #30
Comments
To abort, throw an exception and catch it in a try/catch around parse. To cease recursion, we could add a return value on onObjectBegin and onArrayBegin. If you want to make a PR, I'm happy to take it. |
Just wondering, how would this work? Would returning, say, |
The object will be parsed, just the visitor won't get any callbacks for any of the properties of the object |
Alright, so as per my understanding, if at the start of an object I return Asking this as I'm actually currently trying to work on a PR to add this, and just want to make sure I understand things correctly. Thanks! |
Yes, correct. |
Alright, sorry that it's been quite a while - I've had to put this issue on the back burner for a bit due to a lack of time. However, here is a quick update -- I'm currently working on testing an implementation for this feature I've got, but it seems like my IDE is throwing out a strange error under Specifically, on both L90 and L93: node-jsonc-parser/src/test/json.test.ts Lines 90 to 93 in b6b34ba
Shouldn't In addition, in node-jsonc-parser/src/impl/parser.ts Lines 393 to 404 in b6b34ba
According to the function signature, these should return functions of type Sorry if all of this is a lot... Thanks, though! 😄 |
Yes, that's just to keep the code compact. Yes, |
Alright, I submitted a PR -- feel free to take a look! |
Update -- since the above PR #88 has been merged and the feature implemented into the next version, I believe we should be able to close this issue? |
Yes, thanks! |
I'm working on a code lens that should decorate npm scripts. For this, I'm parsing a JSON file, and only want the top level "scripts" key. I'm entirely uninterested in other properties, and once I have that I'm happy to abort parsing.
It'd be nice to be able to return a value from JSONVisitor methods which could indicate that we want to cease recursion on the current node, or abort parsing entirely.
The text was updated successfully, but these errors were encountered: