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 ab95c81..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+1); + throwSyntaxError(error, problemStartPosition, problemEndPosition + 1); } /** * This method will throw the SyntaxError. It will add the good lines and @@ -273,7 +288,7 @@ public class Parser //extends PHPParserSuperclass } throwSyntaxError("End-of-file not reached."); } - return; + break; } catch (SyntaxError sytaxErr1) { // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(), // ERROR); @@ -292,7 +307,7 @@ public class Parser //extends PHPParserSuperclass getNextToken(); } if (token == TokenNameEOF || token == TokenNameERROR) { - return; + break; } } catch (SyntaxError sytaxErr2) { // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(), @@ -300,10 +315,48 @@ public class Parser //extends PHPParserSuperclass // setMarker(sytaxErr2.getMessage(), // scanner.getCurrentTokenStartPosition(), // scanner.getCurrentTokenEndPosition(), ERROR); - return; + break; } } } while (true); + + endParse(0); + } + + protected CompilationUnitDeclaration endParse(int act) { + + this.lastAct = act; + + if (currentElement != null) { + currentElement.topElement().updateParseTree(); + if (VERBOSE_RECOVERY) { + System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$ + System.out.println("--------------------------"); //$NON-NLS-1$ + System.out.println(compilationUnit); + System.out.println("----------------------------------"); //$NON-NLS-1$ + } + } else { + if (diet & VERBOSE_RECOVERY) { + System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$ + System.out.println("--------------------------"); //$NON-NLS-1$ + System.out.println(compilationUnit); + System.out.println("----------------------------------"); //$NON-NLS-1$ + } + } + if (scanner.recordLineSeparator) { + compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds(); + } + if (scanner.taskTags != null) { + for (int i = 0; i < scanner.foundTaskCount; i++) { + problemReporter().task( + new String(scanner.foundTaskTags[i]), + new String(scanner.foundTaskMessages[i]), + scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]), + scanner.foundTaskPositions[i][0], + scanner.foundTaskPositions[i][1]); + } + } + return compilationUnit; } // public PHPOutlineInfo parseInfo(Object parent, String s) { // PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent); @@ -660,16 +713,16 @@ public class Parser //extends PHPParserSuperclass getNextToken(); if (token == TokenNameLBRACE) { getNextToken(); + if (token != TokenNameRBRACE) { + statementList(); + } + if (token == TokenNameRBRACE) { + getNextToken(); + } else { + throwSyntaxError("'}' expected after 'do' keyword."); + } } else { - throwSyntaxError("'{' expected after 'do' keyword."); - } - if (token != TokenNameRBRACE) { - statementList(); - } - if (token == TokenNameRBRACE) { - getNextToken(); - } else { - throwSyntaxError("'}' expected after 'do' keyword."); + statement(TokenNameEOF); } if (token == TokenNamewhile) { getNextToken(); @@ -850,9 +903,11 @@ public class Parser //extends PHPParserSuperclass throwSyntaxError("'{' expected in 'catch' statement."); } getNextToken(); - statementList(); if (token != TokenNameRBRACE) { - throwSyntaxError("'}' expected in 'catch' statement."); + statementList(); + if (token != TokenNameRBRACE) { + throwSyntaxError("'}' expected in 'catch' statement."); + } } getNextToken(); additional_catches(); @@ -1354,6 +1409,10 @@ public class Parser //extends PHPParserSuperclass // | T_VARIABLE '=' static_scalar do { if (token == TokenNameVariable) { + FieldDeclaration fieldDeclaration = new FieldDeclaration(null, scanner + .getCurrentIdentifierSource(), scanner + .getCurrentTokenStartPosition(), scanner + .getCurrentTokenEndPosition()); getNextToken(); if (token == TokenNameEQUAL) { getNextToken(); @@ -1532,10 +1591,8 @@ public class Parser //extends PHPParserSuperclass expr(); //constant(); if (token == TokenNameCOLON || token == TokenNameSEMICOLON) { getNextToken(); - if (token == TokenNamecase || token == TokenNamedefault) { // empty - // case - // statement - // ? + if (token == TokenNamecase || token == TokenNamedefault) { + // empty case statement ? continue; } statementList(); @@ -1561,6 +1618,10 @@ public class Parser //extends PHPParserSuperclass getNextToken(); if (token == TokenNameCOLON) { getNextToken(); + if (token==TokenNameRBRACE) { + // empty default case + break; + } statementList(); } else { throwSyntaxError("':' character after 'default' expected."); @@ -3409,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