options { STATIC = false; } PARSER_BEGIN(FiqlParser) package org.opendaylight.controller.northbound.commons.query; import java.util.regex.*; /*package*/ class FiqlParser { public static Expression parse(String query) throws ParseException { FiqlParser parser = new FiqlParser(new java.io.StringReader(query)); return parser.START(); } } PARSER_END(FiqlParser) /* whitespace */ SKIP : { " " | "\t" } TOKEN : { <#ALPHA : ( ["a"-"z", "A"-"Z", "0"-"9"] )+ > } TOKEN : { | | } /* comparision ops */ TOKEN : { | ") > | =") > } /* ops */ TOKEN : { | } /* strings */ TOKEN : { ", "!", "~", " "] )+ > | | } /* Root production */ Expression START() : { Expression e; } { e = EXPR() { return e; } } Expression EXPR(): { ExpressionBuilder builder = new ExpressionBuilder(); Expression t; } { t = TERM() { builder.withTerm(t); } ( ( t = TERM()) { builder.withAnd().withTerm(t); } | ( t = TERM() ) { builder.withOr().withTerm(t); } )* { return builder.build(); } } Expression TERM() : { Token selector, arg; Expression exp; CompareExpression.OP op; } { selector = ( ( {op=CompareExpression.OP.EQ;} | {op=CompareExpression.OP.RE;} | {op=CompareExpression.OP.NE;} | {op=CompareExpression.OP.LT;} | {op=CompareExpression.OP.LE;} | {op=CompareExpression.OP.GT;} | {op=CompareExpression.OP.GE;} ) ( arg = | arg = | arg = | arg = ) ) { return new CompareExpression(op, selector.image, arg.image); } | ( exp = EXPR() ) { return exp; } }