From 5b64cbd6b6ef14d1b7f589ac6d1a3dd38c443f0c Mon Sep 17 00:00:00 2001 From: Domenico Date: Wed, 10 Jul 2024 12:19:54 +0200 Subject: [PATCH 1/4] Add missing duration code to AST construction --- .../kotlin/com/smeup/rpgparser/parsing/parsetreetoast/bif.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/bif.kt b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/bif.kt index f4ec36edf..3a5d93472 100644 --- a/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/bif.kt +++ b/rpgJavaInterpreter-core/src/main/kotlin/com/smeup/rpgparser/parsing/parsetreetoast/bif.kt @@ -178,7 +178,12 @@ internal fun RpgParser.Bif_diffContext.toAst(conf: ToAstConfiguration = ToAstCon internal fun RpgParser.DurationCodeContext.toAst(conf: ToAstConfiguration = ToAstConfiguration()): DurationCode = when { SPLAT_MSECONDS() != null || SPLAT_MS() != null -> DurationInMSecs + SPLAT_SECONDS() != null || SPLAT_S() != null -> DurationInSecs + SPLAT_MINUTES() != null || SPLAT_MN() != null -> DurationInMinutes + SPLAT_HOURS() != null || SPLAT_H() != null -> DurationInHours SPLAT_DAYS() != null || SPLAT_D() != null -> DurationInDays + SPLAT_MONTHS() != null || SPLAT_M() != null -> DurationInMonths + SPLAT_YEARS() != null || SPLAT_Y() != null -> DurationInYears else -> todo(conf = conf) } From dd8b530bbd4d36c95ca383f63151a657cdf16e8d Mon Sep 17 00:00:00 2001 From: Domenico Date: Wed, 10 Jul 2024 12:20:03 +0200 Subject: [PATCH 2/4] Add test cases --- .../MULANGT04EssentialsCodopAndBifTest.kt | 32 +++++++++++++++++++ .../test/resources/smeup/MUDRNRAPU00228.rpgle | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt index 2c3757b57..d8875e5c4 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt @@ -1,8 +1,11 @@ package com.smeup.rpgparser.smeup +import com.smeup.rpgparser.interpreter.TimeStampValue import com.smeup.rpgparser.parsing.parsetreetoast.AstResolutionError import org.junit.Test import java.time.LocalDateTime +import java.time.ZoneId +import java.time.temporal.ChronoUnit import kotlin.test.assertEquals import kotlin.test.assertFailsWith @@ -30,4 +33,33 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() { ) assertEquals(expected, "smeup/T04_A80_P05".outputOf()) } + + /** + * %DIFF with several DurationCodes + */ + @Test + fun executeMUDRNRAPU00228() { + val referenceDate = TimeStampValue.of("2024-07-10-10.25.27.921456") + val epochDate = TimeStampValue.of("1970-01-01-00.00.00.000000") + val referenceInstant = referenceDate.asTimeStamp().value.atZone(ZoneId.systemDefault()).toInstant() + val epochInstant = epochDate.asTimeStamp().value.atZone(ZoneId.systemDefault()).toInstant() + + val mseconds = ChronoUnit.MICROS.between(epochInstant, referenceInstant).toString() + val seconds = ChronoUnit.SECONDS.between(epochInstant, referenceInstant).toString() + val minutes = ChronoUnit.MINUTES.between(epochInstant, referenceInstant).toString() + val hours = ChronoUnit.HOURS.between(epochInstant, referenceInstant).toString() + val days = ChronoUnit.DAYS.between(epochInstant, referenceInstant).toString() + val months = ChronoUnit.MONTHS.between(epochDate.localDate, referenceDate.localDate).toString() + val years = ChronoUnit.YEARS.between(epochDate.localDate, referenceDate.localDate).toString() + val expected = listOf( + mseconds, mseconds, + seconds, seconds, + minutes, minutes, + hours, hours, + days, days, + months, months, + years, years + ) + assertEquals(expected, "smeup/MUDRNRAPU00228".outputOf()) + } } \ No newline at end of file diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle new file mode 100644 index 000000000..348e3bdb1 --- /dev/null +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle @@ -0,0 +1,32 @@ + D ut S 30 0 + D dt S Z INZ(Z'2024-07-10-10.25.27.921456') + D t S Z INZ(Z'1970-01-01-00.00.00.000000') + + C EVAL ut=%diff(dt:t:*mseconds) + C ut DSPLY + C EVAL ut=%diff(dt:t:*ms) + C ut DSPLY + C EVAL ut=%diff(dt:t:*seconds) + C ut DSPLY + C EVAL ut=%diff(dt:t:*s) + C ut DSPLY + C EVAL ut=%diff(dt:t:*minutes) + C ut DSPLY + C EVAL ut=%diff(dt:t:*mn) + C ut DSPLY + C EVAL ut=%diff(dt:t:*hours) + C ut DSPLY + C EVAL ut=%diff(dt:t:*h) + C ut DSPLY + C EVAL ut=%diff(dt:t:*days) + C ut DSPLY + C EVAL ut=%diff(dt:t:*d) + C ut DSPLY + C EVAL ut=%diff(dt:t:*months) + C ut DSPLY + C EVAL ut=%diff(dt:t:*m) + C ut DSPLY + C EVAL ut=%diff(dt:t:*years) + C ut DSPLY + C EVAL ut=%diff(dt:t:*y) + C ut DSPLY \ No newline at end of file From ceb323087eb286b1d2467c1144a4b2dd064a5186 Mon Sep 17 00:00:00 2001 From: Domenico Date: Wed, 10 Jul 2024 12:20:23 +0200 Subject: [PATCH 3/4] Fix lexer splat rules order --- .../src/main/antlr/RpgLexer.g4 | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/rpgJavaInterpreter-core/src/main/antlr/RpgLexer.g4 b/rpgJavaInterpreter-core/src/main/antlr/RpgLexer.g4 index 51f111d6d..c78dc4c84 100644 --- a/rpgJavaInterpreter-core/src/main/antlr/RpgLexer.g4 +++ b/rpgJavaInterpreter-core/src/main/antlr/RpgLexer.g4 @@ -373,21 +373,21 @@ SPLAT_LOCK: '*'[lL][oO][cC][kK]; SPLAT_PROGRAM: '*'[pP][rR][oO][gG][rR][aA][mM]; SPLAT_EXTDESC: '*'[eE][xX][tT][dD][eE][sS][cC]; //Durations -SPLAT_D: '*'{getLastTokenType() == COLON}? [dD]; -SPLAT_H: '*'{getLastTokenType() == COLON}? [hH]; -SPLAT_HOURS: '*'{getLastTokenType() == COLON}? [hH][oO][uU][rR][sS]; +SPLAT_YEARS: SPLAT_YEAR[sS]{getLastTokenType() == COLON}?; +SPLAT_MONTHS: SPLAT_MONTH[sS]; SPLAT_DAYS: SPLAT_DAY[sS]{getLastTokenType() == COLON}?; -SPLAT_M: '*'{getLastTokenType() == COLON}? [mM]; +SPLAT_HOURS: '*'{getLastTokenType() == COLON}? [hH][oO][uU][rR][sS]; SPLAT_MINUTES: '*'{getLastTokenType() == COLON}? [mM][iI][nN][uU][tT][eE][sS]; -SPLAT_MONTHS: SPLAT_MONTH[sS]; -SPLAT_MN: '*'{getLastTokenType() == COLON}? [mM][nN]; //Minutes -SPLAT_MS: '*'{getLastTokenType() == COLON}? [mM][sS]; //Minutes -SPLAT_MSECONDS: '*'{getLastTokenType() == COLON}? [mM][sS][eE][cC][oO][nN][dD][sS]; -SPLAT_S: '*'{getLastTokenType() == COLON}? [sS]; SPLAT_SECONDS: '*'{getLastTokenType() == COLON}? [sS][eE][cC][oO][nN][dD][sS]; -SPLAT_Y: '*'{getLastTokenType() == COLON}? [yY]; -SPLAT_YEARS: SPLAT_YEAR[sS]{getLastTokenType() == COLON}?; +SPLAT_MSECONDS: '*'{getLastTokenType() == COLON}? [mM][sS][eE][cC][oO][nN][dD][sS]; +SPLAT_Y: '*'{getLastTokenType() == COLON}? [yY]; +SPLAT_D: '*'{getLastTokenType() == COLON}? [dD]; +SPLAT_H: '*'{getLastTokenType() == COLON}? [hH]; +SPLAT_MN: '*'{getLastTokenType() == COLON}? [mM][nN]; // Minutes +SPLAT_MS: '*'{getLastTokenType() == COLON}? [mM][sS]; // Microseconds +SPLAT_M: '*'{getLastTokenType() == COLON}? [mM]; // Months +SPLAT_S: '*'{getLastTokenType() == COLON}? [sS]; // Reserved Words UDATE : [uU] [dD] [aA] [tT] [eE] ; From 050da9324dd4470c3d0d812f2a8eea92f39e6d4f Mon Sep 17 00:00:00 2001 From: Domenico Date: Wed, 10 Jul 2024 12:25:57 +0200 Subject: [PATCH 4/4] Add action reference to unit test description --- .../smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt | 1 + .../src/test/resources/smeup/MUDRNRAPU00228.rpgle | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt index d8875e5c4..e71cd26a1 100644 --- a/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt +++ b/rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/smeup/MULANGT04EssentialsCodopAndBifTest.kt @@ -36,6 +36,7 @@ open class MULANGT04EssentialsCodopAndBifTest : MULANGTTest() { /** * %DIFF with several DurationCodes + * @see #LS24003282 */ @Test fun executeMUDRNRAPU00228() { diff --git a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle index 348e3bdb1..ca75549bb 100644 --- a/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle +++ b/rpgJavaInterpreter-core/src/test/resources/smeup/MUDRNRAPU00228.rpgle @@ -29,4 +29,4 @@ C EVAL ut=%diff(dt:t:*years) C ut DSPLY C EVAL ut=%diff(dt:t:*y) - C ut DSPLY \ No newline at end of file + C ut DSPLY