Skip to content
Snippets Groups Projects
Commit 93424a08 authored by dgelessus's avatar dgelessus
Browse files

Allow getting structured position info and message from LexerException

parent 8c3679f4
No related branches found
No related tags found
No related merge requests found
......@@ -176,7 +176,7 @@ public class Lexer
case -1:
if(this.text.length() > 0)
{
throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Unknown token: " + this.text);
throw new LexerException(startLine + 1, startPos + 1, "Unknown token: " + this.text);
}
return new EOF(startLine + 1, startPos + 1);
......@@ -350,7 +350,7 @@ public class Lexer
break;
default:
throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
throw new LexerException(startLine + 1, startPos + 1, "Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
}
pushBack(acceptLength);
this.pos = acceptPos;
......
......@@ -5,8 +5,35 @@ package org.sablecc.sablecc.lexer;
@SuppressWarnings({"serial"})
public class LexerException extends Exception
{
private final int line;
private final int pos;
private final String realMsg;
public LexerException(int line, int pos, String message)
{
super("[" + line + "," + pos + "] " + message);
this.line = line;
this.pos = pos;
this.realMsg = message;
}
public LexerException(String message)
{
super(message);
this(0, 0, message);
}
public int getLine()
{
return this.line;
}
public int getPos()
{
return this.pos;
}
public String getRealMsg()
{
return this.realMsg;
}
}
......@@ -13,9 +13,36 @@ package $0$lexer;
@SuppressWarnings({"serial"})
public class LexerException extends Exception
{
private final int line;
private final int pos;
private final String realMsg;
public LexerException(int line, int pos, String message)
{
super("[" + line + "," + pos + "] " + message);
this.line = line;
this.pos = pos;
this.realMsg = message;
}
public LexerException(String message)
{
super(message);
this(0, 0, message);
}
public int getLine()
{
return this.line;
}
public int getPos()
{
return this.pos;
}
public String getRealMsg()
{
return this.realMsg;
}
}
......@@ -200,7 +227,7 @@ public class Lexer
case -1:
if(this.text.length() > 0)
{
throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Unknown token: " + this.text);
throw new LexerException(startLine + 1, startPos + 1, "Unknown token: " + this.text);
}
return new EOF(startLine + 1, startPos + 1);
......@@ -244,7 +271,7 @@ $
Macro:LexerBody
default:
throw new LexerException("[" + (startLine + 1) + "," + (startPos + 1) + "] Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
throw new LexerException(startLine + 1, startPos + 1, "Internal lexer error: invalid accept table entry " + acceptToken + ", current text: " + this.text);
}
pushBack(acceptLength);
this.pos = acceptPos;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment