⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ognl.jjt

📁 ONGL官方源码
💻 JJT
📖 第 1 页 / 共 2 页
字号:
        (
            LOOKAHEAD(2) (
                "(" [ assignmentExpression() ( "," assignmentExpression() )* ] ")"
                    {
                        jjtThis.setClassName(className);
                    }
            )
            |
            LOOKAHEAD(2) (
                "[" "]" "{" [assignmentExpression() ("," assignmentExpression())*] #List "}"
                    {
                        jjtThis.setClassName(className);
                        jjtThis.setArray(true);
                    }
            )
            |
            LOOKAHEAD(2) (
                "[" assignmentExpression() "]"
                    {
                        jjtThis.setClassName(className);
                        jjtThis.setArray(true);
                    }
            )
        )
}

void propertyName() #Property : {
    Token t;
}
{
    t=<IDENT> { jjtThis.setValue( t.image ); } #Const
}

void staticMethodCall( String className ) #StaticMethod : {
    Token t;
}
{
    t=<IDENT> "(" [ assignmentExpression() ( "," assignmentExpression() )* ] ")"
                                        { jjtThis.init( className, t.image ); }
}

void methodCall() #Method : {
    Token t;
}
{
    t=<IDENT> "(" [ assignmentExpression() ( "," assignmentExpression() )* ] ")"
                                        { jjtThis.setMethodName( t.image ); }
}

/**
 * Apply an expression to all elements of a collection, creating a new collection
 * as the result.
 */
void projection() #Project : {}
{
    "{" expression() "}"
}

void selection() : {}
{
        LOOKAHEAD(2) selectAll()
    |
        LOOKAHEAD(2) selectFirst()
    |
        LOOKAHEAD(2) selectLast()
}

/**
 * Apply a boolean expression to all elements of a collection, creating a new collection
 * containing those elements for which the expression returned true.
 */
void selectAll() #Select : {}
{
    "{" "?" expression() "}"
}

/**
 * Apply a boolean expression to all elements of a collection, creating a new collection
 * containing those elements for the first element for which the expression returned true.
 */
void selectFirst() #SelectFirst : {}
{
    "{" "^" expression() "}"
}

/**
 * Apply a boolean expression to all elements of a collection, creating a new collection
 * containing those elements for the first element for which the expression returned true.
 */
void selectLast() #SelectLast : {}
{
    "{" "$" expression() "}"
}

void index() #Property : {}
{
    "[" expression() "]" { jjtThis.setIndexedAccess(true); }
 |
    <DYNAMIC_SUBSCRIPT> { jjtThis.setValue( token_source.literalValue ); } #Const
    {
        jjtThis.setIndexedAccess(true);
    }
}

// LEXER PRODUCTIONS

TOKEN_MGR_DECLS:
{
      /** Holds the last value computed by a constant token. */
    Object literalValue;
      /** Holds the last character escaped or in a character literal. */
    private char charValue;
      /** Holds char literal start token. */
    private char charLiteralStartQuote;
      /** Holds the last string literal parsed. */
    private StringBuffer stringBuffer;

      /** Converts an escape sequence into a character value. */
    private char escapeChar()
    {
        int ofs = image.length() - 1;
        switch ( image.charAt(ofs) ) {
            case 'n':   return '\n';
            case 'r':   return '\r';
            case 't':   return '\t';
            case 'b':   return '\b';
            case 'f':   return '\f';
            case '\\':  return '\\';
            case '\'':  return '\'';
            case '\"':  return '\"';
        }

          // Otherwise, it's an octal number.  Find the backslash and convert.
        while ( image.charAt(--ofs) != '\\' )
          {}
        int value = 0;
        while ( ++ofs < image.length() )
            value = (value << 3) | (image.charAt(ofs) - '0');
        return (char) value;
    }

    private Object makeInt()
    {
        Object  result;
        String  s = image.toString();
        int     base = 10;

        if ( s.charAt(0) == '0' )
            base = (s.length() > 1 && (s.charAt(1) == 'x' || s.charAt(1) == 'X'))? 16 : 8;
        if ( base == 16 )
            s = s.substring(2); // Trim the 0x off the front
        switch ( s.charAt(s.length()-1) ) {
            case 'l': case 'L':
                result = Long.valueOf( s.substring(0,s.length()-1), base );
                break;

            case 'h': case 'H':
                result = new BigInteger( s.substring(0,s.length()-1), base );
                break;

            default:
                result = Integer.valueOf( s, base );
                break;
        }
        return result;
    }

    private Object makeFloat()
    {
        String s = image.toString();
        switch ( s.charAt(s.length()-1) ) {
            case 'f': case 'F':
                return Float.valueOf( s );

            case 'b': case 'B':
                return new BigDecimal( s.substring(0,s.length()-1) );

            case 'd': case 'D':
            default:
                return Double.valueOf( s );
        }
    }
}

