From: khartlage Date: Mon, 1 Mar 2004 21:41:31 +0000 (+0000) Subject: misc parser bugfixes; still very ugly state X-Git-Url: http://git.phpeclipse.com misc parser bugfixes; still very ugly state --- diff --git a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java index 949a9ad..088c75a 100644 --- a/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java +++ b/net.sourceforge.phpeclipse.tests/src/net/sourceforge/phpeclipse/phpeditor/php/test/DualParseSyntaxErrorTest.java @@ -22,7 +22,6 @@ import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem; import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory; import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter; import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration; -import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration; /** * @author khartlage @@ -38,8 +37,8 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest { } public void checkParse( char[] source, - String expectedSyntaxErrorDiagnosis, - String testName) { + String expectedSyntaxErrorDiagnosis) { +// String testName) { UnitParser parser = new UnitParser( @@ -48,7 +47,7 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest { //new CompilerOptions(getCompilerOptions()), new DefaultProblemFactory(Locale.getDefault()))); - ICompilationUnit sourceUnit = new CompilationUnit(source, testName, null); + ICompilationUnit sourceUnit = new CompilationUnit(source, "", null); CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0); CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true); @@ -90,13 +89,43 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest { System.out.println(Util.displayString(computedSyntaxErrorDiagnosis)); } assertEquals( - "Invalid syntax error diagnosis" + testName, + "Invalid syntax error diagnosis", expectedSyntaxErrorDiagnosis, computedSyntaxErrorDiagnosis); } - public void test01() { String s = + " "; + + String expectedSyntaxErrorDiagnosis = + ""; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis); +// testName); + } + public void test02() { + String s = + "class test { \n"+ + " function f0() \n"+ + " { \n"+ + " } \n"+ + "} \n"; + + String expectedSyntaxErrorDiagnosis = + ""; + + String testName = ""; + checkParse( + s.toCharArray(), + expectedSyntaxErrorDiagnosis); +// testName); + } + + public void test97() { + String s = "class class { \n"+ " function &fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null) \n"+ " { \n"+ @@ -116,28 +145,25 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest { "Parse error \"Class name expected after keyword \'class\'.\"\n" + "----------\n"; - String testName = ""; checkParse( s.toCharArray(), - expectedSyntaxErrorDiagnosis, - testName); + expectedSyntaxErrorDiagnosis); +// testName); } - - public void test02() { + public void test98() { String s = "if(!$result = mysql_query($sql)) return(array());\n"; String expectedSyntaxErrorDiagnosis = ""; - String testName = ""; checkParse( s.toCharArray(), - expectedSyntaxErrorDiagnosis, - testName); + expectedSyntaxErrorDiagnosis); +// testName); } - public void test03() { + public void test99() { String s = "class test { \n"+ " murks; \n"+ @@ -149,10 +175,9 @@ public class DualParseSyntaxErrorTest extends AbstractCompilerTest { String expectedSyntaxErrorDiagnosis = ""; - String testName = ""; checkParse( s.toCharArray(), - expectedSyntaxErrorDiagnosis, - testName); + expectedSyntaxErrorDiagnosis); +// testName); } } 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 609a33c..024bb56 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 @@ -216,9 +216,9 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par /** * Create marker for the parse error */ - private void setMarker(String message, int charStart, int charEnd, int errorLevel) throws CoreException { - setMarker(fileToParse, message, charStart, charEnd, errorLevel); - } +// private void setMarker(String message, int charStart, int charEnd, int errorLevel) throws CoreException { +// setMarker(fileToParse, message, charStart, charEnd, errorLevel); +// } /** * This method will throw the SyntaxError. @@ -227,25 +227,9 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par * @throws SyntaxError the error raised */ private void throwSyntaxError(String error) { - - // if (str.length() < chIndx) { - // chIndx--; - // } - // // read until end-of-line - // int eol = chIndx; - // while (str.length() > eol) { - // ch = str.charAt(eol++); - // if (ch == '\n') { - // eol--; - // break; - // } - // } - // throw new SyntaxError( - // rowCount, - // chIndx - columnCount + 1, - // str.substring(columnCount, eol), - // error); - throw new SyntaxError(1, 1, "", error); + int problemStartPosition = scanner.getCurrentTokenStartPosition(); + int problemEndPosition = scanner.getCurrentTokenEndPosition(); + reportSyntaxError(error,problemStartPosition,problemEndPosition); } /** @@ -254,9 +238,9 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par * @param error the error message * @throws SyntaxError the error raised */ - private void throwSyntaxError(String error, int startRow) { - throw new SyntaxError(startRow, 0, " ", error); - } +// private void throwSyntaxError(String error, int startRow) { +// throw new SyntaxError(startRow, 0, " ", error); +// } private void reportSyntaxError(String error, int problemStartPosition, int problemEndPosition) { problemReporter.phpParsingError(new String[] { error }, problemStartPosition, problemEndPosition, referenceContext, compilationUnit.compilationResult); @@ -702,7 +686,7 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par throw err; } else { // setMarker(err.getMessage(), err.getLine(), ERROR); - setMarker(err.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); +// setMarker(err.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); } // if an error occured, // try to find keywords 'class' or 'function' @@ -794,7 +778,7 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par return; } catch (SyntaxError sytaxErr1) { // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(), ERROR); - setMarker(sytaxErr1.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); +// setMarker(sytaxErr1.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); try { // if an error occured, // try to find keywords 'class' or 'function' @@ -810,7 +794,7 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par } } catch (SyntaxError sytaxErr2) { // setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(), ERROR); - setMarker(sytaxErr2.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); +// setMarker(sytaxErr2.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); return; } } @@ -985,11 +969,11 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par } } catch (CoreException e) { } catch (SyntaxError sytaxErr) { - try { - // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR); - setMarker(sytaxErr.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); - } catch (CoreException e) { - } +// try { +// // setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR); +// setMarker(sytaxErr.getMessage(), scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition(), ERROR); +// } catch (CoreException e) { +// } } } @@ -1411,10 +1395,17 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par //identifier //identifier 'extends' identifier - if (token == TokenNameIdentifier) { + + if (token == TokenNameIdentifier || token > TokenNameKEYWORD) { typeDecl.sourceStart = scanner.getCurrentTokenStartPosition(); typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition(); typeDecl.name = scanner.getCurrentIdentifierSource(); + if (token > TokenNameKEYWORD) { + reportSyntaxError( + "Don't use keyword for class declaration [" + scanner.toStringAction(token) + "].", + typeDecl.sourceStart, + typeDecl.sourceEnd); + } getNextToken(); if (token == TokenNameextends) { do { @@ -1423,7 +1414,6 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par getNextToken(); } else { reportSyntaxError("Class name expected after keyword 'extends'.", scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition()); - // throwSyntaxError("ClassDeclaration name expected after keyword 'extends'."); } } while (token == TokenNameCOMMA); } @@ -1431,14 +1421,6 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par typeDecl.sourceStart = scanner.getCurrentTokenStartPosition(); typeDecl.sourceEnd = scanner.getCurrentTokenEndPosition(); - if (token > TokenNameKEYWORD) { - typeDecl.name = scanner.getCurrentIdentifierSource(); - reportSyntaxError( - "Don't use keyword for class declaration [" + scanner.toStringAction(token) + "].", - typeDecl.sourceStart, - typeDecl.sourceEnd); - // throwSyntaxError("Don't use keyword for class declaration [" + token + "]."); - } typeDecl.name = new char[] { ' ' }; reportSyntaxError("Class name expected after keyword 'class'.", typeDecl.sourceStart, typeDecl.sourceEnd); // throwSyntaxError("ClassDeclaration name expected after keyword 'class'."); @@ -1611,30 +1593,26 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par if (token == TokenNamecase) { getNextToken(); expression(); //constant(); - if (token == TokenNameCOLON) { + if (token == TokenNameCOLON || token == TokenNameSEMICOLON) { getNextToken(); if (token == TokenNamecase || token == TokenNamedefault) { // empty case statement ? continue; } statementList(); - } else if (token == TokenNameSEMICOLON) { - // setMarker( - // "':' expected after 'case' keyword (Found token: " - // + scanner.toStringAction(token) - // + ")", - // rowCount, - // PHPParser.INFO); - setMarker( - "':' expected after 'case' keyword (Found token: " + scanner.toStringAction(token) + ")", - scanner.getCurrentTokenStartPosition(), - scanner.getCurrentTokenEndPosition(), - INFO); - getNextToken(); - if (token == TokenNamecase) { // empty case statement ? - continue; - } - statementList(); - } else { + } +// else if (token == TokenNameSEMICOLON) { +// setMarker( +// "':' expected after 'case' keyword (Found token: " + scanner.toStringAction(token) + ")", +// scanner.getCurrentTokenStartPosition(), +// scanner.getCurrentTokenEndPosition(), +// INFO); +// getNextToken(); +// if (token == TokenNamecase) { // empty case statement ? +// continue; +// } +// statementList(); +// } + else { throwSyntaxError("':' character after 'case' constant expected (Found token: " + scanner.toStringAction(token) + ")"); } } else { // TokenNamedefault @@ -2167,11 +2145,11 @@ public class Parser extends PHPParserSuperclass implements ITerminalSymbols, Par // + "' as variable name.", // rowCount, // PHPParser.INFO); - setMarker( - "Avoid using keyword '" + new String(ident) + "' as variable name.", - scanner.getCurrentTokenStartPosition(), - scanner.getCurrentTokenEndPosition(), - INFO); +// setMarker( +// "Avoid using keyword '" + new String(ident) + "' as variable name.", +// scanner.getCurrentTokenStartPosition(), +// scanner.getCurrentTokenEndPosition(), +// INFO); } switch (token) { case TokenNameVariable : 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 c48d451..d7c2618 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 @@ -160,7 +160,7 @@ public class Scanner implements IScanner, ITerminalSymbols { public char[][] taskTags = null; public char[][] taskPriorities = null; - public static final boolean DEBUG = false; + public static final boolean DEBUG = true; public Scanner() { this(false, false); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java index d420454..316c046 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/UnitParser.java @@ -469,7 +469,7 @@ public class UnitParser extends Parser { } public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult) { - return dietParse(sourceUnit, compilationResult, true); + return dietParse(sourceUnit, compilationResult, false); } public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult, boolean phpMode) {