From f00fc8459e47a4a3de43c4995ba822be06657686 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 6 Dec 2024 11:34:38 +0100 Subject: [PATCH] Support time literals in SOQL queries Fixes #58 --- antlr/ApexLexer.g4 | 5 +++-- antlr/ApexParser.g4 | 1 + .../github/apexdevtools/apexparser/SOQLParserTest.java | 10 ++++++++++ npm/src/__tests__/SOQLParserTest.ts | 10 ++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/antlr/ApexLexer.g4 b/antlr/ApexLexer.g4 index fca786a..cc016dc 100644 --- a/antlr/ApexLexer.g4 +++ b/antlr/ApexLexer.g4 @@ -235,9 +235,10 @@ NEXT_N_FISCAL_YEARS_N : 'next_n_fiscal_years'; LAST_N_FISCAL_YEARS_N : 'last_n_fiscal_years'; N_FISCAL_YEARS_AGO_N : 'n_fiscal_years_ago'; -// SOQL Date literal +// SOQL Date and Time literals DateLiteral: Digit Digit Digit Digit '-' Digit Digit '-' Digit Digit; -DateTimeLiteral: DateLiteral 't' Digit Digit ':' Digit Digit ':' Digit Digit ('z' | (('+' | '-') Digit+ ( ':' Digit+)? )); +TimeLiteral: Digit Digit ':' Digit Digit ':' Digit Digit ('.' Digit+ )? ('z' | (('+' | '-') Digit+ ( ':' Digit+)? )); +DateTimeLiteral: DateLiteral 't' TimeLiteral; // SOQL Currency literal // (NOTE: this is also a valid Identifier) diff --git a/antlr/ApexParser.g4 b/antlr/ApexParser.g4 index 9e5763e..1f81e63 100644 --- a/antlr/ApexParser.g4 +++ b/antlr/ApexParser.g4 @@ -696,6 +696,7 @@ value | signedNumber | StringLiteral | DateLiteral + | TimeLiteral | DateTimeLiteral | dateFormula | IntegralCurrencyLiteral (DOT IntegerLiteral?)? diff --git a/jvm/src/test/java/io/github/apexdevtools/apexparser/SOQLParserTest.java b/jvm/src/test/java/io/github/apexdevtools/apexparser/SOQLParserTest.java index 1ec46c5..dde2723 100644 --- a/jvm/src/test/java/io/github/apexdevtools/apexparser/SOQLParserTest.java +++ b/jvm/src/test/java/io/github/apexdevtools/apexparser/SOQLParserTest.java @@ -164,4 +164,14 @@ void testFormatWithAggregate() { assertNotNull(context); assertEquals(0, parserAndCounter.getValue().getNumErrors()); } + + @Test + void timeLiteral() { + Map.Entry parserAndCounter = createParser( + "[SELECT Break__c,Check_Out__c FROM VMS_Time_Card_Item__c WHERE Time_Card__c =:timeCard.Id AND Check_Out__c = 01:00:00.000Z]" + ); + ApexParser.SoqlLiteralContext context = parserAndCounter.getKey().soqlLiteral(); + assertNotNull(context); + assertEquals(0, parserAndCounter.getValue().getNumErrors()); + } } diff --git a/npm/src/__tests__/SOQLParserTest.ts b/npm/src/__tests__/SOQLParserTest.ts index 0bfe787..eb86a16 100644 --- a/npm/src/__tests__/SOQLParserTest.ts +++ b/npm/src/__tests__/SOQLParserTest.ts @@ -172,3 +172,13 @@ test("Format function with aggregate", () => { expect(context).toBeInstanceOf(SoqlLiteralContext); expect(errorCounter.getNumErrors()).toEqual(0); }); + +test("Time Literal", () => { + const [parser, errorCounter] = createParser( + '[SELECT Break__c,Check_Out__c FROM VMS_Time_Card_Item__c WHERE Time_Card__c =:timeCard.Id AND Check_Out__c = 01:00:00.000Z]' + ) + const context = parser.soqlLiteral(); + + expect(context).toBeInstanceOf(SoqlLiteralContext); + expect(errorCounter.getNumErrors()).toEqual(0); +});