- Moved `Coords`

Reporting

- Added Coords
- Cleaned up reporting
This commit is contained in:
Tristan B. Velloza Kildaire 2024-04-02 19:17:59 +02:00
parent 38eac0acc0
commit e74fdd3983
2 changed files with 58 additions and 63 deletions

View File

@ -5,10 +5,13 @@ module tlang.compiler.lexer.core.tokens;
import std.string : cmp, format;
import std.conv : to;
import tlang.compiler.reporting : Coords;
/**
* Defines a `Token` that a lexer
* would be able to produce
*
* Authors: Tristan Brice Velloza Kildaire (deavmi)
*/
public final class Token
{
@ -114,56 +117,4 @@ public final class Token
{
return Coords(this.line, this.column);
}
}
/**
* Represents coordinates
*/
public struct Coords
{
private ulong line;
private ulong column;
/**
* Constructs a new set of coordinates
*
* Params:
* line = the line
* column = the column
*/
this(ulong line, ulong column)
{
this.line = line;
this.column = column;
}
/**
* Returns the line
*
* Returns: line index
*/
public ulong getLine()
{
return this.line;
}
/**
* Returns the column
*
* Returns: column index
*/
public ulong getColumn()
{
return this.column;
}
/**
* Returns a string representation
*
* Returns: the coordinates
*/
public string toString()
{
return format("line %d, column %d", this.line, this.column);
}
}

View File

@ -2,13 +2,67 @@
* Reporting types and utilities
* for error reporting
*
* Authors: Tristan Brice Velloza Kildaire
* Authors: Tristan Brice Velloza Kildaire (deavmi)
*/
module tlang.compiler.reporting;
import tlang.compiler.lexer.core.tokens;
import std.string : strip, format;
/**
* Represents coordinates
*
* Authors: Tristan Brice Velloza Kildaire (deavmi)
*/
public struct Coords
{
private ulong line;
private ulong column;
/**
* Constructs a new set of coordinates
*
* Params:
* line = the line
* column = the column
*/
this(ulong line, ulong column)
{
this.line = line;
this.column = column;
}
/**
* Returns the line
*
* Returns: line index
*/
public ulong getLine()
{
return this.line;
}
/**
* Returns the column
*
* Returns: column index
*/
public ulong getColumn()
{
return this.column;
}
/**
* Returns a string representation
*
* Returns: the coordinates
*/
public string toString()
{
return format("line %d, column %d", this.line, this.column);
}
}
/**
* Represents line information
* which couples the line itself
@ -98,9 +152,6 @@ public string report(string message, LineInfo linfo, ulong cursor = 0)
offendingLocation
);
// import gogga;
// gprintln(fullMessage, DebugType.ERROR);
return fullMessage;
}
@ -108,13 +159,6 @@ public string report(Token offendingToken, string message)
{
string line = offendingToken.getOrigin();
// Needs to have an origin string
if(!line.length)
{
// TODO: assret maybe?
// return;
}
// FIXME: Double check the boundries here
ulong pointerPos = offendingToken.getCoords().getColumn() < message.length ? offendingToken.getCoords().getColumn() : 0;
assert(pointerPos < message.length);