diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/exception/ParserErrorListener.java b/dartagnan/src/main/java/com/dat3m/dartagnan/exception/AbortErrorListener.java similarity index 87% rename from dartagnan/src/main/java/com/dat3m/dartagnan/exception/ParserErrorListener.java rename to dartagnan/src/main/java/com/dat3m/dartagnan/exception/AbortErrorListener.java index 9a79f47665..96fe5d686e 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/exception/ParserErrorListener.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/exception/AbortErrorListener.java @@ -4,8 +4,9 @@ import org.antlr.v4.runtime.RecognitionException; import org.antlr.v4.runtime.Recognizer; -public class ParserErrorListener extends ConsoleErrorListener { +public class AbortErrorListener extends ConsoleErrorListener { + @Override public void syntaxError( Recognizer recognizer, Object offendingSymbol, diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/cat/ParserCat.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/cat/ParserCat.java index 7cc88794ba..753625ce88 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/cat/ParserCat.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/cat/ParserCat.java @@ -2,12 +2,9 @@ import com.dat3m.dartagnan.parsers.CatLexer; import com.dat3m.dartagnan.parsers.CatParser; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.wmm.Wmm; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; import java.io.File; import java.io.FileInputStream; @@ -27,10 +24,13 @@ public Wmm parse(String raw) { private Wmm parse(CharStream charStream){ CatLexer lexer = new CatLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); CatParser parser = new CatParser(tokenStream); - parser.addErrorListener(new ParserErrorListener()); + parser.addErrorListener(new AbortErrorListener()); + parser.addErrorListener(new DiagnosticErrorListener(true)); ParserRuleContext parserEntryPoint = parser.mcm(); return (Wmm) parserEntryPoint.accept(new VisitorBase()); } diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusAArch64.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusAArch64.java index 0934a70b25..423e6c0f17 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusAArch64.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusAArch64.java @@ -1,25 +1,24 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusAArch64Lexer; import com.dat3m.dartagnan.parsers.LitmusAArch64Parser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusAArch64; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusAArch64 implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusAArch64Lexer lexer = new LitmusAArch64Lexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusAArch64Parser parser = new LitmusAArch64Parser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusAArch64 visitor = new VisitorLitmusAArch64(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusC.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusC.java index 8bdf6dcf53..1867b5eb63 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusC.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusC.java @@ -1,23 +1,23 @@ package com.dat3m.dartagnan.parsers.program; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusCLexer; import com.dat3m.dartagnan.parsers.LitmusCParser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusC; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.BailErrorStrategy; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusC implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusCLexer lexer = new LitmusCLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusCParser parser = new LitmusCParser(tokenStream); - parser.setErrorHandler(new BailErrorStrategy()); + parser.addErrorListener(new AbortErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusC visitor = new VisitorLitmusC(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusLISA.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusLISA.java index d940df1c58..b1d0344c40 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusLISA.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusLISA.java @@ -1,25 +1,24 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusLISALexer; import com.dat3m.dartagnan.parsers.LitmusLISAParser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusLISA; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusLISA implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusLISALexer lexer = new LitmusLISALexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusLISAParser parser = new LitmusLISAParser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusLISA visitor = new VisitorLitmusLISA(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPPC.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPPC.java index cf733d26e7..8deeed14e4 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPPC.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPPC.java @@ -1,25 +1,24 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusPPCLexer; import com.dat3m.dartagnan.parsers.LitmusPPCParser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusPPC; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusPPC implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusPPCLexer lexer = new LitmusPPCLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusPPCParser parser = new LitmusPPCParser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusPPC visitor = new VisitorLitmusPPC(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPTX.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPTX.java index b71bc537b1..9e72148684 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPTX.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusPTX.java @@ -1,25 +1,24 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusPTXLexer; import com.dat3m.dartagnan.parsers.LitmusPTXParser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusPTX; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusPTX implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusPTXLexer lexer = new LitmusPTXLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusPTXParser parser = new LitmusPTXParser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusPTX visitor = new VisitorLitmusPTX(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusRISCV.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusRISCV.java index 0113148d59..d5e31b05b0 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusRISCV.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusRISCV.java @@ -1,25 +1,24 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusRISCVLexer; import com.dat3m.dartagnan.parsers.LitmusRISCVParser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusRISCV; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusRISCV implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusRISCVLexer lexer = new LitmusRISCVLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusRISCVParser parser = new LitmusRISCVParser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusRISCV visitor = new VisitorLitmusRISCV(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusVulkan.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusVulkan.java index 6cd1b43c85..62c26d5c51 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusVulkan.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusVulkan.java @@ -1,25 +1,24 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusVulkanLexer; import com.dat3m.dartagnan.parsers.LitmusVulkanParser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusVulkan; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusVulkan implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusVulkanLexer lexer = new LitmusVulkanLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusVulkanParser parser = new LitmusVulkanParser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusVulkan visitor = new VisitorLitmusVulkan(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusX86.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusX86.java index 19c149f5a5..5c8d967034 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusX86.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLitmusX86.java @@ -1,25 +1,24 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LitmusX86Lexer; import com.dat3m.dartagnan.parsers.LitmusX86Parser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLitmusX86; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLitmusX86 implements ParserInterface { @Override public Program parse(CharStream charStream) { LitmusX86Lexer lexer = new LitmusX86Lexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LitmusX86Parser parser = new LitmusX86Parser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.main(); VisitorLitmusX86 visitor = new VisitorLitmusX86(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLlvm.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLlvm.java index 12d82a13d5..2c1702c08a 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLlvm.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserLlvm.java @@ -1,21 +1,23 @@ package com.dat3m.dartagnan.parsers.program; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.LLVMIRLexer; import com.dat3m.dartagnan.parsers.LLVMIRParser; import com.dat3m.dartagnan.parsers.program.visitors.VisitorLlvm; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; class ParserLlvm implements ParserInterface { @Override public Program parse(CharStream charStream) { LLVMIRLexer lexer = new LLVMIRLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); LLVMIRParser parser = new LLVMIRParser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); ParserRuleContext parserEntryPoint = parser.compilationUnit(); VisitorLlvm visitor = new VisitorLlvm(); @@ -25,4 +27,3 @@ public Program parse(CharStream charStream) { return visitor.buildProgram(); } } - diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserSpirv.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserSpirv.java index 3f5d9128fc..dc3e7f10e5 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserSpirv.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/ParserSpirv.java @@ -1,24 +1,23 @@ package com.dat3m.dartagnan.parsers.program; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.*; import com.dat3m.dartagnan.parsers.program.visitors.VisitorSpirv; import com.dat3m.dartagnan.program.Program; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; public class ParserSpirv implements ParserInterface { @Override public Program parse(CharStream charStream) { SpirvLexer lexer = new SpirvLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); SpirvParser parser = new SpirvParser(tokenStream); + parser.addErrorListener(new AbortErrorListener()); parser.addErrorListener(new DiagnosticErrorListener(true)); - parser.addErrorListener(new ParserErrorListener()); ParserRuleContext parserEntryPoint = parser.spv(); VisitorSpirv visitor = new VisitorSpirv(); diff --git a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/witness/ParserWitness.java b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/witness/ParserWitness.java index f0c57d6eee..9a4c72a896 100644 --- a/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/witness/ParserWitness.java +++ b/dartagnan/src/main/java/com/dat3m/dartagnan/parsers/witness/ParserWitness.java @@ -2,13 +2,10 @@ import com.dat3m.dartagnan.parsers.XMLLexer; import com.dat3m.dartagnan.parsers.XMLParser; -import com.dat3m.dartagnan.exception.ParserErrorListener; +import com.dat3m.dartagnan.exception.AbortErrorListener; import com.dat3m.dartagnan.parsers.witness.visitors.VisitorXML; import com.dat3m.dartagnan.witness.WitnessGraph; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.CharStreams; -import org.antlr.v4.runtime.CommonTokenStream; -import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -22,10 +19,13 @@ public class ParserWitness { public WitnessGraph parse(CharStream charStream) { XMLLexer lexer = new XMLLexer(charStream); + lexer.addErrorListener(new AbortErrorListener()); + lexer.addErrorListener(new DiagnosticErrorListener(true)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); XMLParser parser = new XMLParser(tokenStream); - parser.addErrorListener(new ParserErrorListener()); + parser.addErrorListener(new AbortErrorListener()); + parser.addErrorListener(new DiagnosticErrorListener(true)); ParserRuleContext parserEntryPoint = parser.document(); VisitorXML visitor = new VisitorXML();