All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.jexl3.parser.Parser.jjt Maven / Gradle / Ivy

Go to download

The Apache Commons JEXL library is an implementation of the JSTL Expression Language with extensions.

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


options
{
   MULTI=true;
   STATIC=false;
   JAVA_TEMPLATE_TYPE="modern";
   VISITOR=true;
   NODE_SCOPE_HOOK=true;
   NODE_CLASS="JexlNode";
   UNICODE_INPUT=true;
   KEEP_LINE_COLUMN=true;
   TRACK_TOKENS=true;
   CACHE_TOKENS=true;
   ERROR_REPORTING=false;
//   DEBUG_PARSER=true;
//   DEBUG_TOKEN_MANAGER=true;
}

PARSER_BEGIN(Parser)

package org.apache.commons.jexl3.parser;

import java.util.Collections;
import java.util.List;
import java.util.LinkedList;

import org.apache.commons.jexl3.JexlInfo;
import org.apache.commons.jexl3.JexlFeatures;
import org.apache.commons.jexl3.JexlException;
import org.apache.commons.jexl3.internal.Scope;

public final class Parser extends JexlParser
{
    public ASTJexlScript parse(JexlInfo jexlInfo, JexlFeatures jexlFeatures, String jexlSrc, Scope jexlScope) {
        JexlFeatures previous = getFeatures();
        try {
            setFeatures(jexlFeatures);
            // lets do the 'Unique Init' in here to be safe - it's a pain to remember
            info = jexlInfo != null? jexlInfo : new JexlInfo();
            source = jexlSrc;
            pragmas = null;
            this.scope = jexlScope;
            token_source.comparatorNames = jexlFeatures.supportsComparatorNames();
            ReInit(jexlSrc);
            ASTJexlScript script = jexlFeatures.supportsScript()
                ? JexlScript(jexlScope, jexlFeatures)
                : JexlExpression(jexlScope, jexlFeatures);
            script.jjtSetValue(info.detach());
            script.setPragmas(pragmas != null
                             ? Collections.unmodifiableMap(pragmas)
                             : Collections.emptyMap());
            return script;
        } catch (TokenMgrException xtme) {
            throw new JexlException.Tokenization(info, xtme).clean();
        } catch (ParseException xparse) {
            Token errortok = errorToken(jj_lastpos, jj_scanpos, token.next, token);
            throw new JexlException.Parsing(info.at(errortok.beginLine, errortok.beginColumn), errortok.image).clean();
        } finally {
            token_source.defaultLexState = DEFAULT;
            cleanup(previous);
            jjtree.reset();
        }
    }
}

PARSER_END(Parser)

TOKEN_MGR_DECLS : {
    boolean comparatorNames = false;
    boolean jexl331 = true;
}

/***************************************
 *     Skip & Number literal tokens
 ***************************************/

<*> SKIP : /* WHITE SPACE */
{
      " "
    | "\t"
    | "\n"
    | "\r"
    | "\f"
    | <"##" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
    | <"/*" (~["*"])* "*" ("*" | ~["*","/"] (~["*"])* "*")* "/">
    | <"//" (~["\n","\r"])* ("\n" | "\r" | "\r\n")? >
}

 TOKEN : /* Exception handling. */
{
      < THROW : "throw" >
    | < TRY : "try" >
    | < CATCH : "catch" >
    | < FINALLY : "finally" >
}

 TOKEN : /* Type check. */
{
      < ISA : "instanceof" >
}

<*> TOKEN : { /* SEPARATORS */
      < LPAREN : "(">
    | < RPAREN : ")">
    | < LCURLY : "{" >
    | < RCURLY : "}" >
    | < LBRACKET : "[" >
    | < QLBRACKET : "?[" >
    | < RBRACKET : "]" >
    | < SEMICOL : ";" >
    | < COLON : ":" >
    | < COMMA : "," >
    | < DOT : "." > : DOT_ID
    | < QDOT : "?." > : DOT_ID
    | < ELIPSIS : "..." >
}

<*> TOKEN : { /* CONDITIONALS */
      < QMARK : "?" >
    | < ELVIS : "?:" >
    | < NULLP : "??" >
    | < AND : "&&" >
    | < OR : "||" >
    | < NISA : "!instanceof">
}

 TOKEN : { /* CONDITIONALS */
      < _AND :  "and" >
    | < _OR: "or" >
}

