Search in sources :

Example 1 with ConditionLexer

use of com.google.security.zynamics.binnavi.parsers.BreakpointCondition.ConditionLexer in project binnavi by google.

the class BreakpointConditionParser method parse.

/**
 * Parses a breakpoint condition string.
 *
 * @param conditionString The condition string to parse.
 *
 * @return The parsed breakpoint condition tree.
 *
 * @throws RecognitionException Thrown if the condition string could not be parsed.
 * @throws MaybeNullException Thrown if an empty condition string is passed to the function.
 */
public static ConditionNode parse(final String conditionString) throws RecognitionException, MaybeNullException {
    if (conditionString.trim().isEmpty()) {
        throw new MaybeNullException();
    }
    final CharStream charStream = new ANTLRStringStream(conditionString);
    final ConditionLexer lexer = new ConditionLexer(charStream);
    final CommonTokenStream tokens = new CommonTokenStream();
    tokens.setTokenSource(lexer);
    final ConditionParser parser = new ConditionParser(tokens);
    parser.setTreeAdaptor(adaptor);
    try {
        final ConditionParser.prog_return parserResult = parser.prog();
        final CommonTree ast = (CommonTree) parserResult.getTree();
        if (parser.input.index() < parser.input.size()) {
            throw new RecognitionException();
        }
        return convert(ast);
    } catch (final IllegalArgumentException e) {
        throw new RecognitionException();
    }
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) CommonTokenStream(org.antlr.runtime.CommonTokenStream) MaybeNullException(com.google.security.zynamics.binnavi.Exceptions.MaybeNullException) ConditionParser(com.google.security.zynamics.binnavi.parsers.BreakpointCondition.ConditionParser) CommonTree(org.antlr.runtime.tree.CommonTree) ConditionLexer(com.google.security.zynamics.binnavi.parsers.BreakpointCondition.ConditionLexer) CharStream(org.antlr.runtime.CharStream) RecognitionException(org.antlr.runtime.RecognitionException)

Aggregations

MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)1 ConditionLexer (com.google.security.zynamics.binnavi.parsers.BreakpointCondition.ConditionLexer)1 ConditionParser (com.google.security.zynamics.binnavi.parsers.BreakpointCondition.ConditionParser)1 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 CharStream (org.antlr.runtime.CharStream)1 CommonTokenStream (org.antlr.runtime.CommonTokenStream)1 RecognitionException (org.antlr.runtime.RecognitionException)1 CommonTree (org.antlr.runtime.tree.CommonTree)1