Search in sources :

Example 1 with GraqlErrorListener

use of ai.grakn.graql.internal.parser.GraqlErrorListener in project grakn by graknlabs.

the class TemplateParser method parseTemplate.

/**
 * Parse and resolve a graql template.
 * @param templateString a string representing a graql template
 * @param data data to use in template
 * @return resolved graql query string
 */
public String parseTemplate(String templateString, Map<String, Object> data) {
    GraqlErrorListener errorListener = GraqlErrorListener.of(templateString);
    CommonTokenStream tokens = lexGraqlTemplate(templateString, errorListener);
    ParseTree tree = parseGraqlTemplate(tokens, errorListener);
    TemplateVisitor visitor = new TemplateVisitor(tokens, data, macros);
    return visitor.visit(tree).toString();
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) GraqlErrorListener(ai.grakn.graql.internal.parser.GraqlErrorListener) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

GraqlErrorListener (ai.grakn.graql.internal.parser.GraqlErrorListener)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1