<*> TOKEN : { /* COMPARISONS */
      < eq : "==" >
    | < ne : "!=" >
    | < gt : ">" >
    | < ge : ">=" >
    | < lt : "<" >
    | < le : "<=" >
    | < req : "=~" > // regexp equal
    | < rne : "!~" > // regexp not equal
    | < seq : "=^" > // starts equal
    | < eeq : "=$" > // ends equal
    | < sne : "!^" > // start not equal
    | < ene : "!$" > // ends not equal
    | < eqstrict : "===" > // strict equal
    | < neqstrict : "!==" > // strict not equal
}

 TOKEN : { /* COMPARISONS */
      < EQ : "eq" >
    | < NE : "ne" >
    | < GT : "gt" >
    | < GE : "ge" >
    | < LT : "lt" >
    | < LE : "le"  >
}

<*> TOKEN : { /* OPERATORS */
      < plus_assign : "+=" >
    | < minus_assign : "-=" >
    | < mult_assign : "*=" >
    | < div_assign : "/=" >
    | < mod_assign : "%=" >
    | < and_assign : "&=" >
    | < or_assign : "|=" >
    | < xor_assign : "^=" >
    | < lshift_assign : "<<=" >
    | < rshiftu_assign : ">>>=" >
    | < rshift_assign : ">>=" >

    | < assign : "=" >
    | < plus : "+" >
    | < plusplus : "++" >
    | < minus : "-" >
    | < minusminus : "--" >
    | < mult : "*" >
    | < div : "/" >
    | < mod : "%"  >
    | < not : "!" >
    | < and : "&" >
    | < or : "|" >
    | < xor : "^" >
    | < lshift : "<<" >
    | < rshiftu : ">>>" >
    | < rshift : ">>" >

    | < tilda : "~" >
    | < range : ".." >
}

 TOKEN : { /* OPERATORS */
      < NOT : "not" >
    | < DIV : "div" >
    | < MOD : "mod" >
}

<*> TOKEN : /* KEYWORDS */
{
      < LAMBDA : "->" >
    | < FATARROW : "=>" >
    | < PRAGMA : "#pragma" >
}

 TOKEN : /* KEYWORDS */
{
      < IF : "if" >
    | < ELSE : "else" >
    | < DO : "do" >
    | < WHILE : "while" >
    | < FOR : "for" >
    | < BREAK : "break" >
    | < CONTINUE : "continue" >
    | < FUNCTION : "function" >
    | < RETURN : "return" >
    | < NEW : "new" >
    | < SIZE : "size" >
    | < EMPTY : "empty" >
    | < VAR : "var" >
    | < LET : "let" >
    | < CONST : "const" >
    | < NULL : "null" >
    | < TRUE : "true" >
    | < FALSE : "false" >
}


/***************************************
 *     Identifier & String tokens
 ***************************************/
 TOKEN : /* NaN */
{
    < NAN_LITERAL : "NaN" >
}

 TOKEN : /* ANNOTATION */
{
  < ANNOTATION: "@" ( [ "0"-"9", "a"-"z", "A"-"Z", "_", "$" ])+ >
}

 TOKEN : /* IDENTIFIERS */
{
  < DOT_IDENTIFIER: ( [ "0"-"9", "a"-"z", "A"-"Z", "_", "$", "@" ])+ > : DEFAULT
}

 TOKEN : /* IDENTIFIERS */
{
  < IDENTIFIER:  (||)* >
  {
      matchedToken.image = StringParser.unescapeIdentifier(matchedToken.image);
      final int length = matchedToken.image.length();
      if (comparatorNames && length == 2) {
          switch (matchedToken.image) {
             case "ne" : matchedToken.kind = NE; break;
             case "eq" : matchedToken.kind = EQ; break;
             case "lt" : matchedToken.kind = LT; break;
             case "le" : matchedToken.kind = LE; break;
             case "gt" : matchedToken.kind = GT; break;
             case "ge" : matchedToken.kind = GE; break;
          }
      } else if (jexl331 && length >= 3 && length <= 10) {
          switch (matchedToken.image) {
             case "try" : matchedToken.kind = TRY; break;
             case "catch" : matchedToken.kind = CATCH; break;
             case "finally" : matchedToken.kind = FINALLY; break;
             case "throw" : matchedToken.kind = THROW; break;
             case "instanceof": matchedToken.kind = ISA; break;
             case "!instanceof": matchedToken.kind = NISA; break;
          }
      }
  }
|
  < #LETTER: [ "a"-"z", "A"-"Z", "_", "$", "@" ] >
|
  < #DIGIT: [ "0"-"9"] >
|
  < #ESCAPE: "\\" [" ", "'", "\"", "\\"] >
}

 TOKEN :
{
  < REGISTER: "#" (["0"-"9"])+ >
}

 TOKEN : /* LITERALS */
{
  ()?
    |  ()?
    |  ()?
 >
    | <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])*>
    | <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+>
    | <#OCTAL_LITERAL: "0" (["0"-"7"])*>
    | <#INT_SFX : ["l","L","h","H"]>
