*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index e658989..21cdb6f 100644 (file)
@@ -280,7 +280,7 @@ PARSER_END(PHPParser)
 
 <PHPPARSING> SPECIAL_TOKEN :
 {
-  "//" : IN_SINGLE_LINE_COMMENT
+  "//" | "#" : IN_SINGLE_LINE_COMMENT
 |
   <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
 |
@@ -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;
 }
 {
@@ -831,7 +832,17 @@ void MethodDeclaration() :
   final PHPFunctionDeclaration functionDeclaration;
 }
 {
-  <FUNCTION> functionDeclaration = MethodDeclarator()
+  <FUNCTION>
+  try {
+    functionDeclaration = MethodDeclarator()
+  } catch (ParseException e) {
+    if (errorMessage != null) {
+      throw e;
+    }
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
+    errorLevel   = ERROR;
+    throw e;
+  }
   {
     if (currentSegment != null) {
       currentSegment.add(functionDeclaration);
@@ -1305,7 +1316,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+")";}
 }
 
@@ -1414,7 +1432,14 @@ String VariableSuffix() :
   String expr = null;
 }
 {
-  <CLASSACCESS> expr = VariableName()
+  <CLASSACCESS>
+  try {
+    expr = VariableName()
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
+    errorLevel   = ERROR;
+    throw e;
+  }
   {return "->" + expr;}
 | 
   <LBRACKET> [ expr = Expression() ]
@@ -1481,7 +1506,7 @@ String expr = null;
   try {
     <RPAREN>
   } catch (ParseException e) {
-    errorMessage = "')' expected to close the argument list";
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
     errorLevel   = ERROR;
     throw e;
   }
@@ -1516,11 +1541,10 @@ final StringBuffer buff = new StringBuffer();
    {return buff.toString();}
 }
 
-/*
- * Statement syntax follows.
+/**
+ * A Statement without break
  */
-
-void Statement() :
+void StatementNoBreak() :
 {}
 {
   LOOKAHEAD(2)
@@ -1561,8 +1585,6 @@ void Statement() :
 |
   ForeachStatement()
 |
-  BreakStatement()
-|
   ContinueStatement()
 |
   ReturnStatement()
@@ -1576,6 +1598,17 @@ void Statement() :
   GlobalStatement()
 }
 
+/**
+ * A Normal statement
+ */
+void Statement() :
+{}
+{
+  StatementNoBreak()
+|
+  BreakStatement()
+}
+
 void IncludeStatement() :
 {
   final String expr;
@@ -1662,22 +1695,39 @@ String ListExpression() :
   String expr;
 }
 {
-  <LIST> <LPAREN>
+  <LIST>
+  try {
+    <LPAREN>
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
+    errorLevel   = ERROR;
+    throw e;
+  }
   [
     expr = VariableDeclaratorId()
     {buff.append(expr);}
   ]
-  <COMMA>
-  {buff.append(",");}
   [
+    try {
+      <COMMA>
+    } catch (ParseException e) {
+      errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
+      errorLevel   = ERROR;
+      throw e;
+    }
     expr = VariableDeclaratorId()
-    {buff.append(expr);}
+    {buff.append(",").append(expr);}
   ]
-  <RPAREN>
-  {
-    buff.append(")");
-    return buff.toString();
+  {buff.append(")");}
+  try {
+    <RPAREN>
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
+    errorLevel   = ERROR;
+    throw e;
   }
+  [ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
+  {return buff.toString();}
 }
 
 void EchoStatement() :
@@ -1736,7 +1786,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 +1805,19 @@ void BlockStatement() :
   MethodDeclaration()
 }
 
+/**
+ * A Block statement that will not contain any 'break'
+ */
+void BlockStatementNoBreak() :
+{}
+{
+  StatementNoBreak()
+|
+  ClassDeclaration()
+|
+  MethodDeclaration()
+}
+
 void LocalVariableDeclaration() :
 {}
 {
@@ -1815,8 +1884,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 +1981,7 @@ void Condition(final String keyword) :
 }
 
 void IfStatement0(final int start,final int end) :
-{
-}
+{}
 {
   <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
 
@@ -1929,7 +2005,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 +2150,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 +2177,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 +2199,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