Search in sources :

Example 1 with SightlyCompilerException

use of org.apache.sling.scripting.sightly.compiler.SightlyCompilerException in project sling by apache.

the class ExpressionParser method parseInterpolation.

/**
     * Parses the expression string.
     *
     * @param expressionString as defined by the HTL spec (https://github.com/Adobe-Marketing-Cloud/htl-spec/blob/master/SPECIFICATION.md)
     * @return Parsed Expression object
     * @throws NullPointerException     is the given exprString is null
     * @throws SightlyCompilerException if an error occurs while parsing the expression
     */
public Interpolation parseInterpolation(String expressionString) throws SightlyCompilerException {
    SightlyParser parser = createParser(expressionString);
    try {
        Interpolation interpolation = parser.interpolation().interp;
        interpolation.setContent(expressionString);
        return interpolation;
    } catch (RecognitionException e) {
        throw new SightlyCompilerException(e);
    }
}
Also used : SightlyCompilerException(org.apache.sling.scripting.sightly.compiler.SightlyCompilerException) SightlyParser(org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyParser) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 2 with SightlyCompilerException

use of org.apache.sling.scripting.sightly.compiler.SightlyCompilerException in project sling by apache.

the class CallPlugin method invoke.

@Override
public PluginInvoke invoke(final Expression expression, final PluginCallInfo callInfo, final CompilerContext compilerContext) {
    if (callInfo.getArguments().length > 0) {
        throw new SightlyCompilerException("Call plugin should have no arguments.", "data-sly-call." + callInfo.getArguments()[0]);
    }
    return new DefaultPluginInvoke() {

        @Override
        public void beforeChildren(PushStream stream) {
            String templateVar = compilerContext.generateVariable("templateVar");
            String argsVar = compilerContext.generateVariable("templateOptions");
            MapLiteral args = new MapLiteral(expression.getOptions());
            stream.write(new VariableBinding.Start(templateVar, expression.getRoot()));
            stream.write(new VariableBinding.Start(argsVar, args));
            stream.write(new Procedure.Call(templateVar, argsVar));
            stream.write(VariableBinding.END);
            stream.write(VariableBinding.END);
            //ignoring everything else
            Patterns.beginStreamIgnore(stream);
        }

        @Override
        public void afterChildren(PushStream stream) {
            Patterns.endStreamIgnore(stream);
        }
    };
}
Also used : MapLiteral(org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral) SightlyCompilerException(org.apache.sling.scripting.sightly.compiler.SightlyCompilerException) PushStream(org.apache.sling.scripting.sightly.impl.compiler.PushStream) Procedure(org.apache.sling.scripting.sightly.compiler.commands.Procedure) VariableBinding(org.apache.sling.scripting.sightly.compiler.commands.VariableBinding)

Aggregations

SightlyCompilerException (org.apache.sling.scripting.sightly.compiler.SightlyCompilerException)2 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 Procedure (org.apache.sling.scripting.sightly.compiler.commands.Procedure)1 VariableBinding (org.apache.sling.scripting.sightly.compiler.commands.VariableBinding)1 MapLiteral (org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral)1 PushStream (org.apache.sling.scripting.sightly.impl.compiler.PushStream)1 SightlyParser (org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyParser)1