This project has moved. For the latest updates, please go here.

Better highlight of context-sensitive errors

Sep 23, 2012 at 10:38 AM

I was looking at how to better highlight context sensitive errors such as "Octave must be between 0 and 8", by passing a SourceSpan to new LogMessage(...) instead of a SourceLocation. The result of this was that my highlighting routine could do the following to display the entire erroneous token instead of just it's first character:

    err.Location is SourceSpan ? ((SourceSpan)err.Location).Length : 1);

The simplest way I found to achieve this was:

  1. Convert SourceLocation and SourceSpan to classes, sub-classing SourceSpan from SourceLocation.
  2. Adding empty and copy constructors to SourceLocation.
  3. Changing readonly field Location in SourceSpan to a get-only property.
  4. Changing line 1 of Parser.ParseTree to initialize loc with
        new SourceLocation()
    instead of

Is there a bettwer way to get this result?

Of course, the same result is possible by:

  1. Renaming struct SourceLocation to ConcreteSourceLocation;
  2. Defining an interface SourceLocation to be implemented by both ConcreteSourceLocation and SourceSpan; and finally
  3. Fighting one's way through all the consequent code changes.

but I didn't want to tackle that unless you felt it worthwhile.

Sep 26, 2012 at 5:44 PM

hm... will think about this (having span instead location in error message)

Sep 26, 2012 at 6:02 PM

I am happy to make the coding changes once you make the design decision above.