Skip to content

Commit

Permalink
Tokens
Browse files Browse the repository at this point in the history
- Cleaned up

Reporting

- Use new `Token` API
  • Loading branch information
deavmi committed Apr 2, 2024
1 parent f47ed80 commit f2cfa0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 8 additions & 5 deletions source/tlang/compiler/lexer/core/tokens.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 1 addition & 3 deletions source/tlang/compiler/reporting.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f2cfa0b

Please sign in to comment.