X-Git-Url: http://git.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 e6c6133..badc067 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 @@ -459,11 +459,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, * but in switch-case it's recommended to avoid * accidental fall-through later when editing the code */ - problemReporter.unreachableCode(new String(scanner - .getCurrentIdentifierSource()), - statement.sourceStart, statement.sourceEnd, - referenceContext, - compilationUnit.compilationResult); + problemReporter + .unreachableCode( + new String(scanner + .getCurrentIdentifierSource()), + statement.sourceStart, + statement.sourceEnd, referenceContext, + compilationUnit.compilationResult); } } if ((token == TokenNameRBRACE) || (token == TokenNamecase) @@ -856,6 +858,15 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, getNextToken(); } return statement; + } else if (token == TokenNameconst) { + // TODO make sure you clean this hack up ed_mann. + getNextToken(); + if (token == TokenNameIdentifier) { + getNextToken(); + if (token == TokenNameEQUAL) { + getNextToken(); + } + } } else if (token == TokenNamestatic) { getNextToken(); static_var_list(); @@ -1144,11 +1155,11 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, // | '$' '{' expr '}' if (token == TokenNameVariable) { if (fMethodVariables != null) { - VariableInfo info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + VariableInfo info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_GLOBAL_VAR); - fMethodVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fMethodVariables.put( + new String(scanner.getCurrentIdentifierSource()), info); } addVariableSet(set); getNextToken(); @@ -1177,11 +1188,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, while (true) { if (token == TokenNameVariable) { if (fMethodVariables != null) { - VariableInfo info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + VariableInfo info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_STATIC_VAR); - fMethodVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fMethodVariables.put( + new String(scanner.getCurrentIdentifierSource()), + info); } addVariableSet(set); getNextToken(); @@ -1239,11 +1251,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token == TokenNameIdentifier || token > TokenNameKEYWORD) { typeDecl.name = scanner.getCurrentIdentifierSource(); if (token > TokenNameKEYWORD) { - problemReporter.phpKeywordWarning(new String[] { scanner - .toStringAction(token) }, scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, - compilationUnit.compilationResult); + problemReporter + .phpKeywordWarning(new String[] { scanner + .toStringAction(token) }, scanner + .getCurrentTokenStartPosition(), scanner + .getCurrentTokenEndPosition(), + referenceContext, + compilationUnit.compilationResult); // throwSyntaxError("Don't use a keyword for interface // declaration [" // + scanner.toStringAction(token) + "].", @@ -1271,11 +1285,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token == TokenNameIdentifier || token > TokenNameKEYWORD) { typeDecl.name = scanner.getCurrentIdentifierSource(); if (token > TokenNameKEYWORD) { - problemReporter.phpKeywordWarning(new String[] { scanner - .toStringAction(token) }, scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, - compilationUnit.compilationResult); + problemReporter + .phpKeywordWarning(new String[] { scanner + .toStringAction(token) }, scanner + .getCurrentTokenStartPosition(), scanner + .getCurrentTokenEndPosition(), + referenceContext, + compilationUnit.compilationResult); // throwSyntaxError("Don't use a keyword for class // declaration [" + // scanner.toStringAction(token) + "].", @@ -1515,9 +1531,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token == TokenNamevar) { checkAndSetModifiers(AccPublic); - problemReporter.phpVarDeprecatedWarning(scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, + problemReporter.phpVarDeprecatedWarning( + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult); getNextToken(); class_variable_declaration(declarationSourceStart, list); @@ -1574,10 +1590,10 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (token != TokenNameIdentifier) { throwSyntaxError("Identifier expected in class const declaration."); } - FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner - .getCurrentIdentifierSource(), scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition()); + FieldDeclaration fieldDeclaration = new FieldDeclaration( + scanner.getCurrentIdentifierSource(), + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition()); fieldDeclaration.modifiers = this.modifiers; fieldDeclaration.declarationSourceStart = declarationSourceStart; fieldDeclaration.declarationSourceEnd = scanner @@ -1692,11 +1708,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, fieldDeclaration.modifiersSourceStart = declarationSourceStart; list.add(fieldDeclaration); if (fTypeVariables != null) { - VariableInfo info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + VariableInfo info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_CLASS_UNIT); - fTypeVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fTypeVariables.put( + new String(scanner.getCurrentIdentifierSource()), + info); } getNextToken(); if (token == TokenNameEQUAL) { @@ -1735,12 +1752,11 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, typeDecl.methods = new AbstractMethodDeclaration[] { methodDecl }; } else { AbstractMethodDeclaration[] newMethods; - System - .arraycopy( - typeDecl.methods, - 0, - newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], - 0, typeDecl.methods.length); + System.arraycopy( + typeDecl.methods, + 0, + newMethods = new AbstractMethodDeclaration[typeDecl.methods.length + 1], + 0, typeDecl.methods.length); newMethods[typeDecl.methods.length] = methodDecl; typeDecl.methods = newMethods; } @@ -1782,10 +1798,10 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (Scanner.isIdentifierOrKeyword(token)) { methodDecl.selector = scanner.getCurrentIdentifierSource(); if (token > TokenNameKEYWORD) { - problemReporter.phpKeywordWarning(new String[] { scanner - .toStringAction(token) }, scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition(), referenceContext, + problemReporter.phpKeywordWarning( + new String[] { scanner.toStringAction(token) }, + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition(), referenceContext, compilationUnit.compilationResult); } getNextToken(); @@ -1849,17 +1865,18 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, if (fMethodVariables != null) { VariableInfo info; if (methodDecl.type == MethodDeclaration.FUNCTION_DEFINITION) { - info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_FUNCTION_DEFINITION); } else { - info = new VariableInfo(scanner - .getCurrentTokenStartPosition(), + info = new VariableInfo( + scanner.getCurrentTokenStartPosition(), VariableInfo.LEVEL_METHOD_DEFINITION); } info.typeIdentifier = typeIdentifier; - fMethodVariables.put(new String(scanner - .getCurrentIdentifierSource()), info); + fMethodVariables + .put(new String(scanner + .getCurrentIdentifierSource()), info); } addVariableSet(set); getNextToken(); @@ -2473,9 +2490,10 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, case TokenNameinclude_once: case TokenNamerequire: case TokenNamerequire_once: + case TokenNameNamespace: + case TokenNameconst: internal_functions_in_yacc(); break; - // | '(' expr ')' case TokenNameLPAREN: getNextToken(); expr(); @@ -2605,17 +2623,17 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, // } // break; case TokenNameStringDoubleQuote: - expression = new StringLiteralDQ(scanner - .getCurrentStringLiteralSource(), scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition()); + expression = new StringLiteralDQ( + scanner.getCurrentStringLiteralSource(), + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition()); common_scalar(); break; case TokenNameStringSingleQuote: - expression = new StringLiteralSQ(scanner - .getCurrentStringLiteralSource(), scanner - .getCurrentTokenStartPosition(), scanner - .getCurrentTokenEndPosition()); + expression = new StringLiteralSQ( + scanner.getCurrentStringLiteralSource(), + scanner.getCurrentTokenStartPosition(), + scanner.getCurrentTokenEndPosition()); common_scalar(); break; case TokenNameIntegerLiteral: @@ -3018,7 +3036,8 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, int pos = scanner.currentPosition; getNextToken(); if (token == TokenNamePAAMAYIM_NEKUDOTAYIM) { - // Not terminated by T_STRING, reduce to dynamic_class_name_reference + // Not terminated by T_STRING, reduce to + // dynamic_class_name_reference scanner.currentPosition = pos; token = TokenNameIdentifier; ref = null; @@ -3465,9 +3484,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, addVariableSet(); } } - FieldReference ref = new FieldReference(scanner - .getCurrentIdentifierSource(), scanner - .getCurrentTokenStartPosition()); + FieldReference ref = new FieldReference( + scanner.getCurrentIdentifierSource(), + scanner.getCurrentTokenStartPosition()); getNextToken(); return ref; } else { @@ -4091,7 +4110,37 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, // T_REQUIRE_ONCE expr checkFileName(token); break; + case TokenNameNamespace: + // NAMESPACE expr + checkNameSpaceName(); + break; + case TokenNameconst: + getNextToken(); + expr(); + break; + } + } + + /** + * parse and check the namespace name + * + * @since 1.2.3 + * @param namespaceToken + */ + private void checkNameSpaceName() { + getNextToken(); + while (true) { + if (token == TokenNameForwardSlash || token == TokenNameIdentifier) { + getNextToken(); + } else { + break; + } } + if (token != TokenNameSEMICOLON) { + throwSyntaxError("';' expected after keyword '" + + scanner.toStringAction(TokenNameNamespace) + "'"); + } + } /** @@ -4141,8 +4190,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, StringLiteral literal = (StringLiteral) expression; char[] includeName = literal.source(); if (includeName.length == 0) { - reportSyntaxError("Empty filename after keyword '" - + scanner.toStringAction(includeToken) + "'", + reportSyntaxError( + "Empty filename after keyword '" + + scanner.toStringAction(includeToken) + "'", literal.sourceStart, literal.sourceStart + 1); } String includeNameString = new String(includeName); @@ -4185,9 +4235,9 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, IFile f = PHPFileUtil.createFile(path, project); - impt.tokens = CharOperation.splitOn('/', filePath - .toCharArray(), 0, filePath.length() - - fileExtensionLength); + impt.tokens = CharOperation.splitOn('/', + filePath.toCharArray(), 0, + filePath.length() - fileExtensionLength); impt.setFile(f); } catch (Exception e) { // the file is outside of the workspace @@ -4993,12 +5043,12 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, // create a package name similar to java package names String projectPath = ProjectPrefUtil.getDocumentRoot(file.getProject()) .toString(); - String filePath = file.getFullPath().toString(); - - String ext = file.getFileExtension(); - int fileExtensionLength = ext == null ? 0 : ext.length() + 1; - ImportReference impt; - char[][] tokens; + String filePath = file.getFullPath().toString(); + + String ext = file.getFileExtension(); + int fileExtensionLength = ext == null ? 0 : ext.length() + 1; + ImportReference impt; + char[][] tokens; if (filePath.startsWith(projectPath)) { tokens = CharOperation.splitOn('/', filePath.toCharArray(), projectPath.length() + 1, filePath.length()