Skip to content

Commit

Permalink
Updates naming of ANTLR root to statements
Browse files Browse the repository at this point in the history
Removes use of PFile and PFileV1
  • Loading branch information
johnedquinn committed Nov 1, 2024
1 parent 147419f commit b40e03e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion partiql-parser/src/main/antlr/PartiQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ options {
*
*/

file
statements
: statement (COLON_SEMI statement)* COLON_SEMI? EOF
;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -393,12 +393,14 @@ internal class PartiQLParserDefault : PartiQLParser {
*/
fun translate(
tokens: CountingTokenStream,
tree: GeneratedParser.FileContext,
tree: GeneratedParser.StatementsContext,
): PartiQLParser.Result {
val locations = mutableMapOf<String, SourceLocation>()
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(
Expand Down Expand Up @@ -497,11 +499,6 @@ internal class PartiQLParserDefault : PartiQLParser {
)
}

override fun visitFile(ctx: GeneratedParser.FileContext): PFile = translate(ctx) {
val stmts = visitOrEmpty<Statement>(ctx.statement())
PFile(stmts)
}

/**
*
* COMMON USAGES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -367,13 +367,15 @@ internal class PartiQLParserDefaultV1 : PartiQLParserV1 {
*/
fun translate(
tokens: CountingTokenStream,
tree: PartiQLParser.FileContext,
tree: PartiQLParser.StatementsContext,
): PartiQLParserV1.Result {
val locations = mutableMapOf<String, SourceLocation>()
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),
)
}
Expand Down Expand Up @@ -471,11 +473,6 @@ internal class PartiQLParserDefaultV1 : PartiQLParserV1 {
)
}

override fun visitFile(ctx: GeneratedParser.FileContext): PFileV1 = translate(ctx) {
val stmts = visitOrEmpty<Statement>(ctx.statement())
PFileV1(stmts)
}

/**
*
* COMMON USAGES
Expand Down

0 comments on commit b40e03e

Please sign in to comment.