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

com.sun.el.parser.ELParser.jjt Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

/*
	Author:	Jacob Hookom
	Email:	jacob at hookom.net

        Author: Kin-man Chung (EL 2.2 and EL 3.0)
*/

/* == Option Declaration == */
options
{
	STATIC=false;
	NODE_PREFIX="Ast";
	VISITOR_EXCEPTION="ELException";
	VISITOR=false;
	MULTI=true;
	NODE_DEFAULT_VOID=true;
	JAVA_UNICODE_ESCAPE=false;
  	UNICODE_INPUT=true;
	BUILD_NODE_FILES=true;
}

/* == Parser Declaration == */
PARSER_BEGIN( ELParser )
package com.sun.el.parser;
import java.io.StringReader;
import ELException;
public class ELParser
{
    public static Node parse(String ref) throws ELException
    {
        try {
        	return (new ELParser(new StringReader(ref))).CompositeExpression();
        } catch (ParseException pe) {
           	throw new ELException(pe.getMessage());
        }
    }
}
PARSER_END( ELParser )

/*
 * CompositeExpression
 * Allow most flexible parsing, restrict by examining
 * type of returned node
 */
AstCompositeExpression CompositeExpression() #CompositeExpression : {}
{
	(DeferredExpression() | DynamicExpression() | LiteralExpression())*  { return jjtThis; }
}

/*
 * LiteralExpression
 * Non-EL Expression blocks
 */
void LiteralExpression() #LiteralExpression : { Token t = null; }
{
	t= { jjtThis.setImage(t.image); }
}

/*
 * DeferredExpression
 * #{..} Expressions
 */
void DeferredExpression() #DeferredExpression : {}
{
	 Expression()  
}

/*
 * DynamicExpression
 * ${..} Expressions
 */
void DynamicExpression() #DynamicExpression : {}
{
	 Expression()  
}

/*
 * Expression
 * EL Expression Language Root
 */
void Expression() : {}
{
        SemiColon()
}

/*
 * SemiColon
 */
void SemiColon() : {}
{
        Assignment() ( Assignment() #SemiColon(2) )*
}

/*
 * Assignment
 * For '=', right associatve, then LambdaExpression or Choice or Assignment
 */
void Assignment() : {}
{
        LOOKAHEAD(4) LambdaExpression() | // Do not mistake ((i)) with Lambdaexp check until the arrow
        Choice() ( LOOKAHEAD(2)  Assignment() #Assign(2) )* // avoid failure of expr ${x = 10}
}

/*
 * LambdaExpression
 */
void LambdaExpression() #LambdaExpression : {}
{
       LambdaParameters() 
       (LOOKAHEAD(3) LambdaExpression() | Choice() )
}

void LambdaParameters() #LambdaParameters: {}
{
       Identifier()
       | 
            (Identifier() ( Identifier())*)?
         
}

/*
 * Choice
 * For Choice markup a ? b : c, right associative
 */
void Choice() : {}
{
	Or() ( Choice()  Choice() #Choice(3))?
}

/*
 * Or
 * For 'or' '||', then And
 */
void Or() : {}
{
	And() ((|) And() #Or(2))*
}

/*
 * And
 * For 'and' '&&', then Equality
 */
void And() : {}
{
	Equality() ((|) Equality() #And(2))*
}

/*
 * Equality
 * For '==' 'eq' '!=' 'ne', then Compare
 */
void Equality() : {}
{
	Compare()
	(
		((|) Compare() #Equal(2))
	|
		((|) Compare() #NotEqual(2))
	)*
}

/*
 * Compare
 * For a bunch of them, then Math
 */
void Compare() : {}
{
	Concatenation()
	(
		((|) Concatenation() #LessThan(2))
	|
		((|) Concatenation() #GreaterThan(2))
	|
		((|) Concatenation() #LessThanEqual(2))
	|
		((|) Concatenation() #GreaterThanEqual(2))
	)*
}

/*
 * Concatenation
 * For '&', then Math()
 */
void Concatenation() : {}
{
        Math() (  Math() #Concat(2) )*
}

/*
 * Math
 * For '+' '-', then Multiplication
 */
void Math() : {}
{
	Multiplication()
	(
		( Multiplication() #Plus(2))
	|
		( Multiplication() #Minus(2))
	)*
}

/*
 * Multiplication
 * For a bunch of them, then Unary
 */
void Multiplication() : {}
{
	Unary()
	(
		( Unary() #Mult(2))
	|
		((|) Unary() #Div(2))
	|
		((|) Unary() #Mod(2))	
	)*	
}

/*
 * Unary
 * For '-' '!' 'not' 'empty', then Value
 */
void Unary() : {}
{
		 Unary() #Negative 
	|
		(|) Unary() #Not 
	|
		 Unary() #Empty
	|	
		Value()
}

/*
 * Value
 * Defines Prefix plus zero or more Suffixes
 */
void Value() : {}
{
	(ValuePrefix() (ValueSuffix())*) #Value(>1)
}

/*
 * ValuePrefix
 * For Literals, Variables, and Functions
 */
void ValuePrefix() : {}
{
	Literal()
	| NonLiteral()
}

/*
 * ValueSuffix
 * Either dot or bracket notation
 */
void ValueSuffix() : {}
{
	DotSuffix() | BracketSuffix()
}

/*
 * DotSuffix
 * Dot Property and Dot Method
 */
void DotSuffix() #DotSuffix : {  Token t = null; }
{
         t= { jjtThis.setImage(t.image); }
        (MethodArguments())?
}

/*
 * BracketSuffix
 * Sub Expression Suffix
 */
void BracketSuffix() #BracketSuffix : {}
{
	 Expression() 
        (MethodArguments())?
}


/*
 * MethodArguments
 */
void MethodArguments() #MethodArguments : {}
{
         (Expression() ( Expression())*)? 
}

/*
 * Parenthesized Lambda Expression, with optional invokation
 */
void LambdaExpressionOrCall() #LambdaExpression : {}

{
    
        LambdaParameters() 
        (LOOKAHEAD(3) LambdaExpression() | Choice() )
    
    (MethodArguments())*
}

/*
 * NonLiteral
 * For Grouped Operations, Identifiers, and Functions
 */
void NonLiteral() : {}
{
        LOOKAHEAD(5) LambdaExpressionOrCall() // check beyond the arrow 
 	|  Expression() 
 	| LOOKAHEAD(4) Function()
	| Identifier()
        | MapData()
        | ListData()
}

void MapData() #MapData: {}
{
    
        ( MapEntry() (  MapEntry() )* )?
    
}

void MapEntry() #MapEntry: {}
{
    Expression() ( Expression())?
}

void ListData() #ListData: {}
{
    
        ( Expression() (  Expression() )* )?
    
}

/*
 * Identifier
 * Java Language Identifier
 */
void Identifier() #Identifier : { Token t = null; }
{
	t= { jjtThis.setImage(t.image); }
}

/*
 * Function
 * Namespace:Name(a,b,c)
 */
void Function() #Function :
{
	Token t0 = null;
	Token t1 = null;
}
{
	t0= ( t1=)?
	{
		if (t1 != null) {
			jjtThis.setPrefix(t0.image);
			jjtThis.setLocalName(t1.image);
		} else {
			jjtThis.setLocalName(t0.image);
		}
	}
        (MethodArguments())+
}


/*
 * Literal
 * Reserved Keywords
 */
void Literal() : {}
{
	Boolean()
	| FloatingPoint()
	| Integer()
	| String()
	| Null()
}

/*
 * Boolean
 * For 'true' 'false'
 */
void Boolean() : {}
{
	 #True
	|  #False
}

/*
 * FloatinPoint
 * For Decimal and Floating Point Literals
 */
void FloatingPoint() #FloatingPoint : { Token t = null; }
{
	t= { jjtThis.setImage(t.image); }
}

/*
 * Integer
 * For Simple Numeric Literals
 */
void Integer() #Integer : { Token t = null; }
{
	t= { jjtThis.setImage(t.image); }
}

/*
 * String
 * For Quoted Literals
 */
void String() #String : { Token t = null; }
{
	t= { jjtThis.setImage(t.image); }
}

/*
 * Null
 * For 'null'
 */
void Null() #Null : {}
{
	
}


/* ========================================================================== */
TOKEN_MGR_DECLS:
{
    java.util.Stack stack = new java.util.Stack();
}

 TOKEN :
{
  < LITERAL_EXPRESSION:
    ((~["\\", "$", "#"])
      | ("\\" ("\\" | "$" | "#"))
      | ("$" ~["{", "$", "#", "\\"])
      | ("#" ~["{", "$", "#", "\\"])
    )+
    | "$"
    | "#"
  >
|
  < START_DYNAMIC_EXPRESSION: "${" > {stack.push(DEFAULT);}: IN_EXPRESSION
|
  < START_DEFERRED_EXPRESSION: "#{" > {stack.push(DEFAULT);}: IN_EXPRESSION
}

 SKIP : { "\\" }

 SKIP:
{ " " | "\t" | "\n" | "\r" }

 TOKEN :
{
        < START_MAP : "{" > {stack.push(curLexState);}: IN_MAP
|       < RCURL: "}" > {SwitchTo(stack.pop());}
|       < INTEGER_LITERAL: ["0"-"9"] (["0"-"9"])* >
|	< FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* ()? 
		| "." (["0"-"9"])+ ()?
		| (["0"-"9"])+ 
	>
|	< #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|	< STRING_LITERAL: ("\"" ((~["\"","\\"])
		| ("\\" ( ["\\","\""] )))* "\"")
		| ("\'" ((~["\'","\\"])
		| ("\\" ( ["\\","\'"] )))* "\'")
	>
|	< BADLY_ESCAPED_STRING_LITERAL: ("\"" (~["\"","\\"])* ("\\" ( ~["\\","\""] )))
		| ("\'" (~["\'","\\"])* ("\\" ( ~["\\","\'"] )))
	>
|	< TRUE : "true" >
|	< FALSE : "false" >
|	< NULL : "null" >
|	< DOT : "." >
|	< LPAREN : "(" >
|	< RPAREN : ")" >
|	< LBRACK : "[" >
|	< RBRACK : "]" >
|	< COLON : ":" >
|	< COMMA : "," >
|       < SEMICOLON : ";" >
|	< GT0 : ">" >
|	< GT1 : "gt" >
|	< LT0 : "<" >
|	< LT1 : "lt" >
|	< GE0 : ">=" >
|	< GE1 : "ge" >
|	< LE0 : "<=" >
|	< LE1 : "le" >
|	< EQ0 : "==" >
|	< EQ1 : "eq" >
|	< NE0 : "!=" >
|	< NE1 : "ne" >
|	< NOT0 : "!" >
|	< NOT1 : "not" >
|	< AND0 : "&&" >
|	< AND1 : "and" >
|	< OR0 : "||" >
|	< OR1 : "or" >
|	< EMPTY : "empty" >
|	< INSTANCEOF : "instanceof" >
|	< MULT : "*" >
|	< PLUS : "+" >
|	< MINUS : "-" >
|	< QUESTIONMARK : "?" >
|	< DIV0 : "/" >
|	< DIV1 : "div" >
|	< MOD0 : "%" >
|	< MOD1 : "mod" >
|       < CONCAT : "+=" >
|       < ASSIGN : "=" >
|       < ARROW : "->" >
|	< IDENTIFIER : (|) (|)* >
|	< #IMPL_OBJ_START: "#" >
|	< #LETTER:
		[
		"\u0024",
		"\u0041"-"\u005a",
		"\u005f",
		"\u0061"-"\u007a",
		"\u00c0"-"\u00d6",
		"\u00d8"-"\u00f6",
		"\u00f8"-"\u00ff",
		"\u0100"-"\u1fff",
		"\u3040"-"\u318f",
		"\u3300"-"\u337f",
		"\u3400"-"\u3d2d",
		"\u4e00"-"\u9fff",
		"\uf900"-"\ufaff"
		]
	>
|	< #DIGIT:
		[
		"\u0030"-"\u0039",
		"\u0660"-"\u0669",
		"\u06f0"-"\u06f9",
		"\u0966"-"\u096f",
		"\u09e6"-"\u09ef",
		"\u0a66"-"\u0a6f",
		"\u0ae6"-"\u0aef",
		"\u0b66"-"\u0b6f",
		"\u0be7"-"\u0bef",
		"\u0c66"-"\u0c6f",
		"\u0ce6"-"\u0cef",
		"\u0d66"-"\u0d6f",
		"\u0e50"-"\u0e59",
		"\u0ed0"-"\u0ed9",
		"\u1040"-"\u1049"
		]
	>
|	< ILLEGAL_CHARACTER: (~[]) >
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy