From: khartlage Date: Fri, 26 Mar 2004 21:41:41 +0000 (+0000) Subject: misc parser changes X-Git-Url: http://git.phpeclipse.com misc parser changes --- diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java index 11e7ed1..b9e7618 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java @@ -7,18 +7,18 @@ package net.sourceforge.phpeclipse.phpeditor.php.test; import java.util.Map; import junit.framework.TestCase; +import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.internal.corext.codemanipulation.StubUtility; import net.sourceforge.phpdt.internal.corext.util.Strings; import net.sourceforge.phpdt.internal.formatter.CodeFormatter; import net.sourceforge.phpdt.internal.ui.preferences.CodeFormatterPreferencePage; -import net.sourceforge.phpeclipse.PHPCore; import org.eclipse.jface.text.IDocument; /** * Testcase for the PHP CodeFormatter * @author Stefan Langer - * @version $Revision: 1.1 $ + * @version $Revision: 1.2 $ */ public class PHPFormatterTest extends TestCase { private CodeFormatter fFormatter; @@ -29,7 +29,7 @@ public class PHPFormatterTest extends TestCase { * @see junit.framework.TestCase#setUp() */ protected void setUp() throws Exception { - Map options = PHPCore.getOptions(); + Map options = JavaCore.getOptions(); fFormatter = new CodeFormatter(options); fDocument = new DummyDocument(); } 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 d7759ea..c8b0443 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 @@ -6,7 +6,6 @@ package net.sourceforge.phpeclipse.tests.parser; * distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html ******************************************************************************/ import net.sourceforge.phpdt.core.tests.util.AbstractCompilerTest; -import net.sourceforge.phpdt.internal.compiler.parser.Parser; import net.sourceforge.phpdt.internal.compiler.parser.Scanner; /** * Tests the php parser @@ -20,7 +19,19 @@ public class PHPParserTestCase extends AbstractCompilerTest { * Test the PHP Parser with different PHP snippets */ public void testPHPParser() { - checkHTML(""); + checkHTML(" "); + checkHTML("\n" + + "test me\n" + + ""); + + checkHTML(""); + checkPHP("function clean_words($mode, &$entry, &$stopword_list, &$synonym_list)\r\n" + + "{ static $drop_char_match = array(\'^\', \'$\'); }"); + checkPHP("if ($topic<1) { $topic = 1;}"); checkPHP("$this->result_field_names[$result_id][] = odbc_field_name($result_id, $i);"); checkPHP("$db->sql_query($sql);"); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java index 7d6e6b7..4a841f4 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java @@ -38,8 +38,8 @@ public interface ITerminalSymbols { public final static int TokenNameWHITESPACE = 900, TokenNameCOMMENT_LINE = 901, TokenNameCOMMENT_BLOCK = 902, - TokenNameCOMMENT_PHPDOC = 903, - TokenNameHTML = 904; + TokenNameCOMMENT_PHPDOC = 903; +// TokenNameHTML = 904; final static int TokenNameEOF = 0; final static int TokenNameERROR = 1; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index 820b0c7..c9b73cf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -2938,9 +2938,13 @@ getNextToken(); if (Scanner.TRACE) { System.out.println("TRACE: variable_name()"); } - if (token == TokenNameIdentifier) { + if (token == TokenNameIdentifier || token > TokenNameKEYWORD) { + if (token > TokenNameKEYWORD) { + // TODO show a warning "Keyword used as variable" ? + } getNextToken(); } else { + if (token != TokenNameLBRACE) { throwSyntaxError("'{' expected in variable name."); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index 9b91cf2..ff11fa1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -804,65 +804,8 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameLPAREN; } public int getNextToken() throws InvalidInputException { - int htmlPosition = currentPosition; - try { - while (!phpMode) { - currentCharacter = source[currentPosition++]; - if (currentCharacter == '<') { - if (getNextChar('?')) { - currentCharacter = source[currentPosition++]; - if ((currentCharacter == ' ') - || Character.isWhitespace(currentCharacter)) { - // = 0) { - test = getNextChar('P', 'p'); - if (test >= 0) { - // ')) { phpMode = false; - return TokenNameINLINE_HTML; + if (currentPosition==source.length) { + phpMode = true; + return TokenNameINLINE_HTML; + } + return getInlinedHTML(currentPosition - 2); } return TokenNameQUESTION; case ':' : @@ -1702,7 +1649,6 @@ public class Scanner implements IScanner, ITerminalSymbols { int oldPosition = currentPosition; try { currentCharacter = source[currentPosition++]; - if (isPHPIdentifierStart(currentCharacter)) { return scanIdentifierOrKeyword(true); } else { @@ -1727,6 +1673,63 @@ public class Scanner implements IScanner, ITerminalSymbols { } return TokenNameEOF; } + /** + * @return @throws + * InvalidInputException + */ + private int getInlinedHTML(int start) throws InvalidInputException { + // int htmlPosition = start; + if (currentPosition>source.length) { + currentPosition = source.length; + return TokenNameEOF; + } + startPosition = start; + try { + while (!phpMode) { + currentCharacter = source[currentPosition++]; + if (currentCharacter == '<') { + if (getNextChar('?')) { + currentCharacter = source[currentPosition++]; + if ((currentCharacter == ' ') + || Character.isWhitespace(currentCharacter)) { + // = 0) { + test = getNextChar('P', 'p'); + if (test >= 0) { + //