diff --git a/src/main/java/org/xembly/Verbs.java b/src/main/java/org/xembly/Verbs.java index 43cd072..96d8f9e 100644 --- a/src/main/java/org/xembly/Verbs.java +++ b/src/main/java/org/xembly/Verbs.java @@ -44,6 +44,26 @@ */ final class Verbs { + /** + * Errors listener. + */ + private static final ANTLRErrorListener ERRORS = new BaseErrorListener() { + // @checkstyle ParameterNumberCheck (10 lines) + @Override + public void syntaxError(final Recognizer recognizer, + final Object symbol, final int line, + final int position, final String msg, + final RecognitionException error) { + throw new SyntaxException( + String.format( + "\"%s\" at line #%d, position #%d, symbol %s", + msg, line, position, symbol + ), + error + ); + } + }; + /** * The text. */ @@ -70,45 +90,21 @@ public Collection directives() { new CommonTokenStream(lexer) ); lexer.removeErrorListeners(); - lexer.addErrorListener(Verbs.errors()); + lexer.addErrorListener(Verbs.ERRORS); parser.removeErrorListeners(); - parser.addErrorListener(Verbs.errors()); + parser.addErrorListener(Verbs.ERRORS); try { return parser.directives().ret; } catch (final ParsingException ex) { throw new SyntaxException( String.format( - "%s \"%s\" in \"%s\"", + "Parsing failed as %s: \"%s\"", ex.getClass().getCanonicalName(), - ex.getLocalizedMessage(), - this.text + ex.getLocalizedMessage() ), ex ); } } - /** - * Errors listener. - * @return Listener - */ - private static ANTLRErrorListener errors() { - return new BaseErrorListener() { - // @checkstyle ParameterNumberCheck (10 lines) - @Override - public void syntaxError(final Recognizer recognizer, - final Object symbol, final int line, - final int position, final String msg, - final RecognitionException error) { - throw new SyntaxException( - String.format( - "\"%s\" at line #%d, position #%d, symbol %s", - msg, line, position, symbol - ), - error - ); - } - }; - } - } diff --git a/src/test/java/org/xembly/DirectivesTest.java b/src/test/java/org/xembly/DirectivesTest.java index 2251b61..85046c7 100644 --- a/src/test/java/org/xembly/DirectivesTest.java +++ b/src/test/java/org/xembly/DirectivesTest.java @@ -95,7 +95,7 @@ void throwsOnBrokenXmlContent() { SyntaxException.class, () -> new Directives("ADD 't';\nADD '\u001b';") ).getMessage(), - Matchers.containsString("ADD") + Matchers.containsString("Character #1B is in the restricted XML") ); }