*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 00cc6c9..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  : "::">
@@ -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 */
@@ -1556,11 +1535,15 @@ 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()
@@ -1804,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());}
 }
 
 /**