diff --git a/partiql-cli/src/main/kotlin/org/partiql/cli/shell/ShellHighlighter.kt b/partiql-cli/src/main/kotlin/org/partiql/cli/shell/ShellHighlighter.kt index 058d66220..e89c39bed 100644 --- a/partiql-cli/src/main/kotlin/org/partiql/cli/shell/ShellHighlighter.kt +++ b/partiql-cli/src/main/kotlin/org/partiql/cli/shell/ShellHighlighter.kt @@ -89,7 +89,7 @@ internal object ShellHighlighter : Highlighter { // Parse and Replace Token Style if Failures try { - parser.file() + parser.statements() } catch (e: RethrowErrorListener.OffendingSymbolException) { val offending = e.offendingSymbol val prefix = builder.substring(0, offending.startIndex) diff --git a/partiql-parser/src/main/antlr/PartiQLParser.g4 b/partiql-parser/src/main/antlr/PartiQLParser.g4 index b32a2d20c..dafc1fd00 100644 --- a/partiql-parser/src/main/antlr/PartiQLParser.g4 +++ b/partiql-parser/src/main/antlr/PartiQLParser.g4 @@ -11,7 +11,7 @@ options { * */ -file +statements : statement (COLON_SEMI statement)* COLON_SEMI? EOF ; diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PFile.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PFile.kt deleted file mode 100644 index db8942d47..000000000 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PFile.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.partiql.parser.internal - -import org.partiql.ast.AstNode -import org.partiql.ast.Statement -import org.partiql.ast.visitor.AstVisitor - -internal class PFile( - internal val statements: List, -) : AstNode() { - - override val children: List = this.statements - - override fun accept(visitor: AstVisitor, ctx: C): R { - error("This is an internal ast node and cannot be passed to a visitor.") - } -} diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PFileV1.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PFileV1.kt deleted file mode 100644 index ff59342d1..000000000 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PFileV1.kt +++ /dev/null @@ -1,17 +0,0 @@ -package org.partiql.parser.internal - -import org.partiql.ast.v1.AstNode -import org.partiql.ast.v1.AstVisitor -import org.partiql.ast.v1.Statement - -internal class PFileV1( - internal val statements: List, -) : AstNode() { - override fun children(): MutableCollection { - return statements.toMutableList() - } - - override fun accept(visitor: AstVisitor, ctx: C): R { - error("This is an internal ast node and cannot be passed to a visitor.") - } -} diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt index 7fe7de28f..04cdcf5f7 100644 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt +++ b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefault.kt @@ -270,7 +270,7 @@ internal class PartiQLParserDefault : PartiQLParser { PredictionMode.LL -> parser.addErrorListener(ParseErrorListener(listener)) else -> throw IllegalArgumentException("Unsupported parser mode: $mode") } - val tree = parser.file() + val tree = parser.statements() return Visitor.translate(tokens, tree) } @@ -393,12 +393,14 @@ internal class PartiQLParserDefault : PartiQLParser { */ fun translate( tokens: CountingTokenStream, - tree: GeneratedParser.FileContext, + tree: GeneratedParser.StatementsContext, ): PartiQLParser.Result { val locations = mutableMapOf() val visitor = Visitor(tokens, locations, tokens.parameterIndexes) - val root: PFile = visitor.visitFile(tree) - return PartiQLParser.Result(root.statements, SourceLocations(locations)) + val statements = tree.statement().map { statementCtx -> + visitor.visit(statementCtx) as Statement + } + return PartiQLParser.Result(statements, SourceLocations(locations)) } fun error( @@ -497,11 +499,6 @@ internal class PartiQLParserDefault : PartiQLParser { ) } - override fun visitFile(ctx: GeneratedParser.FileContext): PFile = translate(ctx) { - val stmts = visitOrEmpty(ctx.statement()) - PFile(stmts) - } - /** * * COMMON USAGES diff --git a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefaultV1.kt b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefaultV1.kt index 6914391b2..e861073bc 100644 --- a/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefaultV1.kt +++ b/partiql-parser/src/main/kotlin/org/partiql/parser/internal/PartiQLParserDefaultV1.kt @@ -251,7 +251,7 @@ internal class PartiQLParserDefaultV1 : PartiQLParserV1 { PredictionMode.LL -> parser.addErrorListener(ParseErrorListener(listener)) else -> throw IllegalArgumentException("Unsupported parser mode: $mode") } - val tree = parser.file() + val tree = parser.statements() return Visitor.translate(tokens, tree) } @@ -367,13 +367,15 @@ internal class PartiQLParserDefaultV1 : PartiQLParserV1 { */ fun translate( tokens: CountingTokenStream, - tree: PartiQLParser.FileContext, + tree: PartiQLParser.StatementsContext, ): PartiQLParserV1.Result { val locations = mutableMapOf() val visitor = Visitor(tokens, locations, tokens.parameterIndexes) - val root: PFileV1 = visitor.visitFile(tree) + val statements = tree.statement().map { statementCtx -> + visitor.visit(statementCtx) as Statement + } return PartiQLParserV1.Result( - root.statements.toMutableList(), + statements, SourceLocations(locations), ) } @@ -471,11 +473,6 @@ internal class PartiQLParserDefaultV1 : PartiQLParserV1 { ) } - override fun visitFile(ctx: GeneratedParser.FileContext): PFileV1 = translate(ctx) { - val stmts = visitOrEmpty(ctx.statement()) - PFileV1(stmts) - } - /** * * COMMON USAGES