From d7f79406924410e00335547b16a21e14494cf15f Mon Sep 17 00:00:00 2001 From: khartlage Date: Fri, 22 Nov 2002 22:01:42 +0000 Subject: [PATCH] imporved php parser --- .../sourceforge/phpeclipse/PHPParserTestCase.java | 29 +- .../phpeclipse/PHPEclipsePreferencePage.java | 79 +- .../sourceforge/phpeclipse/PHPeclipsePlugin.java | 5 + .../phpeclipse/actions/PHPStartApacheAction.java | 19 +- .../phpeclipse/phpeditor/PHPParser.java | 1215 +++++++++++++++----- .../phpeclipse/phpeditor/php/PHPKeywords.java | 155 ++-- .../sourceforge/phpeclipse/views/PHPConsole.java | 97 +- 7 files changed, 1136 insertions(+), 463 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/junit/sourceforge/phpeclipse/PHPParserTestCase.java b/net.sourceforge.phpeclipse/src/junit/sourceforge/phpeclipse/PHPParserTestCase.java index 1eecdec..c0a677c 100644 --- a/net.sourceforge.phpeclipse/src/junit/sourceforge/phpeclipse/PHPParserTestCase.java +++ b/net.sourceforge.phpeclipse/src/junit/sourceforge/phpeclipse/PHPParserTestCase.java @@ -26,14 +26,29 @@ public class PHPParserTestCase extends TestCase { * Test the PHP Parser with different PHP snippets */ public void testPHPParser() { - check("if (isset($test)) { }"); + check("if (isset($test)) { } elseif (isset($lang)) { }"); check("require_once(\"mainfile.php\"); "); - check("if (eregi(\"footer.php\",$PHP_SELF)) {\n" + - "Header(\"Location: index.php\");\n" + - "die();\n" + - "}\n"); - - + check("if (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n"); + check("while (eregi(\"footer.php\",$PHP_SELF)) {\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "}\n"); + check("while (eregi(\"footer.php\",$PHP_SELF)) :\n" + "Header(\"Location: index.php\");\n" + "die();\n" + "endwhile;\n"); + check("$tipath = \"images/topics/\";"); + check("$reasons = array(\"1\", \"2\",\"test\");"); + check("if ($home == 1) { message_box(); blocks(Center);}"); + check("$bresult = sql_query(\"select * from \".$prefix.\"_banner WHERE type='0' AND active='1'\", $dbi);"); + check("switch($func) {\n case \"f1\":\n f1();\n break; \n default: \n f0(); \n break;\n }"); + check("list ($catid) = sql_fetch_row($result, $dbi);"); + check("if (!$name) { \n }"); + check("mt_srand((double)microtime()*1000000);"); + check("\"\\\"\";"); + check("$alttext = ereg_replace(\"\\\"\", \"\", $alttext);"); + check("$message .= \"\"._THISISAUTOMATED.\"\\n\\n\";"); + check("if (!empty($pass) AND $pass==$passwd) { }"); + check("$AllowableHTML = array(\"b\"=>1,\n \"i\"=>1);"); + check("if ($term{0}!=$firstChar) {}"); + check("echo \"
\"._NOADMINYET.\"


\"\n" + + ".\"
\"\n" + + ".\"\"._NICKNAME.\":\"\n" + +";"); } public void check(String strEval) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java index b0c494c..065a53d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPEclipsePreferencePage.java @@ -25,57 +25,58 @@ import org.eclipse.ui.IWorkbenchPreferencePage; */ public class PHPEclipsePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { - public PHPEclipsePreferencePage() { - super(FieldEditorPreferencePage.GRID); - //Initialize the preference store we wish to use - setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore()); - } + public PHPEclipsePreferencePage() { + super(FieldEditorPreferencePage.GRID); + //Initialize the preference store we wish to use + setPreferenceStore(PHPeclipsePlugin.getDefault().getPreferenceStore()); + } - protected void createFieldEditors() { - final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); + protected void createFieldEditors() { + final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore(); - StringFieldEditor localhost = new StringFieldEditor(PHPeclipsePlugin.LOCALHOST_PREF, "&Localhost:", 60, getFieldEditorParent()); + StringFieldEditor localhost = new StringFieldEditor(PHPeclipsePlugin.LOCALHOST_PREF, "&Localhost:", 60, getFieldEditorParent()); - DirectoryFieldEditor documentRoot = - new DirectoryFieldEditor(PHPeclipsePlugin.DOCUMENTROOT_PREF, "&DocumentRoot:", getFieldEditorParent()); + DirectoryFieldEditor documentRoot = + new DirectoryFieldEditor(PHPeclipsePlugin.DOCUMENTROOT_PREF, "&DocumentRoot:", getFieldEditorParent()); - BooleanFieldEditor useExternalBrowser = - new BooleanFieldEditor(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF, "&Use External Browser", getFieldEditorParent()); + BooleanFieldEditor useExternalBrowser = + new BooleanFieldEditor(PHPeclipsePlugin.USE_EXTERNAL_BROWSER_PREF, "&Use External Browser", getFieldEditorParent()); - StringFieldEditor externalBrowser = - new StringFieldEditor(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF, "&External Browser command:", 60, getFieldEditorParent()); + StringFieldEditor externalBrowser = + new StringFieldEditor(PHPeclipsePlugin.EXTERNAL_BROWSER_PREF, "&External Browser command:", 60, getFieldEditorParent()); - StringFieldEditor startMySQL = - new StringFieldEditor(PHPeclipsePlugin.MYSQL_PREF, "&MySQL command:", 60, getFieldEditorParent()); + StringFieldEditor startMySQL = + new StringFieldEditor(PHPeclipsePlugin.MYSQL_PREF, "&MySQL command:", 60, getFieldEditorParent()); + StringFieldEditor startApache = + new StringFieldEditor(PHPeclipsePlugin.APACHE_START_PREF, "Start &Apache command:", 60, getFieldEditorParent()); - StringFieldEditor startApache = - new StringFieldEditor(PHPeclipsePlugin.APACHE_START_PREF, "Start &Apache command:", 60, getFieldEditorParent()); + StringFieldEditor stopApache = + new StringFieldEditor(PHPeclipsePlugin.APACHE_STOP_PREF, "&Stop Apache command:", 60, getFieldEditorParent()); + StringFieldEditor restartApache = + new StringFieldEditor(PHPeclipsePlugin.APACHE_RESTART_PREF, "&Restart Apache command:", 60, getFieldEditorParent()); - StringFieldEditor stopApache = - new StringFieldEditor(PHPeclipsePlugin.APACHE_STOP_PREF, "&Stop Apache command:", 60, getFieldEditorParent()); + StringFieldEditor externalParser = + new StringFieldEditor(PHPeclipsePlugin.EXTERNAL_PARSER_PREF, "&External Parser command:", 60, getFieldEditorParent()); - - StringFieldEditor restartApache = - new StringFieldEditor(PHPeclipsePlugin.APACHE_RESTART_PREF, "&Restart Apache command:", 60, getFieldEditorParent()); + addField(localhost); + addField(documentRoot); + addField(useExternalBrowser); + addField(externalBrowser); + addField(startMySQL); + addField(startApache); + addField(stopApache); + addField(restartApache); - addField(localhost); - addField(documentRoot); - addField(useExternalBrowser); - addField(externalBrowser); - addField(startMySQL); - addField(startApache); - - addField(stopApache); - addField(restartApache); - } - - /** - * @see IWorkbenchPreferencePage#init - */ - public void init(IWorkbench workbench) { - } + addField(externalParser); + } + + /** + * @see IWorkbenchPreferencePage#init + */ + public void init(IWorkbench workbench) { + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index 5e95d2e..23d818c 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -44,6 +44,8 @@ public class PHPeclipsePlugin extends AbstractUIPlugin { public static final String APACHE_STOP_PREF = "_apache_stop"; public static final String APACHE_RESTART_PREF = "_apache_restart"; public static final String SHOW_OUTPUT_IN_CONSOLE = "_sho_output_in_console"; + public static final String EXTERNAL_PARSER_PREF = "_external_parser"; + /** * The id of the PHP plugin (value "net.sourceforge.phpeclipse"). */ @@ -231,17 +233,20 @@ public class PHPeclipsePlugin extends AbstractUIPlugin { store.setDefault(EXTERNAL_BROWSER_PREF, "netscape {0}"); } if ((jvm == WINDOWS_9x) || (jvm == WINDOWS_NT)) { + store.setDefault(EXTERNAL_PARSER_PREF, "c:\\apache\\php\\php -l -f {0}"); store.setDefault(DOCUMENTROOT_PREF, "c:\\eclipse\\workspace"); store.setDefault(MYSQL_PREF, "c:\\apache\\mysql\\bin\\mysqld.exe --standalone"); store.setDefault(APACHE_START_PREF, "c:\\apache\\apache.exe -c \"DocumentRoot \"{0}\"\""); store.setDefault(APACHE_STOP_PREF, "c:\\apache\\apache.exe -k shutdown"); store.setDefault(APACHE_RESTART_PREF, "c:\\apache\\apache.exe -k restart"); } else { + store.setDefault(EXTERNAL_PARSER_PREF, "/apache/php/php -l -f {0}"); store.setDefault(DOCUMENTROOT_PREF, "/eclipse/workspace"); store.setDefault(MYSQL_PREF, "/apache/mysql/bin/mysqld --standalone"); store.setDefault(APACHE_START_PREF, "/apache/apache -c \"DocumentRoot \"{0}\"\""); store.setDefault(APACHE_STOP_PREF, "/apache/apache.exe -k shutdown"); store.setDefault(APACHE_RESTART_PREF, "/apache/apache -k restart"); + } } } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java index 8a6b5e2..3f1839a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPStartApacheAction.java @@ -43,7 +43,7 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { execute(form.format(arguments), "Start Apache: "); } - public void execute(String command, String consoleMessage) { + public static String execute(String command, String consoleMessage) { // MessageDialog.openInformation(activeWindow.getShell(), "Exec command: ", command); try { PHPConsole.write(consoleMessage+command+"\n"); @@ -55,23 +55,20 @@ public class PHPStartApacheAction implements IWorkbenchWindowActionDelegate { // gets the input stream to have the post-compile-time information InputStream stream = p.getInputStream(); - // and get the string from it - String compilerOutput = PHPConsole.getStringFromStream(stream); + // get the string from Stream + String consoleOutput = PHPConsole.getStringFromStream(stream); // prints out the information - PHPConsole.write(compilerOutput); - - // parse the buffer to find the errors and create markers - // createMarkers(compilerOutput, fileToCompile); + PHPConsole.write(consoleOutput); + return consoleOutput; } catch (IOException e) { - // @todo should throw the exception again + System.err.println("Problem"); e.printStackTrace(); -// } catch (CoreException e) { -// e.printStackTrace(); -// // @todo do something here ! + } + return ""; } public void selectionChanged(IAction action, ISelection selection) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java index fd8bec2..5848e7d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java @@ -42,10 +42,11 @@ public class PHPParser extends PHPKeywords { final static int TT_EOF = 0; final static int TT_UNDEFINED = 1; + final static int TT_MOD = 30; final static int TT_NOT = 31; final static int TT_DOT = 32; final static int TT_POW = 33; - final static int TT_DIVIDE = 34; + final static int TT_DIV = 34; final static int TT_MULTIPLY = 35; final static int TT_SUBTRACT = 36; final static int TT_ADD = 37; @@ -66,6 +67,8 @@ public class PHPParser extends PHPKeywords { final static int TT_FOREACH = 51; final static int TT_AMPERSAND = 52; final static int TT_DOLLARLISTOPEN = 53; + final static int TT_TILDE = 54; + final static int TT_ARGOPEN = 128; final static int TT_ARGCLOSE = 129; final static int TT_LISTOPEN = 130; @@ -73,7 +76,7 @@ public class PHPParser extends PHPKeywords { final static int TT_PARTOPEN = 132; final static int TT_PARTCLOSE = 133; final static int TT_COMMA = 134; - final static int TT_PERCENT = 135; + final static int TT_STRING = 136; final static int TT_IDENTIFIER = 138; final static int TT_DIGIT = 139; @@ -91,6 +94,12 @@ public class PHPParser extends PHPKeywords { final static int TT_DOUBLE_NUMBER = 152; final static int TT_INTERPOLATED_STRING = 153; final static int TT_STRING_CONSTANT = 154; + + final static int TT_LSHIFT = 155; + final static int TT_RSHIFT = 156; + final static int TT_EX_EQUAL = 157; + final static int TT_EX_UNEQUAL = 158; + final static int TT_LINE = 159; // final static int TT_AT = 153; // @ /** * Class Constructor. @@ -201,41 +210,50 @@ public class PHPParser extends PHPKeywords { continue; } else if (ch == '"') { // read string until end - while ((str.length() > chIndx) && (str.charAt(chIndx++) != '"')) { - if (str.charAt(chIndx) == '\\') { + boolean openString = true; + while (str.length() > chIndx) { + ch = str.charAt(chIndx++); + if (ch == '\\') { if (str.length() > chIndx) { - chIndx++; - } - if (str.length() > chIndx) { - chIndx++; + ch = str.charAt(chIndx++); } + } else if (ch == '"') { + openString = false; + break; } else { - if (str.charAt(chIndx) == '\n') { + if (ch == '\n') { rowCount++; columnCount = chIndx; } } } - // if (str.length() > chIndx) { - // chIndx++; - // } + if (openString) { + throwSyntaxError("Open string character '\"' at end of file."); + } token = TT_INTERPOLATED_STRING; return; } else if (ch == '\'') { // read string until end - while ((str.length() > chIndx) && (str.charAt(chIndx++) != '\'')) { - if (str.charAt(chIndx) == '\\') { + boolean openString = true; + while (str.length() > chIndx) { + ch = str.charAt(chIndx++); + if (ch == '\\') { if (str.length() > chIndx) { - chIndx++; + ch = str.charAt(chIndx++); } - if (str.length() > chIndx) { - chIndx++; + } else if (ch == '\'') { + openString = false; + break; + } else { + if (ch == '\n') { + rowCount++; + columnCount = chIndx; } } } - // if (str.length() > chIndx) { - // chIndx++; - // } + if (openString) { + throwSyntaxError("Open string character \"'\" at end of file."); + } token = TT_STRING_CONSTANT; return; } @@ -270,7 +288,10 @@ public class PHPParser extends PHPKeywords { token = TT_COMMA; break; + case '~' : + token = TT_TILDE; + break; case '.' : token = TT_DOT; if (str.length() > chIndx) { @@ -288,7 +309,7 @@ public class PHPParser extends PHPKeywords { break; case '%' : - token = TT_PERCENT; + token = TT_MOD; break; case ';' : @@ -300,7 +321,7 @@ public class PHPParser extends PHPKeywords { break; case '/' : - token = TT_DIVIDE; + token = TT_DIV; if (str.length() > chIndx) { if (str.charAt(chIndx) == '=') { @@ -380,7 +401,14 @@ public class PHPParser extends PHPKeywords { if (ch == '=') { chIndx++; token = TT_EQUAL; + if (str.length() > chIndx) { + ch = str.charAt(chIndx); + if (ch == '=') { + chIndx++; + token = TT_EX_EQUAL; + } + } break; } if (ch == '>') { @@ -399,7 +427,14 @@ public class PHPParser extends PHPKeywords { if (str.charAt(chIndx) == '=') { chIndx++; token = TT_UNEQUAL; + if (str.length() > chIndx) { + ch = str.charAt(chIndx); + if (ch == '=') { + chIndx++; + token = TT_EX_UNEQUAL; + } + } break; } } @@ -415,6 +450,12 @@ public class PHPParser extends PHPKeywords { break; } + if (str.charAt(chIndx) == '>') { + chIndx++; + token = TT_RSHIFT; + + break; + } } break; @@ -428,11 +469,19 @@ public class PHPParser extends PHPKeywords { break; } + if (str.charAt(chIndx) == '<') { + chIndx++; + token = TT_LSHIFT; + + break; + } } break; case '|' : + token = TT_LINE; + if (str.length() > chIndx) { if (str.charAt(chIndx) == '|') { chIndx++; @@ -497,7 +546,7 @@ public class PHPParser extends PHPKeywords { token = TT_IDENTIFIER; } getChar(); - while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch >= '_')) { + while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch == '_')) { ident.append(ch); getChar(); } @@ -635,6 +684,8 @@ public class PHPParser extends PHPKeywords { do { statement(); if ((token == TT_LISTCLOSE) + || (token == TT_case) + || (token == TT_default) || (token == TT_elseif) || (token == TT_endif) || (token == TT_endfor) @@ -647,336 +698,599 @@ public class PHPParser extends PHPKeywords { } while (true); } + public void compoundStatement() { + // '{' [statement-list] '}' + if (token == TT_LISTOPEN) { + getNextToken(); + } else { + throwSyntaxError("'{' expected in compound-statement."); + } + if (token != TT_LISTCLOSE) { + statementList(); + } + if (token == TT_LISTCLOSE) { + getNextToken(); + } else { + throwSyntaxError("'}' expected in compound-statement."); + } + } + public void statement() { - while (token != TT_UNDEFINED && token != TT_EOF) { - if (token > TT_KEYWORD) { - if (token == TT_case) { + if (token > TT_KEYWORD && token != TT_list) { + String keyword = identifier; + if (token == TT_include || token == TT_include_once) { + getNextToken(); + expression(); + if (token == TT_SEMICOLON) { getNextToken(); - constant(); - if (token == TT_DDOT) { - getNextToken(); - statement(); - } else { - throwSyntaxError("':' character after 'case' constant expected."); - } - return; - } else if (token == TT_default) { + } else { + throwSyntaxError("';' character after 'include' or 'include_once' expected."); + } + return; + } else if (token == TT_require || token == TT_require_once) { + getNextToken(); + //constant(); + expression(); + if (token == TT_SEMICOLON) { getNextToken(); - if (token == TT_DDOT) { - getNextToken(); - statement(); - } else { - throwSyntaxError("':' character after 'default' expected."); - } - return; - } else if (token == TT_include || token == TT_include_once) { + } else { + throwSyntaxError("';' character after 'require' or 'require_once' expected."); + } + return; + } else if (token == TT_if) { + getNextToken(); + if (token == TT_ARGOPEN) { + getNextToken(); + } else { + throwSyntaxError("'(' expected after 'if' keyword."); + } + expression(); + if (token == TT_ARGCLOSE) { + getNextToken(); + } else { + throwSyntaxError("')' expected after 'if' condition."); + } + ifStatement(); + return; + + } else if (token == TT_switch) { + getNextToken(); + if (token == TT_ARGOPEN) { + getNextToken(); + } else { + throwSyntaxError("'(' expected after 'switch' keyword."); + } + expression(); + if (token == TT_ARGCLOSE) { + getNextToken(); + } else { + throwSyntaxError("')' expected after 'switch' condition."); + } + switchStatement(); + return; + } else if (token == TT_for) { + getNextToken(); + if (token == TT_ARGOPEN) { getNextToken(); + } else { + throwSyntaxError("'(' expected after 'for' keyword."); + } + if (token == TT_SEMICOLON) { + getNextToken(); + } else { expression(); if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' character after 'include' or 'include_once' expected."); + throwSyntaxError("';' character after 'for' expected."); } - return; - } else if (token == TT_require || token == TT_require_once) { + } + if (token == TT_SEMICOLON) { getNextToken(); - //constant(); + } else { expression(); if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' character after 'require' or 'require_once' expected."); + throwSyntaxError("';' character after 'for' expected."); } - return; - } else if (token == TT_if) { + } + if (token == TT_ARGCLOSE) { getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'if' keyword."); - } + } else { expression(); if (token == TT_ARGCLOSE) { getNextToken(); } else { - throwSyntaxError("')' expected after 'if' condition."); + throwSyntaxError("')' expected after 'for' condition."); } - ifStatement(); - return; - - } else if (token == TT_switch) { + } + forStatement(); + return; + } else if (token == TT_while) { + getNextToken(); + if (token == TT_ARGOPEN) { getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'switch' keyword."); - } - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'switch' condition."); - } - switchStatement(); - return; - } else if (token == TT_for) { + } else { + throwSyntaxError("'(' expected after 'while' keyword."); + } + expression(); + if (token == TT_ARGCLOSE) { getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'for' keyword."); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - expression(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' character after 'for' expected."); - } - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - expression(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' character after 'for' expected."); - } - } - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'for' condition."); - } - } - forStatement(); - return; - } else if (token == TT_while) { + } else { + throwSyntaxError("')' expected after 'while' condition."); + } + whileStatement(); + return; + } else if (token == TT_foreach) { + getNextToken(); + if (token == TT_ARGOPEN) { getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'while' keyword."); - } - expression(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'while' condition."); - } - whileStatement(); - return; - } else if (token == TT_foreach) { + } else { + throwSyntaxError("'(' expected after 'foreach' keyword."); + } + expression(); + if (token == TT_as) { + getNextToken(); + } else { + throwSyntaxError("'as' expected after 'foreach' exxpression."); + } + variable(); + if (token == TT_FOREACH) { getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'foreach' keyword."); - } - expression(); - if (token == TT_as) { - getNextToken(); - } else { - throwSyntaxError("'as' expected after 'foreach' exxpression."); - } variable(); - if (token == TT_FOREACH) { - getNextToken(); - variable(); - } - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'foreach' expression."); - } - foreachStatement(); - return; - - } else if (token == TT_continue || token == TT_break || token == TT_return) { + } + if (token == TT_ARGCLOSE) { getNextToken(); - if (token != TT_SEMICOLON) { - expression(); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'continue', 'break' or 'return'."); - } - return; + } else { + throwSyntaxError("')' expected after 'foreach' expression."); + } + foreachStatement(); + return; - } else if (token == TT_echo) { + } else if (token == TT_continue || token == TT_break || token == TT_return) { + getNextToken(); + if (token != TT_SEMICOLON) { + expression(); + } + if (token == TT_SEMICOLON) { getNextToken(); - expressionList(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'echo' statement."); - } - return; + } else { + throwSyntaxError("';' expected after 'continue', 'break' or 'return'."); + } + return; - } else if (token == TT_print) { + } else if (token == TT_echo) { + getNextToken(); + expressionList(); + if (token == TT_SEMICOLON) { getNextToken(); - expression(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'print' statement."); - } - return; + } else { + throwSyntaxError("';' expected after 'echo' statement."); + } + return; - } else if (token == TT_global || token == TT_static) { + } else if (token == TT_print) { + getNextToken(); + expression(); + if (token == TT_SEMICOLON) { getNextToken(); - variableList(); - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'global' or 'static' statement."); - } - return; + } else { + throwSyntaxError("';' expected after 'print' statement."); + } + return; - } else if (token == TT_unset) { + } else if (token == TT_global || token == TT_static) { + getNextToken(); + variableList(); + if (token == TT_SEMICOLON) { getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'unset' keyword."); - } - variableList(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'unset' statement."); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'unset' statement."); - } - return; + } else { + throwSyntaxError("';' expected after 'global' or 'static' statement."); + } + return; - } else if (token == TT_exit || token == TT_die) { + } else if (token == TT_unset) { + getNextToken(); + if (token == TT_ARGOPEN) { getNextToken(); - if (token != TT_SEMICOLON) { - exitStatus(); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'exit' or 'die' statement."); - } - return; - - } else if (token == TT_define) { + } else { + throwSyntaxError("'(' expected after 'unset' keyword."); + } + variableList(); + if (token == TT_ARGCLOSE) { getNextToken(); - if (token == TT_ARGOPEN) { - getNextToken(); - } else { - throwSyntaxError("'(' expected after 'define' keyword."); - } - constant(); - if (token == TT_COMMA) { - getNextToken(); - } else { - throwSyntaxError("',' expected after first 'define' constant."); - } - constant(); - if (token == TT_ARGCLOSE) { - getNextToken(); - } else { - throwSyntaxError("')' expected after 'define' statement."); - } - if (token == TT_SEMICOLON) { - getNextToken(); - } else { - throwSyntaxError("';' expected after 'define' statement."); - } - return; + } else { + throwSyntaxError("')' expected after 'unset' statement."); + } + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after 'unset' statement."); + } + return; + } else if (token == TT_exit || token == TT_die) { + getNextToken(); + if (token != TT_SEMICOLON) { + exitStatus(); + } + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after 'exit' or 'die' statement."); } + return; - } else if (token == TT_LISTOPEN) { - // compundStatement + } else if (token == TT_define) { getNextToken(); - if (token != TT_LISTCLOSE) { - statementList(); + if (token == TT_ARGOPEN) { + getNextToken(); + } else { + throwSyntaxError("'(' expected after 'define' keyword."); } - if (token == TT_LISTCLOSE) { + constant(); + if (token == TT_COMMA) { getNextToken(); } else { - throwSyntaxError("'}' expected."); + throwSyntaxError("',' expected after first 'define' constant."); } - } else { - if (token != TT_SEMICOLON) { - expression(); + constant(); + if (token == TT_ARGCLOSE) { + getNextToken(); + } else { + throwSyntaxError("')' expected after 'define' statement."); } if (token == TT_SEMICOLON) { getNextToken(); } else { - throwSyntaxError("';' expected after expression."); + throwSyntaxError("';' expected after 'define' statement."); } + return; + } else if (token == TT_function) { + getNextToken(); + functionDefinition(); + return; + } else { + throwSyntaxError("Unexpected keyword '" + keyword + "'"); + } + + } else if (token == TT_LISTOPEN) { + // compundStatement + getNextToken(); + if (token != TT_LISTCLOSE) { + statementList(); + } + if (token == TT_LISTCLOSE) { + getNextToken(); + return; + } else { + throwSyntaxError("'}' expected."); + } + } else { + if (token != TT_SEMICOLON) { + expression(); + } + if (token == TT_SEMICOLON) { + getNextToken(); + return; + } else { + throwSyntaxError("';' expected after expression."); } } - } - public void labeledStatement() { } - public void expressionStatement() { + public void functionDefinition() { + functionDeclarator(); + compoundStatement(); } - public void inclusionStatement() { + public void functionDeclarator() { + //identifier '(' [parameter-list] ')' + if (token == TT_IDENTIFIER) { + getNextToken(); + if (token == TT_ARGOPEN) { + getNextToken(); + } else { + throwSyntaxError("'(' expected in function declaration."); + } + if (token != TT_ARGCLOSE) { + parameterList(); + } + if (token != TT_ARGCLOSE) { + throwSyntaxError("')' expected in function declaration."); + } else { + getNextToken(); + } + } } - - // public void compoundStatement() { - // } - - public void selectionStatement() { + // + public void parameterList() { + //parameter-declaration + //parameter-list ',' parameter-declaration + do { + parameterDeclaration(); + if (token != TT_COMMA) { + break; + } + getNextToken(); + } while (true); } - public void iterationStatement() { + public void parameterDeclaration() { + //variable + //variable-reference + //variable '=' constant + if (token == TT_VARIABLE) { + getNextToken(); + if (token == TT_SET) { + getNextToken(); + constant(); + } + return; + } } - public void jumpStatement() { + public void labeledStatementList() { + if (token != TT_case && token != TT_default) { + throwSyntaxError("'case' or 'default' expected."); + } + do { + if (token == TT_case) { + getNextToken(); + constant(); + if (token == TT_DDOT) { + getNextToken(); + statementList(); + } else { + throwSyntaxError("':' character after 'case' constant expected."); + } + } else { // TT_default + getNextToken(); + if (token == TT_DDOT) { + getNextToken(); + statementList(); + } else { + throwSyntaxError("':' character after 'default' expected."); + } + } + } while (token == TT_case || token == TT_default); } - public void outputStatement() { - } + // public void labeledStatement() { + // if (token == TT_case) { + // getNextToken(); + // constant(); + // if (token == TT_DDOT) { + // getNextToken(); + // statement(); + // } else { + // throwSyntaxError("':' character after 'case' constant expected."); + // } + // return; + // } else if (token == TT_default) { + // getNextToken(); + // if (token == TT_DDOT) { + // getNextToken(); + // statement(); + // } else { + // throwSyntaxError("':' character after 'default' expected."); + // } + // return; + // } + // } - public void scopeStatement() { + public void expressionStatement() { } - public void flowStatement() { + public void inclusionStatement() { } - public void definitionStatement() { - } + // public void compoundStatement() { + // } + + // public void selectionStatement() { + // } + // + // public void iterationStatement() { + // } + // + // public void jumpStatement() { + // } + // + // public void outputStatement() { + // } + // + // public void scopeStatement() { + // } + // + // public void flowStatement() { + // } + // + // public void definitionStatement() { + // } public void ifStatement() { - // statement [else-statement] - statement(); - if (token == TT_else) { + // ':' statement-list [elseif-list] [else-colon-statement] 'endif' ';' + if (token == TT_DDOT) { getNextToken(); + statementList(); + switch (token) { + case TT_else : + getNextToken(); + if (token == TT_DDOT) { + getNextToken(); + statementList(); + } else { + if (token == TT_if) { //'else if' + getNextToken(); + elseifStatementList(); + } else { + throwSyntaxError("':' expected after 'else'."); + } + } + break; + case TT_elseif : + getNextToken(); + elseifStatementList(); + break; + } + + if (token != TT_endif) { + throwSyntaxError("'endif' expected."); + } + getNextToken(); + if (token != TT_SEMICOLON) { + throwSyntaxError("';' expected after if-statement."); + } + getNextToken(); + } else { + // statement [else-statement] statement(); + if (token == TT_elseif) { + getNextToken(); + if (token == TT_ARGOPEN) { + getNextToken(); + } else { + throwSyntaxError("'(' expected after 'elseif' keyword."); + } + expression(); + if (token == TT_ARGCLOSE) { + getNextToken(); + } else { + throwSyntaxError("')' expected after 'elseif' condition."); + } + ifStatement(); + } else if (token == TT_else) { + getNextToken(); + statement(); + } + } + } + public void elseifStatementList() { + do { + elseifStatement(); + switch (token) { + case TT_else : + getNextToken(); + if (token == TT_DDOT) { + getNextToken(); + statementList(); + return; + } else { + if (token == TT_if) { //'else if' + getNextToken(); + } else { + throwSyntaxError("':' expected after 'else'."); + } + } + break; + case TT_elseif : + getNextToken(); + break; + default : + return; + } + } while (true); + } + + public void elseifStatement() { + if (token == TT_ARGOPEN) { + getNextToken(); + expression(); + if (token != TT_ARGOPEN) { + throwSyntaxError("')' expected in else-if-statement."); + } + getNextToken(); + if (token != TT_DDOT) { + throwSyntaxError("':' expected in else-if-statement."); + } + getNextToken(); + statementList(); } } public void switchStatement() { + if (token == TT_DDOT) { + // ':' [labeled-statement-list] 'endswitch' ';' + getNextToken(); + labeledStatementList(); + if (token != TT_endswitch) { + throwSyntaxError("'endswitch' expected."); + } + getNextToken(); + if (token != TT_SEMICOLON) { + throwSyntaxError("';' expected after switch-statement."); + } + getNextToken(); + } else { + // '{' [labeled-statement-list] '}' + if (token != TT_LISTOPEN) { + throwSyntaxError("'{' expected in switch statement."); + } + getNextToken(); + if (token != TT_LISTCLOSE) { + labeledStatementList(); + } + if (token != TT_LISTCLOSE) { + throwSyntaxError("'}' expected in switch statement."); + } + getNextToken(); + + } } public void forStatement() { + if (token == TT_DDOT) { + getNextToken(); + statementList(); + if (token != TT_endfor) { + throwSyntaxError("'endfor' expected."); + } + getNextToken(); + if (token != TT_SEMICOLON) { + throwSyntaxError("';' expected after for-statement."); + } + getNextToken(); + } else { + statement(); + } } public void whileStatement() { + // ':' statement-list 'endwhile' ';' + if (token == TT_DDOT) { + getNextToken(); + statementList(); + if (token != TT_endwhile) { + throwSyntaxError("'endwhile' expected."); + } + getNextToken(); + if (token != TT_SEMICOLON) { + throwSyntaxError("';' expected after while-statement."); + } + getNextToken(); + } else { + statement(); + } } public void foreachStatement() { + if (token == TT_DDOT) { + getNextToken(); + statementList(); + if (token != TT_endforeach) { + throwSyntaxError("'endforeach' expected."); + } + getNextToken(); + if (token != TT_SEMICOLON) { + throwSyntaxError("';' expected after foreach-statement."); + } + getNextToken(); + } else { + statement(); + } } public void exitStatus() { @@ -1007,21 +1321,51 @@ public class PHPParser extends PHPKeywords { } public void expression() { - if (token == TT_STRING_CONSTANT || token == TT_INTERPOLATED_STRING) { - getNextToken(); - } else { - postfixExpression(); - // while (token != TT_SEMICOLON) { - // getNextToken(); - // } - } + // if (token == TT_STRING_CONSTANT || token == TT_INTERPOLATED_STRING) { + // getNextToken(); + // } else { + logicalinclusiveorExpression(); + // while (token != TT_SEMICOLON) { + // getNextToken(); + // // } + // } } public void postfixExpression() { + String ident; + boolean castFlag = false; switch (token) { + case TT_STRING_CONSTANT : + getNextToken(); + break; + case TT_INTERPOLATED_STRING : + getNextToken(); + break; case TT_ARGOPEN : getNextToken(); - expression(); + if (token == TT_IDENTIFIER) { + // check if identifier is a type: + ident = identifier; + String str = identifier.toLowerCase(); + for (int i = 0; i < PHP_TYPES.length; i++) { + if (PHP_TYPES[i].equals(str)) { + castFlag = true; + break; + } + } + if (castFlag) { + getNextToken(); + if (token != TT_ARGCLOSE) { + throwSyntaxError(") expected after cast-type '" + ident + "'."); + } + getNextToken(); + expression(); + break; + } + } + if (!castFlag) { + expression(); + } if (token != TT_ARGCLOSE) { throwSyntaxError(") expected in postfix-expression."); } @@ -1034,22 +1378,71 @@ public class PHPParser extends PHPKeywords { getNextToken(); break; case TT_VARIABLE : + ident = identifier; getNextToken(); + if (token == TT_LISTOPEN) { + getNextToken(); + expression(); + if (token != TT_LISTCLOSE) { + throwSyntaxError("'}' expected after variable '" + ident + "' in variable-expression."); + } + getNextToken(); + } break; case TT_IDENTIFIER : + ident = identifier; getNextToken(); if (token == TT_ARGOPEN) { getNextToken(); if (token != TT_ARGCLOSE) { expressionList(); if (token != TT_ARGCLOSE) { - throwSyntaxError(") expected after identifier in postfix-expression."); + throwSyntaxError("')' expected after identifier '" + ident + "' in postfix-expression."); } } getNextToken(); } break; - + case TT_list : + getNextToken(); + if (token == TT_ARGOPEN) { + getNextToken(); + if (token == TT_COMMA) { + getNextToken(); + } + expressionList(); + if (token != TT_ARGCLOSE) { + throwSyntaxError("')' expected after 'list' keyword."); + } + getNextToken(); + // if (token == TT_SET) { + // getNextToken(); + // logicalinclusiveorExpression(); + // } + } else { + throwSyntaxError("'(' expected after 'list' keyword."); + } + break; + // case TT_array : + // getNextToken(); + // if (token == TT_ARGOPEN) { + // getNextToken(); + // if (token == TT_COMMA) { + // getNextToken(); + // } + // expressionList(); + // if (token != TT_ARGCLOSE) { + // throwSyntaxError("')' expected after 'list' keyword."); + // } + // getNextToken(); + // if (token == TT_SET) { + // getNextToken(); + // logicalinclusiveorExpression(); + // } + // } else { + // throwSyntaxError("'(' expected after 'list' keyword."); + // } + // break; } boolean while_flag = true; do { @@ -1062,7 +1455,7 @@ public class PHPParser extends PHPKeywords { } getNextToken(); break; - case TT_REF : + case TT_REF : // -> switch (token) { case TT_VARIABLE : getNextToken(); @@ -1074,7 +1467,7 @@ public class PHPParser extends PHPKeywords { getNextToken(); expression(); if (token != TT_LISTCLOSE) { - throwSyntaxError("] expected in postfix-expression."); + throwSyntaxError("} expected in postfix-expression."); } getNextToken(); break; @@ -1093,6 +1486,253 @@ public class PHPParser extends PHPKeywords { } while (while_flag); } + public void unaryExpression() { + switch (token) { + case TT_INCREMENT : + getNextToken(); + unaryExpression(); + break; + case TT_DECREMENT : + getNextToken(); + unaryExpression(); + break; + //'&' '*' '+' '-' '~' '!' + case TT_AMPERSAND : + getNextToken(); + castExpression(); + break; + case TT_MULTIPLY : + getNextToken(); + castExpression(); + break; + case TT_ADD : + getNextToken(); + castExpression(); + break; + case TT_SUBTRACT : + getNextToken(); + castExpression(); + break; + case TT_TILDE : + getNextToken(); + castExpression(); + break; + case TT_NOT : + getNextToken(); + castExpression(); + break; + default : + postfixExpression(); + } + } + + public void castExpression() { + // if (token == TT_ARGOPEN) { + // getNextToken(); + // typeName(); + // if (token != TT_ARGCLOSE) { + // throwSyntaxError(") expected after cast-expression."); + // } + // getNextToken(); + // } + unaryExpression(); + } + + public void typeName() { + //'string' 'unset' 'array' 'object' + //'bool' 'boolean' + //'real' 'double' 'float' + //'int' 'integer' + String ident = ""; + if (token == TT_IDENTIFIER) { + ident = identifier; + String str = identifier.toLowerCase(); + getNextToken(); + for (int i = 0; i < PHP_TYPES.length; i++) { + if (PHP_TYPES[i].equals(str)) { + return; + } + } + } + throwSyntaxError("Expected type cast '( )'; Got '" + ident + "'."); + } + + public void assignExpression() { + castExpression(); + if (token == TT_SET) { // = + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_DOTASSIGN) { // .= + getNextToken(); + logicalinclusiveorExpression(); + } else if (token == TT_FOREACH) { // => + getNextToken(); + logicalinclusiveorExpression(); + } + } + + public void multiplicativeExpression() { + do { + assignExpression(); + if (token != TT_MULTIPLY && token != TT_DIV && token != TT_MOD) { + return; + } + getNextToken(); + } while (true); + } + + public void concatenationExpression() { + do { + multiplicativeExpression(); + if (token != TT_DOT) { + return; + } + getNextToken(); + } while (true); + } + + public void additiveExpression() { + do { + concatenationExpression(); + if (token != TT_ADD && token != TT_SUBTRACT) { + return; + } + getNextToken(); + } while (true); + } + + public void shiftExpression() { + do { + additiveExpression(); + if (token != TT_LSHIFT && token != TT_RSHIFT) { + return; + } + getNextToken(); + } while (true); + } + + public void relationalExpression() { + do { + shiftExpression(); + if (token != TT_LESS && token != TT_GREATER && token != TT_LESSEQUAL && token != TT_GREATEREQUAL) { + return; + } + getNextToken(); + } while (true); + } + + public void identicalExpression() { + do { + relationalExpression(); + if (token != TT_EX_EQUAL && token != TT_EX_UNEQUAL) { + return; + } + getNextToken(); + } while (true); + } + + public void equalityExpression() { + do { + identicalExpression(); + if (token != TT_EQUAL && token != TT_UNEQUAL) { + return; + } + getNextToken(); + } while (true); + } + + public void andExpression() { + do { + equalityExpression(); + if (token != TT_AMPERSAND) { + return; + } + getNextToken(); + } while (true); + } + + public void exclusiveorExpression() { + do { + andExpression(); + if (token != TT_POW) { + return; + } + getNextToken(); + } while (true); + } + + public void inclusiveorExpression() { + do { + exclusiveorExpression(); + if (token != TT_LINE) { + return; + } + getNextToken(); + } while (true); + } + + public void booleanandExpression() { + do { + inclusiveorExpression(); + if (token != TT_AND) { + return; + } + getNextToken(); + } while (true); + } + + public void booleanorExpression() { + do { + booleanandExpression(); + if (token != TT_OR) { + return; + } + getNextToken(); + } while (true); + } + + public void logicalandExpression() { + do { + booleanorExpression(); + if (token != TT_and) { + return; + } + getNextToken(); + } while (true); + } + + public void logicalexclusiveorExpression() { + do { + logicalandExpression(); + if (token != TT_xor) { + return; + } + getNextToken(); + } while (true); + } + + public void logicalinclusiveorExpression() { + do { + logicalexclusiveorExpression(); + if (token != TT_or) { + return; + } + getNextToken(); + } while (true); + } + + // public void assignmentExpression() { + // if (token == TT_VARIABLE) { + // getNextToken(); + // if (token == TT_SET) { + // getNextToken(); + // logicalinclusiveorExpression(); + // } + // } else { + // logicalinclusiveorExpression(); + // } + // } + public void variableList() { do { variable(); @@ -1113,7 +1753,22 @@ public class PHPParser extends PHPKeywords { } public void constant() { - + switch (token) { + case TT_STRING_CONSTANT : + getNextToken(); + break; + case TT_INTERPOLATED_STRING : + getNextToken(); + break; + case TT_DOUBLE_NUMBER : + getNextToken(); + break; + case TT_INT_NUMBER : + getNextToken(); + break; + default : + throwSyntaxError("Constant expected."); + } } } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPKeywords.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPKeywords.java index f4f7ddd..8e86fb0 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPKeywords.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPKeywords.java @@ -11,8 +11,6 @@ Contributors: **********************************************************************/ package net.sourceforge.phpeclipse.phpeditor.php; - - /** * PHP keyWords and Token definitions */ @@ -50,16 +48,15 @@ public class PHPKeywords { "foreach", "endforeach", "extends", - "empty", - "array", - // "isset", - "echo", - "var", - "as", - "print", - "unset", - "exit", - "die" }; + // "empty", + // "array", + // "isset", + "echo", "var", "as", "print", + "unset", "exit", "die", "and", "or", "xor", + "list" }; + + public final static String[] PHP_TYPES = + { "string", "unset", "array", "object", "bool", "boolean", "real", "double", "float", "int", "integer", }; public final static int TT_KEYWORD = 1000; public final static int TT_if = 1001; @@ -68,33 +65,32 @@ public class PHPKeywords { public final static int TT_endif = 1004; public final static int TT_for = 1005; public final static int TT_endfor = 1006; - public final static int TT_while = 100; - public final static int TT_endwhile = 1007; - public final static int TT_switch = 1008; - public final static int TT_case = 1009; - public final static int TT_endswitch = 1010; - public final static int TT_break = 1011; - public final static int TT_continue = 1012; - public final static int TT_return = 1013; - public final static int TT_define = 1014; - public final static int TT_include = 1015; - public final static int TT_include_once = 1016; - public final static int TT_require = 1017; - public final static int TT_require_once = 1018; - public final static int TT_function = 1019; - public final static int TT_class = 1020; - public final static int TT_new = 1021; - public final static int TT_do = 1022; - public final static int TT_old_function = 1023; - public final static int TT_default = 1024; - public final static int TT_global = 1025; - public final static int TT_static = 1026; - public final static int TT_foreach = 1027; - public final static int TT_endforeach = 1028; - public final static int TT_extends = 1029; - public final static int TT_empty = 1030; - public final static int TT_array = 1031; - // public final static int TT_isset = 1032; + public final static int TT_while = 1007; + public final static int TT_endwhile = 1008; + public final static int TT_switch = 1009; + public final static int TT_case = 10010; + public final static int TT_endswitch = 1011; + public final static int TT_break = 1012; + public final static int TT_continue = 1013; + public final static int TT_return = 1014; + public final static int TT_define = 1015; + public final static int TT_include = 1016; + public final static int TT_include_once = 1017; + public final static int TT_require = 1018; + public final static int TT_require_once = 1019; + public final static int TT_function = 1020; + public final static int TT_class = 1021; + public final static int TT_new = 1022; + public final static int TT_do = 1023; + public final static int TT_old_function = 1024; + public final static int TT_default = 1025; + public final static int TT_global = 1026; + public final static int TT_static = 1027; + public final static int TT_foreach = 1028; + public final static int TT_endforeach = 1029; + public final static int TT_extends = 1030; + // public final static int TT_empty = 1031; + // public final static int TT_array = 1032; public final static int TT_echo = 1033; public final static int TT_var = 1034; public final static int TT_as = 1035; @@ -102,47 +98,46 @@ public class PHPKeywords { public final static int TT_unset = 1037; public final static int TT_exit = 1038; public final static int TT_die = 1039; - + public final static int TT_and = 1040; + public final static int TT_or = 1041; + public final static int TT_xor = 1042; + public final static int TT_list = 1043; + public final static int[] PHP_KEYWORD_TOKEN = { - TT_if, - TT_elseif, - TT_else, - TT_endif, - TT_for, - TT_endfor, - TT_while, - TT_endwhile, - TT_switch, - TT_case, - TT_endswitch, - TT_break, - TT_continue, - TT_return, - TT_define, - TT_include, - TT_include_once, - TT_require, - TT_require_once, - TT_function, - TT_class, - TT_new, - TT_do, - TT_old_function, - TT_default, - TT_global, - TT_static, - TT_foreach, - TT_endforeach, - TT_extends, - TT_empty, - TT_array, - // TT_isset, - TT_echo, - TT_var, - TT_as, - TT_print, - TT_unset, - TT_exit, - TT_die }; + TT_if, + TT_elseif, + TT_else, + TT_endif, + TT_for, + TT_endfor, + TT_while, + TT_endwhile, + TT_switch, + TT_case, + TT_endswitch, + TT_break, + TT_continue, + TT_return, + TT_define, + TT_include, + TT_include_once, + TT_require, + TT_require_once, + TT_function, + TT_class, + TT_new, + TT_do, + TT_old_function, + TT_default, + TT_global, + TT_static, + TT_foreach, + TT_endforeach, + TT_extends, + // TT_empty, + // TT_array, + // TT_isset, + TT_echo, TT_var, TT_as, TT_print, TT_unset, TT_exit, + TT_die, TT_and, TT_or, TT_xor, TT_list }; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java index ad72992..40e2fce 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/views/PHPConsole.java @@ -44,70 +44,78 @@ import sun.security.krb5.internal.crypto.e; */ public class PHPConsole extends ViewPart { - public static final String CONSOLE_ID = "net.sourceforge.phpeclipse.views.phpconsoleview"; - - private TextViewer viewer = null; - private Document document = null; - - /** - * The constructor. - */ - public PHPConsole() { - } - - /** - * Insert the method's description here. - * @see ViewPart#createPartControl - */ - public void createPartControl(Composite parent) { - viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); - GridData viewerData = new GridData(GridData.FILL_BOTH); - viewer.getControl().setLayoutData(viewerData); - viewer.setEditable(false); - } - - /** - * Insert the method's description here. - * @see ViewPart#setFocus - */ - public void setFocus() { - } - - /** - * Set the text for the viewer - */ - public void setOutputText(String text) { - document = new Document(text); - viewer.setDocument(document); - } + public static final String CONSOLE_ID = "net.sourceforge.phpeclipse.views.phpconsoleview"; + + private TextViewer viewer = null; + private Document document = null; + + /** + * The constructor. + */ + public PHPConsole() { + } + + /** + * Insert the method's description here. + * @see ViewPart#createPartControl + */ + public void createPartControl(Composite parent) { + viewer = new TextViewer(parent, SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); + GridData viewerData = new GridData(GridData.FILL_BOTH); + viewer.getControl().setLayoutData(viewerData); + viewer.setEditable(false); + } + + /** + * Insert the method's description here. + * @see ViewPart#setFocus + */ + public void setFocus() { + } + + /** + * Set the text for the viewer + */ + public void setOutputText(String text) { + document = new Document(text); + viewer.setDocument(document); + } public void appendOutputText(String text) { try { + if (document == null) { + document = new Document(text); + viewer.setDocument(document); + } document.replace(document.getLength(), 0, text); } catch (BadLocationException e) { } - // viewer.setDocument(document); + // viewer.setDocument(document); } - + /** * Prints out the string represented by the string buffer */ - static public void write(String output) { + public static void write(String output) { try { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); PHPConsole console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); if (console != null) { console.appendOutputText(output); - } else if ( - PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) { + } else if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PHPeclipsePlugin.SHOW_OUTPUT_IN_CONSOLE) == true) { page.showView(PHPConsole.CONSOLE_ID); console = (PHPConsole) page.findView(PHPConsole.CONSOLE_ID); console.setOutputText(output); } } catch (PartInitException e) { PHPeclipsePlugin.getDefault().getLog().log( - new Status(IStatus.ERROR, PHPeclipsePlugin.getPluginId(), 0, PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"), e)); + new Status( + IStatus.ERROR, + PHPeclipsePlugin.getPluginId(), + 0, + PHPActionMessages.getString("PHPStartApacheAction.consoleViewOpeningProblem"), + e)); } } @@ -115,7 +123,7 @@ public class PHPConsole extends ViewPart { /** * Creates a string buffer from the given input stream */ - static public String getStringFromStream(InputStream stream) throws IOException { + public static String getStringFromStream(InputStream stream) throws IOException { StringBuffer buffer = new StringBuffer(); byte[] b = new byte[100]; int finished = 0; @@ -129,7 +137,4 @@ public class PHPConsole extends ViewPart { return buffer.toString(); } - - - } -- 1.7.1