*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index c348a5e..17511d5 100644 (file)
@@ -38,6 +38,7 @@ import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpdt.internal.compiler.ast.*;
 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
+import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
 
 /**
@@ -391,6 +392,7 @@ MORE :
 | <INCLUDE_ONCE       : "include_once">
 | <REQUIRE_ONCE       : "require_once">
 | <GLOBAL             : "global">
+| <DEFINE             : "define">
 | <STATIC             : "static">
 | <CLASSACCESS        : "->">
 | <STATICCLASSACCESS  : "::">
@@ -456,8 +458,8 @@ MORE :
 {
   <OR_OR              : "||">
 | <AND_AND            : "&&">
-| <INCR               : "++">
-| <DECR               : "--">
+| <PLUS_PLUS          : "++">
+| <MINUS_MINUS        : "--">
 | <PLUS               : "+">
 | <MINUS              : "-">
 | <STAR               : "*">
@@ -498,32 +500,9 @@ MORE :
   <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 |
   <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
-|    <STRING_1:
-      "\""
-      (
-          ~["\""]
-        | "\\\""
-        | "\\"
-      )*
-      "\""
-    >
-|    <STRING_2:
-      "'"
-      (
-         ~["'"]
-       | "\\'"
-      )*
-
-      "'"
-    >
-|   <STRING_3:
-      "`"
-      (
-        ~["`"]
-      | "\\`"
-      )*
-      "`"
-    >
+|   <STRING_1: "\"" ( ~["\""] | "\\\"" | "\\" )* "\"">
+|   <STRING_2: "'" ( ~["'"] | "\\'" )* "'">
+|   <STRING_3: "`" ( ~["`"] | "\\`" )* "`">
 }
 
 /* IDENTIFIERS */
@@ -1480,8 +1459,8 @@ final int operator;
   final int pos = SimpleCharStream.getPosition();
 }
 {
-  (  <INCR> {operator = OperatorIds.PLUS_PLUS;}
-   | <DECR> {operator = OperatorIds.MINUS_MINUS;})
+  (  <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
+   | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
    expr = PrimaryExpression()
   {return new PrefixedUnaryExpression(expr,operator,pos);}
 }
@@ -1532,8 +1511,8 @@ Expression PostfixExpression() :
 }
 {
   expr = PrimaryExpression()
-  [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
-  | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
+  [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
+  | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
   {
     if (operator == -1) {
       return expr;
@@ -1556,17 +1535,26 @@ Expression PrimaryExpression() :
                                                  SimpleCharStream.getPosition()),
                           expr,
                           ClassAccess.STATIC);}
-  (expr = PrimarySuffix(expr))*
+  (
+  LOOKAHEAD(PrimarySuffix())
+  expr = PrimarySuffix(expr))*
   {return expr;}
 |
   expr = PrimaryPrefix()
-  (expr = PrimarySuffix(expr))*
+  (
+  LOOKAHEAD(PrimarySuffix())
+  expr = PrimarySuffix(expr))*
   {return expr;}
 |
   expr = ArrayDeclarator()
   {return expr;}
 }
 
+/**
+ * An array declarator.
+ * array(vars)
+ * @return an array
+ */
 ArrayInitializer ArrayDeclarator() :
 {
   final ArrayVariableDeclaration[] vars;
@@ -1591,9 +1579,10 @@ Expression PrimaryPrefix() :
 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
                                                                      OperatorIds.NEW,
                                                                      pos);}
-| var = VariableDeclaratorId()  {return new ConstantIdentifier(var.toCharArray(),
-                                                               pos,
-                                                               SimpleCharStream.getPosition());}
+| var = VariableDeclaratorId()  {return new VariableDeclaration(currentSegment,
+                                                                var.toCharArray(),
+                                                                pos,
+                                                                SimpleCharStream.getPosition());}
 }
 
 PrefixedUnaryExpression classInstantiation() :
@@ -1798,6 +1787,69 @@ Statement StatementNoBreak() :
   return statement;}
 | statement = StaticStatement()         {return statement;}
 | statement = GlobalStatement()         {return statement;}
+| statement = defineStatement()         {currentSegment.add((Outlineable)statement);return statement;}
+}
+
+Define defineStatement() :
+{
+  final int start = SimpleCharStream.getPosition();
+  Expression defineName,defineValue;
+}
+{
+  <DEFINE>
+  try {
+    <LPAREN>
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
+    errorLevel   = ERROR;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
+  }
+  try {
+    defineName = Expression()
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
+    errorLevel   = ERROR;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    throw e;
+  }
+  try {
+    <COMMA>
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
+    errorLevel   = ERROR;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
+  }
+  try {
+    (   defineValue = PrintExpression()
+      | LOOKAHEAD(varAssignation())
+        defineValue = varAssignation()
+      | defineValue = ConditionalExpression())
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
+    errorLevel   = ERROR;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    throw e;
+  }
+  try {
+    <RPAREN>
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
+    errorLevel   = ERROR;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
+  }
+  {return new Define(currentSegment,
+                     defineName,
+                     defineValue,
+                     start,
+                     SimpleCharStream.getPosition());}
 }
 
 /**
@@ -2182,7 +2234,7 @@ EmptyStatement EmptyStatement() :
    return new EmptyStatement(pos-1,pos);}
 }
 
-Statement StatementExpression() :
+Expression StatementExpression() :
 {
   Expression expr,expr2;
   int operator;
@@ -2191,10 +2243,10 @@ Statement StatementExpression() :
   expr = PreIncDecExpression() {return expr;}
 |
   expr = PrimaryExpression()
-  [ <INCR> {return new PostfixedUnaryExpression(expr,
+  [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
                                                 OperatorIds.PLUS_PLUS,
                                                 SimpleCharStream.getPosition());}
-  | <DECR> {return new PostfixedUnaryExpression(expr,
+  | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
                                                 OperatorIds.MINUS_MINUS,
                                                 SimpleCharStream.getPosition());}
   | operator = AssignmentOperator() expr2 = Expression()
@@ -2743,9 +2795,9 @@ ForStatement ForStatement() :
 {
 final Token token;
 final int pos = SimpleCharStream.getPosition();
-Statement[] initializations = null;
+Expression[] initializations = null;
 Expression condition = null;
-Statement[] increments = null;
+Expression[] increments = null;
 Statement action;
 final ArrayList list = new ArrayList();
 final int startBlock, endBlock;
@@ -2809,31 +2861,31 @@ final int startBlock, endBlock;
     )
 }
 
-Statement[] ForInit() :
+Expression[] ForInit() :
 {
-  Statement[] statements;
+  Expression[] exprs;
 }
 {
   LOOKAHEAD(LocalVariableDeclaration())
-  statements = LocalVariableDeclaration()
-  {return statements;}
+  exprs = LocalVariableDeclaration()
+  {return exprs;}
 |
-  statements = StatementExpressionList()
-  {return statements;}
+  exprs = StatementExpressionList()
+  {return exprs;}
 }
 
-Statement[] StatementExpressionList() :
+Expression[] StatementExpressionList() :
 {
   final ArrayList list = new ArrayList();
-  Statement expr;
+  Expression expr;
 }
 {
   expr = StatementExpression()   {list.add(expr);}
   (<COMMA> StatementExpression() {list.add(expr);})*
   {
-  Statement[] stmtsArray = new Statement[list.size()];
-  list.toArray(stmtsArray);
-  return stmtsArray;}
+  Expression[] exprsArray = new Expression[list.size()];
+  list.toArray(exprsArray);
+  return exprsArray;}
 }
 
 Continue ContinueStatement() :