-
Notifications
You must be signed in to change notification settings - Fork 5
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
Refactor: separate parsing and output generation via events #11
Comments
For the typed API also:
|
I glanced over quick-xml's event API, since it was mentioned in pest-parser/pest#885 (reply in thread), and it looks nice ! A question I have is what kind of events are intended for user to have ? I'll now try to see if there can be ambiguity with that choice from the event listener.
When parsing A thing I noticed in quick-xml is that for rules that are nested there is a
isolated events would be fired, named
would fire a sequence similar to " But what about a recursive rule like:
Here applying the previous suggestion looks horrible to me. Also the behaviour is not well defined since the rule has some times element nesting in it and others not. I will continue this analysis/questions about what decisions have been made later. |
Yes, it's the closest to what I had in mind. There's also PEGTL: which looks interesting, but it's a bit different.
Probably rule-level events if the rule matched (but I guess for a debugger etc., it'd probably need other events)
Those weren't sure whether to include them, but some thoughts:
I guess for unlabelled choice branches, the event could include the branch index?
Why does it look horrible? In XML, one may also have nested recursive tags and the events will be fired in that order (I think?). Anyway, this is all open to discussion and implementation on what would make most sense (I haven't thought in detail about it, quick-xml-like API looked like it could work, but there may be instances where it's not nice which didn't occur to me). |
Reading their Getting Started page it looks like they have a tracer, which could be similar to events. But I don't remember enough about C++ to understand what is going on in there.
Agree. Maybe make a low-level tracer for debugging like in PEGTL. Maybe even such a tracer could be the main event generator. I don't think an event generator needs to handle multiple listeners at the same time, so usage could look like: // For regular user:
for event in event_generator.clone() {
...
}
// For low level stuff:
for event in event_generator.clone().low_level() {
...
}
// For a step by step VM
let event = event_generator.next()
let low_level = event_generator.new_low_level() Doing things this way would basically turn the parser in to an iterable pest-VM. The regular iteration yielding highlevel events, and the low level iteration yielding more details like every attempt/failure.
I am not sure about that. Indeed it would be useful to add such tags for generating events, but maybe if the event system is done right they will be just boiler plate ? the examples given by oovm show tags indicating the start/end of rules (from what I understood, I maybe wrong). I hope pest users won't need to add those things.
Rewriting that rule like that:
is horrible because to the listener of things it will look like;
It would be nicer if it looked like:
How to get there ? I don't know 😅. Would it be worth that I try now experimenting with a low level "tracer" ? From there, if it went well, it would be possible to experiment with higher level events. |
@Tartasprint @TheVeryDarkness one possible alternative output format would be to process parsing into cstree -- so that could be one potential concrete use case to motivate this refactoring that one could choose between the outputting the current typed API and cstree. @Tartasprint for that event "separation" vs "separated", maybe it could pass some kind of call depth/trace? |
pest-parser/pest#885 (reply in thread)
The text was updated successfully, but these errors were encountered: