Skip to content
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

[Feature Request] Add Expression name to wanted when parsing error occured #69

Open
F4ncyMooN opened this issue Jul 12, 2018 · 4 comments

Comments

@F4ncyMooN
Copy link

When I use pigeon, parsing error information is very important to me.

Metric "METRIC" = left:ValidString+ "::" right:ValidString+ {
// some code...
return metric, nil
}

ValidString = ':'? [a-zA-Z0-9_.-]+ {
return string(c.text), nil
}

For my use case, when I type something not correct, I want to get the expression name "METRIC". And then I will give a metric list to user. The metric list is about to change all the time so it can't be added to peg file.
The generated program will give detailed literal options in the expected list. But I want the optional expression name when parsing error occured.

Thanks in advance.

@breml
Copy link
Collaborator

breml commented Jul 12, 2018

@F4ncyMooN Thanks for your feature request. At the moment I feel like all the necessary possibilities to achieve your goal are already present in pigeon grammar.

Have you read the section about error reporting on godoc? Additionally there is also the concept of labeled failures, which is described in the documentation as well (at the end of this section).
With these mechanics it is possible to return custom error messages, which then may include the information you prefer. So I suggest, you have a look at these possibilities.

@F4ncyMooN
Copy link
Author

I tried the labeled failure, but it seems only error message could be customized. What I want is to customize the expected field in parserError.

For example,

ValidString "METRIC" = ':'? [a-zA-Z0-9_.-]+ 

When parse ValidString failed, pigeon will recover and throw an error with expected:[":", [a-zA-Z0-9_.-]], digging into the code, only litMatcher' val field will be written in the expected area. Maybe putting METRIC into the expected is more understandable and convenient for users.

Thanks for your kindly reply.

@breml
Copy link
Collaborator

breml commented Jul 29, 2018

@F4ncyMooN I am currently on vacation. I will have a look when I am back.

@breml
Copy link
Collaborator

breml commented Aug 8, 2018

@F4ncyMooN Are you willing to provide a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants