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

Allow adding causes to lexer and parser exceptions

Not used by SableCC-generated code (yet?), but may be used by other code
that modifies lexer/parser exceptions.
parent 6ca86e1b
No related branches found
No related tags found
No related merge requests found
Pipeline #142418 passed
......@@ -9,14 +9,19 @@ public class LexerException extends Exception
private final int pos;
private final String realMsg;
public LexerException(int line, int pos, String message)
public LexerException(int line, int pos, String message, Throwable cause)
{
super("[" + line + "," + pos + "] " + message);
super("[" + line + "," + pos + "] " + message, cause);
this.line = line;
this.pos = pos;
this.realMsg = message;
}
public LexerException(int line, int pos, String message)
{
this(line, pos, message, null);
}
public LexerException(String message)
{
this(0, 0, message);
......
......@@ -10,13 +10,18 @@ public class ParserException extends Exception
private final Token token;
private final String realMsg;
public ParserException(Token token, String message)
public ParserException(Token token, String message, Throwable cause)
{
super("[" + token.getLine() + "," + token.getPos() + "] " + message);
super("[" + token.getLine() + "," + token.getPos() + "] " + message, cause);
this.token = token;
this.realMsg = message;
}
public ParserException(Token token, String message)
{
this(token, message, (Throwable)null);
}
/**
* @deprecated Use {@link #ParserException(Token, String)} instead.
* The token position info is now added automatically to the message.
......
......@@ -17,14 +17,19 @@ public class LexerException extends Exception
private final int pos;
private final String realMsg;
public LexerException(int line, int pos, String message)
public LexerException(int line, int pos, String message, Throwable cause)
{
super("[" + line + "," + pos + "] " + message);
super("[" + line + "," + pos + "] " + message, cause);
this.line = line;
this.pos = pos;
this.realMsg = message;
}
public LexerException(int line, int pos, String message)
{
this(line, pos, message, null);
}
public LexerException(String message)
{
this(0, 0, message);
......
......@@ -512,13 +512,18 @@ public class ParserException extends Exception
private final Token token;
private final String realMsg;
public ParserException(Token token, String message)
public ParserException(Token token, String message, Throwable cause)
{
super("[" + token.getLine() + "," + token.getPos() + "] " + message);
super("[" + token.getLine() + "," + token.getPos() + "] " + message, cause);
this.token = token;
this.realMsg = message;
}
public ParserException(Token token, String message)
{
this(token, message, (Throwable)null);
}
/**
* @deprecated Use {@link #ParserException(Token, String)} instead.
* The token position info is now added automatically to the message.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment