From b9a81a00fdb8099f61f2b6d30de1b8a7ff5e6ec9 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 25 Sep 2023 15:09:03 -0700 Subject: [PATCH] Adds CURRENT_DATE special form to parser --- CHANGELOG.md | 1 + buildSrc/src/main/kotlin/partiql.conventions.gradle.kts | 4 ++++ partiql-ast/src/main/resources/partiql_ast.ion | 1 + partiql-parser/src/main/antlr/PartiQL.g4 | 1 + .../kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt | 4 ++++ 5 files changed, 11 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4acaad18b8..fcd1ae6770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Adds overridden `toString()` method for Sprout-generated code. +- Adds CURRENT_DATE session variable to PartiQL.g4 and PartiQLParser ### Changed diff --git a/buildSrc/src/main/kotlin/partiql.conventions.gradle.kts b/buildSrc/src/main/kotlin/partiql.conventions.gradle.kts index 9d07abba0b..ad66de402c 100644 --- a/buildSrc/src/main/kotlin/partiql.conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/partiql.conventions.gradle.kts @@ -77,6 +77,10 @@ configure { } } +tasks.named("build") { + dependsOn("ktlintFormat") +} + sourceSets { main { java.srcDir(generatedSrc) diff --git a/partiql-ast/src/main/resources/partiql_ast.ion b/partiql-ast/src/main/resources/partiql_ast.ion index e4cf854f28..e8fbea1037 100644 --- a/partiql-ast/src/main/resources/partiql_ast.ion +++ b/partiql-ast/src/main/resources/partiql_ast.ion @@ -277,6 +277,7 @@ expr::[ session_attribute::{ attribute: [ CURRENT_USER, + CURRENT_DATE, ], }, diff --git a/partiql-parser/src/main/antlr/PartiQL.g4 b/partiql-parser/src/main/antlr/PartiQL.g4 index b7b0561bf2..90c1c2440d 100644 --- a/partiql-parser/src/main/antlr/PartiQL.g4 +++ b/partiql-parser/src/main/antlr/PartiQL.g4 @@ -602,6 +602,7 @@ exprPrimary exprTerm : PAREN_LEFT expr PAREN_RIGHT # ExprTermWrappedQuery | CURRENT_USER # ExprTermCurrentUser + | CURRENT_DATE # ExprTermCurrentDate | parameter # ExprTermBase | varRefExpr # ExprTermBase | literal # ExprTermBase diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt index 330ba2bf92..7145922c69 100644 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt +++ b/partiql-parser/src/main/kotlin/org/partiql/parser/impl/PartiQLParserDefault.kt @@ -1475,6 +1475,10 @@ internal class PartiQLParserDefault : PartiQLParser { exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_USER) } + override fun visitExprTermCurrentDate(ctx: org.partiql.parser.antlr.PartiQLParser.ExprTermCurrentDateContext) = translate(ctx) { + exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_DATE) + } + /** * * FUNCTIONS