- Cleaned up

Reporting

- Use new `Token` API
This commit is contained in:
Tristan B. Velloza Kildaire 2024-04-02 19:31:33 +02:00
parent f47ed805b1
commit f2cfa0bbbc
2 changed files with 9 additions and 8 deletions

View File

@ -6,8 +6,7 @@ module tlang.compiler.lexer.core.tokens;
import std.string : cmp, format;
import std.conv : to;
import tlang.compiler.reporting : Coords;
// TODO: Below could have linof?!?!?!
import tlang.compiler.reporting : LineInfo;
/**
* Defines a `Token` that a lexer
@ -120,9 +119,13 @@ public final class Token
return Coords(this.line, this.column);
}
// TODO: Switch to this
import tlang.compiler.reporting :LineInfo;
public LineInfo deriveLineInfo()
/**
* Returns the line information
* of this particular token
*
* Returns: the `LineInfo`
*/
public LineInfo getLineInfo()
{
return LineInfo(getOrigin(), getCoords());
}

View File

@ -157,13 +157,11 @@ public string report(string message, LineInfo linfo, ulong cursor = 0)
public string report(Token offendingToken, string message)
{
string line = offendingToken.getOrigin();
// FIXME: Double check the boundries here
ulong pointerPos = offendingToken.getCoords().getColumn() < message.length ? offendingToken.getCoords().getColumn() : 0;
assert(pointerPos < message.length);
return report(message, offendingToken.deriveLineInfo(), pointerPos);
return report(message, offendingToken.getLineInfo(), pointerPos);
}
version(unittest)