From adffaces-commits-return-226-apmail-incubator-adffaces-commits-archive=incubator.apache.org@incubator.apache.org Tue Jul 25 00:25:20 2006 Return-Path: Delivered-To: apmail-incubator-adffaces-commits-archive@locus.apache.org Received: (qmail 81334 invoked from network); 25 Jul 2006 00:25:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Jul 2006 00:25:19 -0000 Received: (qmail 45251 invoked by uid 500); 25 Jul 2006 00:25:18 -0000 Delivered-To: apmail-incubator-adffaces-commits-archive@incubator.apache.org Received: (qmail 45203 invoked by uid 500); 25 Jul 2006 00:25:18 -0000 Mailing-List: contact adffaces-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: adffaces-dev@incubator.apache.org Delivered-To: mailing list adffaces-commits@incubator.apache.org Received: (qmail 45166 invoked by uid 99); 25 Jul 2006 00:25:17 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jul 2006 17:25:17 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Jul 2006 17:25:11 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id B61131A982D; Mon, 24 Jul 2006 17:24:27 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r425235 [9/11] - in /incubator/adffaces/branches/matzew-repackaging-trinidad/plugins: ./ maven-adf-archetype/ maven-adf-archetype/src/main/resources/archetype-resources/ maven-adf-archetype/src/main/resources/archetype-resources/src/main/ja... Date: Tue, 25 Jul 2006 00:24:18 -0000 To: adffaces-commits@incubator.apache.org From: matzew@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060725002427.B61131A982D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj?rev=425235&r1=425234&r2=425235&view=diff ============================================================================== --- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj (original) +++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj Mon Jul 24 17:24:16 2006 @@ -1,1174 +1,1174 @@ -/* - * Copyright 2006 The Apache Software Foundation. - * - * Licensed 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 { - STATIC=false; - DEBUG_TOKEN_MANAGER=false; - DEBUG_PARSER=false; -} - -PARSER_BEGIN(JSParser15) -package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser; -import java.util.Vector; -import java.io.IOException; -public class JSParser15 -{ - // This is a stack of symbol tables for the JS file - protected ProgramContextStack _contextStack = new ProgramContextStack(); - -} - -PARSER_END(JSParser15) - -///////////////////////////////////////////////////// -// LEXICAL RULES Section -///////////////////////////////////////////////////// -TOKEN_MGR_DECLS : -{ - private boolean isRegValid = true; - public void setRegInvalid() - { - isRegValid = false; - } - public void setRegValid() - { - isRegValid = true; - } -} - -///////////////////////////////////////////////////// -// WHITE SPACE -///////////////////////////////////////////////////// -SPECIAL_TOKEN : -{ - - | -} -///////////////////////////////////////////////////// -// COMMENTS -///////////////////////////////////////////////////// -MORE : -{ - "//" : IN_SINGLE_LINE_COMMENT - | "/*" : IN_MULTI_LINE_COMMENT -} - - -SPECIAL_TOKEN : -{ - < SINGLE_LINE_COMMENT: (~["\n","\r"])* ("\n"|"\r"|"\r\n")? > : DEFAULT -} - - -SPECIAL_TOKEN : -{ - : DEFAULT -} - - -MORE : -{ - < ~[] > -} -///////////////////////////////////////////////////// -// RESERVED WORDS AND LITERALS -///////////////////////////////////////////////////// -TOKEN : -{ - < BREAK: "break" > - | < CONTINUE: "continue" > - | < DELETE: "delete" > - | < ELSE: "else" > - | < FOR: "for" > - | < FUNCTION: "function" > - | < FUNCTION_: "Function" > - | < IF: "if" > - | < IN: "in" > - | < NEW: "new" > - | < RETURN: "return" > - | < THIS: "this" > - | < TYPEOF: "typeof" > - | < INSTANCEOF: "instanceof" > - | < VAR: "var" > - | < VOID: "void" > - | < WHILE: "while" > - | < WITH: "with" > - | < CASE: "case" > - | < CATCH: "catch" > - | < CLASS: "class" > - | < CONST: "const" > - | < DEBUGGER: "debugger" > - | < _DEFAULT: "default" > - | < DO: "do" > - | < ENUM: "enum" > - | < EXPORT: "export" > - | < EXTENDS: "extends" > - | < FINALLY: "finally" > - | < IMPORT: "import" > - | < SUPER: "super" > - | < SWITCH: "switch" > - | < THROW: "throw" > - | < TRY: "try" > - | < TRUE: "true" > // They are not supposed to be keywords - | < FALSE: "false" > // They are not supposed to be keywords - | < NULL: "null" > // They are not supposed to be keywords -} -///////////////////////////////////////////////////// -// LITERALS -///////////////////////////////////////////////////// -TOKEN : -{ - < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > - | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > - | < OCTAL_LITERAL: "0" (["0"-"7"])* > - | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* ()? - | "." (["0"-"9"])+ ()? - | (["0"-"9"])+ ()? - > - | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > - | < STRING_LITERAL: "\"" - ( (~["\"","\\","\n","\r"]) | )* - "\"" - | "\"" - ( (~["\"", "\\"]) | "\\" ("\n" | "\r" | "\r\n") | )* - "\"" - | "'" - ( (~["'","\\","\n","\r"]) | )* - "'" - > - | < #ESCAPE_SEQUENCE: - "\\" - ( ["n","t","b","r","f","\\","'","\"","[","]"] - | ["0"-"7"] ( ["0"-"7"] )? - | ["0"-"3"] ["0"-"7"] ["0"-"7"] - | ["x"] ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"] - | ["u"] ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"] - ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"] - ) - > - | < UNTERMINATED_STRING_LITERAL: - "\"" ( | (~["\"","\\","\n","\r"]) )* ( ["\n","\r"] )? - | "'" ( | (~["'","\\","\n","\r"]) )* ( ["\n","\r"] )? - > -} -///////////////////////////////////////////////////// -// REGULAR EXPRESSIONS -///////////////////////////////////////////////////// -TOKEN : -{ - < #REGX_START_CHAR : ~["\r","\n","/","=","*"] | "\\/"> - | < #REGX_BODY_CHAR_EXCLUSION : ~["\r","\n","/"] > - | < #REGX_BODY_CHAR : ( | "\\/" ) > - | < #REGEX_END_CHAR : "i" - | "g" - | "m" - | "ig" - | "im" - | "gi" - | "gm" - | "mi" - | "mg" - | "igm" - | "img" - | "gmi" - | "gim" - | "mig" - | "mgi" - > -} - -TOKEN : -{ - ()* "/" ()? > - { - try { - // Peek at the next character. - char nextCh = input_stream.readChar(); - input_stream.backup(1); - if (isRegValid == false || nextCh == '/' || nextCh == '*') { - // - // Lexecal analyser thinks it is a RE - // operator such as /...../ - // Put the everything to the first "/" back on the input stream - // - input_stream.backup(lengthOfMatch-1); - // - // And remove it from the token - // - matchedToken.image = matchedToken.image.substring(0, 1); - image.delete(0, image.length() - 1); - image.append('/'); - matchedToken.kind=SLASH; - } - } catch (IOException e) { - throw new Error(e.toString()); - } - } - -} -///////////////////////////////////////////////////// -// IDENTIFIERS -///////////////////////////////////////////////////// -TOKEN : -{ - < IDENTIFIER: (|)* > - | < #LETTER: ["a"-"z","A"-"Z","$","_"] > - | < #DIGIT: ["0"-"9"]> -} -///////////////////////////////////////////////////// -// SEPARATORS -///////////////////////////////////////////////////// -TOKEN : -{ - < LPAREN: "(" > - | < RPAREN: ")" > - | < LBRACE: "{" > - | < RBRACE: "}" > - | < LBRACKET: "[" > - | < RBRACKET: "]" > - | < SEMICOLON: ";" > - | < COMMA: "," > - | < DOT: "." > -} - -///////////////////////////////////////////////////// -// OPERATORS -///////////////////////////////////////////////////// -TOKEN : -{ - < ASSIGN: "=" > - | < GT: ">" > - | < LT: "<" > - | < BANG: "!" > - | < TILDE: "~" > - | < HOOK: "?" > - | < COLON: ":" > - | < EQ: "==" > - | < LE: "<=" > - | < GE: ">=" > - | < NE: "!=" > - | < SC_OR: "||" > - | < SC_AND: "&&" > - | < INCR: "++" > - | < DECR: "--" > - | < PLUS: "+" > - | < MINUS: "-" > - | < STAR: "*" > - | < SLASH: "/" > - | < BIT_AND: "&" > - | < BIT_OR: "|" > - | < XOR: "^" > - | < REM: "%" > - | < LSHIFT: "<<" > - | < RSIGNEDSHIFT: ">>" > - | < RUNSIGNEDSHIFT: ">>>" > - | < PLUSASSIGN: "+=" > - | < MINUSASSIGN: "-=" > - | < STARASSIGN: "*=" > - | < SLASHASSIGN: "/=" > - | < ANDASSIGN: "&=" > - | < ORASSIGN: "|=" > - | < XORASSIGN: "^=" > - | < REMASSIGN: "%=" > - | < LSHIFTASSIGN: "<<=" > - | < RSIGNEDSHIFTASSIGN: ">>=" > - | < RUNSIGNEDSHIFTASSIGN: ">>>=" > - | < IDENTITYOPER: "===" > - | < NOTIDENTITYOPER: "!==" > -} -/////////////////////////////////////////////////////////////////// -// GRAMMAR Section -/////////////////////////////////////////////////////////////////// - -void Literal(): -{} -{ - - | - | - | - | - | - | - | - | -} - -Token Identifier(): -{ - Token t; -} -{ - t = {return t;} -} - -void PrimaryExpression(): -{ - Token prefixToken = null; -} -{ - ( - prefixToken = (PrimarySuffix())* - { - JSParserUtils.tagObjectIdentifier(prefixToken, getToken(1)); - } - | prefixToken=Identifier() (PrimarySuffix())* - { - JSParserUtils.tagObjectIdentifier(prefixToken, getToken(1)); - JSParserUtils.tagMethodInvocation(_contextStack, - (AnnotatedToken)prefixToken, - (AnnotatedToken)getToken(1)); - } - | LOOKAHEAD(2) (PrimarySuffix())* - | LOOKAHEAD(2) (PrimarySuffix())* - | LOOKAHEAD(2) Literal() - | FunctionLiteral() - | NestedArrayLiteral() (PrimarySuffix())* - | ObjectLiteral() - | Expression() (PrimarySuffix())* - | AllocationExpression() - ) - { - token_source.setRegValid(); - } -} - - -void PrimarySuffix(): -{} -{ - Arguments() - | {token_source.setRegInvalid();} Expression() - | {token_source.setRegInvalid();} Identifier() -} - -void Arguments(): -{} -{ - {token_source.setRegValid();} [ArgumentList()] -} - -void ArgumentList(): -{} -{ - AssignmentExpression() ( AssignmentExpression())* -} - -void LiteralArgumentList(): -{} -{ - ( )* -} - -void NewSuffix(): -{} -{ - Identifier() -} - -void AllocationExpression(): -{ - Token t; -} -{ - LOOKAHEAD(2) t= (NewSuffix())* [Arguments()] - {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - | LOOKAHEAD(2) t= Identifier() (NewSuffix())* [Arguments()] - {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - | LOOKAHEAD(2) t= FunctionConstructor() (NewSuffix())* [Arguments()] - {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} -} - - -void PostfixOp(): -{} -{ - - | -} - -void PostfixExpression(): -{} -{ - PrimaryExpression() [PostfixOp()] -} - - -void UnaryOp(): -{ - Token t; -} -{ - t= - {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - | t= - {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - | t= - {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - | - | - | - | - | - | -} - -void UnaryExpression(): -{} -{ - PostfixExpression() - | UnaryOp() UnaryExpression() -} - -void MulOp(): -{} -{ - - | - | -} - -void MultiplicativeExpression(): -{} -{ - UnaryExpression() (MulOp() UnaryExpression())* -} - -void AddOp(): -{} -{ - - | -} - -void AdditiveExpression(): -{} -{ - MultiplicativeExpression() (AddOp() MultiplicativeExpression())* -} - -void ShiftOp(): -{} -{ - - | - | -} - -void ShiftExpression(): -{} -{ - AdditiveExpression() (ShiftOp() AdditiveExpression())* -} - -void RelOp(): -{} -{ - - | - | - | -} - -void RelationalExpression(): -{ - Token t; -} -{ - ShiftExpression() - (LOOKAHEAD(3) ( RelOp() - | t= - {JSParserUtils.annotateToken(t, - AnnotationConstants.UNDEFINED, - null, 2);} - | t= - {JSParserUtils.annotateToken(t, - AnnotationConstants.UNDEFINED, - null, 2);}) - ShiftExpression())* -} - -void RelationalExpressionNoIN(): -{ - Token t; -} -{ - ShiftExpression() - ( ( RelOp() - | t= - {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, - null, 2);}) - ShiftExpression())* -} - -void EqualOp(): -{} -{ - - | - | - | -} - -void EqualityExpression(): -{} -{ - RelationalExpression() (EqualOp() RelationalExpression())* -} - -void EqualityExpressionNoIN(): -{} -{ - RelationalExpressionNoIN() (EqualOp() RelationalExpressionNoIN())* -} - - -void BitwiseANDOp(): -{} -{ - -} - -void BitwiseANDExpression(): -{} -{ - EqualityExpression() (BitwiseANDOp() EqualityExpression())* -} - -void BitwiseANDExpressionNoIN(): -{} -{ - EqualityExpressionNoIN() (BitwiseANDOp() EqualityExpressionNoIN())* -} - - -void BitwiseXOROp(): -{} -{ - -} - -void BitwiseXORExpression(): -{} -{ - BitwiseANDExpression() (BitwiseXOROp() BitwiseANDExpression())* -} - -void BitwiseXORExpressionNoIN(): -{} -{ - BitwiseANDExpressionNoIN() (BitwiseXOROp() BitwiseANDExpressionNoIN())* -} - -void BitwiseOROp(): -{} -{ - -} - -void BitwiseORExpression(): -{} -{ - BitwiseXORExpression() (BitwiseOROp() BitwiseXORExpression())* -} - -void BitwiseORExpressionNoIN(): -{} -{ - BitwiseXORExpressionNoIN() (BitwiseOROp() BitwiseXORExpressionNoIN())* -} - -void LogicalANDExpression(): -{} -{ - BitwiseORExpression() ( BitwiseORExpression())* -} - -void LogicalANDExpressionNoIN(): -{} -{ - BitwiseORExpressionNoIN() ( BitwiseORExpressionNoIN())* -} - -void LogicalORExpression(): -{} -{ - LogicalANDExpression() ( LogicalANDExpression())* -} - -void LogicalORExpressionNoIN(): -{} -{ - LogicalANDExpressionNoIN() ( LogicalANDExpressionNoIN())* -} - -void ConditionalExpression(): -{} -{ - LogicalORExpression() [ Expression() ConditionalExpression()] -} - -void ConditionalExpressionNoIN(): -{} -{ - LogicalORExpressionNoIN() [ ExpressionNoIN() ConditionalExpressionNoIN()] -} - -Token AssignementOperator(): -{ - Token t; -} -{ - ( t= - | t= - | t= - | t= - | t= - | t= - | t= - | t= - | t= - | t= - | t= - | t= ) - { return t; } -} - -void AssignmentExpression(): -{ - Token tLHS = getToken(1); - Token tOperator = null; - Token tRHS = null; - Token tEnd = null; -} -{ - ConditionalExpression() - [ (AssignementOperator() - {tRHS=getToken(1);} - AssignmentExpression()) - { - tEnd = getToken(1); - JSParserUtils.tagAssignmentExpression(_contextStack, null, - (AnnotatedToken)tLHS, - (AnnotatedToken)tOperator, - (AnnotatedToken)tRHS, - (AnnotatedToken)tEnd); - } - ] -} - -void AssignmentExpressionNoIN(): -{ - Token tLHS = getToken(1); - Token tOperator = null; - Token tRHS = null; - Token tEnd = null; -} -{ - ConditionalExpressionNoIN() - [ (AssignementOperator() {tRHS=getToken(1);} - AssignmentExpressionNoIN()) - { - tEnd = getToken(1); - JSParserUtils.tagAssignmentExpression(_contextStack, null, - (AnnotatedToken)tLHS, - (AnnotatedToken)tOperator, - (AnnotatedToken)tRHS, - (AnnotatedToken)tEnd); - } - ] -} - - -void Expression() : -{} -{ - AssignmentExpression() ( "," AssignmentExpression() )* -} - -void ExpressionNoIN() : -{} -{ - AssignmentExpressionNoIN() ( "," AssignmentExpressionNoIN() )* -} - - -void Statement(): -{} -{ - LOOKAHEAD(3) Block(null) - | VariableStatement() - | EmptyStatement() - | ExpressionStatement() - | IfStatement() - | IterationStatement() - | ContinueStatement() - | BreakStatement() - | ReturnStatement() - | WithStatement() - | TryStatement() - | ThrowStatement() - | SwitchStatement() -} - -void Block(ProgramContext context): -{} -{ - LOOKAHEAD(3) - | { - if (context == null) { - _contextStack.pushContext(new ProgramContext("block")); - } - } - [StatementList()] - - { - _contextStack.popContext(); - } -} - -void VariableStatement(): -{ - Token t; -} -{ - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - VariableDeclarationList(t) Sc() -} - -void VariableDeclarationList(Token varToken): -{} -{ - VariableDeclaration(varToken) ( VariableDeclaration(varToken) )* -} - -void VariableDeclaration(Token varToken): -{ - Token lhs = null; - Token[] tArray = null; -} -{ - lhs=Identifier() [Initializer()] - { - JSParserUtils.annotateToken(lhs, AnnotationConstants.VAR_IDENTIFIER, null, -1); - JSParserUtils.pushToken(_contextStack, (AnnotatedToken)lhs); - - if(tArray != null) { - Token end = getToken(1); - JSParserUtils.tagAssignmentExpression(_contextStack, (AnnotatedToken)varToken, - (AnnotatedToken)lhs, (AnnotatedToken)tArray[0], - (AnnotatedToken)tArray[1], (AnnotatedToken)end); - } - } -} - -Token[] Initializer(): -{ - Token[] tArray = new Token[2]; -} -{ - tArray[0]= {tArray[1]=getToken(1);} - AssignmentExpression() - {return tArray;} -} - -void EmptyStatement(): -{} -{ - -} - -void ExpressionStatement(): -{} -{ - Expression() Sc() -} - -JAVACODE - void Sc() { - - Token tok = getToken(1); - if (tok.kind == SEMICOLON) { - tok = getNextToken(); - } else if (tok.specialToken != null) { - if (!EolCommentSkipWs(tok.specialToken) && (tok.kind != EOF)) { - throw generateParseException(); - } - } else if ((tok.kind != EOF) && (tok.kind!=RBRACE)) { - throw generateParseException(); - } - } - -JAVACODE - boolean EolCommentSkipWs(Token t) { - boolean retVal = false; - Token specialToken = t; - while(specialToken != null) { - if(specialToken.kind == WS) { - specialToken = specialToken.specialToken; - continue; - } - else if(specialToken.kind == EOL || - specialToken.kind == SINGLE_LINE_COMMENT) { - retVal = true; - break; - } - else { - break; - } - } - return retVal; - } - -void IfStatement(): -{ - Token t; -} -{ - Expression() - Statement() - [ LOOKAHEAD(1) t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, - null, 1);} - Statement() - ] -} - - -void IterationStatement(): -{} -{ - WhileStatement() - | DoStatement() - | LOOKAHEAD( Expression() ) - ForStatement() - | LOOKAHEAD( ) - ForStatement() - | LOOKAHEAD( varToekn= VariableDeclarationList(varToken) ) - ForVarStatement() - | LOOKAHEAD(3) ForInStatement() - | LOOKAHEAD(3) ForVarInStatement() -} - -void DoStatement(): -{} -{ - Statement() Expression() -} - -void WhileStatement(): -{} -{ - Expression() - Statement() -} - -void ForStatement(): -{} -{ - [Expression()] - [Expression()] - [Expression()] - Statement() -} - -void ForVarStatement(): -{ - Token t; -} -{ - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, - null, 1);} - VariableDeclarationList(t) - [Expression()] - [Expression()] - Statement() -} - -void ForInStatement(): -{ - Token t; -} -{ - ExpressionNoIN() - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, - null, 2);} - ExpressionNoIN() - Statement() -} - -void ForVarInStatement(): -{ - Token t; -} -{ - - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - t=Identifier() - { - JSParserUtils.annotateToken(t, AnnotationConstants.VAR_IDENTIFIER, null, 1); - JSParserUtils.pushToken(_contextStack, (AnnotatedToken)t); - } - [Initializer()] - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 2);} - ExpressionNoIN() - - Statement() -} - -void ContinueStatement(): -{} -{ - Sc() -} - -void BreakStatement(): -{} -{ - Sc() -} - -void ReturnStatement(): -{ - Token t; -} -{ - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - [Expression()] Sc() -} - -void WithStatement(): -{} -{ - Expression() - Statement() -} - -void TryStatement(): -{} -{ - Block(null) - ( Identifier() Block(null))* - [ Block(null)] -} - -void ThrowStatement(): -{ - Token t; -} -{ - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - [Expression()] Sc() -} - -void CaseGuard(): -{ - Token t; -} -{ - t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} - Expression() - | <_DEFAULT> -} - -void CaseGroup(): -{} -{ - CaseGuard() (Statement())* -} - -void SwitchStatement(): -{} -{ - Expression() - (CaseGroup())* -} - -void NamedFunction(): -{ - Token tIdentifier = null; - Token tFunction = null; - Token blockStart = null; - Token blockEnd = null; - Vector params = new Vector(); -} -{ - tFunction= - tIdentifier=Identifier() - { - JSParserUtils.annotateToken(tIdentifier, AnnotationConstants.FUNCTION_NAME_IDENTIFIER, - null, -1); - ProgramContext context = new ProgramContext(tIdentifier.image); - _contextStack.pushContext(context); - } - - [params=FormalParameterList()] - { - JSParserUtils.annotateTokens(params, - AnnotationConstants.FUNCTION_PARAM_IDENTIFIER, - null, -1); - JSParserUtils.annotateToken(tFunction, AnnotationConstants.NAMED_FUNCTION, - params, 1); - JSParserUtils.pushTokens(_contextStack, params); - } - - - {blockStart = getToken(1);} - Block(context) - { - blockEnd = getToken(1); - JSParserUtils.tagEvalCalls(tFunction, blockStart, blockEnd); - } -} - -void AnonymousFunction(): -{ - Token tFunction = null; - Token blockStart = null; - Token blockEnd = null; - Vector params = new Vector(); -} -{ - tFunction= - { - ProgramContext context = new ProgramContext("anonymous"); - _contextStack.pushContext(context); - } - - [params=FormalParameterList()] - { - JSParserUtils.annotateTokens(params, - AnnotationConstants.FUNCTION_PARAM_IDENTIFIER, - null, -1); - JSParserUtils.annotateToken(tFunction, - AnnotationConstants.ANONYMOUS_FUNCTION, - params, -1); - JSParserUtils.pushTokens(_contextStack, params); - } - - {blockStart = getToken(1);} - Block(context) - { - blockEnd = getToken(1); - JSParserUtils.tagEvalCalls(tFunction, blockStart, blockEnd); - } -} - -void FunctionConstructor(): -{} -{ - ArgumentList() -} - -void FunctionDeclaration(): -{} -{ - LOOKAHEAD(2) NamedFunction() - | LOOKAHEAD(2) AnonymousFunction() -} - -void FunctionLiteral(): -{} -{ - AnonymousFunction() -} - -Vector FormalParameterList(): -{ - Token t = null; - Vector v = new Vector(); -} -{ - t=Identifier() {v.add(t);} - ( t=Identifier() {v.add(t);})* - {return v;} -} - -void LiteralElement() : -{} -{ - AssignmentExpression() -} - -void ElementList(): -{} -{ - LiteralElement() ( LiteralElement())* -} - -void ArrayLiteral(): -{} -{ - LOOKAHEAD(2) - | LOOKAHEAD(2) ElementList() -} - -void NestedArrayLiteral(): -{} -{ - LOOKAHEAD(3) ArrayLiteral() - | LOOKAHEAD(3) NestedArrayLiteral() -} - -void LiteralField(): -{ - Token t = null; -} -{ - t=Identifier() AssignmentExpression() - {JSParserUtils.annotateToken(t, AnnotationConstants.LITERAL_OBJECT_KEY_IDENTIFIER,null,-1); } - | t= AssignmentExpression() - {JSParserUtils.annotateToken(t, AnnotationConstants.LITERAL_OBJECT_KEY_IDENTIFIER,null,-1); } -} - -void FieldList(): -{} -{ - LiteralField() ( LiteralField())* -} - -void ObjectLiteral(): -{} -{ - LOOKAHEAD(2) - | LOOKAHEAD(2) FieldList() -} - - -Token Program(): -{ - Token retval = getToken(1); -} -{ - {_contextStack.pushContext(new ProgramContext("root"));} - (SourceElement())* - { - return retval; - } -} - -void SourceElement(): -{} -{ - LOOKAHEAD(2) Statement() - | FunctionDeclaration() -} - -void StatementList(): -{ -// Token t; -} -{ - (Statement())+ -} +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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 { + STATIC=false; + DEBUG_TOKEN_MANAGER=false; + DEBUG_PARSER=false; +} + +PARSER_BEGIN(JSParser15) +package org.apache.myfaces.trinidadbuild.plugin.javascript.obfuscator.javascript15parser; +import java.util.Vector; +import java.io.IOException; +public class JSParser15 +{ + // This is a stack of symbol tables for the JS file + protected ProgramContextStack _contextStack = new ProgramContextStack(); + +} + +PARSER_END(JSParser15) + +///////////////////////////////////////////////////// +// LEXICAL RULES Section +///////////////////////////////////////////////////// +TOKEN_MGR_DECLS : +{ + private boolean isRegValid = true; + public void setRegInvalid() + { + isRegValid = false; + } + public void setRegValid() + { + isRegValid = true; + } +} + +///////////////////////////////////////////////////// +// WHITE SPACE +///////////////////////////////////////////////////// +SPECIAL_TOKEN : +{ + + | +} +///////////////////////////////////////////////////// +// COMMENTS +///////////////////////////////////////////////////// +MORE : +{ + "//" : IN_SINGLE_LINE_COMMENT + | "/*" : IN_MULTI_LINE_COMMENT +} + + +SPECIAL_TOKEN : +{ + < SINGLE_LINE_COMMENT: (~["\n","\r"])* ("\n"|"\r"|"\r\n")? > : DEFAULT +} + + +SPECIAL_TOKEN : +{ + : DEFAULT +} + + +MORE : +{ + < ~[] > +} +///////////////////////////////////////////////////// +// RESERVED WORDS AND LITERALS +///////////////////////////////////////////////////// +TOKEN : +{ + < BREAK: "break" > + | < CONTINUE: "continue" > + | < DELETE: "delete" > + | < ELSE: "else" > + | < FOR: "for" > + | < FUNCTION: "function" > + | < FUNCTION_: "Function" > + | < IF: "if" > + | < IN: "in" > + | < NEW: "new" > + | < RETURN: "return" > + | < THIS: "this" > + | < TYPEOF: "typeof" > + | < INSTANCEOF: "instanceof" > + | < VAR: "var" > + | < VOID: "void" > + | < WHILE: "while" > + | < WITH: "with" > + | < CASE: "case" > + | < CATCH: "catch" > + | < CLASS: "class" > + | < CONST: "const" > + | < DEBUGGER: "debugger" > + | < _DEFAULT: "default" > + | < DO: "do" > + | < ENUM: "enum" > + | < EXPORT: "export" > + | < EXTENDS: "extends" > + | < FINALLY: "finally" > + | < IMPORT: "import" > + | < SUPER: "super" > + | < SWITCH: "switch" > + | < THROW: "throw" > + | < TRY: "try" > + | < TRUE: "true" > // They are not supposed to be keywords + | < FALSE: "false" > // They are not supposed to be keywords + | < NULL: "null" > // They are not supposed to be keywords +} +///////////////////////////////////////////////////// +// LITERALS +///////////////////////////////////////////////////// +TOKEN : +{ + < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* > + | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ > + | < OCTAL_LITERAL: "0" (["0"-"7"])* > + | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])* ()? + | "." (["0"-"9"])+ ()? + | (["0"-"9"])+ ()? + > + | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > + | < STRING_LITERAL: "\"" + ( (~["\"","\\","\n","\r"]) | )* + "\"" + | "\"" + ( (~["\"", "\\"]) | "\\" ("\n" | "\r" | "\r\n") | )* + "\"" + | "'" + ( (~["'","\\","\n","\r"]) | )* + "'" + > + | < #ESCAPE_SEQUENCE: + "\\" + ( ["n","t","b","r","f","\\","'","\"","[","]"] + | ["0"-"7"] ( ["0"-"7"] )? + | ["0"-"3"] ["0"-"7"] ["0"-"7"] + | ["x"] ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"] + | ["u"] ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"] + ["0"-"9","a"-"f","A"-"F"] ["0"-"9","a"-"f","A"-"F"] + ) + > + | < UNTERMINATED_STRING_LITERAL: + "\"" ( | (~["\"","\\","\n","\r"]) )* ( ["\n","\r"] )? + | "'" ( | (~["'","\\","\n","\r"]) )* ( ["\n","\r"] )? + > +} +///////////////////////////////////////////////////// +// REGULAR EXPRESSIONS +///////////////////////////////////////////////////// +TOKEN : +{ + < #REGX_START_CHAR : ~["\r","\n","/","=","*"] | "\\/"> + | < #REGX_BODY_CHAR_EXCLUSION : ~["\r","\n","/"] > + | < #REGX_BODY_CHAR : ( | "\\/" ) > + | < #REGEX_END_CHAR : "i" + | "g" + | "m" + | "ig" + | "im" + | "gi" + | "gm" + | "mi" + | "mg" + | "igm" + | "img" + | "gmi" + | "gim" + | "mig" + | "mgi" + > +} + +TOKEN : +{ + ()* "/" ()? > + { + try { + // Peek at the next character. + char nextCh = input_stream.readChar(); + input_stream.backup(1); + if (isRegValid == false || nextCh == '/' || nextCh == '*') { + // + // Lexecal analyser thinks it is a RE + // operator such as /...../ + // Put the everything to the first "/" back on the input stream + // + input_stream.backup(lengthOfMatch-1); + // + // And remove it from the token + // + matchedToken.image = matchedToken.image.substring(0, 1); + image.delete(0, image.length() - 1); + image.append('/'); + matchedToken.kind=SLASH; + } + } catch (IOException e) { + throw new Error(e.toString()); + } + } + +} +///////////////////////////////////////////////////// +// IDENTIFIERS +///////////////////////////////////////////////////// +TOKEN : +{ + < IDENTIFIER: (|)* > + | < #LETTER: ["a"-"z","A"-"Z","$","_"] > + | < #DIGIT: ["0"-"9"]> +} +///////////////////////////////////////////////////// +// SEPARATORS +///////////////////////////////////////////////////// +TOKEN : +{ + < LPAREN: "(" > + | < RPAREN: ")" > + | < LBRACE: "{" > + | < RBRACE: "}" > + | < LBRACKET: "[" > + | < RBRACKET: "]" > + | < SEMICOLON: ";" > + | < COMMA: "," > + | < DOT: "." > +} + +///////////////////////////////////////////////////// +// OPERATORS +///////////////////////////////////////////////////// +TOKEN : +{ + < ASSIGN: "=" > + | < GT: ">" > + | < LT: "<" > + | < BANG: "!" > + | < TILDE: "~" > + | < HOOK: "?" > + | < COLON: ":" > + | < EQ: "==" > + | < LE: "<=" > + | < GE: ">=" > + | < NE: "!=" > + | < SC_OR: "||" > + | < SC_AND: "&&" > + | < INCR: "++" > + | < DECR: "--" > + | < PLUS: "+" > + | < MINUS: "-" > + | < STAR: "*" > + | < SLASH: "/" > + | < BIT_AND: "&" > + | < BIT_OR: "|" > + | < XOR: "^" > + | < REM: "%" > + | < LSHIFT: "<<" > + | < RSIGNEDSHIFT: ">>" > + | < RUNSIGNEDSHIFT: ">>>" > + | < PLUSASSIGN: "+=" > + | < MINUSASSIGN: "-=" > + | < STARASSIGN: "*=" > + | < SLASHASSIGN: "/=" > + | < ANDASSIGN: "&=" > + | < ORASSIGN: "|=" > + | < XORASSIGN: "^=" > + | < REMASSIGN: "%=" > + | < LSHIFTASSIGN: "<<=" > + | < RSIGNEDSHIFTASSIGN: ">>=" > + | < RUNSIGNEDSHIFTASSIGN: ">>>=" > + | < IDENTITYOPER: "===" > + | < NOTIDENTITYOPER: "!==" > +} +/////////////////////////////////////////////////////////////////// +// GRAMMAR Section +/////////////////////////////////////////////////////////////////// + +void Literal(): +{} +{ + + | + | + | + | + | + | + | + | +} + +Token Identifier(): +{ + Token t; +} +{ + t = {return t;} +} + +void PrimaryExpression(): +{ + Token prefixToken = null; +} +{ + ( + prefixToken = (PrimarySuffix())* + { + JSParserUtils.tagObjectIdentifier(prefixToken, getToken(1)); + } + | prefixToken=Identifier() (PrimarySuffix())* + { + JSParserUtils.tagObjectIdentifier(prefixToken, getToken(1)); + JSParserUtils.tagMethodInvocation(_contextStack, + (AnnotatedToken)prefixToken, + (AnnotatedToken)getToken(1)); + } + | LOOKAHEAD(2) (PrimarySuffix())* + | LOOKAHEAD(2) (PrimarySuffix())* + | LOOKAHEAD(2) Literal() + | FunctionLiteral() + | NestedArrayLiteral() (PrimarySuffix())* + | ObjectLiteral() + | Expression() (PrimarySuffix())* + | AllocationExpression() + ) + { + token_source.setRegValid(); + } +} + + +void PrimarySuffix(): +{} +{ + Arguments() + | {token_source.setRegInvalid();} Expression() + | {token_source.setRegInvalid();} Identifier() +} + +void Arguments(): +{} +{ + {token_source.setRegValid();} [ArgumentList()] +} + +void ArgumentList(): +{} +{ + AssignmentExpression() ( AssignmentExpression())* +} + +void LiteralArgumentList(): +{} +{ + ( )* +} + +void NewSuffix(): +{} +{ + Identifier() +} + +void AllocationExpression(): +{ + Token t; +} +{ + LOOKAHEAD(2) t= (NewSuffix())* [Arguments()] + {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + | LOOKAHEAD(2) t= Identifier() (NewSuffix())* [Arguments()] + {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + | LOOKAHEAD(2) t= FunctionConstructor() (NewSuffix())* [Arguments()] + {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} +} + + +void PostfixOp(): +{} +{ + + | +} + +void PostfixExpression(): +{} +{ + PrimaryExpression() [PostfixOp()] +} + + +void UnaryOp(): +{ + Token t; +} +{ + t= + {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + | t= + {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + | t= + {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + | + | + | + | + | + | +} + +void UnaryExpression(): +{} +{ + PostfixExpression() + | UnaryOp() UnaryExpression() +} + +void MulOp(): +{} +{ + + | + | +} + +void MultiplicativeExpression(): +{} +{ + UnaryExpression() (MulOp() UnaryExpression())* +} + +void AddOp(): +{} +{ + + | +} + +void AdditiveExpression(): +{} +{ + MultiplicativeExpression() (AddOp() MultiplicativeExpression())* +} + +void ShiftOp(): +{} +{ + + | + | +} + +void ShiftExpression(): +{} +{ + AdditiveExpression() (ShiftOp() AdditiveExpression())* +} + +void RelOp(): +{} +{ + + | + | + | +} + +void RelationalExpression(): +{ + Token t; +} +{ + ShiftExpression() + (LOOKAHEAD(3) ( RelOp() + | t= + {JSParserUtils.annotateToken(t, + AnnotationConstants.UNDEFINED, + null, 2);} + | t= + {JSParserUtils.annotateToken(t, + AnnotationConstants.UNDEFINED, + null, 2);}) + ShiftExpression())* +} + +void RelationalExpressionNoIN(): +{ + Token t; +} +{ + ShiftExpression() + ( ( RelOp() + | t= + {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, + null, 2);}) + ShiftExpression())* +} + +void EqualOp(): +{} +{ + + | + | + | +} + +void EqualityExpression(): +{} +{ + RelationalExpression() (EqualOp() RelationalExpression())* +} + +void EqualityExpressionNoIN(): +{} +{ + RelationalExpressionNoIN() (EqualOp() RelationalExpressionNoIN())* +} + + +void BitwiseANDOp(): +{} +{ + +} + +void BitwiseANDExpression(): +{} +{ + EqualityExpression() (BitwiseANDOp() EqualityExpression())* +} + +void BitwiseANDExpressionNoIN(): +{} +{ + EqualityExpressionNoIN() (BitwiseANDOp() EqualityExpressionNoIN())* +} + + +void BitwiseXOROp(): +{} +{ + +} + +void BitwiseXORExpression(): +{} +{ + BitwiseANDExpression() (BitwiseXOROp() BitwiseANDExpression())* +} + +void BitwiseXORExpressionNoIN(): +{} +{ + BitwiseANDExpressionNoIN() (BitwiseXOROp() BitwiseANDExpressionNoIN())* +} + +void BitwiseOROp(): +{} +{ + +} + +void BitwiseORExpression(): +{} +{ + BitwiseXORExpression() (BitwiseOROp() BitwiseXORExpression())* +} + +void BitwiseORExpressionNoIN(): +{} +{ + BitwiseXORExpressionNoIN() (BitwiseOROp() BitwiseXORExpressionNoIN())* +} + +void LogicalANDExpression(): +{} +{ + BitwiseORExpression() ( BitwiseORExpression())* +} + +void LogicalANDExpressionNoIN(): +{} +{ + BitwiseORExpressionNoIN() ( BitwiseORExpressionNoIN())* +} + +void LogicalORExpression(): +{} +{ + LogicalANDExpression() ( LogicalANDExpression())* +} + +void LogicalORExpressionNoIN(): +{} +{ + LogicalANDExpressionNoIN() ( LogicalANDExpressionNoIN())* +} + +void ConditionalExpression(): +{} +{ + LogicalORExpression() [ Expression() ConditionalExpression()] +} + +void ConditionalExpressionNoIN(): +{} +{ + LogicalORExpressionNoIN() [ ExpressionNoIN() ConditionalExpressionNoIN()] +} + +Token AssignementOperator(): +{ + Token t; +} +{ + ( t= + | t= + | t= + | t= + | t= + | t= + | t= + | t= + | t= + | t= + | t= + | t= ) + { return t; } +} + +void AssignmentExpression(): +{ + Token tLHS = getToken(1); + Token tOperator = null; + Token tRHS = null; + Token tEnd = null; +} +{ + ConditionalExpression() + [ (AssignementOperator() + {tRHS=getToken(1);} + AssignmentExpression()) + { + tEnd = getToken(1); + JSParserUtils.tagAssignmentExpression(_contextStack, null, + (AnnotatedToken)tLHS, + (AnnotatedToken)tOperator, + (AnnotatedToken)tRHS, + (AnnotatedToken)tEnd); + } + ] +} + +void AssignmentExpressionNoIN(): +{ + Token tLHS = getToken(1); + Token tOperator = null; + Token tRHS = null; + Token tEnd = null; +} +{ + ConditionalExpressionNoIN() + [ (AssignementOperator() {tRHS=getToken(1);} + AssignmentExpressionNoIN()) + { + tEnd = getToken(1); + JSParserUtils.tagAssignmentExpression(_contextStack, null, + (AnnotatedToken)tLHS, + (AnnotatedToken)tOperator, + (AnnotatedToken)tRHS, + (AnnotatedToken)tEnd); + } + ] +} + + +void Expression() : +{} +{ + AssignmentExpression() ( "," AssignmentExpression() )* +} + +void ExpressionNoIN() : +{} +{ + AssignmentExpressionNoIN() ( "," AssignmentExpressionNoIN() )* +} + + +void Statement(): +{} +{ + LOOKAHEAD(3) Block(null) + | VariableStatement() + | EmptyStatement() + | ExpressionStatement() + | IfStatement() + | IterationStatement() + | ContinueStatement() + | BreakStatement() + | ReturnStatement() + | WithStatement() + | TryStatement() + | ThrowStatement() + | SwitchStatement() +} + +void Block(ProgramContext context): +{} +{ + LOOKAHEAD(3) + | { + if (context == null) { + _contextStack.pushContext(new ProgramContext("block")); + } + } + [StatementList()] + + { + _contextStack.popContext(); + } +} + +void VariableStatement(): +{ + Token t; +} +{ + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + VariableDeclarationList(t) Sc() +} + +void VariableDeclarationList(Token varToken): +{} +{ + VariableDeclaration(varToken) ( VariableDeclaration(varToken) )* +} + +void VariableDeclaration(Token varToken): +{ + Token lhs = null; + Token[] tArray = null; +} +{ + lhs=Identifier() [Initializer()] + { + JSParserUtils.annotateToken(lhs, AnnotationConstants.VAR_IDENTIFIER, null, -1); + JSParserUtils.pushToken(_contextStack, (AnnotatedToken)lhs); + + if(tArray != null) { + Token end = getToken(1); + JSParserUtils.tagAssignmentExpression(_contextStack, (AnnotatedToken)varToken, + (AnnotatedToken)lhs, (AnnotatedToken)tArray[0], + (AnnotatedToken)tArray[1], (AnnotatedToken)end); + } + } +} + +Token[] Initializer(): +{ + Token[] tArray = new Token[2]; +} +{ + tArray[0]= {tArray[1]=getToken(1);} + AssignmentExpression() + {return tArray;} +} + +void EmptyStatement(): +{} +{ + +} + +void ExpressionStatement(): +{} +{ + Expression() Sc() +} + +JAVACODE + void Sc() { + + Token tok = getToken(1); + if (tok.kind == SEMICOLON) { + tok = getNextToken(); + } else if (tok.specialToken != null) { + if (!EolCommentSkipWs(tok.specialToken) && (tok.kind != EOF)) { + throw generateParseException(); + } + } else if ((tok.kind != EOF) && (tok.kind!=RBRACE)) { + throw generateParseException(); + } + } + +JAVACODE + boolean EolCommentSkipWs(Token t) { + boolean retVal = false; + Token specialToken = t; + while(specialToken != null) { + if(specialToken.kind == WS) { + specialToken = specialToken.specialToken; + continue; + } + else if(specialToken.kind == EOL || + specialToken.kind == SINGLE_LINE_COMMENT) { + retVal = true; + break; + } + else { + break; + } + } + return retVal; + } + +void IfStatement(): +{ + Token t; +} +{ + Expression() + Statement() + [ LOOKAHEAD(1) t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, + null, 1);} + Statement() + ] +} + + +void IterationStatement(): +{} +{ + WhileStatement() + | DoStatement() + | LOOKAHEAD( Expression() ) + ForStatement() + | LOOKAHEAD( ) + ForStatement() + | LOOKAHEAD( varToekn= VariableDeclarationList(varToken) ) + ForVarStatement() + | LOOKAHEAD(3) ForInStatement() + | LOOKAHEAD(3) ForVarInStatement() +} + +void DoStatement(): +{} +{ + Statement() Expression() +} + +void WhileStatement(): +{} +{ + Expression() + Statement() +} + +void ForStatement(): +{} +{ + [Expression()] + [Expression()] + [Expression()] + Statement() +} + +void ForVarStatement(): +{ + Token t; +} +{ + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, + null, 1);} + VariableDeclarationList(t) + [Expression()] + [Expression()] + Statement() +} + +void ForInStatement(): +{ + Token t; +} +{ + ExpressionNoIN() + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, + null, 2);} + ExpressionNoIN() + Statement() +} + +void ForVarInStatement(): +{ + Token t; +} +{ + + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + t=Identifier() + { + JSParserUtils.annotateToken(t, AnnotationConstants.VAR_IDENTIFIER, null, 1); + JSParserUtils.pushToken(_contextStack, (AnnotatedToken)t); + } + [Initializer()] + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 2);} + ExpressionNoIN() + + Statement() +} + +void ContinueStatement(): +{} +{ + Sc() +} + +void BreakStatement(): +{} +{ + Sc() +} + +void ReturnStatement(): +{ + Token t; +} +{ + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + [Expression()] Sc() +} + +void WithStatement(): +{} +{ + Expression() + Statement() +} + +void TryStatement(): +{} +{ + Block(null) + ( Identifier() Block(null))* + [ Block(null)] +} + +void ThrowStatement(): +{ + Token t; +} +{ + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + [Expression()] Sc() +} + +void CaseGuard(): +{ + Token t; +} +{ + t= {JSParserUtils.annotateToken(t, AnnotationConstants.UNDEFINED, null, 1);} + Expression() + | <_DEFAULT> +} + +void CaseGroup(): +{} +{ + CaseGuard() (Statement())* +} + +void SwitchStatement(): +{} +{ + Expression() + (CaseGroup())* +} + +void NamedFunction(): +{ + Token tIdentifier = null; + Token tFunction = null; + Token blockStart = null; + Token blockEnd = null; + Vector params = new Vector(); +} +{ + tFunction= + tIdentifier=Identifier() + { + JSParserUtils.annotateToken(tIdentifier, AnnotationConstants.FUNCTION_NAME_IDENTIFIER, + null, -1); + ProgramContext context = new ProgramContext(tIdentifier.image); + _contextStack.pushContext(context); + } + + [params=FormalParameterList()] + { + JSParserUtils.annotateTokens(params, + AnnotationConstants.FUNCTION_PARAM_IDENTIFIER, + null, -1); + JSParserUtils.annotateToken(tFunction, AnnotationConstants.NAMED_FUNCTION, + params, 1); + JSParserUtils.pushTokens(_contextStack, params); + } + + + {blockStart = getToken(1);} + Block(context) + { + blockEnd = getToken(1); + JSParserUtils.tagEvalCalls(tFunction, blockStart, blockEnd); + } +} + +void AnonymousFunction(): +{ + Token tFunction = null; + Token blockStart = null; + Token blockEnd = null; + Vector params = new Vector(); +} +{ + tFunction= + { + ProgramContext context = new ProgramContext("anonymous"); + _contextStack.pushContext(context); + } + + [params=FormalParameterList()] + { + JSParserUtils.annotateTokens(params, + AnnotationConstants.FUNCTION_PARAM_IDENTIFIER, + null, -1); + JSParserUtils.annotateToken(tFunction, + AnnotationConstants.ANONYMOUS_FUNCTION, + params, -1); + JSParserUtils.pushTokens(_contextStack, params); + } + + {blockStart = getToken(1);} + Block(context) + { + blockEnd = getToken(1); + JSParserUtils.tagEvalCalls(tFunction, blockStart, blockEnd); + } +} + +void FunctionConstructor(): +{} +{ + ArgumentList() +} + +void FunctionDeclaration(): +{} +{ + LOOKAHEAD(2) NamedFunction() + | LOOKAHEAD(2) AnonymousFunction() +} + +void FunctionLiteral(): +{} +{ + AnonymousFunction() +} + +Vector FormalParameterList(): +{ + Token t = null; + Vector v = new Vector(); +} +{ + t=Identifier() {v.add(t);} + ( t=Identifier() {v.add(t);})* + {return v;} +} + +void LiteralElement() : +{} +{ + AssignmentExpression() +} + +void ElementList(): +{} +{ + LiteralElement() ( LiteralElement())* +} + +void ArrayLiteral(): +{} +{ + LOOKAHEAD(2) + | LOOKAHEAD(2) ElementList() +} + +void NestedArrayLiteral(): +{} +{ + LOOKAHEAD(3) ArrayLiteral() + | LOOKAHEAD(3) NestedArrayLiteral() +} + +void LiteralField(): +{ + Token t = null; +} +{ + t=Identifier() AssignmentExpression() + {JSParserUtils.annotateToken(t, AnnotationConstants.LITERAL_OBJECT_KEY_IDENTIFIER,null,-1); } + | t= AssignmentExpression() + {JSParserUtils.annotateToken(t, AnnotationConstants.LITERAL_OBJECT_KEY_IDENTIFIER,null,-1); } +} + +void FieldList(): +{} +{ + LiteralField() ( LiteralField())* +} + +void ObjectLiteral(): +{} +{ + LOOKAHEAD(2) + | LOOKAHEAD(2) FieldList() +} + + +Token Program(): +{ + Token retval = getToken(1); +} +{ + {_contextStack.pushContext(new ProgramContext("root"));} + (SourceElement())* + { + return retval; + } +} + +void SourceElement(): +{} +{ + LOOKAHEAD(2) Statement() + | FunctionDeclaration() +} + +void StatementList(): +{ +// Token t; +} +{ + (Statement())+ +} Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/obfuscator/javascript15parser/js1.5.jj ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java?rev=425235&r1=425234&r2=425235&view=diff ============================================================================== --- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java (original) +++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java Mon Jul 24 17:24:16 2006 @@ -1,100 +1,100 @@ -/* - * Copyright 2000,2006 The Apache Software Foundation. - * - * Licensed 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. - */ -package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools; - -import java.io.IOException; -import java.io.Writer; -import java.io.PrintWriter; - -/** - * Converts Token Objects into a JavaScript file - * @version $Name: $ ($Revision$) $Date$ - * @author Arjuna Wijeyekoon - arjuna.wijeyekoon@oracle.com - */ -public class Detokenizer -{ - private final PrintWriter _out; - - /** - * @param out the file to write the output to. - */ - public Detokenizer(PrintWriter out) - { - this._out = out; - } - - /** - * Creates a new PrintWriter and calls the other constructor. - */ - public Detokenizer(Writer out) - { - this(new PrintWriter(out)); - } - - /** - * decodes a token and writes the result - * @param tok the token to decode. - */ - public void write(Token tok) throws IOException - { - int com = tok.code; - switch(com) - { - case Token.NEWLINE : - _out.println(); - break; - case Token.WHITESPACE : - _out.print(' '); - break; - case Token.PERIOD : - _out.print('.'); - break; - case Token.SEMICOLON : - _out.print(';'); - break; - case Token.QUOTED : - { - char ch = tok.ch; - _out.print(ch+tok.string+ch); - } - break; - case Token.CONTROL : - case Token.LEFT_BRACE : - case Token.RIGHT_BRACE : - _out.print(tok.ch); - break; - case Token.NUMBER : - case Token.RESERVED : - case Token.NAME : - _out.print(tok.string); - break; - case Token.COMMENT : - _out.print("/*"+tok.string+"*/"); - break; - case Token.REGULAR_EXP : - _out.print("/"+tok.string+"/"); - break; - case Token.REGULAR_EXP_MODIFIER : - _out.print(tok.ch); - break; - case Token.EOF : - _out.close(); - break; - default : - throw new RuntimeException("Unknown Token:"+tok); - } - } +/* + * Copyright 2000,2006 The Apache Software Foundation. + * + * Licensed 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. + */ +package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools; + +import java.io.IOException; +import java.io.Writer; +import java.io.PrintWriter; + +/** + * Converts Token Objects into a JavaScript file + * @version $Name: $ ($Revision$) $Date$ + * @author Arjuna Wijeyekoon - arjuna.wijeyekoon@oracle.com + */ +public class Detokenizer +{ + private final PrintWriter _out; + + /** + * @param out the file to write the output to. + */ + public Detokenizer(PrintWriter out) + { + this._out = out; + } + + /** + * Creates a new PrintWriter and calls the other constructor. + */ + public Detokenizer(Writer out) + { + this(new PrintWriter(out)); + } + + /** + * decodes a token and writes the result + * @param tok the token to decode. + */ + public void write(Token tok) throws IOException + { + int com = tok.code; + switch(com) + { + case Token.NEWLINE : + _out.println(); + break; + case Token.WHITESPACE : + _out.print(' '); + break; + case Token.PERIOD : + _out.print('.'); + break; + case Token.SEMICOLON : + _out.print(';'); + break; + case Token.QUOTED : + { + char ch = tok.ch; + _out.print(ch+tok.string+ch); + } + break; + case Token.CONTROL : + case Token.LEFT_BRACE : + case Token.RIGHT_BRACE : + _out.print(tok.ch); + break; + case Token.NUMBER : + case Token.RESERVED : + case Token.NAME : + _out.print(tok.string); + break; + case Token.COMMENT : + _out.print("/*"+tok.string+"*/"); + break; + case Token.REGULAR_EXP : + _out.print("/"+tok.string+"/"); + break; + case Token.REGULAR_EXP_MODIFIER : + _out.print(tok.ch); + break; + case Token.EOF : + _out.close(); + break; + default : + throw new RuntimeException("Unknown Token:"+tok); + } + } } Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Detokenizer.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java?rev=425235&r1=425234&r2=425235&view=diff ============================================================================== --- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java (original) +++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java Mon Jul 24 17:24:16 2006 @@ -1,150 +1,150 @@ -/* - * Copyright 2000-2002,2006 The Apache Software Foundation. - * - * Licensed 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. - */ -package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools; - -import java.io.File; -import java.io.FilenameFilter; - -/** - * This utility class can be used to perform some processing on input files, - * and write the results to corresponding output files. It supports recursing - * into subdirectories. - * @version $Name: $ ($Revision$) $Date$ - * @author Arjuna Wijeyekoon (arjuna.wijeyekoon@oracle.com) */ -public abstract class FileProcessor -{ - /** - * @param filenameExt the filename extension to accept. If null, all files - * are accepted. - * @return a filter that only accepts files with names that end with the - * specified extension. However, the filter accepts all subdirectories. - */ - public static FilenameFilter getExtensionFilter(final String filenameExt) - { - return new FilenameFilter() { - public boolean accept(File dir, String name) - { - if ((filenameExt==null) || (name.endsWith(filenameExt))) return true; - File f = new File(dir, name); - return f.isDirectory(); - } - }; - } - - /** - * @param filter used to select files and/or subdirectories. - * @param failFast if true, terminates at the first error (otherwise, - * continues with the next file). - * @param overwrite if false, will not overwrite existing output files (That - * particular input and output file will be skipped). - * @param verbose if true, generates verbose output. */ - public FileProcessor(FilenameFilter filter, - boolean failFast, boolean overwrite, boolean verbose) - { - _filter = filter; - _failFast = failFast; - _dontOverwrite = !overwrite; - isVerbose = verbose; - } - - /** - * Creates a Fileprocessor that overwrites all output files, and does not - * fail fast. - * @param filter used to select files and/or subdirectories. */ - public FileProcessor(FilenameFilter filter, boolean verbosity) - { - this(filter, false, true, verbosity); - } - - /** - * Creates a Fileprocessor that overwrites all output files, and does not - * fail fast. - * @param extension the file extension to filter for. if this is null, all - * files and subdirectories in a directory will be processed recursively. - * @see #getExtensionFilter(String extension) - */ - public FileProcessor(String extension, boolean verbosity) - { - this(getExtensionFilter(extension), verbosity); - } - - /** - * @param in the input file or directory - * @param out if the input is a directory, then this must be the output - * directory. Otherwise, this is the output file. - * @return true if there were no errors. false otherwise. */ - public boolean process(File in, File out) - { - if (isVerbose) System.out.println("Processing file:"+in+" to file:"+out); - - if (in.isDirectory()) - { - boolean success = true; - String[] names = in.list(_filter); - for(int i=0, sz=names.length; ifail fast then any - * exception thrown will cause all execution to halt. If this class does not - * fail fast, then the exception will be reported and execution will - * continue with the next file. */ - protected abstract void processFile(File in, File out) throws Exception; - - /** - * If this is true, verbose output will be generated. - */ - protected final boolean isVerbose; - - private final boolean _failFast, _dontOverwrite; - private final FilenameFilter _filter; +/* + * Copyright 2000-2002,2006 The Apache Software Foundation. + * + * Licensed 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. + */ +package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools; + +import java.io.File; +import java.io.FilenameFilter; + +/** + * This utility class can be used to perform some processing on input files, + * and write the results to corresponding output files. It supports recursing + * into subdirectories. + * @version $Name: $ ($Revision$) $Date$ + * @author Arjuna Wijeyekoon (arjuna.wijeyekoon@oracle.com) */ +public abstract class FileProcessor +{ + /** + * @param filenameExt the filename extension to accept. If null, all files + * are accepted. + * @return a filter that only accepts files with names that end with the + * specified extension. However, the filter accepts all subdirectories. + */ + public static FilenameFilter getExtensionFilter(final String filenameExt) + { + return new FilenameFilter() { + public boolean accept(File dir, String name) + { + if ((filenameExt==null) || (name.endsWith(filenameExt))) return true; + File f = new File(dir, name); + return f.isDirectory(); + } + }; + } + + /** + * @param filter used to select files and/or subdirectories. + * @param failFast if true, terminates at the first error (otherwise, + * continues with the next file). + * @param overwrite if false, will not overwrite existing output files (That + * particular input and output file will be skipped). + * @param verbose if true, generates verbose output. */ + public FileProcessor(FilenameFilter filter, + boolean failFast, boolean overwrite, boolean verbose) + { + _filter = filter; + _failFast = failFast; + _dontOverwrite = !overwrite; + isVerbose = verbose; + } + + /** + * Creates a Fileprocessor that overwrites all output files, and does not + * fail fast. + * @param filter used to select files and/or subdirectories. */ + public FileProcessor(FilenameFilter filter, boolean verbosity) + { + this(filter, false, true, verbosity); + } + + /** + * Creates a Fileprocessor that overwrites all output files, and does not + * fail fast. + * @param extension the file extension to filter for. if this is null, all + * files and subdirectories in a directory will be processed recursively. + * @see #getExtensionFilter(String extension) + */ + public FileProcessor(String extension, boolean verbosity) + { + this(getExtensionFilter(extension), verbosity); + } + + /** + * @param in the input file or directory + * @param out if the input is a directory, then this must be the output + * directory. Otherwise, this is the output file. + * @return true if there were no errors. false otherwise. */ + public boolean process(File in, File out) + { + if (isVerbose) System.out.println("Processing file:"+in+" to file:"+out); + + if (in.isDirectory()) + { + boolean success = true; + String[] names = in.list(_filter); + for(int i=0, sz=names.length; ifail fast then any + * exception thrown will cause all execution to halt. If this class does not + * fail fast, then the exception will be reported and execution will + * continue with the next file. */ + protected abstract void processFile(File in, File out) throws Exception; + + /** + * If this is true, verbose output will be generated. + */ + protected final boolean isVerbose; + + private final boolean _failFast, _dontOverwrite; + private final FilenameFilter _filter; } Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/FileProcessor.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java?rev=425235&r1=425234&r2=425235&view=diff ============================================================================== --- incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java (original) +++ incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java Mon Jul 24 17:24:16 2006 @@ -1,91 +1,91 @@ -/* - * Copyright 2000-2001,2006 The Apache Software Foundation. - * - * Licensed 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. - */ -package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools; - -import java.io.IOException; - -/** - * Removes all comments and redundant whitespace - * @version $Name: $ ($Revision$) $Date$ - * @author Arjuna Wijeyekoon - arjuna.wijeyekoon@oracle.com - */ -public class Filter1 implements TokenReader -{ - - /** - * blocks until is has read atleast one token from the input reader - */ - public Filter1(TokenReader in) throws IOException, InterruptedException - { - _in = in; - _next = _in.read(); - } - - /** - * @see TokenReader - */ - public Token read() throws IOException, InterruptedException - { - Token cur = _next; - Token res = cur; - for(;cur!=null;) - { - _next = _in.read(); - res = _filter(_prev, cur, _next) ; - if (res!=null) - { - _prev = res; - break; - } - else cur = _next; - } - return res; - } - - /** - * Removes extra spaces/newlines and all comments - */ - private Token _filter(Token prev, Token cur, Token next) - { - //ystem.out.println("filtering token:"+cur); - int ccode = cur.code; - if ((ccode==Token.COMMENT) || //skip comments - ((ccode==Token.WHITESPACE) && - !(_isSpaceSensitive(prev) && _isSpaceSensitive(next))) || - ((ccode==Token.NEWLINE) && - ((prev==null) || (prev.code==Token.NEWLINE)))) - return null; - else return cur; - } - - /** - * @return true if the given token is affected by whitespace preceding or - * following it. - */ - private boolean _isSpaceSensitive(Token tok) - { - if (tok==null) return false; - int i = tok.code; - if ((i == Token.NAME) || (i == Token.NUMBER) || (i == Token.RESERVED) || - (i == Token.PERIOD)) - return true; - else return false; - } - - private final TokenReader _in; - private Token _prev = null; - private Token _next; +/* + * Copyright 2000-2001,2006 The Apache Software Foundation. + * + * Licensed 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. + */ +package org.apache.myfaces.trinidadbuild.plugin.javascript.uixtools; + +import java.io.IOException; + +/** + * Removes all comments and redundant whitespace + * @version $Name: $ ($Revision$) $Date$ + * @author Arjuna Wijeyekoon - arjuna.wijeyekoon@oracle.com + */ +public class Filter1 implements TokenReader +{ + + /** + * blocks until is has read atleast one token from the input reader + */ + public Filter1(TokenReader in) throws IOException, InterruptedException + { + _in = in; + _next = _in.read(); + } + + /** + * @see TokenReader + */ + public Token read() throws IOException, InterruptedException + { + Token cur = _next; + Token res = cur; + for(;cur!=null;) + { + _next = _in.read(); + res = _filter(_prev, cur, _next) ; + if (res!=null) + { + _prev = res; + break; + } + else cur = _next; + } + return res; + } + + /** + * Removes extra spaces/newlines and all comments + */ + private Token _filter(Token prev, Token cur, Token next) + { + //ystem.out.println("filtering token:"+cur); + int ccode = cur.code; + if ((ccode==Token.COMMENT) || //skip comments + ((ccode==Token.WHITESPACE) && + !(_isSpaceSensitive(prev) && _isSpaceSensitive(next))) || + ((ccode==Token.NEWLINE) && + ((prev==null) || (prev.code==Token.NEWLINE)))) + return null; + else return cur; + } + + /** + * @return true if the given token is affected by whitespace preceding or + * following it. + */ + private boolean _isSpaceSensitive(Token tok) + { + if (tok==null) return false; + int i = tok.code; + if ((i == Token.NAME) || (i == Token.NUMBER) || (i == Token.RESERVED) || + (i == Token.PERIOD)) + return true; + else return false; + } + + private final TokenReader _in; + private Token _prev = null; + private Token _next; } Propchange: incubator/adffaces/branches/matzew-repackaging-trinidad/plugins/maven-javascript-plugin/src/main/java/org/apache/myfaces/trinidadbuild/plugin/javascript/uixtools/Filter1.java ------------------------------------------------------------------------------ svn:eol-style = native