a lot of new exception handled
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index e658989..2de24e2 100644 (file)
@@ -578,18 +578,19 @@ void PhpBlock() :
   <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
 |
   [ <PHPSTARTLONG>
-  | <PHPSTARTSHORT>
-  {try {
-    setMarker(fileToParse,
-              "You should use '<?php' instead of '<?' it will avoid some problems with XML",
-              start,
-              jj_input_stream.bufpos,
-              INFO,
-              "Line " + token.beginLine);
-  } catch (CoreException e) {
-    PHPeclipsePlugin.log(e);
-  }}
-  ]Php()
+    | <PHPSTARTSHORT>
+    {try {
+      setMarker(fileToParse,
+                "You should use '<?php' instead of '<?' it will avoid some problems with XML",
+                start,
+                jj_input_stream.bufpos,
+                INFO,
+                "Line " + token.beginLine);
+    } catch (CoreException e) {
+      PHPeclipsePlugin.log(e);
+    }}
+  ]
+  Php()
   try {
     <PHPEND>
   } catch (ParseException e) {
@@ -687,7 +688,7 @@ void FieldDeclaration() :
 PHPVarDeclaration VariableDeclarator() :
 {
   final String varName;
-  String varValue = null;
+  String varValue;
   final int pos = jj_input_stream.bufpos;
 }
 {
@@ -1305,7 +1306,14 @@ String UnaryExpressionNotPlusMinus() :
   expr = Literal()
   {return expr;}
 |
-  <LPAREN> expr = Expression()<RPAREN>
+  <LPAREN> expr = Expression()
+  try {
+    <RPAREN>
+  } catch (ParseException e) {
+    errorMessage = "')' expected";
+    errorLevel   = ERROR;
+    throw e;
+  }
   {return "("+expr+")";}
 }
 
@@ -1520,7 +1528,7 @@ final StringBuffer buff = new StringBuffer();
  * Statement syntax follows.
  */
 
-void Statement() :
+void StatementNoBreak() :
 {}
 {
   LOOKAHEAD(2)
@@ -1561,8 +1569,6 @@ void Statement() :
 |
   ForeachStatement()
 |
-  BreakStatement()
-|
   ContinueStatement()
 |
   ReturnStatement()
@@ -1576,6 +1582,14 @@ void Statement() :
   GlobalStatement()
 }
 
+void Statement() :
+{}
+{
+  StatementNoBreak()
+|
+  BreakStatement()
+}
+
 void IncludeStatement() :
 {
   final String expr;
@@ -1673,11 +1687,10 @@ String ListExpression() :
     expr = VariableDeclaratorId()
     {buff.append(expr);}
   ]
+  {buff.append(")");}
   <RPAREN>
-  {
-    buff.append(")");
-    return buff.toString();
-  }
+  [ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
+  {return buff.toString();}
 }
 
 void EchoStatement() :
@@ -1736,7 +1749,13 @@ void Block() :
     throw e;
   }
   ( BlockStatement() )*
-  <RBRACE>
+  try {
+    <RBRACE>
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : "+ e.currentToken.image +", '}' expected";
+    errorLevel   = ERROR;
+    throw e;
+  }
 }
 
 void BlockStatement() :
@@ -1749,6 +1768,16 @@ void BlockStatement() :
   MethodDeclaration()
 }
 
+void BlockStatementNoBreak() :
+{}
+{
+  StatementNoBreak()
+|
+  ClassDeclaration()
+|
+  MethodDeclaration()
+}
+
 void LocalVariableDeclaration() :
 {}
 {
@@ -1815,8 +1844,16 @@ void SwitchStatement() :
   }
     (
       line = SwitchLabel()
-      ( BlockStatement() )*
-      [ breakToken = <BREAK> ]
+      ( BlockStatementNoBreak() )*
+      [ breakToken = <BREAK>
+        try {
+          <SEMICOLON>
+        } catch (ParseException e) {
+          errorMessage = "';' expected after 'break' keyword";
+          errorLevel   = ERROR;
+          throw e;
+        }
+      ]
       {
         try {
           if (breakToken == null) {
@@ -1904,8 +1941,7 @@ void Condition(final String keyword) :
 }
 
 void IfStatement0(final int start,final int end) :
-{
-}
+{}
 {
   <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
 
@@ -1929,7 +1965,7 @@ void IfStatement0(final int start,final int end) :
   try {
     <SEMICOLON>
   } catch (ParseException e) {
-    errorMessage = "';' expected 'endif' keyword";
+    errorMessage = "';' expected after 'endif' keyword";
     errorLevel   = ERROR;
     throw e;
   }
@@ -2074,7 +2110,7 @@ final int pos = jj_input_stream.bufpos;
     errorLevel   = ERROR;
     throw e;
   }
-     [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ ForUpdate() ] <RPAREN>
+     [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ StatementExpressionList() ] <RPAREN>
     (
       Statement()
     |
@@ -2101,7 +2137,7 @@ final int pos = jj_input_stream.bufpos;
       try {
         <SEMICOLON>
       } catch (ParseException e) {
-        errorMessage = "';' expected 'endfor' keyword";
+        errorMessage = "';' expected after 'endfor' keyword";
         errorLevel   = ERROR;
         throw e;
       }
@@ -2123,26 +2159,41 @@ void StatementExpressionList() :
   StatementExpression() ( <COMMA> StatementExpression() )*
 }
 
-void ForUpdate() :
-{}
-{
-  StatementExpressionList()
-}
-
 void BreakStatement() :
 {}
 {
-  <BREAK> [ <IDENTIFIER> ] <SEMICOLON>
+  <BREAK> [ <IDENTIFIER> ]
+  try {
+    <SEMICOLON>
+  } catch (ParseException e) {
+    errorMessage = "';' expected after 'break' statement";
+    errorLevel   = ERROR;
+    throw e;
+  }
 }
 
 void ContinueStatement() :
 {}
 {
-  <CONTINUE> [ <IDENTIFIER> ] <SEMICOLON>
+  <CONTINUE> [ <IDENTIFIER> ]
+  try {
+    <SEMICOLON>
+  } catch (ParseException e) {
+    errorMessage = "';' expected after 'continue' statement";
+    errorLevel   = ERROR;
+    throw e;
+  }
 }
 
 void ReturnStatement() :
 {}
 {
-  <RETURN> [ Expression() ] <SEMICOLON>
+  <RETURN> [ Expression() ]
+  try {
+    <SEMICOLON>
+  } catch (ParseException e) {
+    errorMessage = "';' expected after 'return' statement";
+    errorLevel   = ERROR;
+    throw e;
+  }
 }
\ No newline at end of file