// Whitespace -- ignored
SKIP:
{  " " | "\t" | "\f" | "\r" | "\n" }

// An identifier.
TOKEN:
{
    < IDENT: <LETTER> (<LETTER>|<DIGIT>)* >
 |
    < #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"
      ] >
}

/**
 * Token for "dynamic subscripts", which are one of: [^], [|], [$], and [*].  The
 * appropriate constant from the DynamicSubscript class is stored in the token manager's
 * "value" field.
 */
TOKEN:
{
    < DYNAMIC_SUBSCRIPT: "[" ["^","|","$","*"] "]" >
        {
            switch (image.charAt(1)) {
              case '^': literalValue = DynamicSubscript.first; break;
              case '|': literalValue = DynamicSubscript.mid;   break;
              case '$': literalValue = DynamicSubscript.last;  break;
              case '*': literalValue = DynamicSubscript.all;   break;
          }
        }
}

/**
 * Character and string literals, whose object value is stored in the token manager's
 * "literalValue" field.
 */
MORE:
{
    "`"     : WithinBackCharLiteral
 |
    "'"     { stringBuffer = new StringBuffer(); }: WithinCharLiteral
 |
    "\""    { stringBuffer = new StringBuffer(); }: WithinStringLiteral
}

<WithinCharLiteral> MORE:
{
    < ESC: "\\" ( ["n","r","t","b","f","\\","'","`","\""]
                | (["0"-"3"])? ["0"-"7"] (["0"-"7"])?
                )
    >
        { charValue = escapeChar(); stringBuffer.append(charValue); }
 |
    < (~["'","\\"]) >
        { charValue = image.charAt( image.length()-1 ); stringBuffer.append(charValue); }
}

<WithinCharLiteral> TOKEN:
{
    < CHAR_LITERAL: "'">
        {
            if (stringBuffer.length() == 1) {
                literalValue = new Character( charValue );
            } else {
                literalValue = new String( stringBuffer );
            }
        }
        : DEFAULT
}

<WithinBackCharLiteral> MORE:
{
    < BACK_CHAR_ESC: <ESC> >
        { charValue = escapeChar(); }
 |
    < (~["`","\\"]) >
        { charValue = image.charAt( image.length()-1 ); }
}

<WithinBackCharLiteral> TOKEN:
{
    < BACK_CHAR_LITERAL: "`">
        { literalValue = new Character( charValue ); }: DEFAULT
}

<WithinStringLiteral> MORE:
{
    < STRING_ESC: <ESC> >
        { stringBuffer.append( escapeChar() ); }
 |
    < (~["\"","\\"]) >
        { stringBuffer.append( image.charAt(image.length()-1) ); }
}

<WithinStringLiteral> TOKEN:
{
    <STRING_LITERAL: "\"">
        { literalValue = new String( stringBuffer ); }
        : DEFAULT
}

/**
 * Integer or real Numeric literal, whose object value is stored in the token manager's
 * "literalValue" field.
 */
TOKEN:
{
    < INT_LITERAL:
        ( "0" (["0"-"7"])* | ["1"-"9"] (["0"-"9"])* | "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ )
        (["l","L","h","H"])?
    >
        { literalValue =
        makeInt(); }
 |
    < FLT_LITERAL:
        ( <DEC_FLT> (<EXPONENT>)? (<FLT_SUFF>)?
        | <DEC_DIGITS> <EXPONENT> (<FLT_SUFF>)?
        | <DEC_DIGITS> <FLT_SUFF>
        )
    >
        { literalValue = makeFloat(); }

 |  < #DEC_FLT: (["0"-"9"])+ "." (["0"-"9"])* | "." (["0"-"9"])+ >
 |  < #DEC_DIGITS: (["0"-"9"])+ >
 |  < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 |  < #FLT_SUFF: ["d","D","f","F","b","B"] >
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -