Reporting

- New module added

LineInfo

- Added newtype
This commit is contained in:
Tristan B. Velloza Kildaire 2024-04-02 09:02:27 +02:00
parent 4f474a3e89
commit f15079b8cc
1 changed files with 79 additions and 0 deletions

View File

@ -0,0 +1,79 @@
/**
* Reporting types and utilities
* for error reporting
*
* Authors: Tristan Brice Velloza Kildaire
*/
module tlang.compiler.parsing.reporting;
import tlang.compiler.lexer.core.tokens;
import std.string : strip;
/**
* Represents line information
*/
public struct LineInfo
{
private Token[] line;
/**
* Appends the given token to the
* line
*
* Params:
* tok = the token to append
*/
public void add(Token tok)
{
this.line ~= tok;
}
/**
* Clears all tokens from
* this line info
*/
public void clear()
{
this.line.length = 0;
}
/**
* Returns the coordinates of
* the start of the line
*
* Returns: starting coordinates
*/
public Coords getStart()
{
return this.line.length ? this.line[0].getCoords() : Coords(0,0);
}
/**
* Returns the coordinates of
* the end of the line
*
* Returns: ending coordinates
*/
public Coords getEnd()
{
return this.line.length ? this.line[$-1].getCoords() : Coords(0,0);
}
/**
* Returns the complete line
* of all tokens strung together
*
* Returns: the line
*/
public string getLine()
{
string fullLine;
foreach(Token tok; this.line)
{
fullLine ~= tok.getToken() ~" ";
}
fullLine = strip(fullLine);
return fullLine;
}
}