Closed syyyr closed 5 years ago
I am sorry, but it is not clear for me what is the question. This is the issue tracker (primary for bug reports), please be specific about your problem. For general discussions it is better to use spirit mail list or stack overflow.
The idea behind the on_success handler is, that I don't know what files are there in the filesystem, so I use the
x3::alpha
parser to parse anything, that could be a valid path fragment and then I use the handler to check whether that path really exists with the help of context_path and checkPath and then either failing the parser
You cannot fail parser that already succeeded, but you can attach a semantic action that will fail parsing depends on a result of a parser it was attached to.
or pushing the path fragment into context_path. Now let's say I want to implement some of sort of auto-completion for my program. Now, I would like to use Spirit to parse this string and tell me which rule was the first to fail parsing.
You should check out tutorials, there is one on an error handling topic. Googling the auto-completion topic should have been led you to a great answer by @sehesnips on stack overflow (it is for Qi, but should be possible to implement the same for X3 without huge changes).
For example, the user types in "ls directory/another_dir/nonexistent_dir" and the parsing stops just before the last slash (because I would artificially fail the rule because of the nonexistent directory) and the first failed rule would be the name rule.
I do not see why you want to perform such validation/autocompletion (you mentioned both of them in your question) inside a parser. I would suggest you not to mix an app logic with parsing, separating responsibilities will save you a lot of maintenance time.
I am closing this because there was no response for a long time and it is not a bug report.
Hello, I'm trying to create an interactive shell with the help of Spirit X3. Let's say I want to create a parser for the "ls" command:
The idea behind the on_success handler is, that I don't know what files are there in the filesystem, so I use the
x3::alpha
parser to parse anything, that could be a valid path fragment and then I use the handler to check whether that path really exists with the help ofcontext_path
andcheckPath
and then either failing the parser or pushing the path fragment intocontext_path
. Now let's say I want to implement some of sort of auto-completion for my program. Now, I would like to use Spirit to parse this string and tell me which rule was the first to fail parsing. For example, the user types in "ls directory/another_dir/nonexistent_dir" and the parsing stops just before the last slash (because I would artificially fail the rule because of the nonexistent directory) and the first failed rule would be thename
rule.