"unexpected" rule
See original GitHub issue- Feature Request:
Add “unexpected” rule to override standard error message.
unexpected =
keywords { return "Unexpected keyword "+text()+"."; }
/ expression { return "Unexpected expression «"+text()+"»."; }
/ lamdba_function { return "Unexpected lambda function."; } ;
To implement it just change peg$buildError by:
function peg$buildError() {
var expected = peg$expected[0];
var failPos = expected.pos;
// if "unexpected" rule exist this might throw the appropriate error.
if (typeof peg$parseunexpected !== 'undefined') {
// make peg$expect temporary unavailable, set the cursor position to the fail position
// next get the output of the rule, if it's a string, return it.
const tmp = peg$expect;
peg$expect = new Function();
peg$currPos = failPos;
const unexpected = peg$parseunexpected();
peg$expect = tmp;
if (typeof unexpected === 'string') {
const length = peg$currPos - failPos;
const location = failPos < input.length
? peg$computeLocation(failPos, failPos + length)
: peg$computeLocation(failPos, failPos);
return new peg$SyntaxError(unexpected, expected.variants, unexpected, location);
}
}
// else return standard error.
const unexpected = input.charAt(failPos);
const location = failPos < input.length
? peg$computeLocation(failPos, failPos + 1)
: peg$computeLocation(failPos, failPos);
return new peg$SyntaxError(
peg$SyntaxError.buildMessage(expected.variants, unexpected), expected.variants, unexpected, location);
}
Expected behavior: Improve error handling.
If it’s not ethical, is there anyone who can tell me how to create a plugin that would make the change? Thanks a lot
Issue Analytics
- State:
- Created 4 years ago
- Comments:25 (4 by maintainers)
Top Results From Across the Web
Unexpected rules using a conceptual distance based on fuzzy ...
This concept is based on the contradiction of the consequence of the rule and the consequence of belief. Given a rule A →...
Read more >Mining Unexpected Rules by Pushing User Dynamics
ABSTRACT. Unexpected rules are interesting because they are either pre- viously unknown or deviate from what prior user knowledge would suggest.
Read more >Snakemake 'Unexpected keyword ref in rule definition' - Biostar
I have tried the following script, and got this error: WorkflowError: Target rules may not contain wildcards. Please specify concrete files or a...
Read more >Unexpected Rule of Thirds (Unexpected Series) - Amazon.com
Mary has rushed to Sedona to be by Sarah's side after a car accident leaves John in a coma and the mess she...
Read more >css - Unexpected unknown at-rule "@tailwind" scss/at-rule-no ...
Does this help? rules: { 'at-rule-no-unknown': null, 'scss/at-rule-no-unknown': [ true, { 'ignoreAtRules': ['tailwind'] } ], }.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just some bikeshedding, but when such feature is implemented, it should be let to the user the choice of the rule to be defined as the “unexpected” rule, e.g. with
Use a tokenizer has a cost. such feature is simple to implement and cost nothing to nobody