Skip to content

Commit

Permalink
Fixes ANTLR parser grammar and renames parser g4 file (#1474)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchowell committed Jun 26, 2024
1 parent 2e22c43 commit 005dbce
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ import org.partiql.lang.util.checkThreadInterrupted
import org.partiql.lang.util.error
import org.partiql.lang.util.getPrecisionFromTimeString
import org.partiql.lang.util.unaryMinus
import org.partiql.parser.antlr.PartiQLBaseVisitor
import org.partiql.parser.antlr.PartiQLParser
import org.partiql.parser.antlr.PartiQLParserBaseVisitor
import org.partiql.pig.runtime.SymbolPrimitive
import org.partiql.value.datetime.DateTimeException
import org.partiql.value.datetime.TimeZone
Expand All @@ -73,12 +73,12 @@ import java.time.format.DateTimeFormatter
import java.time.format.DateTimeParseException

/**
* Extends ANTLR's generated [PartiQLBaseVisitor] to visit an ANTLR ParseTree and convert it into a PartiQL AST. This
* Extends ANTLR's generated [PartiQLParserBaseVisitor] to visit an ANTLR ParseTree and convert it into a PartiQL AST. This
* class uses the [PartiqlAst.PartiqlAstNode] to represent all nodes within the new AST.
*
* When the grammar in PartiQL.g4 is extended with a new rule, one needs to override corresponding visitor methods
* in this class, in order to extend the transformation from an ANTLR parse tree into a [PartqlAst] tree.
* (Trivial implementations of these methods are generated into [PartiQLBaseVisitor].)
* (Trivial implementations of these methods are generated into [PartiQLParserBaseVisitor].)
*
* For a rule of the form
* ```
Expand Down Expand Up @@ -119,7 +119,7 @@ internal class PartiQLPigVisitor(
val customTypes: List<CustomType> = listOf(),
private val parameterIndexes: Map<Int, Int> = mapOf(),
) :
PartiQLBaseVisitor<PartiqlAst.PartiqlAstNode>() {
PartiQLParserBaseVisitor<PartiqlAst.PartiqlAstNode>() {

companion object {
internal val TRIM_SPECIFICATION_KEYWORDS = setOf("both", "leading", "trailing")
Expand Down
2 changes: 2 additions & 0 deletions partiql-parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ tasks.processResources {
from("src/main/antlr") {
include("**/*.g4")
}
// TODO remove in next major version release.
rename("PartiQLParser.g4", "PartiQL.g4")
}

publish {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar PartiQL;
parser grammar PartiQLParser;

options {
tokenVocab=PartiQLTokens;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ import org.partiql.parser.PartiQLParserException
import org.partiql.parser.PartiQLSyntaxException
import org.partiql.parser.SourceLocation
import org.partiql.parser.SourceLocations
import org.partiql.parser.antlr.PartiQLBaseVisitor
import org.partiql.parser.antlr.PartiQLParserBaseVisitor
import org.partiql.parser.internal.util.DateTimeUtils
import org.partiql.value.NumericValue
import org.partiql.value.PartiQLValueExperimental
Expand Down Expand Up @@ -422,7 +422,7 @@ internal class PartiQLParserDefault : PartiQLParser {
private class Visitor(
private val locations: SourceLocations.Mutable,
private val parameters: Map<Int, Int> = mapOf(),
) : PartiQLBaseVisitor<AstNode>() {
) : PartiQLParserBaseVisitor<AstNode>() {

companion object {

Expand Down

0 comments on commit 005dbce

Please sign in to comment.