misc parser changes
authorkhartlage <khartlage>
Fri, 26 Mar 2004 21:41:41 +0000 (21:41 +0000)
committerkhartlage <khartlage>
Fri, 26 Mar 2004 21:41:41 +0000 (21:41 +0000)
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/PHPFormatterTest.java
net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/tests/parser/PHPParserTestCase.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java

index 11e7ed1..b9e7618 100644 (file)
@@ -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();
   }
index d7759ea..c8b0443 100644 (file)
@@ -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("<?php echo $bgcolor2?>");
+    checkHTML("<?php if ($a==$b) {\n" +
+               "}\n" +
+               ""+
+               "?> ");
+    checkHTML("<?php if ($a==$b) {?>\n" +
+               "<b>test <?php echo \"test\";?> me</b>\n" +
+               "<?php } \n" +
+               "echo $bgcolor2 ?>");
+   
+    checkHTML("<?php echo $bgcolor2 ?>");
+    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);");
index 7d6e6b7..4a841f4 100644 (file)
@@ -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;
index 820b0c7..c9b73cf 100644 (file)
@@ -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.");
       }
index 9b91cf2..ff11fa1 100644 (file)
@@ -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)) {
-              // <?
-              startPosition = currentPosition;
-              phpMode = true;
-              if (tokenizeWhiteSpace) {
-                // && (whiteStart != currentPosition - 1)) {
-                // reposition scanner in case we are interested by spaces as
-                // tokens
-                startPosition = htmlPosition;
-                return TokenNameHTML;
-              }
-            } else {
-              boolean phpStart = (currentCharacter == 'P')
-                  || (currentCharacter == 'p');
-              if (phpStart) {
-                int test = getNextChar('H', 'h');
-                if (test >= 0) {
-                  test = getNextChar('P', 'p');
-                  if (test >= 0) {
-                    // <?PHP <?php
-                    startPosition = currentPosition;
-                    phpMode = true;
-                    if (tokenizeWhiteSpace) {
-                      // && (whiteStart != currentPosition - 1)) {
-                      // reposition scanner in case we are interested by spaces
-                      // as tokens
-                      startPosition = htmlPosition;
-                      return TokenNameHTML;
-                    }
-                  }
-                }
-              }
-            }
-          }
-        }
-        if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
-          if (recordLineSeparator) {
-            pushLineSeparator();
-          } else {
-            currentLine = null;
-          }
-        }
-      }
-    } //-----------------end switch while try--------------------
-    catch (IndexOutOfBoundsException e) {
-      if (tokenizeWhiteSpace) {
-        // && (whiteStart != currentPosition - 1)) {
-        // reposition scanner in case we are interested by spaces as tokens
-        startPosition = htmlPosition;
-      }
-      return TokenNameEOF;
+    if (!phpMode) {
+      return getInlinedHTML(currentPosition);
     }
     if (phpMode) {
       this.wasAcr = false;
@@ -1081,7 +1024,11 @@ public class Scanner implements IScanner, ITerminalSymbols {
             case '?' :
               if (getNextChar('>')) {
                 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)) {
+              // <?
+              phpMode = true;
+              return TokenNameINLINE_HTML;
+            } else {
+              boolean phpStart = (currentCharacter == 'P')
+                  || (currentCharacter == 'p');
+              if (phpStart) {
+                int test = getNextChar('H', 'h');
+                if (test >= 0) {
+                  test = getNextChar('P', 'p');
+                  if (test >= 0) {
+                    // <?PHP <?php
+                    phpMode = true;
+                    return TokenNameINLINE_HTML;
+                  }
+                }
+              }
+            }
+          }
+        }
+        if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
+          if (recordLineSeparator) {
+            pushLineSeparator();
+          } else {
+            currentLine = null;
+          }
+        }
+      } //-----------------while--------------------
+      phpMode = true;
+      return TokenNameINLINE_HTML;
+    } //-----------------try--------------------
+    catch (IndexOutOfBoundsException e) {
+      startPosition = start;
+      currentPosition--;
+    }
+    phpMode = true;
+    return TokenNameINLINE_HTML;
+  }
   //  public final void getNextUnicodeChar()
   //    throws IndexOutOfBoundsException, InvalidInputException {
   //    //VOID
@@ -3472,7 +3475,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
         return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
       // //$NON-NLS-1$
       case TokenNameINLINE_HTML :
-        return "StopPHP(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
+        return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
       case TokenNameIdentifier :
         return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
       case TokenNameVariable :
@@ -3714,8 +3717,9 @@ public class Scanner implements IScanner, ITerminalSymbols {
         return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
       case TokenNameCOMMENT_PHPDOC :
         return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
-      case TokenNameHTML :
-        return "HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
+        //      case TokenNameHTML :
+        //        return "HTML(" + new String(getCurrentTokenSource()) + ")";
+        // //$NON-NLS-1$
       case TokenNameFILE :
         return "__FILE__"; //$NON-NLS-1$
       case TokenNameLINE :