public static int syntaxLength(final String str, EvalEngine engine) throws SyntaxError { try { ExprParser parser = new ExprParser(engine); parser.parse(str); } catch (final SyntaxError e) { return e.getStartOffset(); } return str.length(); }
@Override public IExpr evaluate(final IAST ast) { Validate.checkSize(ast,2); if (!(ast.get(1) instanceof IStringX)) { return null; } final String str = ast.get(1).toString(); try { new Parser().parse(str); } catch (final SyntaxError e) { return F.integer(e.getStartOffset()); } return F.integer(str.length()); }
/** * {@inheritDoc} */ @Override public Criteria fromQuery( String aQuery ) throws ParseException { // 1.: Normalize the query to use a simple regular expression: aQuery = toNormalized( aQuery ); // 2.: Now escape chars being reserved by the used parser: aQuery = toEscaped( aQuery ); // 3.: Now remove any remaining single quotes: // aQuery = toStripped( aQuery ); if ( aQuery.equals( "" + Wildcard.QUERY.getChar() ) ) { return null; } Parser theParser = new Parser(); try { ASTNode theNode = theParser.parse( aQuery ); if ( theNode instanceof FunctionNode ) { return toCriteria( (FunctionNode) theNode ); } } catch ( SyntaxError e ) { throw new ParseException( aQuery, e.getStartOffset() ); } throw new ParseException( aQuery, 0 ); }