Closed siy closed 3 years ago
@siy, thanks for the feedback. I probably don't fully understand what you actually want to do. Could you send me a pull request for the feature? The start rule name is kept in start_
in class parser
. If you can manage it properly, it may be possible to start parsing from some rules rather than the first specified rule in a given grammar. I am not 100% sure that it can be really possible though, it would be nice to give it a try. Thanks!
The use case can be modelled, for example, using PL/0 grammar. Let's imagine that we have loaded and parsed some PL/0 source file and showing it in the editor. Then the user modifies some code inside a nested BEGIN - END block somewhere deep inside the PROCEDURE. To parse changed code we need either parse everything from scratch using full grammar or find the outer rule (in this case it will be 'statements' rule) and parse code only inside the modified BEGIN - END block.
I'll definitely try to experiment with this and if my experiments will be successful, I'll submit a PR.
@siy, do you think if the following change is enough for what you are trying to do?
class parser {
public:
...
void set_start_rule(std::string_view rule) {
start_ = rule;
}
@siy, I'll close it for now since I am not planning to implement this feature.
Sometimes it's necessary to reparse input from given point. For example this happens in interactive apps which analyse input as user types it. If whole input is rather big, then parsing from scratch could be too time consuming. Instead it's possible to find nearest outer node in AST and reparse only changed part of the input. For this use case it would be convenient to restart parsing from the given rule.