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

Retrieving error correction tokens #455

Open
stephe-ada-guru opened this issue Feb 22, 2020 · 2 comments
Open

Retrieving error correction tokens #455

stephe-ada-guru opened this issue Feb 22, 2020 · 2 comments

Comments

@stephe-ada-guru
Copy link

stephe-ada-guru commented Feb 22, 2020

I'm trying to compare the error correction in the libadalang parser with the parser in Emacs Ada mode (and other parsers). One way to do that is to retrieve the token list of the final parse, including "virtual tokens" inserted for error correction, and excluding deleted tokens. Diffing that token list with the similar lists from the other parsers, and with the user-expected "correct" token list, gives a fairly objective measure of error correction.

In doing this for libadalang, I first tried:

   for T in Token_Range (Root (Unit)) loop
      Ada.Wide_Wide_Text_IO.Put_Line (Libadalang.Common.Text (T));
   end loop;

This only gives the "real" tokens; the ones present in the source text.

The diagnostics gives some hints about inserted and deleted tokens, but is not explicit enough for this use.

I don't see any mention of something like virtual tokens in the libadalang specs.

One way to output the list I'm looking for would be to traverse the AST, outputting the tokens implied by the structure. This is a lot of work, although I suspect I can copy code from gnatpp that does mostly the same thing. I can't just use gnatpp; it refuses to output anything when there are syntax errors in the source.

An LSP language server should be able to provide a source edit script for each detected syntax error; if that functionality is in libadalang or ada_language_server somewhere, I could use that.

Is there another way?

NOTE: edited by @raph-amiard for style corrections

@raph-amiard raph-amiard changed the title retrieving error correction tokens Retrieving error correction tokens Jun 2, 2020
@raph-amiard
Copy link
Member

Hello @stephe-ada-guru,

Really sorry about the time we took to answer. Somehow this got lost in the flux of internal & external issues we handle.

We don't (yet) have a lot of stored information wrt. error recovery, and there is no notion of inserted/deleted tokens, even though we do kind of insert and delete tokens.

"deleted" tokens are stored in ErrorDecl nodes, one token per node, so those should be pretty easy for you to recover.

OTOH, we don't keep track of "inserted" tokens directly, and we don't actually insert any tokens, instead we presume that the tokens were here even if they're not (sort of).

Now, I'm wondering if that would be a worthwhile addition to our parser, because it might make things easier to use. But that's a pretty big overhaul of the current API. We'll discuss this with the team and keep you updated!

@stephe-ada-guru
Copy link
Author

stephe-ada-guru commented Jun 3, 2020 via email

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