X-Git-Url: http://git.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
index e9930a3..0f04260 100644
--- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj
+++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
@@ -29,7 +29,6 @@ import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.jface.preference.IPreferenceStore;
import java.util.Hashtable;
-import java.util.Enumeration;
import java.util.ArrayList;
import java.io.StringReader;
import java.io.*;
@@ -39,6 +38,7 @@ import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import net.sourceforge.phpdt.internal.compiler.ast.*;
import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
+import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
/**
@@ -47,6 +47,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
* given with JavaCC. You can get JavaCC at http://www.webgain.com
* You can test the parser with the PHPParserTestCase2.java
* @author Matthieu Casanova
+ * @version $Reference: 1.0$
*/
public final class PHPParser extends PHPParserSuperclass {
@@ -60,8 +61,6 @@ public final class PHPParser extends PHPParserSuperclass {
private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
static PHPOutlineInfo outlineInfo;
- private static boolean assigning;
-
/** The error level of the current ParseException. */
private static int errorLevel = ERROR;
/** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
@@ -70,6 +69,8 @@ public final class PHPParser extends PHPParserSuperclass {
private static int errorStart = -1;
private static int errorEnd = -1;
private static PHPDocument phpDocument;
+
+ private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
/**
* The point where html starts.
* It will be used by the token manager to create HTMLCode objects
@@ -108,12 +109,12 @@ public final class PHPParser extends PHPParserSuperclass {
* Add an php node on the stack.
* @param node the node that will be added to the stack
*/
- private static final void pushOnAstNodes(AstNode node) {
+ private static final void pushOnAstNodes(final AstNode node) {
try {
nodes[++nodePtr] = node;
} catch (IndexOutOfBoundsException e) {
- int oldStackLength = nodes.length;
- AstNode[] oldStack = nodes;
+ final int oldStackLength = nodes.length;
+ final AstNode[] oldStack = nodes;
nodes = new AstNode[oldStackLength + AstStackIncrement];
System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
nodePtr = oldStackLength;
@@ -135,7 +136,9 @@ public final class PHPParser extends PHPParserSuperclass {
parse();
phpDocument.nodes = new AstNode[nodes.length];
System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
- phpDocument.toString();
+ if (PHPeclipsePlugin.DEBUG) {
+ PHPeclipsePlugin.log(1,phpDocument.toString());
+ }
} catch (ParseException e) {
processParseException(e);
}
@@ -156,6 +159,7 @@ public final class PHPParser extends PHPParserSuperclass {
}
setMarker(e);
errorMessage = null;
+ if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
}
/**
@@ -186,31 +190,6 @@ public final class PHPParser extends PHPParserSuperclass {
}
}
- /**
- * Create markers according to the external parser output
- */
- private static void createMarkers(final String output, final IFile file) throws CoreException {
- // delete all markers
- file.deleteMarkers(IMarker.PROBLEM, false, 0);
-
- int indx = 0;
- int brIndx;
- boolean flag = true;
- while ((brIndx = output.indexOf("
", indx)) != -1) {
- // newer php error output (tested with 4.2.3)
- scanLine(output, file, indx, brIndx);
- indx = brIndx + 6;
- flag = false;
- }
- if (flag) {
- while ((brIndx = output.indexOf("
", indx)) != -1) {
- // older php error output (tested with 4.2.3)
- scanLine(output, file, indx, brIndx);
- indx = brIndx + 4;
- }
- }
- }
-
private static void scanLine(final String output,
final IFile file,
final int indx,
@@ -293,13 +272,32 @@ public final class PHPParser extends PHPParserSuperclass {
*/
public static final void createNewHTMLCode() {
final int currentPosition = SimpleCharStream.getPosition();
- if (currentPosition == htmlStart) {
+ if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
return;
}
final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
}
+ /**
+ * Create a new task.
+ */
+ public static final void createNewTask() {
+ final int currentPosition = SimpleCharStream.getPosition();
+ final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
+ SimpleCharStream.currentBuffer.indexOf("\n",
+ currentPosition)-1);
+ try {
+ setMarker(fileToParse,
+ "todo : " + todo,
+ SimpleCharStream.getBeginLine(),
+ TASK,
+ "Line "+SimpleCharStream.getBeginLine());
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }
+ }
+
private static final void parse() throws ParseException {
phpFile();
}
@@ -340,34 +338,30 @@ PARSER_END(PHPParser)
SPECIAL_TOKEN :
{
"//" : IN_SINGLE_LINE_COMMENT
-|
- "#" : IN_SINGLE_LINE_COMMENT
-|
- <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
-|
- "/*" : IN_MULTI_LINE_COMMENT
+| "#" : IN_SINGLE_LINE_COMMENT
+| <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
+| "/*" : IN_MULTI_LINE_COMMENT
}
SPECIAL_TOKEN :
{
: PHPPARSING
+| "?>" : DEFAULT
}
- SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
{
- " > : DEFAULT
+ "todo" {PHPParser.createNewTask();}
}
-
-SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
{
- : PHPPARSING
+ "*/" : PHPPARSING
}
-
-SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
{
- : PHPPARSING
+ "*/" : PHPPARSING
}
@@ -400,6 +394,7 @@ MORE :
|
|
|
+|
|
| ">
|
@@ -465,8 +460,8 @@ MORE :
{
|
-|
-|
+|
+|
|
|
|
@@ -507,39 +502,16 @@ MORE :
<#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|
| | )>
-|
-|
-|
+|
+|
+|
}
/* IDENTIFIERS */
TOKEN :
{
- < IDENTIFIER: (|) (||)* >
+ |) (||)* >
|
< #LETTER:
["a"-"z"] | ["A"-"Z"]
@@ -604,7 +576,7 @@ MORE :
TOKEN :
{
- < DOLLAR_ID: >
+ >
}
void phpFile() :
@@ -612,7 +584,7 @@ void phpFile() :
{
try {
(PhpBlock())*
-
+ {PHPParser.createNewHTMLCode();}
} catch (TokenMgrError e) {
PHPeclipsePlugin.log(e);
errorStart = SimpleCharStream.getPosition();
@@ -631,11 +603,13 @@ void phpFile() :
void PhpBlock() :
{
final int start = SimpleCharStream.getPosition();
+ final PHPEchoBlock phpEchoBlock;
}
{
- phpEchoBlock()
+ phpEchoBlock = phpEchoBlock()
+ {pushOnAstNodes(phpEchoBlock);}
|
- [
+ [
|
{try {
setMarker(fileToParse,
@@ -656,7 +630,7 @@ void PhpBlock() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
}
@@ -664,7 +638,7 @@ PHPEchoBlock phpEchoBlock() :
{
final Expression expr;
final int pos = SimpleCharStream.getPosition();
- PHPEchoBlock echoBlock;
+ final PHPEchoBlock echoBlock;
}
{
expr = Expression() [ ]
@@ -683,44 +657,48 @@ void Php() :
ClassDeclaration ClassDeclaration() :
{
final ClassDeclaration classDeclaration;
- final Token className;
- Token superclassName = null;
+ final Token className,superclassName;
final int pos;
+ char[] classNameImage = SYNTAX_ERROR_CHAR;
+ char[] superclassNameImage = null;
}
{
+ {pos = SimpleCharStream.getPosition();}
try {
- {pos = SimpleCharStream.getPosition();}
className =
+ {classNameImage = className.image.toCharArray();}
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
[
try {
superclassName =
+ {superclassNameImage = superclassName.image.toCharArray();}
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
+ superclassNameImage = SYNTAX_ERROR_CHAR;
}
]
{
- if (superclassName == null) {
+ if (superclassNameImage == null) {
classDeclaration = new ClassDeclaration(currentSegment,
- className.image.toCharArray(),
+ classNameImage,
pos,
0);
} else {
classDeclaration = new ClassDeclaration(currentSegment,
- className.image.toCharArray(),
- superclassName.image.toCharArray(),
+ classNameImage,
+ superclassNameImage,
pos,
0);
}
@@ -734,7 +712,7 @@ ClassDeclaration ClassDeclaration() :
return classDeclaration;}
}
-void ClassBody(ClassDeclaration classDeclaration) :
+void ClassBody(final ClassDeclaration classDeclaration) :
{}
{
try {
@@ -761,14 +739,14 @@ void ClassBody(ClassDeclaration classDeclaration) :
/**
* A class can contain only methods and fields.
*/
-void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
+void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
{
- MethodDeclaration method;
- FieldDeclaration field;
+ final MethodDeclaration method;
+ final FieldDeclaration field;
}
{
- method = MethodDeclaration() {method.setParent(classDeclaration);}
-| field = FieldDeclaration()
+ method = MethodDeclaration() {classDeclaration.addMethod(method);}
+| field = FieldDeclaration() {classDeclaration.addField(field);}
}
/**
@@ -777,19 +755,17 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
FieldDeclaration FieldDeclaration() :
{
VariableDeclaration variableDeclaration;
- VariableDeclaration[] list;
+ final VariableDeclaration[] list;
final ArrayList arrayList = new ArrayList();
final int pos = SimpleCharStream.getPosition();
}
{
variableDeclaration = VariableDeclarator()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));
- currentSegment.add(variableDeclaration);}
+ outlineInfo.addVariable(new String(variableDeclaration.name));}
( variableDeclaration = VariableDeclarator()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));
- currentSegment.add(variableDeclaration);}
+ outlineInfo.addVariable(new String(variableDeclaration.name));}
)*
try {
@@ -798,7 +774,7 @@ FieldDeclaration FieldDeclaration() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
{list = new VariableDeclaration[arrayList.size()];
@@ -849,23 +825,26 @@ VariableDeclaration VariableDeclarator() :
*/
String VariableDeclaratorId() :
{
- String expr;
- Expression expression;
- final StringBuffer buff = new StringBuffer();
+ final String expr;
+ Expression expression = null;
final int pos = SimpleCharStream.getPosition();
ConstantIdentifier ex;
}
{
try {
- expr = Variable() {buff.append(expr);}
+ expr = Variable()
( LOOKAHEAD(2)
{ex = new ConstantIdentifier(expr.toCharArray(),
pos,
SimpleCharStream.getPosition());}
expression = VariableSuffix(ex)
- {buff.append(expression.toStringExpression());}
)*
- {return buff.toString();}
+ {
+ if (expression == null) {
+ return expr;
+ }
+ return expression.toStringExpression();
+ }
} catch (ParseException e) {
errorMessage = "'$' expected for variable identifier";
errorLevel = ERROR;
@@ -875,6 +854,10 @@ String VariableDeclaratorId() :
}
}
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ */
String Variable():
{
final StringBuffer buff;
@@ -885,24 +868,28 @@ String Variable():
{
token = [ expression = Expression() ]
{
- if (expression == null && !assigning) {
+ if (expression == null) {
return token.image.substring(1);
}
buff = new StringBuffer(token.image);
- buff.append('{');
+ buff.append("{");
buff.append(expression.toStringExpression());
- buff.append('}');
+ buff.append("}");
return buff.toString();
}
|
expr = VariableName()
- {return "$" + expr;}
+ {return expr;}
}
+/**
+ * A Variable name (without the $)
+ * @return a variable name String
+ */
String VariableName():
{
final StringBuffer buff;
- String expr = null;
+ final String expr;
Expression expression = null;
final Token token;
}
@@ -919,15 +906,15 @@ String VariableName():
return token.image;
}
buff = new StringBuffer(token.image);
- buff.append('{');
+ buff.append("{");
buff.append(expression.toStringExpression());
- buff.append('}');
+ buff.append("}");
return buff.toString();
}
|
expr = VariableName()
{
- buff = new StringBuffer('$');
+ buff = new StringBuffer("$");
buff.append(expr);
return buff.toString();
}
@@ -968,7 +955,7 @@ Expression VariableInitializer() :
ArrayVariableDeclaration ArrayVariable() :
{
-Expression expr,expr2;
+final Expression expr,expr2;
}
{
expr = Expression()
@@ -993,7 +980,7 @@ ArrayVariableDeclaration[] ArrayInitializer() :
[ {list.add(null);}]
{
- ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
+ final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
list.toArray(vars);
return vars;}
}
@@ -1006,6 +993,7 @@ MethodDeclaration MethodDeclaration() :
{
final MethodDeclaration functionDeclaration;
final Block block;
+ final OutlineableWithChildren seg = currentSegment;
}
{
@@ -1020,20 +1008,11 @@ MethodDeclaration MethodDeclaration() :
errorEnd = SimpleCharStream.getPosition() + 1;
throw e;
}
- {
- if (currentSegment != null) {
- currentSegment.add(functionDeclaration);
- currentSegment = functionDeclaration;
- }
- }
+ {currentSegment = functionDeclaration;}
block = Block()
- {
- functionDeclaration.statements = block.statements;
- if (currentSegment != null) {
- currentSegment = (OutlineableWithChildren) currentSegment.getParent();
- }
- return functionDeclaration;
- }
+ {functionDeclaration.statements = block.statements;
+ currentSegment = seg;
+ return functionDeclaration;}
}
/**
@@ -1047,16 +1026,27 @@ MethodDeclaration MethodDeclarator() :
Token reference = null;
final Hashtable formalParameters;
final int pos = SimpleCharStream.getPosition();
+ char[] identifierChar = SYNTAX_ERROR_CHAR;
}
{
- [reference = ] identifier =
+ [reference = ]
+ try {
+ identifier =
+ {identifierChar = identifier.image.toCharArray();}
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseException(e);
+ }
formalParameters = FormalParameters()
{return new MethodDeclaration(currentSegment,
- identifier.image.toCharArray(),
- formalParameters,
- reference != null,
- pos,
- SimpleCharStream.getPosition());}
+ identifierChar,
+ formalParameters,
+ reference != null,
+ pos,
+ SimpleCharStream.getPosition());}
}
/**
@@ -1076,7 +1066,7 @@ Hashtable FormalParameters() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
[ var = FormalParameter()
{parameters.put(new String(var.name),var);}
@@ -1092,7 +1082,7 @@ Hashtable FormalParameters() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
{return parameters;}
}
@@ -1119,79 +1109,83 @@ ConstantIdentifier Type() :
{final int pos;}
{
{pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.STRING,
- pos,pos-6);}
+ return new ConstantIdentifier(Types.STRING,pos,pos-6);}
| {pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.BOOL,
- pos,pos-4);}
+ return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
| {pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.BOOLEAN,
- pos,pos-7);}
+ return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
| {pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.REAL,
- pos,pos-4);}
+ return new ConstantIdentifier(Types.REAL,pos,pos-4);}
| {pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.DOUBLE,
- pos,pos-5);}
+ return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
| {pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.FLOAT,
- pos,pos-5);}
+ return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
| {pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.INT,
- pos,pos-3);}
+ return new ConstantIdentifier(Types.INT,pos,pos-3);}
| {pos = SimpleCharStream.getPosition();
- return new ConstantIdentifier(Types.INTEGER,
- pos,pos-7);}
+ return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
|