question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"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:open
  • Created 4 years ago
  • Comments:25 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Seb35commented, Apr 3, 2020

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

pegjs.generate( grammar, { unexpected: "unrecognised_token" } )
1reaction
log4b0atcommented, Feb 5, 2020

Use a tokenizer has a cost. such feature is simple to implement and cost nothing to nobody

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found