From 70cf806acfa3a80ca9e41a49c300da0ddcb0d959 Mon Sep 17 00:00:00 2001 From: axelcl Date: Sat, 20 Nov 2004 12:39:23 +0000 Subject: [PATCH 1/1] fixed additional catches block bug fixed missing declare parsing bug --- .../phpdt/internal/compiler/parser/Parser.java | 79 +++++++++++++++++--- .../phpdt/internal/compiler/parser/Scanner.java | 2 +- 2 files changed, 69 insertions(+), 12 deletions(-) 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 91197e9..c81e972 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 @@ -587,7 +587,7 @@ public class Parser //extends PHPParserSuperclass statement(TokenNameEOF); if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse) || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor) - || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch) + || (token == TokenNameendforeach) || (token == TokenNameendwhile) || (token == TokenNameendswitch) || (token == TokenNameenddeclare) || (token == TokenNameEOF) || (token == TokenNameERROR)) { return; } @@ -861,6 +861,20 @@ public class Parser //extends PHPParserSuperclass getNextToken(); functionDefinition(methodDecl); return statement; + } else if (token == TokenNamedeclare) { + //T_DECLARE '(' declare_list ')' declare_statement + getNextToken(); + if (token != TokenNameLPAREN) { + throwSyntaxError("'(' expected in 'declare' statement."); + } + getNextToken(); + declare_list(); + if (token != TokenNameRPAREN) { + throwSyntaxError("')' expected in 'declare' statement."); + } + getNextToken(); + declare_statement(); + return statement; } else if (token == TokenNametry) { getNextToken(); if (token != TokenNameLBRACE) { @@ -958,6 +972,47 @@ public class Parser //extends PHPParserSuperclass return statement; } + private void declare_statement() { + // statement + //| ':' inner_statement_list T_ENDDECLARE ';' + //; + if (token == TokenNameCOLON) { + getNextToken(); + // TODO: implement inner_statement_list(); + statementList(); + if (token != TokenNameenddeclare) { + throwSyntaxError("'enddeclare' expected in 'declare' statement."); + } + getNextToken(); + if (token != TokenNameSEMICOLON) { + throwSyntaxError("';' expected after 'enddeclare' keyword."); + } + getNextToken(); + } else { + statement(TokenNameRPAREN); + } + } + + private void declare_list() { + // T_STRING '=' static_scalar + //| declare_list ',' T_STRING '=' static_scalar + while (true) { + if (token != TokenNameIdentifier) { + throwSyntaxError("Identifier expected in 'declare' list."); + } + getNextToken(); + if (token != TokenNameEQUAL) { + throwSyntaxError("'=' expected in 'declare' list."); + } + getNextToken(); + static_scalar(); + if (token != TokenNameCOMMA) { + break; + } + getNextToken(); + } + } + private void additional_catches() { while (token == TokenNamecatch) { getNextToken(); @@ -978,9 +1033,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(); } @@ -2153,8 +2210,8 @@ public class Parser //extends PHPParserSuperclass if (token != TokenNameEQUAL) { throwSyntaxError("'=' expected after 'list' keyword."); } - getNextToken(); - expr(); + getNextToken(); + expr(); } else { throwSyntaxError("'(' expected after 'list' keyword."); } @@ -2221,8 +2278,8 @@ public class Parser //extends PHPParserSuperclass case TokenNameXOR_EQUAL: case TokenNameRIGHT_SHIFT_EQUAL: case TokenNameLEFT_SHIFT_EQUAL: - getNextToken(); - expr(); + getNextToken(); + expr(); break; case TokenNamePLUS_PLUS: case TokenNameMINUS_MINUS: @@ -2298,8 +2355,8 @@ public class Parser //extends PHPParserSuperclass case TokenNameLESS_EQUAL: case TokenNameGREATER: case TokenNameGREATER_EQUAL: - getNextToken(); - expr(); + getNextToken(); + expr(); break; // | expr T_INSTANCEOF class_name_reference // | expr '?' expr ':' expr @@ -2308,8 +2365,8 @@ public class Parser //extends PHPParserSuperclass class_name_reference(); break; case TokenNameQUESTION: - getNextToken(); - expr(); + getNextToken(); + expr(); if (token == TokenNameCOLON) { getNextToken(); expr(); 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 a8232c2..9146cc7 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 @@ -3143,7 +3143,7 @@ public class Scanner implements IScanner, ITerminalSymbols { if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r') && (data[++index] == 'e')) - return TokenNameendforeach; + return TokenNameenddeclare; index = 0; if ((data[++index] == 'n') // endforeach && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r') -- 1.7.1