From 37b80b31ab155414867ee72bea2fd618bbb3f69d Mon Sep 17 00:00:00 2001 From: Markus Amshove Date: Sun, 10 Sep 2023 16:46:29 +0200 Subject: [PATCH] Raise a diagnostic if FILLER is used outside of REDEFINE --- .../natparse/parsing/DefineDataParser.java | 4 +-- .../parsing/DefineDataParserShould.java | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/libs/natparse/src/main/java/org/amshove/natparse/parsing/DefineDataParser.java b/libs/natparse/src/main/java/org/amshove/natparse/parsing/DefineDataParser.java index 220eefa21..30bd5ddbb 100644 --- a/libs/natparse/src/main/java/org/amshove/natparse/parsing/DefineDataParser.java +++ b/libs/natparse/src/main/java/org/amshove/natparse/parsing/DefineDataParser.java @@ -166,7 +166,7 @@ private ScopeNode scope() throws ParseError checkIndependentVariable(variable); } - if (peekKind(1, SyntaxKind.FILLER)) + if (peekKind(1, SyntaxKind.FILLER) && peekKind(2, SyntaxKind.OPERAND_SKIP)) { var currentRedefineNode = currentRedefine(variable); if (currentRedefineNode != null) @@ -178,7 +178,7 @@ private ScopeNode scope() throws ParseError } else { - // TODO: Diagnostic: Filler can only be used on redefines + report(ParserErrors.unexpectedToken(peek(1), "FILLER can only be used in redefinitions")); } } diff --git a/libs/natparse/src/test/java/org/amshove/natparse/parsing/DefineDataParserShould.java b/libs/natparse/src/test/java/org/amshove/natparse/parsing/DefineDataParserShould.java index 67d57e0fc..7675c19bc 100644 --- a/libs/natparse/src/test/java/org/amshove/natparse/parsing/DefineDataParserShould.java +++ b/libs/natparse/src/test/java/org/amshove/natparse/parsing/DefineDataParserShould.java @@ -990,6 +990,34 @@ void parseFillerInRedefines() assertThat(redefine.fillerBytes()).isEqualTo(90); } + @Test + void raiseADiagnosticIfAFillerIsUsedOutsideOfRedefine() + { + assertDiagnostic(""" + DEFINE DATA + LOCAL + 1 #GRP + 2 FILLER 50X + 2 #SUBSTR (A10) + END-DEFINE + """, ParserError.UNEXPECTED_TOKEN); + } + + @Test + void notRaiseADiagnosticIfAVariableWithNameFillerIsUsedOutsideOfRedefine() + { + var data = assertParsesWithoutDiagnostics(""" + DEFINE DATA + LOCAL + 1 #GRP + 2 FILLER (A5) + 2 #SUBSTR (A10) + END-DEFINE + """); + + assertThat(data.findVariable("FILLER")).isNotNull(); + } + @Test void parseSubsequentRedefineFiller() {