From 0421fd519a5987a458b574fa48b3c5105b86f975 Mon Sep 17 00:00:00 2001 From: aNNiMON Date: Fri, 20 Sep 2024 13:06:35 +0300 Subject: [PATCH] Internal linter mode for unit tests --- .../annimon/ownlang/parser/linters/LinterStage.java | 10 +++++++--- .../java/com/annimon/ownlang/parser/ProgramsTest.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ownlang-parser/src/main/java/com/annimon/ownlang/parser/linters/LinterStage.java b/ownlang-parser/src/main/java/com/annimon/ownlang/parser/linters/LinterStage.java index 61044c6a..03bb84fe 100644 --- a/ownlang-parser/src/main/java/com/annimon/ownlang/parser/linters/LinterStage.java +++ b/ownlang-parser/src/main/java/com/annimon/ownlang/parser/linters/LinterStage.java @@ -12,7 +12,7 @@ import java.util.List; public class LinterStage implements Stage { - public enum Mode { NONE, SEMANTIC, FULL } + public enum Mode { NONE, INTERNAL, SEMANTIC, FULL } private final Mode mode; @@ -29,10 +29,14 @@ public Node perform(StagesData stagesData, Node input) { validators.add(new IncludeSourceValidator(results)); validators.add(new LoopStatementsValidator(results)); - if (mode == Mode.SEMANTIC) { + if (mode == Mode.SEMANTIC || mode == Mode.INTERNAL) { validators.forEach(input::accept); if (results.hasErrors()) { - throw new OwnLangParserException(results.errors().toList()); + if (mode == Mode.INTERNAL) { + System.err.println(results.errors().toList()); + } else { + throw new OwnLangParserException(results.errors().toList()); + } } return input; } diff --git a/ownlang-parser/src/test/java/com/annimon/ownlang/parser/ProgramsTest.java b/ownlang-parser/src/test/java/com/annimon/ownlang/parser/ProgramsTest.java index eb32171b..698f89ef 100644 --- a/ownlang-parser/src/test/java/com/annimon/ownlang/parser/ProgramsTest.java +++ b/ownlang-parser/src/test/java/com/annimon/ownlang/parser/ProgramsTest.java @@ -38,7 +38,7 @@ public static void createStage() { testPipeline = new SourceLoaderStage() .then(new LexerStage()) .then(new ParserStage()) - .then(new LinterStage(LinterStage.Mode.SEMANTIC)) + .then(new LinterStage(LinterStage.Mode.INTERNAL)) .thenConditional(true, new OptimizationStage(9)) .then(new MockOUnitStage()) .then(new ExecutionStage())