Search in sources :

Example 1 with SightlyParser

use of org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyParser 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 SightlyParser

use of org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyParser in project sling by apache.

the class ExpressionParser method createParser.

private SightlyParser createParser(String string) {
    SightlyLexer lexer = new SightlyLexer(new ANTLRInputStream(string));
    lexer.removeErrorListeners();
    lexer.addErrorListener(new SightlyParserErrorListener());
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    SightlyParser parser = new SightlyParser(tokenStream);
    parser.removeErrorListeners();
    parser.addErrorListener(new SightlyParserErrorListener());
    return parser;
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) SightlyLexer(org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyLexer) SightlyParser(org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyParser) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream)

Aggregations

SightlyParser (org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyParser)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 RecognitionException (org.antlr.v4.runtime.RecognitionException)1 SightlyCompilerException (org.apache.sling.scripting.sightly.compiler.SightlyCompilerException)1 SightlyLexer (org.apache.sling.scripting.sightly.impl.parser.expr.generated.SightlyLexer)1