Tokens
- Moved `Coords` Reporting - Added Coords - Cleaned up reporting
This commit is contained in:
parent
38eac0acc0
commit
e74fdd3983
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue