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 org.eclipse.core.resources.IFile;
public class Parser //extends PHPParserSuperclass
implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
// } catch (CoreException e) {
// }
// }
-// public void phpParserTester(String s, int rowCount) {
-// this.str = s;
-// if (s == null) {
-// if (phpList.size() != 0) {
-// this.str = ((PHPString) phpList.get(currentPHPString++)).getPHPString();
-// }
-// }
-// this.token = TokenNameEOF;
-// // this.chIndx = 0;
-// // this.rowCount = rowCount;
-// // this.columnCount = 0;
-// this.phpEnd = false;
-// this.phpMode = true;
-// scanner.setSource(s.toCharArray());
-// scanner.setPHPMode(true);
-// getNextToken();
-// do {
-// try {
-// if (token != TokenNameEOF && token != TokenNameERROR) {
-// statementList();
-// }
-// if (token != TokenNameEOF) {
-// if (token == TokenNameERROR) {
-// throwSyntaxError("Scanner error (Found unknown token: "
-// + scanner.toStringAction(token) + ")");
-// }
-// if (token == TokenNameRPAREN) {
-// throwSyntaxError("Too many closing ')'; end-of-file not reached.");
-// }
-// if (token == TokenNameRBRACE) {
-// throwSyntaxError("Too many closing '}'; end-of-file not reached.");
-// }
-// if (token == TokenNameRBRACKET) {
-// throwSyntaxError("Too many closing ']'; end-of-file not reached.");
-// }
-// if (token == TokenNameLPAREN) {
-// throwSyntaxError("Read character '('; end-of-file not reached.");
-// }
-// if (token == TokenNameLBRACE) {
-// throwSyntaxError("Read character '{'; end-of-file not reached.");
-// }
-// if (token == TokenNameLBRACKET) {
-// throwSyntaxError("Read character '['; end-of-file not reached.");
-// }
-// throwSyntaxError("End-of-file not reached.");
-// }
-// return;
-// } catch (SyntaxError err) {
-// if (s != null) {
-// throw err;
-// } else {
-// // setMarker(err.getMessage(), err.getLine(), ERROR);
-// // setMarker(err.getMessage(),
-// // scanner.getCurrentTokenStartPosition(),
-// // scanner.getCurrentTokenEndPosition(), ERROR);
-// }
-// // if an error occured,
-// // try to find keywords 'class' or 'function'
-// // to parse the rest of the string
-// while (token != TokenNameEOF && token != TokenNameERROR) {
-// if (token == TokenNameabstract || token == TokenNamefinal
-// || token == TokenNameclass || token == TokenNamefunction) {
-// break;
-// }
-// getNextToken();
-// }
-// if (token == TokenNameEOF || token == TokenNameERROR) {
-// return;
-// }
-// }
-// } while (true);
-// }
+ // public void phpParserTester(String s, int rowCount) {
+ // this.str = s;
+ // if (s == null) {
+ // if (phpList.size() != 0) {
+ // this.str = ((PHPString) phpList.get(currentPHPString++)).getPHPString();
+ // }
+ // }
+ // this.token = TokenNameEOF;
+ // // this.chIndx = 0;
+ // // this.rowCount = rowCount;
+ // // this.columnCount = 0;
+ // this.phpEnd = false;
+ // this.phpMode = true;
+ // scanner.setSource(s.toCharArray());
+ // scanner.setPHPMode(true);
+ // getNextToken();
+ // do {
+ // try {
+ // if (token != TokenNameEOF && token != TokenNameERROR) {
+ // statementList();
+ // }
+ // if (token != TokenNameEOF) {
+ // if (token == TokenNameERROR) {
+ // throwSyntaxError("Scanner error (Found unknown token: "
+ // + scanner.toStringAction(token) + ")");
+ // }
+ // if (token == TokenNameRPAREN) {
+ // throwSyntaxError("Too many closing ')'; end-of-file not reached.");
+ // }
+ // if (token == TokenNameRBRACE) {
+ // throwSyntaxError("Too many closing '}'; end-of-file not reached.");
+ // }
+ // if (token == TokenNameRBRACKET) {
+ // throwSyntaxError("Too many closing ']'; end-of-file not reached.");
+ // }
+ // if (token == TokenNameLPAREN) {
+ // throwSyntaxError("Read character '('; end-of-file not reached.");
+ // }
+ // if (token == TokenNameLBRACE) {
+ // throwSyntaxError("Read character '{'; end-of-file not reached.");
+ // }
+ // if (token == TokenNameLBRACKET) {
+ // throwSyntaxError("Read character '['; end-of-file not reached.");
+ // }
+ // throwSyntaxError("End-of-file not reached.");
+ // }
+ // return;
+ // } catch (SyntaxError err) {
+ // if (s != null) {
+ // throw err;
+ // } else {
+ // // setMarker(err.getMessage(), err.getLine(), ERROR);
+ // // setMarker(err.getMessage(),
+ // // scanner.getCurrentTokenStartPosition(),
+ // // scanner.getCurrentTokenEndPosition(), ERROR);
+ // }
+ // // if an error occured,
+ // // try to find keywords 'class' or 'function'
+ // // to parse the rest of the string
+ // while (token != TokenNameEOF && token != TokenNameERROR) {
+ // if (token == TokenNameabstract || token == TokenNamefinal
+ // || token == TokenNameclass || token == TokenNamefunction) {
+ // break;
+ // }
+ // getNextToken();
+ // }
+ // if (token == TokenNameEOF || token == TokenNameERROR) {
+ // return;
+ // }
+ // }
+ // } while (true);
+ // }
public void init(String s) {
this.str = s;
this.token = TokenNameEOF;
// this.rowCount = 1;
// this.columnCount = 0;
this.phpEnd = false;
-// this.phpMode = false;
+ // this.phpMode = false;
/* scanner initialization */
scanner.setSource(s.toCharArray());
scanner.setPHPMode(false);
// this.rowCount = 1;
// this.columnCount = 0;
this.phpEnd = false;
-// this.phpMode = phpMode;
+ // this.phpMode = phpMode;
scanner.setPHPMode(phpMode);
}
/**
} else {
throwSyntaxError("'as' expected after 'foreach' exxpression.");
}
- variable();
+// variable();
+ foreach_variable();
+ foreach_optional_arg();
if (token == TokenNameEQUAL_GREATER) {
getNextToken();
variable();
getNextToken();
}
return;
- }else if (token == TokenNameunset) {
+ } else if (token == TokenNameunset) {
getNextToken();
if (token == TokenNameLPAREN) {
getNextToken();
return;
} else if (token == TokenNametry) {
getNextToken();
-if (token != TokenNameLBRACE) {
+ if (token != TokenNameLBRACE) {
throwSyntaxError("'{' expected in 'try' statement.");
}
getNextToken();
statementList();
-if (token != TokenNameRBRACE) {
+ if (token != TokenNameRBRACE) {
throwSyntaxError("'}' expected in 'try' statement.");
}
-getNextToken();
+ getNextToken();
return;
} else if (token == TokenNamecatch) {
-getNextToken();
-if (token != TokenNameLPAREN) {
+ getNextToken();
+ if (token != TokenNameLPAREN) {
throwSyntaxError("'(' expected in 'catch' statement.");
}
getNextToken();
throwSyntaxError("Variable expected in 'catch' statement.");
}
getNextToken();
-
- if (token != TokenNameRBRACE) {
+ if (token != TokenNameRPAREN) {
throwSyntaxError("')' expected in 'catch' statement.");
}
getNextToken();
-getNextToken();
-if (token != TokenNameLBRACE) {
+ if (token != TokenNameLBRACE) {
throwSyntaxError("'{' expected in 'catch' statement.");
}
getNextToken();
statementList();
-if (token != TokenNameRBRACE) {
+ if (token != TokenNameRBRACE) {
throwSyntaxError("'}' expected in 'catch' statement.");
}
-getNextToken();
+ getNextToken();
additional_catches();
return;
} else if (token == TokenNamethrow) {
getNextToken();
-
expr();
if (token == TokenNameSEMICOLON) {
getNextToken();
} else {
throwSyntaxError("';' expected after 'throw' exxpression.");
}
-
return;
} else if (token == TokenNamefinal || token == TokenNameabstract
|| token == TokenNameclass || token == TokenNameinterface) {
throwSyntaxError("Variable expected in 'catch' statement.");
}
getNextToken();
-
- if (token != TokenNameRBRACE) {
+ if (token != TokenNameRPAREN) {
throwSyntaxError("')' expected in 'catch' statement.");
}
getNextToken();
- getNextToken();
if (token != TokenNameLBRACE) {
throwSyntaxError("'{' expected in 'catch' statement.");
}
getNextToken();
}
}
-
+
+ private void foreach_variable() {
+ // w_variable
+ //| '&' w_variable
+ if (token == TokenNameAND) {
+ getNextToken();
+ }
+ w_variable();
+ }
+ private void foreach_optional_arg() {
+ // /* empty */
+ //| T_DOUBLE_ARROW foreach_variable
+ if (token == TokenNameEQUAL_GREATER) {
+ getNextToken();
+ foreach_variable();
+ }
+ }
+
private void global_var_list() {
// global_var_list:
// global_var_list ',' global_var
} while (token == TokenNamepublic || token == TokenNameprotected
|| token == TokenNameprivate || token == TokenNamestatic
|| token == TokenNameabstract || token == TokenNamefinal
- || token == TokenNamefunction || token == TokenNamevar);
+ || token == TokenNamefunction || token == TokenNamevar
+ || token == TokenNameconst);
}
private void class_statement() {
// class_statement:
compilationUnit.compilationResult);
getNextToken();
class_variable_declaration();
+ } else if (token == TokenNameconst) {
+ class_constant_declaration();
+ if (token != TokenNameSEMICOLON) {
+ throwSyntaxError("';' expected after class const declaration.");
+ }
+ getNextToken();
} else {
boolean hasModifiers = member_modifiers();
if (token == TokenNamefunction) {
// throwSyntaxError("'function' or 'var' expected.");
// }
}
+ private void class_constant_declaration() {
+ // class_constant_declaration ',' T_STRING '=' static_scalar
+ // | T_CONST T_STRING '=' static_scalar
+ if (token != TokenNameconst) {
+ throwSyntaxError("'const' keyword expected in class declaration.");
+ } else {
+ getNextToken();
+ }
+ while (true) {
+ if (token != TokenNameIdentifier) {
+ throwSyntaxError("Identifier expected in class const declaration.");
+ }
+ getNextToken();
+ if (token != TokenNameEQUAL) {
+ throwSyntaxError("'=' expected in class const declaration.");
+ }
+ getNextToken();
+ static_scalar();
+ if (token != TokenNameCOMMA) {
+ break; // while(true)-loop
+ }
+ getNextToken();
+ }
+ }
// private void variable_modifiers() {
// // variable_modifiers:
// // non_empty_member_modifiers
getNextToken();
}
private void functionDefinition(MethodDeclaration methodDecl) {
+ boolean isAbstract = false;
if (astPtr == 0) {
compilationUnit.types.add(methodDecl);
} else {
newMethods[0] = methodDecl;
typeDecl.methods = newMethods;
}
+ if ((typeDecl.modifiers & AccAbstract) == AccAbstract) {
+ isAbstract = true;
+ } else if ((typeDecl.modifiers & AccInterface) == AccInterface) {
+ isAbstract = true;
+ }
}
}
functionDeclarator(methodDecl);
+ if (token == TokenNameSEMICOLON) {
+ if (!isAbstract) {
+ throwSyntaxError("Body declaration expected for method: "
+ + new String(methodDecl.selector));
+ }
+ getNextToken();
+ return;
+ }
functionBody(methodDecl);
}
private void functionDeclarator(MethodDeclaration methodDecl) {
throwSyntaxError("'(' expected in function declaration.");
}
if (token != TokenNameRPAREN) {
- parameterList();
+ parameter_list();
}
if (token != TokenNameRPAREN) {
throwSyntaxError("')' expected in function declaration.");
}
}
//
- private void parameterList() {
- //parameter-declaration
- //parameter-list ',' parameter-declaration
- do {
- parameterDeclaration();
- if (token != TokenNameCOMMA) {
- break;
+ private void parameter_list() {
+ // non_empty_parameter_list
+ // | /* empty */
+ non_empty_parameter_list(true);
+ }
+ private void non_empty_parameter_list(boolean empty_allowed) {
+ // optional_class_type T_VARIABLE
+ // | optional_class_type '&' T_VARIABLE
+ // | optional_class_type '&' T_VARIABLE '=' static_scalar
+ // | optional_class_type T_VARIABLE '=' static_scalar
+ // | non_empty_parameter_list ',' optional_class_type T_VARIABLE
+ // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE
+ // | non_empty_parameter_list ',' optional_class_type '&' T_VARIABLE '='
+ // static_scalar
+ // | non_empty_parameter_list ',' optional_class_type T_VARIABLE '='
+ // static_scalar
+ if (token == TokenNameIdentifier || token == TokenNameVariable
+ || token == TokenNameAND) {
+ while (true) {
+ if (token == TokenNameIdentifier) {
+ getNextToken();
+ }
+ if (token == TokenNameAND) {
+ getNextToken();
+ }
+ if (token == TokenNameVariable) {
+ getNextToken();
+ if (token == TokenNameEQUAL) {
+ getNextToken();
+ static_scalar();
+ }
+ } else {
+ throwSyntaxError("Variable expected in parameter list.");
+ }
+ if (token != TokenNameCOMMA) {
+ break;
+ }
+ getNextToken();
}
- getNextToken();
- } while (true);
+ return;
+ }
+ if (!empty_allowed) {
+ throwSyntaxError("Identifier expected in parameter list.");
+ }
+ }
+ private void optional_class_type() {
+ // /* empty */
+ //| T_STRING
}
private void parameterDeclaration() {
//variable
// | expr '?' expr ':' expr
case TokenNameinstanceof :
getNextToken();
- throwSyntaxError("not yet implemented (class_name_reference)");
- // class_name_reference();
+ class_name_reference();
break;
case TokenNameQUESTION :
getNextToken();
}
}
}
-// private void variableList() {
-// do {
-// variable();
-// if (token == TokenNameCOMMA) {
-// getNextToken();
-// } else {
-// break;
-// }
-// } while (true);
-// }
+ // private void variableList() {
+ // do {
+ // variable();
+ // if (token == TokenNameCOMMA) {
+ // getNextToken();
+ // } else {
+ // break;
+ // }
+ // } while (true);
+ // }
private void variable_without_objects() {
// variable_without_objects:
// reference_variable
getNextToken();
w_variable();
} else {
-// if (token == TokenNameIdentifier || token == TokenNameVariable
-// || token == TokenNameDOLLAR) {
-// variable();
-// } else {
- expr_without_variable(true);
-// }
+ // if (token == TokenNameIdentifier || token == TokenNameVariable
+ // || token == TokenNameDOLLAR) {
+ // variable();
+ // } else {
+ expr_without_variable(true);
+ // }
}
if (token != TokenNameCOMMA) {
break;
}
getNextToken();
} else {
-
if (token != TokenNameLBRACE) {
throwSyntaxError("'{' expected in variable name.");
}