rrevenantt / antlr4rust

ANTLR4 parser generator runtime for Rust programming laguage
Other
404 stars 70 forks source link

Usage questions and comments #19

Open fruffy opened 3 years ago

fruffy commented 3 years ago

First of all, thanks a lot for implementing this tool. I have generated a parser and visitor for the OpenCypher syntax using your generator. Everything has worked well out of the box. I have two small usability questions about working with the DAG.

Is there a way to get the type of a node using a helper function? Right now I am using a hacky method: ruleNames[parserNode.get_rule_index()], but this is a bit unwieldy. However, implementing a helper function seems complicated with the way the traits are set up.

Second, how can you visit a sub node explicitly using the visitor pattern? Currently, I am using child.accept(self);, but I am not sure if that is right way to visit or if it has unintended side effects.

I also have two minor comments on issues I encountered while using the generated code

There is a style issue regarding the generated code. The generated visitor and listener function calls use CamelCase style. Rust-analyzer complains about the lack of snake case, so I have to manually disable these checks. Are there plans to switch to snake case for the generated function calls?

Also another thing I have noticed is that the parser seems to continue even though it encounters an illegal expression. For example, for this piece of code:

let mut parser = CypherParser::new(token_source);
let result = parser.oC_Cypher();
match result {
    Err(e) => {
        log::error!("Error parsing query: {:?}", e);
    }
    Ok(v) => {
        to_ir::visit_result(v);
    }
}

I am unable to catch an error that is thrown in the parser. The program continues despite a parsing error. What is the right way to handle an error here?