/presto_rs

Presto Parser in Rust

Primary LanguageRust

presto_rs

presto_rs is a Presto parser written in rust. It is a hand coded recursive descent parser based on the grammar in https://github.com/prestodb/presto/blob/master/presto-parser/src/main/antlr4/com/facebook/presto/sql/parser/SqlBase.g4.

Example usage:

fn parse(contents: &str) {
    let mut parser = Parser::new(contents);
    let tree = parser.parse_statement();
    let errors = errors_of_tree(&tree);
    if errors.is_empty() {
        println!("{:#?}", tree);
    } else {
        println!("{:#?}", errors[0]);
    }
}

See src/main.rs for the complete example usage.

Developing the parser:

  • parse trees are generated by adding to the list at the top of tools/generate_parse_trees/src/main.rs.
  • Then run ./scripts/generate_parse_trees.sh to regenerate src/parsing/parse_tree.rs.
  • The core parser is in /src/parsing/parser/rs.