|
)?
    | (["0"-"9"])+ (".")? ()
    | "." (["0"-"9"])+ ()
    | "#NaN"
>
    |  <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+>
    |  <#FLT_CLS : ["f","F","d","D","b","B"]>
    |  <#FLT_SFX :  ()? |  >
}

<*> TOKEN :
{
  < STRING_LITERAL:
    "\"" (~["\"","\\","\n","\r","\u2028","\u2029"] | "\\" ~["\n","\r","\u2028","\u2029"])* "\""
  |
    "'" (~["'","\\","\n","\r","\u2028","\u2029"] | "\\" ~["\n","\r","\u2028","\u2029"])* "'"
  > : DEFAULT
}

<*> TOKEN :
{
  < JXLT_LITERAL:
    "`" (~["`","\\"] | "\\" ~["\u0000"])* "`"
  > : DEFAULT
}

 TOKEN :
{
  < REGEX_LITERAL:
    "~" "/" (~["/","\n","\r","\t","\f","\b","\u2028","\u2029"] | "\\" "/" )* "/"
  >
}

/***************************************
 *      Statements
 ***************************************/

ASTJexlScript JexlScript(Scope frame, JexlFeatures features) : {
    jjtThis.setScope(frame);
    jjtThis.setFeatures(features);
}
{
   {
        pushUnit(jjtThis);
   }
        ( LOOKAHEAD() Pragma() | { controlPragmaAnywhere(); } Statement() )* 
   {
        popUnit(jjtThis);
        return jjtThis.script();
   }
}

ASTJexlScript JexlExpression(Scope frame, JexlFeatures features) #JexlScript : {
    jjtThis.setScope(frame);
    jjtThis.setFeatures(features);
}
{
   {
        pushUnit(jjtThis);
   }
   ( Pragma() )* { controlPragmaAnywhere(); } ( Expression() )? 
   {
        popUnit(jjtThis);
        return jjtThis.script();
   }
}

void Annotation() #Annotation :
{
    Token t;
}
{
    t= { jjtThis.setName(t.image); } (LOOKAHEAD() Arguments() )?
}

void AnnotatedStatement() #AnnotatedStatement : {}
 {
    (LOOKAHEAD() Annotation())+ (LOOKAHEAD(1) Block() | Statement())
 }

void Statement() #void : {}
{
    LOOKAHEAD(||) Var()
    |
    LOOKAHEAD( ) FunctionStatement()
    |
    StatementNoVar()
}

void StatementNoVar() #void : {}
{
    
    | LOOKAHEAD() AnnotatedStatement()
    | LOOKAHEAD() IfStatement()
    | LOOKAHEAD() ForeachStatement()
    | LOOKAHEAD() WhileStatement()
    | LOOKAHEAD() DoWhileStatement()
    | LOOKAHEAD() ReturnStatement()
    | LOOKAHEAD() Continue()
    | LOOKAHEAD() Break()
    | LOOKAHEAD() ThrowStatement()
    | LOOKAHEAD() TryStatement()
    | LOOKAHEAD(LambdaLookahead()) Lambda()
    | LOOKAHEAD(Expression()) ExpressionStatement()
    | Block()
    | LOOKAHEAD(, {!getFeatures().isLexical()} ) Var()
}

void Block() #Block : {}
{
     { pushUnit(jjtThis); } ( LOOKAHEAD()  Pragma() | Statement() )* { popUnit(jjtThis); } 
}

void FunctionStatement() #JexlLambda : {}
{
 DeclareFunction() { beginLambda(jjtThis); } Parameters() ( LOOKAHEAD(3) Block() | Expression()) { endLambda(jjtThis); }
}

void ExpressionStatement() #void : {}
{
    Expression() (LOOKAHEAD(Expression()) Expression() #Ambiguous(1))* (LOOKAHEAD(1) )?
}


void IfStatement() : {}
{
      Expression()  (LOOKAHEAD(1) Block() | StatementNoVar())
    ( LOOKAHEAD(2)    Expression()  (LOOKAHEAD(1) Block() | StatementNoVar()) )*
    ( LOOKAHEAD(1)   (LOOKAHEAD(1) Block() | StatementNoVar()) )?
}

void TryStatement() : {}
{
      (LOOKAHEAD(1) TryResources() | Block())
     (LOOKAHEAD(1)  { pushUnit(jjtThis); }  InlineVar()  Block() { jjtThis.catchClause(); popUnit(jjtThis);})?
     (LOOKAHEAD(1)   Block() { jjtThis.finallyClause(); })?
}

void TryResources() : {}
{
    {
        pushUnit(jjtThis);
    }

    TryResource() ( LOOKAHEAD(2)  TryResource() )* ()?

    Block()
    {
        popUnit(jjtThis);
    }
}

void TryResource() #void : {}
{
LOOKAHEAD(2) Var() | Identifier(true)
}

void WhileStatement() : {}
{
      Expression()   { loopCount += 1; }  (LOOKAHEAD(1) Block() | StatementNoVar()) { loopCount -= 1; }
}

void DoWhileStatement() : {}
{
     { loopCount += 1; } (LOOKAHEAD(1) Block() | StatementNoVar())   Expression()  { loopCount -= 1; }
}

void ReturnStatement() : {}
{
     (LOOKAHEAD(2) ExpressionStatement() )?
}

void ThrowStatement() : {}
{
     (LOOKAHEAD(2) ExpressionStatement() )?
}

void Continue() #Continue : {
    Token t;
}
{
    t= { if (loopCount == 0) { throwParsingException(t); } }
}

void Break() #Break : {
    Token t;
}
{
    t= { if (loopCount == 0) { throwParsingException(t); } }
}

void ForeachStatement() : {
 int loopForm = 0;
}
{
    {
        pushUnit(jjtThis);
    }
     
    (
        LOOKAHEAD(3) InlineVar()  Expression() { loopForm = 0; }
    |
        ((LOOKAHEAD(1) Var() | Expression()) { loopForm = 1; })? 
        (Expression() { loopForm |= 2; })? 
        (Expression() { loopForm |= 4; })? { loopForm |= 8; }
    )
    
    {
        loopCount += 1;
    }
        (LOOKAHEAD(1) Block() | StatementNoVar() )
    {
        loopCount -= 1;
        jjtThis.setLoopForm(loopForm);
        popUnit(jjtThis);
    }
}

void InlineVar() #Reference : {}
{
     DeclareVar(false, false)
|
     DeclareVar(true, false)
|
     DeclareVar(true, true)
|
    Identifier(true)
}

void Var() #void : {}
{
    ( DefineVar() ( DefineVar())*) #DefineVars(>1)
    |
    ( DefineLet() ( DefineLet())*) #DefineVars(>1)
    |
    ( DefineConst() ( DefineConst())*) #DefineVars(>1)
}

 void DefineVar() #void : {}
 {
    DeclareVar(false, false) (LOOKAHEAD(1)  Expression() #Assignment(2))?
 }

void DefineLet() #void : {}
{
    DeclareVar(true, false) (LOOKAHEAD(1)  Expression() #Assignment(2))?
}

void DefineConst() #void : {}
{
    DeclareVar(true, true)  Expression() #Assignment(2)
}

void DeclareVar(boolean lexical, boolean constant) #Var :
{
    Token t;
}
{
    t= { declareVariable(jjtThis, t, lexical, constant); }
}
void DeclareFunction() #Var :
{
    Token t;
}
{
    t= { declareFunction(jjtThis, t); }
}

void Pragma() #void :
{
    LinkedList lstr = new LinkedList();
    Object value;
}
{
 pragmaKey(lstr)  value=pragmaValue() { declarePragma(stringify(lstr), value); }
}

void pragmaKey(List lstr) #void :
{
    Token t;
}
{
    t=  { lstr.add(t.image); } ( LOOKAHEAD() pragmaKey(lstr) )*
   |
     t= { lstr.add(t.image); }
}

Object pragmaValue() #void :
{
Token s = null;
Token v;
LinkedList lstr = new LinkedList();
Object result;
}
{
  (
      LOOKAHEAD(2) (s=|s=)? v= { result = NumberParser.parseInteger(s, v); }
    | LOOKAHEAD(2) (s=|s=)? v= { result = NumberParser.parseDouble(s, v); }
    | LOOKAHEAD(1) v= { result = Parser.buildString(v.image, true); }
    | LOOKAHEAD(1)  pragmaKey(lstr) { result = stringify(lstr); }
    | LOOKAHEAD(1)  { result = true; }
    | LOOKAHEAD(1)  { result = false; }
    | LOOKAHEAD(1)  { result = null; }
    | LOOKAHEAD(1)  { result = Double.NaN; }
  )
  {
    return result;
  }
}


/***************************************
 *      Expression syntax
 ***************************************/

void Expression() #void : {}
{
      AssignmentExpression()
}

void AssignmentExpression() #void : {}
{
  ConditionalExpression()
  ( LOOKAHEAD(2) (
      Expression() #SetAddNode(2)
  |
      Expression() #SetMultNode(2)
  |
      Expression() #SetDivNode(2)
  |
      Expression() #SetModNode(2)
  |
      Expression() #SetAndNode(2)
  |
      Expression() #SetOrNode(2)
  |
     Expression() #SetXorNode(2)
  |
      Expression() #SetSubNode(2)
  |
      Expression() #SetShiftLeftNode(2)
  |
      Expression() #SetShiftRightNode(2)
  |
      Expression() #SetShiftRightUnsignedNode(2)
  |
     Expression() #Assignment(2)
  ) )?
}

/***************************************
 *      Conditional & relational
 ***************************************/

void ConditionalExpression() #void : {}
{
  ConditionalOrExpression()
  ( LOOKAHEAD(2) (
     Expression()  Expression() #TernaryNode(3)
     |
     Expression() #TernaryNode(2)
  |
     Expression() #NullpNode(2)
  ) )?
}

void ConditionalOrExpression() #void : {}
{
  ( ConditionalAndExpression()
  ( LOOKAHEAD(2) ( (|<_OR>) ConditionalAndExpression()  ) )* ) #OrNode(>1)
}

void ConditionalAndExpression() #void : {}
{
  ( InclusiveOrExpression()
  ( LOOKAHEAD(2) ( (|<_AND>) InclusiveOrExpression()  ) )* ) #AndNode(>1)
}

void InclusiveOrExpression() #void : {}
{
  ExclusiveOrExpression()
  ( LOOKAHEAD(2) (  ExclusiveOrExpression() #BitwiseOrNode(2) ) )*
}

void ExclusiveOrExpression() #void : {}
{
  AndExpression()
  ( LOOKAHEAD(2) (  AndExpression() #BitwiseXorNode(2) ) )*
}

void AndExpression() #void : {}
{
  EqualityExpression()
  ( LOOKAHEAD(2) ( EqualityExpression() #BitwiseAndNode(2) ) )*
}

void EqualityExpression() #void : {}
{
  RelationalExpression()
  ( LOOKAHEAD(2) (
     ( | ) RelationalExpression() #EQNode(2)
   |
     ( | ) RelationalExpression() #NENode(2)
   |
      RelationalExpression() #EQSNode(2)
   |
      RelationalExpression() #NESNode(2)
   |
      RelationalExpression() #RangeNode(2) // range
  ) )?
}

void RelationalExpression() #void : {}
{
  ShiftExpression()
  ( LOOKAHEAD(2) (
    ( |)  ShiftExpression() #LTNode(2)
   |
    ( | ) ShiftExpression() #GTNode(2)
   |
    ( | ) ShiftExpression() #LENode(2)
   |
    ( | ) ShiftExpression() #GENode(2)
   |
     ShiftExpression() #ERNode(2) // equals regexp
   |
     ShiftExpression() #NRNode(2) // not equals regexp
   |
     ShiftExpression() #SWNode(2) // starts with
   |
     ShiftExpression() #NSWNode(2) // not starts with
   |
     ShiftExpression() #EWNode(2) // ends with
   |
     ShiftExpression() #NEWNode(2) // not ends with
   |
     ShiftExpression() #InstanceOf(2) // instanceof
   |
     ShiftExpression() #NotInstanceOf(2) // not instanceof
  ) )?
}

/***************************************
 *      Arithmetic
 ***************************************/
void ShiftExpression() #void : {}
{
    AdditiveExpression()
    ( LOOKAHEAD(2) (
       AdditiveExpression() #ShiftLeftNode(2) // left shift
    |
       AdditiveExpression() #ShiftRightNode(2) // right shift
    |
       AdditiveExpression() #ShiftRightUnsignedNode(2) // right shift unsigned
    ) )*
}

void AdditiveExpression() #void : {}
{
  MultiplicativeExpression()
  ( LOOKAHEAD(2) (
     MultiplicativeExpression() #AddNode(2)
  |
     MultiplicativeExpression() #SubNode(2)
  ) )*
}

void MultiplicativeExpression() #void : {}
{
  UnaryExpression()
  ( LOOKAHEAD(2) (
     UnaryExpression() #MulNode(2)
  |
    (
|
) UnaryExpression() #DivNode(2) | (|) UnaryExpression() #ModNode(2) ) )* } void UnaryExpression() #void : {} { UnaryExpression() #UnaryMinusNode(1) | UnaryExpression() #UnaryPlusNode(1) | UnaryExpression() #BitwiseComplNode(1) | (|) UnaryExpression() #NotNode(1) | UnaryExpression() #EmptyFunction(1) | UnaryExpression() #SizeFunction(1) | UnaryExpression() #DecrementGetNode(1) | UnaryExpression() #IncrementGetNode(1) | PostfixExpression() } void PostfixOperator() #void : {} { #GetIncrementNode(1) | #GetDecrementNode(1) } void PostfixExpression() #void : {} { ValueExpression() [ LOOKAHEAD(1) PostfixOperator() ] } /*************************************** * Identifier & Literals ***************************************/ void Identifier(boolean top) : { Token t; } { t= { jjtThis.setSymbol(top? checkVariable(jjtThis, t.image) : t.image); } | t= { if (!getFeatures().supportsRegister()) throwParsingException(t); jjtThis.setSymbol(t.image); } } void NamespaceIdentifier() #NamespaceIdentifier : { Token ns; Token id; } { ns= id= { jjtThis.setNamespace(ns.image, id.image); } } void Literal() #void : { Token t; } { IntegerLiteral() | FloatLiteral() | BooleanLiteral() | JxltLiteral() | StringLiteral() | RegexLiteral() | NullLiteral() | NaNLiteral() } void NaNLiteral() #NumberLiteral : {} { { jjtThis.setReal("NaN"); } } void NullLiteral() : {} { } void BooleanLiteral() #void : {} { #TrueNode | #FalseNode } void IntegerLiteral() #NumberLiteral : { Token t; } { t= { jjtThis.setNatural(t.image); } } void FloatLiteral() #NumberLiteral: { Token t; } { t= { jjtThis.setReal(t.image); } } void StringLiteral() : { Token t; } { t= { jjtThis.setLiteral(Parser.buildString(t.image, true)); } } void JxltLiteral() #JxltLiteral : { Token t; } { t= { jjtThis.setLiteral(Parser.buildString(t.image, true)); } } void RegexLiteral() : { Token t; } { t= { jjtThis.setLiteral(Parser.buildRegex(t.image)); } } void ExtendedLiteral() #ExtendedLiteral : {} { } void ArrayLiteral() : {} { ( ()? ExtendedLiteral() | (Expression() (LOOKAHEAD(2) Expression())* ( (ExtendedLiteral() { jjtThis.setExtended(true); })? )? )? ) } void MapLiteral() : {} { ( MapEntry() (LOOKAHEAD(2) MapEntry() )* ( (ExtendedLiteral(){ jjtThis.setExtended(true); })? )? | ) } void MapEntry() : {} { LOOKAHEAD(2) Identifier(true) Expression() | Expression() Expression() } void SetLiteral() : {} { ( Expression() (LOOKAHEAD(2) Expression())* ( (ExtendedLiteral() { jjtThis.setExtended(true); } )? )? )? } /*************************************** * Functions & Methods ***************************************/ void Arguments() #Arguments : {} { (Expression() ( Expression())* )? } void FunctionCallLookahead() #void : {} { LOOKAHEAD(4, , { isNamespaceFuncall(getToken(1), getToken(2), getToken(3), getToken(4)) }) | LOOKAHEAD(2) | LOOKAHEAD(2) } void FunctionCall() #void : {} { LOOKAHEAD(4, , { isNamespaceFuncall(getToken(1), getToken(2), getToken(3), getToken(4)) }) NamespaceIdentifier() Arguments() #FunctionNode(2) | LOOKAHEAD( ) Identifier(true) Arguments() #FunctionNode(2) } void QualifiedIdentifier() #QualifiedIdentifier : { LinkedList lstr = new LinkedList(); } { pragmaKey(lstr) { jjtThis.setName(stringify(lstr));} } void Constructor() #ConstructorNode : {} { LOOKAHEAD(2) Expression() ( Expression() )* | QualifiedIdentifier() [ Expression() ( Expression() )* ] } void Parameter() #void : { Token t; } { ()? t= { declareParameter(t, false, false); } | t= { declareParameter(t, true, false); } | t= { declareParameter(t, true, true); } } void Parameters() #void : {} { [Parameter() ( Parameter())* ] } void ParametersLookahead() #void : {} { [(||)? ( ((||)? ))*] } void LambdaLookahead() #void : {} { ParametersLookahead() | ParametersLookahead() ( | ) | ( | ) } void Lambda() #JexlLambda : { Token arrow; Token name; } { (LOOKAHEAD() DeclareFunction())? { beginLambda(jjtThis); } Parameters() ( LOOKAHEAD(3) Block() | Expression()) { endLambda(jjtThis); } | { beginLambda(jjtThis); } Parameters() (arrow= | arrow=) ( LOOKAHEAD(3) Block() | Expression()) { checkLambda(arrow); endLambda(jjtThis); } | { beginLambda(jjtThis); } Parameter() (arrow= | arrow=)( LOOKAHEAD(3) Block() | Expression()) { checkLambda(arrow); endLambda(jjtThis); } } /*************************************** * References ***************************************/ void IdentifierAccess() #void : { Token t; } { ( t= { jjtThis.setIdentifier(t.image); } #IdentifierAccess | t= { jjtThis.setIdentifier(Parser.buildString(t.image, true)); } #IdentifierAccess | t= { jjtThis.setIdentifier(Parser.buildString(t.image, true)); } #IdentifierAccessJxlt ) | ( t= { jjtThis.setIdentifier(t.image); } #IdentifierAccessSafe | t= { jjtThis.setIdentifier(Parser.buildString(t.image, true)); } #IdentifierAccessSafe | t= { jjtThis.setIdentifier(Parser.buildString(t.image, true)); } #IdentifierAccessSafeJxlt ) } void ArrayAccess() : { long safe = 0L; int s = 0; } { (LOOKAHEAD(2) (| { safe |= (1L << s++); }) Expression() )+ { jjtThis.setSafe(safe); } } void MemberAccess() #void : {} { LOOKAHEAD(|) ArrayAccess() | LOOKAHEAD() IdentifierAccess() | LOOKAHEAD() IdentifierAccess() } void ReferenceExpression() #MethodNode(>1) : {} { Expression() #ReferenceExpression(1) ( LOOKAHEAD() Arguments() )* } void PrimaryExpression() #void : {} { LOOKAHEAD( LambdaLookahead() ) Lambda() | LOOKAHEAD( ) ReferenceExpression() | LOOKAHEAD( Expression() ) MapLiteral() | LOOKAHEAD( ) MapLiteral() | LOOKAHEAD( Expression() ( | )) SetLiteral() | LOOKAHEAD( ) SetLiteral() | LOOKAHEAD( ) ArrayLiteral() | LOOKAHEAD( ) Constructor() | LOOKAHEAD( FunctionCallLookahead() ) FunctionCall() | Identifier(true) | Literal() } void MethodCall() #void : {} { (MemberAccess() (LOOKAHEAD() Arguments())+) #MethodNode(>1) } void MethodCallLookahead() #void : {} { MemberAccess() } void MemberExpression() #void : {} { LOOKAHEAD(MethodCallLookahead()) MethodCall() | MemberAccess() } void ValueExpression() #void : {} { ( PrimaryExpression() ( LOOKAHEAD(2) MemberExpression() )*) #Reference(>1) }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy