/**
* 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.
* @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);
}
/**
* @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);
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'
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'
}
} 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;
}
}
}
} 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) {
+// }
}
}
//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 {
getNextToken();
} else {
reportSyntaxError("Class name expected after keyword 'extends'.", scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
- // throwSyntaxError("ClassDeclaration name expected after keyword 'extends'.");
}
} while (token == TokenNameCOMMA);
}
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'.");
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
// + "' 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 :