AdaCore / AdaCore/libadalang

Retrieving error correction tokens

Open
#455 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement error recovery parsing
Dominant language
Ada
Stars
171
Forks
48
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Token_Range and Root (Unit) APIs, then inspect how diagnostics expose inserted or deleted tokens. Compare those capabilities with the AST traversal approach mentioned from gnatpp and with any source-edit support in ada_language_server. Done means a documented way to retrieve final parse tokens, including virtual tokens and excluding deleted tokens.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.