Using the Parser
If there are inaccuracies discovered with this documentation, please submit a GitHub issue. |
Who is this for?
You can use the partiql-lang-kotlin parser (partiql-parser) to parse statements into an AST (partiql-ast). Common use-cases include:
-
Highlighting text on a CLI.
-
Analyzing the syntactical elements of a user’s query.
-
Allowing or blocking certain syntax.
High-Level Overview
The Parser takes in PartiQL text and outputs an Abstract Syntax Tree (AST).
The parser is designed to act as a singleton in your application by taking in all required information via its parameters on the parse()
method.
Instantiation & Usage
Your Application Code
import org.partiql.ast.Statement
import org.partiql.parser.PartiQLParser
fun main() {
// Instantiate the parser
private val parser: PartiQLParser = PartiQLParser.standard()
// Parse
val parseResult: PartiQLParser.Result = parser.parse(input)
// Assert that the user only entered a single statement, for simplicity
assertEquals(1, parseResult.statements.size)
val statement: Statement = parseResult.statements[0]
// The rest of your application code...
performFurtherAnalysis(statement)
}
Error Handling
The parser also has a method, parse(String, Context)
, that is used to provide a customized error-handling experience. Please see the Error Handling User Guide for more information.