Search in sources :

Example 1 with StringProvider

use of org.apache.commons.jexl3.parser.StringProvider in project commons-jexl by apache.

the class Engine method parse.

/**
 * Parses an expression.
 *
 * @param info      information structure
 * @param parsingf  the set of parsing features
 * @param src      the expression to parse
 * @param scope     the script frame
 * @return the parsed tree
 * @throws JexlException if any error occurred during parsing
 */
protected ASTJexlScript parse(final JexlInfo info, final JexlFeatures parsingf, final String src, final Scope scope) {
    final boolean cached = src.length() < cacheThreshold && cache != null;
    JexlFeatures features = parsingf != null ? parsingf : DEFAULT_FEATURES;
    // if (features.getNameSpaces().isEmpty() && !functions.isEmpty()) {
    // features = new JexlFeatures(features).nameSpaces(functions.keySet());
    // }
    final Source source = cached ? new Source(features, src) : null;
    ASTJexlScript script;
    if (source != null) {
        script = cache.get(source);
        if (script != null) {
            final Scope f = script.getScope();
            if ((f == null && scope == null) || (f != null && f.equals(scope))) {
                return script;
            }
        }
    }
    final JexlInfo ninfo = info == null && debug ? createInfo() : info;
    // if parser not in use...
    if (parsing.compareAndSet(false, true)) {
        try {
            // lets parse
            script = parser.parse(ninfo, features, src, scope);
        } finally {
            // no longer in use
            parsing.set(false);
        }
    } else {
        // ...otherwise parser was in use, create a new temporary one
        final Parser lparser = new Parser(new StringProvider(";"));
        script = lparser.parse(ninfo, features, src, scope);
    }
    if (source != null) {
        cache.put(source, script);
    }
    return script;
}
Also used : ASTJexlScript(org.apache.commons.jexl3.parser.ASTJexlScript) StringProvider(org.apache.commons.jexl3.parser.StringProvider) JexlFeatures(org.apache.commons.jexl3.JexlFeatures) JexlInfo(org.apache.commons.jexl3.JexlInfo) Parser(org.apache.commons.jexl3.parser.Parser)

Aggregations

JexlFeatures (org.apache.commons.jexl3.JexlFeatures)1 JexlInfo (org.apache.commons.jexl3.JexlInfo)1 ASTJexlScript (org.apache.commons.jexl3.parser.ASTJexlScript)1 Parser (org.apache.commons.jexl3.parser.Parser)1 StringProvider (org.apache.commons.jexl3.parser.StringProvider)1