improved parser string handling
authorkhartlage <khartlage>
Sun, 23 May 2004 14:08:08 +0000 (14:08 +0000)
committerkhartlage <khartlage>
Sun, 23 May 2004 14:08:08 +0000 (14:08 +0000)
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java

index 031d81e..a85fa4d 100644 (file)
@@ -16,6 +16,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
 import java.util.Locale;
+import java.util.Map;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
@@ -25,6 +26,7 @@ import net.sourceforge.phpdt.internal.compiler.CompilationResult;
 import net.sourceforge.phpdt.internal.compiler.DefaultErrorHandlingPolicies;
 import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit;
 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
+import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem;
 import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
@@ -56,7 +58,7 @@ public class AbstractCompilerTest extends TestCase {
                        new UnitParser(
                                new ProblemReporter(
                                        DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
-                                       //new CompilerOptions(getCompilerOptions()), 
+                                       new CompilerOptions(getCompilerOptions()), 
                                        new DefaultProblemFactory(Locale.getDefault())));
 
                ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
@@ -114,7 +116,7 @@ public class AbstractCompilerTest extends TestCase {
                        new UnitParser(
                                new ProblemReporter(
                                        DefaultErrorHandlingPolicies.proceedWithAllProblems(), 
-                                       //new CompilerOptions(getCompilerOptions()), 
+                                       new CompilerOptions(getCompilerOptions()), 
                                        new DefaultProblemFactory(Locale.getDefault())));
 
                ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
@@ -256,8 +258,8 @@ public class AbstractCompilerTest extends TestCase {
                super(name);
        }
 
-//     protected Map getCompilerOptions() {
-//             Map options = new CompilerOptions().getMap();
+       protected Map getCompilerOptions() {
+               Map options = new CompilerOptions().getMap();
 //             if (COMPLIANCE_1_3.equals(this.complianceLevel)) {
 //                     options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3);
 //                     options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
@@ -271,8 +273,8 @@ public class AbstractCompilerTest extends TestCase {
 //                     options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
 //                     options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
 //             }
-//             return options;
-//     }
+               return options;
+       }
 
        public String getName() {
                String name = super.getName();
index 535b473..713c56b 100644 (file)
@@ -14,7 +14,7 @@ import org.eclipse.jface.text.rules.*;
 /**
  * Testcase for the PHPPartitionScanner
  * @author Stefan Langer
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
  */
 public class PHPPartitionScannerTest extends TestCase
 {
@@ -114,7 +114,7 @@ public class PHPPartitionScannerTest extends TestCase
         token = fScanner.nextToken();
         junit.framework.Assert.assertEquals(
             "PHPComment Partition 1 not recognized!",
-            IPHPPartitions.PHP_MULTILINE_COMMENT,
+            IPHPPartitions.PHP_PHPDOC_COMMENT,
             (String) token.getData());
         junit.framework.Assert.assertEquals(
             "Length of PHPComment Partition 1 not correct!",
@@ -216,7 +216,7 @@ public class PHPPartitionScannerTest extends TestCase
         token = fScanner.nextToken();
         junit.framework.Assert.assertEquals(
             "PHP Multilinecomment 2 not recognized!",
-            IPHPPartitions.PHP_MULTILINE_COMMENT,
+            IPHPPartitions.PHP_PHPDOC_COMMENT,
             (String) token.getData());
         junit.framework.Assert.assertEquals(
             "Length of PHP Multilinecomment 2  not correct!",
@@ -430,7 +430,7 @@ public class PHPPartitionScannerTest extends TestCase
         token = fScanner.nextToken();
         junit.framework.Assert.assertEquals(
             "PHP Multiline not recognized!",
-            IPHPPartitions.PHP_MULTILINE_COMMENT,
+            IPHPPartitions.PHP_PHPDOC_COMMENT,
             (String) token.getData());
         junit.framework.Assert.assertEquals(
             "Length of PHP Multinline not correct!",
index 3bcfbdd..eb0e083 100644 (file)
@@ -19,7 +19,12 @@ public class PHPParserTestCase extends AbstractCompilerTest {
    * Test the PHP Parser with different PHP snippets
    */
   public void testPHPParser() {
-    checkPHP("switch ($aItem[ELM_NAME]) {\r\n" + 
+    checkPHP("$test=\"{4IP}/{$include}\";");
+    checkPHP("$this->mRegex = \"/{$this->mBaseRegex}/{$case}\";");
+    checkPHP("$schema_create .= \" DEFAULT \'$row[Default]\'\";");
+    checkPHP("$stringVar=\"ein normaler $varText\";");
+    checkPHP("$stringVar=\'ein normaler $varText\';");
+    checkPHP("switch ($aItem[ELM_NAME]) {\r\n" +  
                "                case \'channel\':\r\n" + 
                "                    $this->readChannel($aItem);\r\n" + 
                "                    break;\r\n" + 
@@ -32,8 +37,7 @@ public class PHPParserTestCase extends AbstractCompilerTest {
     checkPHP("try {echo $Stream->readAll(); } catch (Exception $e) {\r\n" + 
                "            // Swallow exception\r\n" + 
                "        }");
-    checkPHP("$this->mRegex = \"/{$this->mBaseRegex}/{$case}\";");
-    checkPHP("$schema_create .= \" DEFAULT \'$row[Default]\'\";");
+
     checkHTML("<?php\n"+
             "    function overLib($path = \"\") {\n" + 
                "\n" + 
index 238bdbe..80f61c9 100644 (file)
@@ -2211,8 +2211,13 @@ public class Parser //extends PHPParserSuperclass
         break;
       default :
         if (token != TokenNameINLINE_HTML) {
-          throwSyntaxError("Error in expression (found token '"
-              + scanner.toStringAction(token) + "').");
+          if (token > TokenNameKEYWORD) {
+            getNextToken();
+            break;
+          } else {
+            throwSyntaxError("Error in expression (found token '"
+                + scanner.toStringAction(token) + "').");
+          }
         }
         return;
     }
@@ -3031,7 +3036,7 @@ public class Parser //extends PHPParserSuperclass
         break;
       case TokenNameCURLY_OPEN :
         getNextToken();
-        if (token == TokenNameIdentifier) {
+        if (token == TokenNameIdentifier||token>TokenNameKEYWORD) {
           getNextToken();
           if (token == TokenNameLBRACKET) {
             getNextToken();