X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java index 5c79a17..81d8579 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java @@ -14,7 +14,6 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; -import java.util.Stack; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; @@ -61,6 +60,12 @@ public class PHPParser extends PHPKeywords { Long longNumber; Double doubleNumber; + + private String stringValue; + + /** Contains the current expression. */ + private StringBuffer expression; + private boolean phpMode; final static int TT_EOF = 0; @@ -752,7 +757,7 @@ public class PHPParser extends PHPKeywords { if (ch2 == '?') { ch2 = str.charAt(chIndx++); if (Character.isWhitespace(ch2)) { - // php start + // php start phpMode = true; phpFound = true; break; @@ -881,73 +886,14 @@ public class PHPParser extends PHPKeywords { continue; } else if (ch == '"') { - // read string until end - boolean openString = true; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '"') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character '\"' at end of file."); - } - token = TT_INTERPOLATED_STRING; + getString('"',TT_INTERPOLATED_STRING,"Open string character '\"' at end of file."); return; } else if (ch == '\'') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '\'') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"'\" at end of file.", startRow); - } - token = TT_STRING_CONSTANT; + getString('\'',TT_STRING_CONSTANT,"Open string character \"'\" at end of file."); return; } else if (ch == '`') { - // read string until end - boolean openString = true; - int startRow = rowCount; - while (str.length() > chIndx) { - ch = str.charAt(chIndx++); - if (ch == '\\') { - if (str.length() > chIndx) { - ch = str.charAt(chIndx++); - } - } else if (ch == '`') { - openString = false; - break; - } else if (ch == '\n') { - rowCount++; - columnCount = chIndx; - } - } - if (openString) { - throwSyntaxError("Open string character \"`\" at end of file.", startRow); - } + getString('`',TT_STRING_CONSTANT,"Open string character \"`\" at end of file."); setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO); - token = TT_STRING_CONSTANT; return; } @@ -1329,6 +1275,7 @@ public class PHPParser extends PHPKeywords { // } } + private void getIdentifier() { StringBuffer ident = new StringBuffer(); @@ -1352,7 +1299,7 @@ public class PHPParser extends PHPKeywords { chIndx--; // determine if this identitfer is a keyword - // @todo improve this in future version + // @todo improve this in future version Integer i = (Integer) keywordMap.get(identifier.toLowerCase()); if (i != null) { token = i.intValue(); @@ -1444,6 +1391,45 @@ public class PHPParser extends PHPKeywords { } } + /** + * Get a String. + * @param openChar the opening char ('\'', '"', '`') + * @param typeString the type of string {@link #TT_STRING_CONSTANT},{@link #TT_INTERPOLATED_STRING} + * @param errorMsg the error message in case of parse error in the string + */ + private void getString(final char openChar, final int typeString, final String errorMsg) { + StringBuffer sBuffer = new StringBuffer(); + boolean openString = true; + int startRow = rowCount; + while (str.length() > chIndx) { + ch = str.charAt(chIndx++); + if (ch == '\\') { + sBuffer.append(ch); + if (str.length() > chIndx) { + ch = str.charAt(chIndx++); + sBuffer.append(ch); + } + } else if (ch == openChar) { + openString = false; + break; + } else if (ch == '\n') { + rowCount++; + columnCount = chIndx; + } else { + sBuffer.append(ch); + } + } + if (openString) { + if (typeString == TT_STRING_CONSTANT) { + throwSyntaxError(errorMsg, startRow); + } else { + throwSyntaxError(errorMsg); + } + } + token = typeString; + stringValue = sBuffer.toString(); + } + public void htmlParserTester(String input) { int lineNumber = 1; int startLineNumber = 1; @@ -1468,7 +1454,7 @@ public class PHPParser extends PHPKeywords { if (ch2 == '?') { ch2 = input.charAt(i++); if (Character.isWhitespace(ch2)) { - // php start + // php start phpMode = true; phpFound = true; startIndex = i; @@ -1617,7 +1603,7 @@ public class PHPParser extends PHPKeywords { // String temp = ((PHPString)phpList.get(j)).getPHPString(); // int startIndx = temp.length()-10; // if (startIndx<0) { - // startIndx = 0; + // startIndx = 0; // } // System.out.println(temp.substring(startIndx)+"?>"); // } @@ -1626,7 +1612,7 @@ public class PHPParser extends PHPKeywords { // for(int j=0;j