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

Is it possible to also jump to definition on input error in the playground ? #226

Closed
mingodad opened this issue Jun 26, 2022 · 4 comments
Closed

Comments

@mingodad
Copy link
Contributor

Trying to develop/debug grammars using the playground would be easier if when there is an error in the input/source and we click the error message it also jumped to the definition/rule in the grammar.
If the parser knows the rule that failed somehow this info could be encoded in the error message to allow jump to it.

Attached is a grammar and input file that actually gives this error message on input:

39:29 syntax error, unexpected ';', expecting 'construct', 'static', 'destruct', 'set', 'operator'.

It seems clear that the failing rule is known due to the expecting list provided, so if that rule could also be shown on the grammar editor when clicking the error message that would be nice.

Maybe something like this pseudo code:

function generateErrorListHTML(errors) {
  let html = '<ul>';

  html += $.map(errors, function (x) {
    return '<li data-ln="' + x.ln + '" data-col="' + x.col + '" data-gln="' + xg.ln + '" data-gcol="' + xg.col + '"><span>' + x.ln + ':' + x.col + '</span> <span>' + escapeHtml(x.msg) + '</span></li>';
  }).join('');

  html += '<ul>';

  return html;
}
...
// Event handing in the info area
function makeOnClickInInfo(editor) {
  return function () {
    const el = $(this);
    editor.navigateTo(el.data('ln') - 1, el.data('col') - 1);
    editor.scrollToLine(el.data('ln') - 1, true, false, null);
    editor.focus();
    if(el.data('gln')) {
      grammar.navigateTo(el.data('gln') - 1, el.data('gcol') - 1);
      grammar.scrollToLine(el.data('gln') - 1, true, false, null);
    }
  }
};

jancy.peg.zip

@yhirose
Copy link
Owner

yhirose commented Jun 26, 2022

@mingodad, I think it's possible to make links for definition rules in expecting lists. (By the way, in your examples, 'construct', 'static', ... are not rules, but tokens. So they cannot be links.)

@mingodad
Copy link
Contributor Author

Yes I know that they are tokens, but to show then probably the parser used the known failed rule.

@yhirose
Copy link
Owner

yhirose commented Jul 17, 2022

There is no way to report line no and column offset if a parser isn't made from a grammar, but constructed with parser combinators. I'll close it for now since I am not planning to implement it.

@yhirose yhirose closed this as completed Jul 17, 2022
@mingodad
Copy link
Contributor Author

Just for an working example of this feature on a related project (base on your playground) see https://mingodad.github.io/CocoR-Typescript/playground , for example select the Json parser (using the select at the upper middle screen) and edit the Input example to make it invalid the click parse to see the error message and when clicking see that both grammar/input editor show the the offending rule/input.

yhirose added a commit that referenced this issue Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants