X-Git-Url: http://secure.phpeclipse.com 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 12b9245..238bdbe 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 @@ -10,19 +10,25 @@ **********************************************************************/ package net.sourceforge.phpdt.internal.compiler.parser; import java.util.ArrayList; + import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; import net.sourceforge.phpdt.core.compiler.InvalidInputException; +import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions; import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext; import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers; import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants; import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter; +import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities; import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration; import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode; import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration; +import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration; import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration; import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference; import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration; +import net.sourceforge.phpdt.internal.compiler.util.Util; + import org.eclipse.core.resources.IFile; public class Parser //extends PHPParserSuperclass implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation { @@ -64,7 +70,9 @@ public class Parser //extends PHPParserSuperclass //private boolean phpMode; protected int modifiers; protected int modifiersSourceStart; - protected Parser() { + protected Parser(ProblemReporter problemReporter) { + this.problemReporter = problemReporter; + this.options = problemReporter.options; this.currentPHPString = 0; // PHPParserSuperclass.fileToParse = fileToParse; this.phpList = null; @@ -114,7 +122,14 @@ public class Parser //extends PHPParserSuperclass this.initializeScanner(); } public void initializeScanner() { - this.scanner = new Scanner(false, false, false, false); + this.scanner = new Scanner( + false /*comment*/, + false /*whitespace*/, + this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/, + false, + false, + this.options.taskTags/*taskTags*/, + this.options.taskPriorites/*taskPriorities*/); } /** * Create marker for the parse error @@ -135,7 +150,7 @@ public class Parser //extends PHPParserSuperclass private void throwSyntaxError(String error) { int problemStartPosition = scanner.getCurrentTokenStartPosition(); int problemEndPosition = scanner.getCurrentTokenEndPosition(); - throwSyntaxError(error, problemStartPosition, problemEndPosition); + throwSyntaxError(error, problemStartPosition, problemEndPosition + 1); } /** * This method will throw the SyntaxError. It will add the good lines and @@ -205,426 +220,6 @@ public class Parser //extends PHPParserSuperclass } return; } - /** - * Get a number. if it's a double the number will be stored in - * doubleNumber and the token will have the value - * {@link Parser#TokenNameDOUBLE_NUMBER}
- * if it's a double the number will be stored in longNumber - * and the token will have the value {@link Parser#TokenNameINT_NUMBER} - */ - // private void getNumber() { - // StringBuffer inum = new StringBuffer(); - // char dFlag = ' '; - // int numFormat = 10; - // - // // save first digit - // char firstCh = ch; - // inum.append(ch); - // - // getChar(); - // // determine number conversions: - // if (firstCh == '0') { - // switch (ch) { - // case 'b' : - // numFormat = 2; - // getChar(); - // break; - // case 'B' : - // numFormat = 2; - // getChar(); - // break; - // case 'o' : - // numFormat = 8; - // getChar(); - // break; - // case 'O' : - // numFormat = 8; - // getChar(); - // break; - // case 'x' : - // numFormat = 16; - // getChar(); - // break; - // case 'X' : - // numFormat = 16; - // getChar(); - // break; - // } - // } - // - // if (numFormat == 16) { - // while ((ch >= '0' && ch <= '9') - // || (ch >= 'a' && ch <= 'f') - // || (ch >= 'A' && ch <= 'F')) { - // inum.append(ch); - // getChar(); - // } - // } else { - // while ((ch >= '0' && ch <= '9') - // || (ch == '.') - // || (ch == 'E') - // || (ch == 'e')) { - // if ((ch == '.') || (ch == 'E') || (ch == 'e')) { - // if (ch == '.' && dFlag != ' ') { - // break; - // } - // if ((dFlag == 'E') || (dFlag == 'e')) { - // break; - // } - // dFlag = ch; - // inum.append(ch); - // getChar(); - // if ((ch == '-') || (ch == '+')) { - // inum.append(ch); - // getChar(); - // } - // } else { - // inum.append(ch); - // getChar(); - // } - // } - // } - // chIndx--; - // - // try { - // if (dFlag != ' ') { - // doubleNumber = new Double(inum.toString()); - // token = TokenNameDoubleLiteral; - // return; - // } else { - // longNumber = Long.valueOf(inum.toString(), numFormat); - // token = TokenNameIntegerLiteral; - // return; - // } - // - // } catch (Throwable e) { - // throwSyntaxError("Number format error: " + inum.toString()); - // } - // } - // - // /** - // * Get a String. - // * @param openChar the opening char ('\'', '"', '`') - // * @param typeString the type of string {@link - // #TokenNameSTRING_CONSTANT},{@link #TokenNameINTERPOLATED_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 == TokenNameStringConstant) { - // throwSyntaxError(errorMsg, startRow); - // } else { - // throwSyntaxError(errorMsg); - // } - // } - // token = typeString; - // stringValue = sBuffer.toString(); - // } - // public void htmlParserTester(String input) { - // int lineNumber = 1; - // int startLineNumber = 1; - // int startIndex = 0; - // char ch; - // char ch2; - // boolean phpMode = false; - // boolean phpFound = false; - // - // phpList = new ArrayList(); - // currentPHPString = 0; - // - // try { - // int i = 0; - // while (i < input.length()) { - // ch = input.charAt(i++); - // if (ch == '\n') { - // lineNumber++; - // } - // if ((!phpMode) && ch == '<') { - // ch2 = input.charAt(i++); - // if (ch2 == '?') { - // ch2 = input.charAt(i++); - // if (Character.isWhitespace(ch2)) { - // // php start - // phpMode = true; - // phpFound = true; - // startIndex = i; - // startLineNumber = lineNumber; - // continue; - // } else if (ch2 == 'p') { - // ch2 = input.charAt(i++); - // if (ch2 == 'h') { - // ch2 = input.charAt(i++); - // if (ch2 == 'p') { - // phpMode = true; - // phpFound = true; - // startIndex = i; - // startLineNumber = lineNumber; - // continue; - // } - // i--; - // } - // i--; - // } else if (ch2 == 'P') { - // ch2 = input.charAt(i++); - // if (ch2 == 'H') { - // ch2 = input.charAt(i++); - // if (ch2 == 'P') { - // phpMode = true; - // phpFound = true; - // startIndex = i; - // startLineNumber = lineNumber; - // continue; - // } - // i--; - // } - // i--; - // } - // i--; - // } - // i--; - // } - // - // if (phpMode) { - // if (ch == '/' && i < input.length()) { - // ch2 = input.charAt(i++); - // if (ch2 == '/') { - // while (i < input.length()) { - // ch = input.charAt(i++); - // if (ch == '?' && i < input.length()) { - // ch2 = input.charAt(i++); - // if (ch2 == '>') { - // // php end - // phpMode = false; - // phpList.add( - // new PHPString( - // input.substring( - // startIndex, - // i - 2), - // startLineNumber)); - // continue; - // } - // i--; - // } else if (ch == '\n') { - // lineNumber++; - // break; - // } - // } - // continue; - // } else if (ch2 == '*') { - // // multi-line comment - // while (i < input.length()) { - // ch = input.charAt(i++); - // if (ch == '\n') { - // lineNumber++; - // } else if (ch == '*' && i < input.length()) { - // ch2 = input.charAt(i++); - // if (ch2 == '/') { - // break; - // } - // i--; - // } - // } - // continue; - // } else { - // i--; - // } - // } else if (ch == '#') { - // while (i < input.length()) { - // ch = input.charAt(i++); - // if (ch == '?' && i < input.length()) { - // ch2 = input.charAt(i++); - // if (ch2 == '>') { - // // php end - // phpMode = false; - // phpList.add( - // new PHPString( - // input.substring(startIndex, i - 2), - // startLineNumber)); - // continue; - // } - // i--; - // } else if (ch == '\n') { - // lineNumber++; - // break; - // } - // } - // continue; - // } else if (ch == '"') { - // ch = ' '; - // while (i < input.length()) { - // ch = input.charAt(i++); - // if (ch == '\n') { - // lineNumber++; - // } else if ( - // ch == '\\' && i < input.length()) { // escape - // i++; - // } else if (ch == '"') { - // break; - // } - // } - // continue; - // } else if (ch == '\'') { - // ch = ' '; - // while (i < input.length()) { - // ch = input.charAt(i++); - // if (ch == '\n') { - // lineNumber++; - // } else if ( - // ch == '\\' && i < input.length()) { // escape - // i++; - // } else if (ch == '\'') { - // break; - // } - // } - // continue; - // } - // - // if (ch == '?' && i < input.length()) { - // ch2 = input.charAt(i++); - // if (ch2 == '>') { - // // php end - // phpMode = false; - // phpList.add( - // new PHPString( - // input.substring(startIndex, i - 2), - // startLineNumber)); - // continue; - // } - // i--; - // } - // } - // } - // - // if (!phpFound) { - // setMarker( - // "No PHP source code found.", - // lineNumber, - // PHPParser.INFO); - // } else { - // if (phpMode) { - // setMarker( - // "Open PHP tag at end of file.", - // lineNumber, - // PHPParser.INFO); - // phpList.add( - // new PHPString( - // input.substring(startIndex, i - 2), - // startLineNumber)); - // } - // // for (int j=0;j"); - // // } - // phpParserTester(null, 1); - // // PHPString temp; - // // for(int j=0;j'."); + } + // scanner.encapsedStringStack.pop(); + getNextToken(); + } + // else { + // // scanner.encapsedStringStack.pop(); + // int tempToken = TokenNameSTRING; + // if (!scanner.encapsedStringStack.isEmpty() + // && (token == TokenNameEncapsedString0 + // || token == TokenNameEncapsedString1 + // || token == TokenNameEncapsedString2 || token == TokenNameERROR)) { + // char encapsedChar = ((Character) scanner.encapsedStringStack.peek()) + // .charValue(); + // switch (token) { + // case TokenNameEncapsedString0 : + // if (encapsedChar == '`') { + // tempToken = TokenNameEncapsedString0; + // } + // break; + // case TokenNameEncapsedString1 : + // if (encapsedChar == '\'') { + // tempToken = TokenNameEncapsedString1; + // } + // break; + // case TokenNameEncapsedString2 : + // if (encapsedChar == '"') { + // tempToken = TokenNameEncapsedString2; + // } + // break; + // case TokenNameERROR : + // if (scanner.source[scanner.currentPosition - 1] == '\\') { + // scanner.currentPosition--; + // getNextToken(); + // } + // break; + // } + // } + // token = tempToken; + // } + break; + case TokenNameDOLLAR_LBRACE : + getNextToken(); + if (token == TokenNameIdentifier) { + getNextToken(); + if (token == TokenNameLBRACKET) { + getNextToken(); + // if (token == TokenNameRBRACKET) { + // getNextToken(); + // } else { + expr(); + if (token != TokenNameRBRACKET) { + throwSyntaxError("']' expected after '${'."); + } + getNextToken(); + // } + } + if (token != TokenNameRBRACE) { + throwSyntaxError("'}' expected after '${'."); + } + // scanner.encapsedStringStack.pop(); + getNextToken(); + } else { + expr(); + if (token != TokenNameRBRACE) { + throwSyntaxError("'}' expected."); + } + // scanner.encapsedStringStack.pop(); + getNextToken(); + } + break; + case TokenNameCURLY_OPEN : + getNextToken(); + if (token == TokenNameIdentifier) { + getNextToken(); + if (token == TokenNameLBRACKET) { + getNextToken(); + // if (token == TokenNameRBRACKET) { + // getNextToken(); + // } else { + expr(); + if (token != TokenNameRBRACKET) { + throwSyntaxError("']' expected after '{$'."); + } + getNextToken(); + // } + } else if (token == TokenNameMINUS_GREATER) { + getNextToken(); + if (token != TokenNameIdentifier) { + throwSyntaxError("String token expected."); + } + getNextToken(); + } + // if (token != TokenNameRBRACE) { + // throwSyntaxError("'}' expected after '{$'."); + // } + // // scanner.encapsedStringStack.pop(); + // getNextToken(); + } else { + expr(); + if (token != TokenNameRBRACE) { + throwSyntaxError("'}' expected."); + } + // scanner.encapsedStringStack.pop(); + getNextToken(); + } + break; + } + } + private void encaps_var_offset() { + // T_STRING + // | T_NUM_STRING + // | T_VARIABLE + switch (token) { + case TokenNameSTRING : + getNextToken(); + break; + case TokenNameIntegerLiteral : + getNextToken(); + break; + case TokenNameVariable : + getNextToken(); + break; + case TokenNameIdentifier : + getNextToken(); + break; + default : + throwSyntaxError("Variable or String token expected."); + break; + } + } private void internal_functions_in_yacc() { switch (token) { case TokenNameisset : @@ -3314,6 +3247,48 @@ public class Parser //extends PHPParserSuperclass } } break; + case TokenNameEncapsedString0 : + try { + scanner.currentCharacter = scanner.source[scanner.currentPosition++]; + while (scanner.currentCharacter != '`') { + if (scanner.currentCharacter == '\\') { + scanner.currentPosition++; + } + scanner.currentCharacter = scanner.source[scanner.currentPosition++]; + } + getNextToken(); + } catch (IndexOutOfBoundsException e) { + throwSyntaxError("'`' expected at end of static string."); + } + break; + case TokenNameEncapsedString1 : + try { + scanner.currentCharacter = scanner.source[scanner.currentPosition++]; + while (scanner.currentCharacter != '\'') { + if (scanner.currentCharacter == '\\') { + scanner.currentPosition++; + } + scanner.currentCharacter = scanner.source[scanner.currentPosition++]; + } + getNextToken(); + } catch (IndexOutOfBoundsException e) { + throwSyntaxError("'\'' expected at end of static string."); + } + break; + case TokenNameEncapsedString2 : + try { + scanner.currentCharacter = scanner.source[scanner.currentPosition++]; + while (scanner.currentCharacter != '"') { + if (scanner.currentCharacter == '\\') { + scanner.currentPosition++; + } + scanner.currentCharacter = scanner.source[scanner.currentPosition++]; + } + getNextToken(); + } catch (IndexOutOfBoundsException e) { + throwSyntaxError("'\"' expected at end of static string."); + } + break; case TokenNamePLUS : getNextToken(); static_scalar(); @@ -3495,6 +3470,7 @@ public class Parser //extends PHPParserSuperclass */ protected ReferenceContext referenceContext; protected ProblemReporter problemReporter; + protected CompilerOptions options; // protected CompilationResult compilationResult; /** * Returns this parser's problem reporter initialized with its reference