From c2cb39df80fcc6d1b14726f0ed282183d5fb28f9 Mon Sep 17 00:00:00 2001 From: khartlage Date: Sun, 23 May 2004 14:08:08 +0000 Subject: [PATCH 1/1] improved parser string handling --- .../core/tests/util/AbstractCompilerTest.java | 14 ++++++++------ .../php/test/PHPPartitionScannerTest.java | 8 ++++---- .../phpeclipse/tests/parser/PHPParserTestCase.java | 10 +++++++--- .../phpdt/internal/compiler/parser/Parser.java | 11 ++++++++--- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java index 031d81e..a85fa4d 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpdt/core/tests/util/AbstractCompilerTest.java @@ -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(); diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java index 535b473..713c56b 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPPartitionScannerTest.java @@ -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!", diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java index 3bcfbdd..eb0e083 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java @@ -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(" 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(); -- 1.7.1