From 7f39ebda90803af38342c9f6acd82d9ae23f7206 Mon Sep 17 00:00:00 2001 From: khartlage Date: Wed, 13 Nov 2002 20:48:12 +0000 Subject: [PATCH 1/1] Added first PHP parser version (doesn't work correct actually) --- net.sourceforge.phpeclipse/.classpath | 10 +- net.sourceforge.phpeclipse/plugin.properties | 1 + net.sourceforge.phpeclipse/plugin.xml | 43 +- .../phpeclipse/actions/PHPActionMessages.java | 31 + .../actions/PHPActionMessages.properties | 4 + .../phpeclipse/phpeditor/PHPParser.java | 994 ++++++++ .../phpeclipse/phpeditor/PHPParserAction.java | 307 +++ .../phpeclipse/phpeditor/SyntaxError.java | 62 + .../net/sourceforge/phpeclipse/phpeditor/java.gif | Bin 0 -> 140 bytes .../phpeditor/php/PHPFunctionDescription.java | 2388 ++++++++++++++++++++ .../phpeclipse/phpeditor/php/PHPFunctionNames.java | 2360 +++++++++++++++++++ .../phpeclipse/phpeditor/php/PHPKeywords.java | 148 ++ 12 files changed, 6337 insertions(+), 11 deletions(-) create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.properties create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/SyntaxError.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/java.gif create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPFunctionDescription.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPFunctionNames.java create mode 100644 net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPKeywords.java diff --git a/net.sourceforge.phpeclipse/.classpath b/net.sourceforge.phpeclipse/.classpath index bb58950..08c0bf7 100644 --- a/net.sourceforge.phpeclipse/.classpath +++ b/net.sourceforge.phpeclipse/.classpath @@ -1,17 +1,21 @@ + + + + - - diff --git a/net.sourceforge.phpeclipse/plugin.properties b/net.sourceforge.phpeclipse/plugin.properties index 5169f87..1d7f7bd 100644 --- a/net.sourceforge.phpeclipse/plugin.properties +++ b/net.sourceforge.phpeclipse/plugin.properties @@ -8,6 +8,7 @@ providerName = EclipseProject.de # Extension point names # phpEditorName=PHP Editor +phpConsoleView=PHP Console phpFileExtension=php php3FileExtension=php3 php4FileExtension=php4 diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index b8fec77..85b01be 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -16,7 +16,6 @@ - - @@ -124,7 +123,7 @@ id="net.sourceforge.phpeclipse.actions.showAction"> - @@ -144,7 +143,7 @@ menubarPath="additions" id="net.sourceforge.phpeclipse.actions.editor.contexthelp"> - + @@ -162,7 +161,7 @@ id="net.sourceforge.phpeclipse.phpeditor.PHPDocumentProvider"> - - - - + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.java new file mode 100644 index 0000000..352a5dd --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.java @@ -0,0 +1,31 @@ +/* + * (c) Copyright Improve S.A., 2002. + * All Rights Reserved. + */ +package net.sourceforge.phpeclipse.actions; + + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class PHPActionMessages { + + private static final String RESOURCE_BUNDLE= "net.sourceforge.phpeclipse.actions.PHPActionMessages";//$NON-NLS-1$ + + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + private PHPActionMessages() { + } + + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ + } + } + + public static ResourceBundle getResourceBundle() { + return fgResourceBundle; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.properties b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.properties new file mode 100644 index 0000000..417a814 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPActionMessages.properties @@ -0,0 +1,4 @@ +## Actions + +PHPStartApacheAction.consoleViewOpeningProblem=A problem occured while opening the PHP console view + diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java new file mode 100644 index 0000000..e2f1dce --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParser.java @@ -0,0 +1,994 @@ +package net.sourceforge.phpeclipse.phpeditor; + +import java.util.HashMap; + +import net.sourceforge.phpeclipse.phpeditor.php.PHPKeywords; + +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ + +public class PHPParser extends PHPKeywords { + + private static HashMap keywordMap = null; + private String str; + + // current character + char ch; + // current token + int token; + + // row counter for syntax errors: + int rowCount; + // column counter for syntax errors: + int columnCount; + + int chIndx; + + // current identifier + String identifier; + + Long longNumber; + Double doubleNumber; + + final static int TT_EOF = 0; + final static int TT_UNDEFINED = 1; + + 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_MULTIPLY = 35; + final static int TT_SUBTRACT = 36; + final static int TT_ADD = 37; + final static int TT_EQUAL = 38; + final static int TT_UNEQUAL = 39; + final static int TT_GREATER = 40; + final static int TT_GREATEREQUAL = 41; + final static int TT_LESS = 42; + final static int TT_LESSEQUAL = 43; + final static int TT_AND = 44; + final static int TT_OR = 45; + final static int TT_HASH = 46; + final static int TT_DDOT = 47; + final static int TT_DOTASSIGN = 48; + + final static int TT_SET = 49; + + final static int TT_FOREACH = 51; + final static int TT_ARGOPEN = 128; + final static int TT_ARGCLOSE = 129; + final static int TT_LISTOPEN = 130; + final static int TT_LISTCLOSE = 131; + 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; + final static int TT_SEMICOLON = 140; + final static int TT_SLOT = 141; + final static int TT_SLOTSEQUENCE = 142; + final static int TT_DECREMENT = 144; + final static int TT_INCREMENT = 145; + final static int TT_ADDTO = 146; + final static int TT_DIVIDEBY = 147; + final static int TT_SUBTRACTFROM = 148; + final static int TT_TIMESBY = 149; + final static int TT_VARIABLE = 150; + final static int TT_INT_NUMBER = 151; + 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_AT = 153; // @ + /** + * Class Constructor. + * + *@param s + *@param sess Description of Parameter + *@see + */ + public PHPParser(String s, int rowCount) { + if (keywordMap == null) { + keywordMap = new HashMap(); + for (int i = 0; i < PHP_KEYWORS.length; i++) { + keywordMap.put(PHP_KEYWORS[i], new Integer(PHP_KEYWORD_TOKEN[i])); + } + } + this.str = s; + this.token = TT_EOF; + this.chIndx = 0; + this.rowCount = rowCount; + this.columnCount = 0; + + getNextToken(); + } + + 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, str.substring(columnCount + 1, eol), error); + } + + /** + * Method Declaration. + * + *@see + */ + void getChar() { + if (str.length() > chIndx) { + ch = str.charAt(chIndx++); + + return; + } + + chIndx = str.length() + 1; + ch = ' '; + token = TT_EOF; + } + + /** + * gets the next token from input + */ + void getNextToken() { + while (str.length() > chIndx) { + ch = str.charAt(chIndx++); + token = TT_UNDEFINED; + if (ch == '\n') { + rowCount++; + columnCount = chIndx; + continue; // while loop + } + + if (!Character.isWhitespace(ch)) { + if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch == '_') || (ch == '$') || (ch == '@')) { + getIdentifier(); + return; + } + if (ch >= '0' && ch <= '9') { + getNumber(); + return; + } + if (ch == '/') { + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '/') { + chIndx++; + // read comment until end of line: + while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { + chIndx++; + } + continue; + } else if (str.charAt(chIndx) == '*') { + chIndx++; + // multi line comment: + while (str.length() > chIndx) { + if (str.charAt(chIndx) == '*' && + (str.length() > (chIndx+1) ) && + str.charAt(chIndx+1) == '/') { + chIndx += 2; + break; + } + chIndx++; + } + continue; + } + } + } else if (ch == '#') { + // read comment until end of line: + while ((str.length() > chIndx) && (str.charAt(chIndx) != '\n')) { + chIndx++; + } + continue; + } else if (ch == '"') { + // read string until end + while ((str.length() > chIndx) && (str.charAt(chIndx++) != '"')) { + if (str.charAt(chIndx) == '\\') { + if (str.length() > chIndx) { + chIndx++; + } + if (str.length() > chIndx) { + chIndx++; + } + } else { + if (str.charAt(chIndx) == '\n') { + rowCount++; + columnCount = chIndx; + } + } + } + if (str.length() > chIndx) { + chIndx++; + } + token = TT_INTERPOLATED_STRING; + return; + } else if (ch == '\'') { + // read string until end + while ((str.length() > chIndx) && (str.charAt(chIndx++) != '\'')) { + if (str.charAt(chIndx) == '\\') { + if (str.length() > chIndx) { + chIndx++; + } + if (str.length() > chIndx) { + chIndx++; + } + } + } + if (str.length() > chIndx) { + chIndx++; + } + token = TT_STRING_CONSTANT; + return; + } + + switch (ch) { + + case '(' : + token = TT_ARGOPEN; + + break; + case ')' : + token = TT_ARGCLOSE; + + break; + case '{' : + token = TT_LISTOPEN; + + break; + case '}' : + token = TT_LISTCLOSE; + + break; + case '[' : + token = TT_PARTOPEN; + + break; + case ']' : + token = TT_PARTCLOSE; + + break; + case ',' : + token = TT_COMMA; + + break; + + case '.' : + token = TT_DOT; + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_DOTASSIGN; + + break; + } + } + + break; + case '"' : + token = TT_STRING; + + break; + case '%' : + token = TT_PERCENT; + + break; + case ';' : + token = TT_SEMICOLON; + + break; + case '^' : + token = TT_POW; + + break; + case '/' : + token = TT_DIVIDE; + + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_DIVIDEBY; + + break; + } + } + + break; + case '*' : + token = TT_MULTIPLY; + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '*') { + chIndx++; + token = TT_POW; + + break; + } + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_TIMESBY; + + break; + } + } + + break; + case '+' : + token = TT_ADD; + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '+') { + chIndx++; + token = TT_INCREMENT; + + break; + } + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_ADDTO; + + break; + } + } + break; + case '-' : + token = TT_SUBTRACT; + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '-') { + chIndx++; + token = TT_DECREMENT; + + break; + } + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_SUBTRACTFROM; + + break; + } + } + + break; + case '=' : + token = TT_SET; + + if (str.length() > chIndx) { + ch = str.charAt(chIndx); + + if (ch == '=') { + chIndx++; + token = TT_EQUAL; + + break; + } + if (ch == '>') { + chIndx++; + token = TT_FOREACH; + + break; + } + } + + break; + case '!' : + token = TT_NOT; + + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_UNEQUAL; + + break; + } + } + + break; + case '>' : + token = TT_GREATER; + + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_GREATEREQUAL; + + break; + } + } + + break; + case '<' : + token = TT_LESS; + + if (str.length() > chIndx) { + if (str.charAt(chIndx) == '=') { + chIndx++; + token = TT_LESSEQUAL; + + break; + } + } + + break; + + case '|' : + if (str.length() > chIndx) { + if (str.charAt(chIndx++) == '|') { + token = TT_OR; + + break; + } + } + + break; + case '&' : + if (str.length() > chIndx) { + if (str.charAt(chIndx++) == '&') { + token = TT_AND; + + break; + } + } + + break; + case ':' : + token = TT_DDOT; + + break; + case '#' : + token = TT_HASH; + + break; + // case '@' : + // token = TT_AT; + // + // break; + default : + throwSyntaxError("unexpected character: '" + ch + "'"); + } + + if (token == TT_UNDEFINED) { + throwSyntaxError("token not found"); + } + + return; + } + } + + chIndx = str.length() + 1; + ch = ' '; + token = TT_EOF; + } + + void getIdentifier() { + StringBuffer ident = new StringBuffer(); + ident.append(ch); + + ident.append(ch); + if (ch == '$') { + token = TT_VARIABLE; + } else { + token = TT_IDENTIFIER; + } + getChar(); + while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || (ch >= '_')) { + ident.append(ch); + getChar(); + } + identifier = ident.toString(); + + Integer i = (Integer) keywordMap.get(identifier); + if (i != null) { + token = i.intValue(); + } + } + + void getNumber() { + StringBuffer inum = new StringBuffer(); + char dFlag = ' '; + int numFormat = 10; + + // save first digit + char firstCh = ch; + inum.append(ch); + + getChar(); + // determine number conversions: + if (firstCh == '0') { + switch (ch) { + case 'b' : + numFormat = 2; + getChar(); + break; + case 'B' : + numFormat = 2; + getChar(); + break; + case 'o' : + numFormat = 8; + getChar(); + break; + case 'O' : + numFormat = 8; + getChar(); + break; + case 'x' : + numFormat = 16; + getChar(); + break; + case 'X' : + numFormat = 16; + getChar(); + break; + } + } + + if (numFormat == 16) { + while ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F')) { + inum.append(ch); + getChar(); + } + } else { + while ((ch >= '0' && ch <= '9') || (ch == '.') || (ch == 'E') || (ch == 'e')) { + if ((ch == '.') || (ch == 'E') || (ch == 'e')) { + if (ch == '.' && dFlag != ' ') { + break; + } + if ((dFlag == 'E') || (dFlag == 'e')) { + break; + } + dFlag = ch; + inum.append(ch); + getChar(); + if ((ch == '-') || (ch == '+')) { + inum.append(ch); + getChar(); + } + } else { + inum.append(ch); + getChar(); + } + } + } + + // token = TT_INT_NUMBER; + + try { + if (dFlag != ' ') { + doubleNumber = new Double(inum.toString()); + token = TT_DOUBLE_NUMBER; + return; + } else { + longNumber = Long.valueOf(inum.toString(), numFormat); + token = TT_INT_NUMBER; + return; + } + + } catch (Throwable e) { + throwSyntaxError("Number format error: " + inum.toString()); + } + } + + public void start() throws SyntaxError { + statementList(); + if (token != TT_EOF) { + if (token == TT_ARGCLOSE) { + throwSyntaxError("too many closing ')'; end-of-file not reached"); + } + if (token == TT_LISTCLOSE) { + throwSyntaxError("too many closing '}'; end-of-file not reached"); + } + if (token == TT_PARTCLOSE) { + throwSyntaxError("too many closing ']'; end-of-file not reached"); + } + + throwSyntaxError("end-of-file not reached"); + } + + } + + public void statementList() { + statement(); + } + + public void statement() { + while (token != TT_UNDEFINED) { + if (token > TT_KEYWORD) { + 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; + } else if (token == TT_include || token == TT_include_once) { + getNextToken(); + expression(); + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' character after 'include' or 'include_once' expected."); + } + return; + } else if (token == TT_require || token == TT_require_once) { + getNextToken(); + constant(); + if (token == TT_SEMICOLON) { + getNextToken(); + } 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 '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) { + 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) { + 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) { + getNextToken(); + if (token != TT_SEMICOLON) { + expression(); + } + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after 'continue', 'break' or 'return'."); + } + return; + + } else if (token == TT_echo) { + getNextToken(); + expressionList(); + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after 'echo' statement."); + } + return; + + } else if (token == TT_print) { + getNextToken(); + expression(); + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after 'print' statement."); + } + return; + + } else if (token == TT_global || token == TT_static) { + getNextToken(); + variableList(); + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after 'global' or 'static' statement."); + } + return; + + } else if (token == TT_unset) { + 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 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_define) { + 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 { + if (token == TT_LISTOPEN) { + getNextToken(); + statementList(); + if (token == TT_LISTCLOSE) { + getNextToken(); + } else { + throwSyntaxError("'}' expected."); + } + } + } + expression(); + if (token == TT_SEMICOLON) { + getNextToken(); + } else { + throwSyntaxError("';' expected after expression."); + } + } + } + + public void labeledStatement() { + } + + public void expressionStatement() { + } + + public void inclusionStatement() { + } + + 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() { + } + + public void switchStatement() { + } + + public void forStatement() { + } + + public void whileStatement() { + } + + public void foreachStatement() { + } + + public void exitStatus() { + if (token == TT_ARGOPEN) { + getNextToken(); + } else { + throwSyntaxError("'(' expected in 'exit-status'."); + } + if (token != TT_ARGCLOSE) { + expression(); + } + if (token == TT_ARGCLOSE) { + getNextToken(); + } else { + throwSyntaxError("')' expected after 'exit-status'."); + } + } + + public void expressionList() { + do { + expression(); + if (token == TT_COMMA) { + getNextToken(); + } else { + break; + } + } while (true); + } + + public void expression() { + if (token == TT_STRING_CONSTANT || token == TT_INTERPOLATED_STRING) { + getNextToken(); + } else { + postfixExpression(); + // while (token != TT_SEMICOLON) { + // getNextToken(); + // } + } + } + + public void postfixExpression() { + + } + + public void variableList() { + do { + variable(); + if (token == TT_COMMA) { + getNextToken(); + } else { + break; + } + } while (true); + } + + public void variable() { + if (token == TT_VARIABLE) { + getNextToken(); + } else { + throwSyntaxError("$-variable expected in variable-list."); + } + } + + public void constant() { + + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java new file mode 100644 index 0000000..a5ae10a --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java @@ -0,0 +1,307 @@ +package net.sourceforge.phpeclipse.phpeditor; + +/********************************************************************** +Copyright (c) 2000, 2002 IBM Corp. and others. +All rights reserved. This program and the accompanying materials +are made available under the terms of the Common Public License v1.0 +which accompanies this distribution, and is available at +http://www.eclipse.org/legal/cpl-v10.html + +Contributors: + IBM Corporation - Initial implementation + Klaus Hartlage - www.eclipseproject.de +**********************************************************************/ + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Hashtable; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.Position; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.MarkerUtilities; +import org.eclipse.ui.texteditor.TextEditorAction; + +/** + * Class that defines the action for parsing the current PHP file + */ +public class PHPParserAction extends TextEditorAction { + + // public static final String EXE = "exe"; //$NON-NLS-1$ + // public static final String WINEXE = "winexe"; //$NON-NLS-1$ + // public static final String LIBRARY = "library"; //$NON-NLS-1$ + // public static final String MODULE = "module"; //$NON-NLS-1$ + + private static final String ERROR = "error"; //$NON-NLS-1$ + private static final String WARNING = "warning"; //$NON-NLS-1$ + + private static PHPParserAction instance = new PHPParserAction(); + + protected IFile fileToParse; + protected List fVariables = new ArrayList(100); + + /** + * Constructs and updates the action. + */ + private PHPParserAction() { + super(PHPEditorMessages.getResourceBundle(), "ParserAction.", null); //$NON-NLS-1$ + update(); + } + + public static PHPParserAction getInstance() { + return instance; + } + + /** + * Code called when the action is fired. + */ + public void run() { + try { + fileToParse = getPHPFile(); + if (fileToParse == null) { + // should never happen + System.err.println("Error : no file in the editor"); + // should throw an exception + return; + } + // first delete all the previous markers + fileToParse.deleteMarkers(IMarker.PROBLEM, false, 0); + //IDocument document = getTextEditor().getDocumentProvider().getDocument(null); + //String text = document.get(); + + // String text = + // parse(document); + try { + InputStream iStream = fileToParse.getContents(); + // int c = iStream.read(); + parse(iStream); + iStream.close(); + } catch (IOException e) { + } + + // String message = "Test error"; + // int lineNumber = 1; + // + // // create marker for the error + // + // setMarker(message, lineNumber, fileToParse); + } catch (CoreException e) { + } + + } + + /** + * Finds the file that's currently opened in the PHP Text Editor + */ + protected IFile getPHPFile() { + ITextEditor editor = getTextEditor(); + + IEditorInput editorInput = null; + if (editor != null) { + editorInput = editor.getEditorInput(); + } + + if (editorInput instanceof IFileEditorInput) + return ((IFileEditorInput) editorInput).getFile(); + + // if nothing was found, which should never happen + return null; + } + + /** + * Create marker for the parse error + */ + protected void setMarker(String message, int lineNumber) throws CoreException { + + Hashtable attributes = new Hashtable(); + MarkerUtilities.setMessage(attributes, message); + if (message.startsWith(ERROR)) + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR)); + else if (message.startsWith(WARNING)) + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING)); + else + attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO)); + MarkerUtilities.setLineNumber(attributes, lineNumber); + MarkerUtilities.createMarker(fileToParse, attributes, IMarker.PROBLEM); + } + + // private String getIdentifier(InputStream iStream, int c) { + // // int i = 0; + // // char c; + // // int textLength = text.length(); + // StringBuffer identifier = new StringBuffer(); + // identifier.append((char) c); + // try { + // while ((c = iStream.read()) != (-1)) { + // if (Character.isJavaIdentifierPart((char) c)) { + // identifier.append((char) c); + // // } else if ((i == 0) && (c == '$')) { + // // identifier.append((char)c); + // } else { + // return identifier.toString(); + // } + // // i++; + // } + // } catch (IOException e) { + // } + // return identifier.toString(); + // } + + protected void parse(InputStream iStream) { + boolean lineCommentMode = false; + boolean multiLineCommentMode = false; + boolean stringMode = false; + + // ArrayList phpList = new ArrayList(); + StringBuffer buf = new StringBuffer(); + int c0; + try { + while ((c0 = iStream.read()) != (-1)) { + buf.append((char) c0); + } + } catch (IOException e) { + return; + } + String input = buf.toString(); + int lineNumber = 1; + int startLineNumber = 1; + int startIndex = 0; + char ch; + char ch2; + boolean phpMode = false; + boolean phpFound = false; + + try { + int i = 0; + while (i < input.length()) { + ch = input.charAt(i++); + if (ch == '\n') { + lineNumber++; + } + if ( (! phpMode) && ch == '<') { + ch2 = input.charAt(i++); + if (ch2 == '?') { + ch2 = input.charAt(i++); + if (Character.isWhitespace(ch2)) { + // php start + phpMode = true; + phpFound = true; + startIndex = i; + startLineNumber = lineNumber; + continue; + } else if (ch2 == 'p') { + ch2 = input.charAt(i++); + if (ch2 == 'h') { + ch2 = input.charAt(i++); + if (ch2 == 'p') { + phpMode = true; + phpFound = true; + startIndex = i; + startLineNumber = lineNumber; + continue; + } + i--; + } + i--; + } else if (ch2 == 'P') { + ch2 = input.charAt(i++); + if (ch2 == 'H') { + ch2 = input.charAt(i++); + if (ch2 == 'P') { + phpMode = true; + phpFound = true; + startIndex = i; + startLineNumber = lineNumber; + continue; + } + i--; + } + i--; + } + i--; + } + i--; + } + + if (phpMode) { + buf.append(ch); + if (lineCommentMode && (ch == '\n')) { + lineCommentMode = false; + // read until end of line + } else if ((!stringMode) && (ch == '#')) { + // read until end of line + lineCommentMode = true; + continue; + } else if ((!stringMode) && (!multiLineCommentMode) && (ch == '/')) { + ch2 = input.charAt(i++); + if (ch2 == '/') { + lineCommentMode = true; + continue; + } else if (ch2 == '*') { + multiLineCommentMode = true; + continue; + } else { + i--; + } + } else if (ch == '*' && multiLineCommentMode) { + ch2 = input.charAt(i++); + if (ch2 == '/') { + multiLineCommentMode = false; + continue; + } else { + i--; + } + } else if (ch == '\\' && stringMode) { + ch2 = input.charAt(i++); + if (ch2 == '"') { + continue; + } else { + i--; + } + } else if ((!lineCommentMode) && (!multiLineCommentMode) && (ch == '"')) { + if (stringMode) { + stringMode = false; + } else { + stringMode = true; + } + continue; + } + if (lineCommentMode || multiLineCommentMode || stringMode) { + continue; + } + + if (ch == '?') { + ch2 = input.charAt(i++); + if (ch2 == '>') { + // php end + phpMode = false; + // phpList.add(input.substring(startIndex, i-2)); + try { + PHPParser parser = new PHPParser(input.substring(startIndex, i - 2), startLineNumber); + parser.start(); + } catch (SyntaxError err) { + setMarker(err.getMessage(), err.getLine()); + } + continue; + } + i--; + } + } else { + } + } + if (!phpFound) { + setMarker("No PHP source code found.", lineNumber); + } + } catch (CoreException e) { + } + } +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/SyntaxError.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/SyntaxError.java new file mode 100644 index 0000000..3ba2e99 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/SyntaxError.java @@ -0,0 +1,62 @@ +/* + * SyntaxError.java + * Copyright (C) 2000 Klaus Hartlage + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package net.sourceforge.phpeclipse.phpeditor; + +/** + * Exception for a syntax error detected by the HartMath parser + * + */ +public class SyntaxError extends Error { + + int lineNumber; + int columnNumber; + String currentLine; + String error; + /** + * SyntaxError exception + * + * + * @see + */ + public SyntaxError(int lineNumber, int columnNumber, String currentLine, String error) { + this.lineNumber = lineNumber; + this.columnNumber = columnNumber; + this.currentLine = currentLine; + this.error = error; + } + + public String getMessage() { + // StringBuffer buf = new StringBuffer(256); + // buf.append("Syntax error in line:"); + // buf.append(lineNumber+1); + // buf.append(": "+ error + "\n"); + // buf.append( currentLine + "\n"); + // for (int i=0; i<(columnNumber-1); i++) { + // buf.append(' '); + // } + // buf.append('^'); + // return buf.toString(); + System.err.println(currentLine); + return error; + } + + public int getLine() { + return lineNumber; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/java.gif b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/java.gif new file mode 100644 index 0000000000000000000000000000000000000000..83de817b7190e7053ab1cca6a6686c2553c8ab1b GIT binary patch literal 140 zcmZ?wbhEHb6krfw*vtR{4Gawp2M!!)XlP*g4+2nOY?R_p7DfgJRt6oAB*+X07RwDM zJhfGiwVY`@db6!kK3(dG>zXyDjk9O&duX}4VqLRL;pJI9{2vY