Remove ANTLR's error listeners, which print on System.err

This commit is contained in:
0xb00bface 2023-03-12 16:10:17 +01:00
parent cf9dc5ab67
commit 51d0ec3083
1 changed files with 3 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.ConsoleErrorListener;
import javax.annotation.Nullable;
import java.io.IOException;
@ -30,8 +31,10 @@ abstract class AbstractVariableExpander {
try (StringReader reader = new StringReader(input)) {
CharStream s = CharStreams.fromReader(reader);
PostProcessingLexer lexer = new PostProcessingLexer(s);
lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
PostProcessingParser parser = new PostProcessingParser(tokens);
parser.removeErrorListener(ConsoleErrorListener.INSTANCE);
Optional.ofNullable(errorListener).ifPresent(parser::addErrorListener);
PostProcessingParser.LineContext ctx = parser.line();
ParserVisitor visitor = new ParserVisitor(variables);