From a8802766d96ae4cc71eae69f6e6d9be599cf0359 Mon Sep 17 00:00:00 2001 From: dgelessus <dgelessus@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:40:14 +0200 Subject: [PATCH] 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. --- .../java/org/sablecc/sablecc/lexer/LexerException.java | 9 +++++++-- .../java/org/sablecc/sablecc/parser/ParserException.java | 9 +++++++-- src/main/resources/org/sablecc/sablecc/lexer.txt | 9 +++++++-- src/main/resources/org/sablecc/sablecc/parser.txt | 9 +++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/sablecc/sablecc/lexer/LexerException.java b/src/main/java/org/sablecc/sablecc/lexer/LexerException.java index ff4967e..dc2e254 100644 --- a/src/main/java/org/sablecc/sablecc/lexer/LexerException.java +++ b/src/main/java/org/sablecc/sablecc/lexer/LexerException.java @@ -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); diff --git a/src/main/java/org/sablecc/sablecc/parser/ParserException.java b/src/main/java/org/sablecc/sablecc/parser/ParserException.java index 6ba7aa8..af942d5 100644 --- a/src/main/java/org/sablecc/sablecc/parser/ParserException.java +++ b/src/main/java/org/sablecc/sablecc/parser/ParserException.java @@ -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. diff --git a/src/main/resources/org/sablecc/sablecc/lexer.txt b/src/main/resources/org/sablecc/sablecc/lexer.txt index aa9b584..eede12a 100644 --- a/src/main/resources/org/sablecc/sablecc/lexer.txt +++ b/src/main/resources/org/sablecc/sablecc/lexer.txt @@ -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); diff --git a/src/main/resources/org/sablecc/sablecc/parser.txt b/src/main/resources/org/sablecc/sablecc/parser.txt index 0613a91..b591f3e 100644 --- a/src/main/resources/org/sablecc/sablecc/parser.txt +++ b/src/main/resources/org/sablecc/sablecc/parser.txt @@ -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. -- GitLab