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 e69a928..2c1b336 100644
--- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj
+++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
@@ -3,7 +3,7 @@ options {
CHOICE_AMBIGUITY_CHECK = 2;
OTHER_AMBIGUITY_CHECK = 1;
STATIC = true;
- DEBUG_PARSER = false;
+ DEBUG_PARSER = true;
DEBUG_LOOKAHEAD = false;
DEBUG_TOKEN_MANAGER = false;
OPTIMIZE_TOKEN_MANAGER = false;
@@ -30,14 +30,17 @@ import org.eclipse.jface.preference.IPreferenceStore;
import java.util.Hashtable;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.io.StringReader;
import java.io.*;
import java.text.MessageFormat;
import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpdt.internal.compiler.parser.*;
+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;
+import net.sourceforge.phpdt.internal.corext.Assert;
/**
* A new php parser.
@@ -48,17 +51,12 @@ import net.sourceforge.phpdt.internal.compiler.parser.*;
*/
public final class PHPParser extends PHPParserSuperclass {
- /** The file that is parsed. */
- private static IFile fileToParse;
-
- /** The current segment */
- private static PHPSegmentWithChildren currentSegment;
+ /** The current segment. */
+ private static OutlineableWithChildren currentSegment;
private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
- PHPOutlineInfo outlineInfo;
-
- private static PHPFunctionDeclaration currentFunction;
+ static PHPOutlineInfo outlineInfo;
/** The error level of the current ParseException. */
private static int errorLevel = ERROR;
@@ -67,67 +65,131 @@ public final class PHPParser extends PHPParserSuperclass {
private static int errorStart = -1;
private static int errorEnd = -1;
+ private static PHPDocument phpDocument;
- public PHPParser() {
- }
+ 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
+ */
+ public static int htmlStart;
+
+ //ast stack
+ private final static int AstStackIncrement = 100;
+ /** The stack of node. */
+ private static AstNode[] nodes;
+ /** The cursor in expression stack. */
+ private static int nodePtr;
+
+ private static final boolean PARSER_DEBUG = true;
public final void setFileToParse(final IFile fileToParse) {
- this.fileToParse = fileToParse;
+ PHPParser.fileToParse = fileToParse;
+ }
+
+ public PHPParser() {
}
public PHPParser(final IFile fileToParse) {
this(new StringReader(""));
- this.fileToParse = fileToParse;
+ PHPParser.fileToParse = fileToParse;
}
- public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
- PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
+ public static final void phpParserTester(final String strEval) throws ParseException {
final StringReader stream = new StringReader(strEval);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
ReInit(new StringReader(strEval));
+ init();
+ phpDocument = new PHPDocument(null,"_root".toCharArray());
+ currentSegment = phpDocument;
+ outlineInfo = new PHPOutlineInfo(null, currentSegment);
+ PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
phpTest();
}
- public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
- try {
- final Reader stream = new FileReader(fileName);
- if (jj_input_stream == null) {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
- }
- ReInit(stream);
- phpFile();
- } catch (FileNotFoundException e) {
- e.printStackTrace(); //To change body of catch statement use Options | File Templates.
+ public static final void htmlParserTester(final File fileName) throws FileNotFoundException, ParseException {
+ final Reader stream = new FileReader(fileName);
+ if (jj_input_stream == null) {
+ jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
+ ReInit(stream);
+ init();
+ phpDocument = new PHPDocument(null,"_root".toCharArray());
+ currentSegment = phpDocument;
+ outlineInfo = new PHPOutlineInfo(null, currentSegment);
+ phpFile();
}
- public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
+ public static final void htmlParserTester(final String strEval) throws ParseException {
final StringReader stream = new StringReader(strEval);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
ReInit(stream);
+ init();
+ phpDocument = new PHPDocument(null,"_root".toCharArray());
+ currentSegment = phpDocument;
+ outlineInfo = new PHPOutlineInfo(null, currentSegment);
phpFile();
}
+ /**
+ * Reinitialize the parser.
+ */
+ private static final void init() {
+ nodes = new AstNode[AstStackIncrement];
+ nodePtr = -1;
+ htmlStart = 0;
+ }
+
+ /**
+ * Add an php node on the stack.
+ * @param node the node that will be added to the stack
+ */
+ private static final void pushOnAstNodes(final AstNode node) {
+ try {
+ nodes[++nodePtr] = node;
+ } catch (IndexOutOfBoundsException e) {
+ final int oldStackLength = nodes.length;
+ final AstNode[] oldStack = nodes;
+ nodes = new AstNode[oldStackLength + AstStackIncrement];
+ System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
+ nodePtr = oldStackLength;
+ nodes[nodePtr] = node;
+ }
+ }
+
public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
- outlineInfo = new PHPOutlineInfo(parent);
- currentSegment = outlineInfo.getDeclarations();
+ phpDocument = new PHPDocument(parent,"_root".toCharArray());
+ currentSegment = phpDocument;
+ outlineInfo = new PHPOutlineInfo(parent, currentSegment);
final StringReader stream = new StringReader(s);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
ReInit(stream);
+ init();
try {
parse();
+ phpDocument.nodes = new AstNode[nodes.length];
+ System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
+ if (PHPeclipsePlugin.DEBUG) {
+ PHPeclipsePlugin.log(1,phpDocument.toString());
+ }
} catch (ParseException e) {
processParseException(e);
}
return outlineInfo;
}
+ private static void processParseExceptionDebug(final ParseException e) throws ParseException {
+ if (PARSER_DEBUG) {
+ throw e;
+ }
+ processParseException(e);
+ }
/**
* This method will process the parse exception.
* If the error message is null, the parse exception wasn't catched and a trace is written in the log
@@ -137,15 +199,16 @@ public final class PHPParser extends PHPParserSuperclass {
if (errorMessage == null) {
PHPeclipsePlugin.log(e);
errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
- errorStart = jj_input_stream.getPosition();
+ errorStart = SimpleCharStream.getPosition();
errorEnd = errorStart + 1;
}
setMarker(e);
errorMessage = null;
+ // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
}
/**
- * Create marker for the parse error
+ * Create marker for the parse error.
* @param e the ParseException
*/
private static void setMarker(final ParseException e) {
@@ -153,8 +216,8 @@ public final class PHPParser extends PHPParserSuperclass {
if (errorStart == -1) {
setMarker(fileToParse,
errorMessage,
- jj_input_stream.tokenBegin,
- jj_input_stream.tokenBegin + e.currentToken.image.length(),
+ SimpleCharStream.tokenBegin,
+ SimpleCharStream.tokenBegin + e.currentToken.image.length(),
errorLevel,
"Line " + e.currentToken.beginLine);
} else {
@@ -172,42 +235,17 @@ 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,
final int brIndx) throws CoreException {
String current;
- StringBuffer lineNumberBuffer = new StringBuffer(10);
+ final StringBuffer lineNumberBuffer = new StringBuffer(10);
char ch;
current = output.substring(indx, brIndx);
if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
- int onLine = current.indexOf("on line ");
+ final int onLine = current.indexOf("on line ");
if (onLine != -1) {
lineNumberBuffer.delete(0, lineNumberBuffer.length());
for (int i = onLine; i < current.length(); i++) {
@@ -217,9 +255,9 @@ public final class PHPParser extends PHPParserSuperclass {
}
}
- int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
+ final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
- Hashtable attributes = new Hashtable();
+ final Hashtable attributes = new Hashtable();
current = current.replaceAll("\n", "");
current = current.replaceAll("", "");
@@ -238,12 +276,13 @@ public final class PHPParser extends PHPParserSuperclass {
}
}
- public final void parse(final String s) throws CoreException {
+ public final void parse(final String s) {
final StringReader stream = new StringReader(s);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
ReInit(stream);
+ init();
try {
parse();
} catch (ParseException e) {
@@ -273,7 +312,37 @@ public final class PHPParser extends PHPParserSuperclass {
}
}
- public static final void parse() throws ParseException {
+ /**
+ * Put a new html block in the stack.
+ */
+ public static final void createNewHTMLCode() {
+ final int currentPosition = SimpleCharStream.getPosition();
+ 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-3,
+ SimpleCharStream.currentBuffer.indexOf("\n",
+ currentPosition)-1);
+ PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString());
+ try {
+ setMarker(fileToParse,
+ todo,
+ SimpleCharStream.getBeginLine(),
+ TASK,
+ "Line "+SimpleCharStream.getBeginLine());
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }
+ }
+
+ private static final void parse() throws ParseException {
phpFile();
}
}
@@ -282,14 +351,14 @@ PARSER_END(PHPParser)
TOKEN :
{
- : PHPPARSING
-| : PHPPARSING
-| : PHPPARSING
+ {PHPParser.createNewHTMLCode();} : PHPPARSING
+| {PHPParser.createNewHTMLCode();} : PHPPARSING
+| {PHPParser.createNewHTMLCode();} : PHPPARSING
}
TOKEN :
{
- "> : DEFAULT
+ "> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
}
/* Skip any character if we are not in php mode */
@@ -313,34 +382,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
}
@@ -373,6 +438,7 @@ MORE :
|
|
|
+|
|
| ">
|
@@ -422,73 +488,74 @@ MORE :
|
}
+//Misc token
+ TOKEN :
+{
+
+|
+|
+|
+|
+|
+}
+
+/* OPERATORS */
TOKEN :
{
- <_ORL : "OR">
-| <_ANDL : "AND">
+
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+| >">
+| >>">
+| <_ORL : "OR">
+| <_ANDL : "AND">
}
/* LITERALS */
TOKEN :
{
- < INTEGER_LITERAL:
+ (["l","L"])?
| (["l","L"])?
| (["l","L"])?
>
|
- < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+ <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
|
- < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+ <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
|
- < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+ <#OCTAL_LITERAL: "0" (["0"-"7"])* >
|
- < FLOATING_POINT_LITERAL:
+ )? (["f","F","d","D"])?
| "." (["0"-"9"])+ ()? (["f","F","d","D"])?
| (["0"-"9"])+ (["f","F","d","D"])?
| (["0"-"9"])+ ()? ["f","F","d","D"]
>
|
- < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+ <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|
- < STRING_LITERAL: ( | | )>
-| < STRING_1:
- "\""
- (
- ~["\""] | ~["{"]
- |
- "\\\""
- | "{" ~["\""] "}"
- )*
- "\""
- >
-| < STRING_2:
- "'"
- (
- ~["'"]
- |
- "\\'"
- )*
-
- "'"
- >
-| < STRING_3:
- "`"
- (
- ~["`"]
- |
- "\\`"
- )*
- "`"
- >
+ | | )>
+|
+|
+|
}
/* IDENTIFIERS */
TOKEN :
{
- < IDENTIFIER: (|) (||)* >
+ |) (||)* >
|
< #LETTER:
["a"-"z"] | ["A"-"Z"]
@@ -524,10 +591,10 @@ MORE :
{
">
|
-|
+|
|
| =">
-|
+|
| ">
|
|
@@ -547,39 +614,13 @@ MORE :
|
|
|
-}
-
-/* OPERATORS */
- TOKEN :
-{
-
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-|
-| >">
-| >>">
|
| >=">
}
TOKEN :
{
- < DOLLAR_ID: >
+ >
}
void phpTest() :
@@ -594,7 +635,7 @@ void phpFile() :
{
try {
(PhpBlock())*
-
+ {PHPParser.createNewHTMLCode();}
} catch (TokenMgrError e) {
PHPeclipsePlugin.log(e);
errorStart = SimpleCharStream.getPosition();
@@ -612,18 +653,20 @@ void phpFile() :
*/
void PhpBlock() :
{
- final int start = jj_input_stream.getPosition();
+ final int start = SimpleCharStream.getPosition();
+ final PHPEchoBlock phpEchoBlock;
}
{
- phpEchoBlock()
+ phpEchoBlock = phpEchoBlock()
+ {pushOnAstNodes(phpEchoBlock);}
|
- [
+ [
|
{try {
setMarker(fileToParse,
"You should use '' expected";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
}
-void phpEchoBlock() :
-{}
+PHPEchoBlock phpEchoBlock() :
{
- Expression() [ ]
+ final Expression expr;
+ final int pos = SimpleCharStream.getPosition();
+ final PHPEchoBlock echoBlock;
+}
+{
+ expr = Expression() [ ]
+ {
+ echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
+ pushOnAstNodes(echoBlock);
+ return echoBlock;}
}
void Php() :
@@ -654,350 +705,447 @@ void Php() :
(BlockStatement())*
}
-void ClassDeclaration() :
+ClassDeclaration ClassDeclaration() :
{
- final PHPClassDeclaration classDeclaration;
- final Token className;
+ final ClassDeclaration classDeclaration;
+ final Token className,superclassName;
final int pos;
+ char[] classNameImage = SYNTAX_ERROR_CHAR;
+ char[] superclassNameImage = null;
}
{
+ {pos = SimpleCharStream.getPosition();}
try {
- {pos = jj_input_stream.getPosition();}
className =
+ {classNameImage = className.image.toCharArray();}
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
[
try {
-
+ superclassName =
+ {superclassNameImage = superclassName.image.toCharArray();}
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
+ superclassNameImage = SYNTAX_ERROR_CHAR;
}
]
{
- if (currentSegment != null) {
- classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
+ if (superclassNameImage == null) {
+ classDeclaration = new ClassDeclaration(currentSegment,
+ classNameImage,
+ pos,
+ 0);
+ } else {
+ classDeclaration = new ClassDeclaration(currentSegment,
+ classNameImage,
+ superclassNameImage,
+ pos,
+ 0);
+ }
currentSegment.add(classDeclaration);
currentSegment = classDeclaration;
- }
- }
- ClassBody()
- {
- if (currentSegment != null) {
- currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
- }
}
+ ClassBody(classDeclaration)
+ {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
+ classDeclaration.setSourceEnd(SimpleCharStream.getPosition());
+ pushOnAstNodes(classDeclaration);
+ return classDeclaration;}
}
-void ClassBody() :
+void ClassBody(final ClassDeclaration classDeclaration) :
{}
{
try {
} catch (ParseException e) {
- errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
- ( ClassBodyDeclaration() )*
+ ( ClassBodyDeclaration(classDeclaration) )*
try {
} catch (ParseException e) {
- errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
}
/**
* A class can contain only methods and fields.
*/
-void ClassBodyDeclaration() :
-{}
+void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
{
- MethodDeclaration()
-|
- FieldDeclaration()
+ final MethodDeclaration method;
+ final FieldDeclaration field;
+}
+{
+ method = MethodDeclaration() {method.analyzeCode();
+ classDeclaration.addMethod(method);}
+| field = FieldDeclaration() {classDeclaration.addField(field);}
}
/**
* A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
+ * it is only used by ClassBodyDeclaration()
*/
-void FieldDeclaration() :
+FieldDeclaration FieldDeclaration() :
{
- PHPVarDeclaration variableDeclaration;
+ VariableDeclaration variableDeclaration;
+ final VariableDeclaration[] list;
+ final ArrayList arrayList = new ArrayList();
+ final int pos = SimpleCharStream.getPosition();
}
{
- variableDeclaration = VariableDeclarator()
- {
- if (currentSegment != null) {
- currentSegment.add(variableDeclaration);
- }
- }
- (
- variableDeclaration = VariableDeclarator()
- {
- if (currentSegment != null) {
- currentSegment.add(variableDeclaration);
- }
- }
+ variableDeclaration = VariableDeclaratorNoSuffix()
+ {arrayList.add(variableDeclaration);
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
+ (
+ variableDeclaration = VariableDeclaratorNoSuffix()
+ {arrayList.add(variableDeclaration);
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
)*
try {
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
+
+ {list = new VariableDeclaration[arrayList.size()];
+ arrayList.toArray(list);
+ return new FieldDeclaration(list,
+ pos,
+ SimpleCharStream.getPosition(),
+ currentSegment);}
}
-PHPVarDeclaration VariableDeclarator() :
+/**
+ * a strict variable declarator : there cannot be a suffix here.
+ * It will be used by fields and formal parameters
+ */
+VariableDeclaration VariableDeclaratorNoSuffix() :
{
- final String varName, varValue;
- final int pos = jj_input_stream.getPosition();
+ final Token varName;
+ Expression initializer = null;
}
{
- varName = VariableDeclaratorId()
+ varName =
+ {final int pos = SimpleCharStream.getPosition()-varName.image.length();}
[
try {
- varValue = VariableInitializer()
- {return new PHPVarDeclaration(currentSegment,varName.substring(1),pos,varValue);}
+ initializer = VariableInitializer()
} catch (ParseException e) {
errorMessage = "Literal expression expected in variable initializer";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
]
- {return new PHPVarDeclaration(currentSegment,varName,pos);}
+ {
+ if (initializer == null) {
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName.image.substring(1),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
+ pos,
+ SimpleCharStream.getPosition());
+ }
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName.image.substring(1),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
+ initializer,
+ VariableDeclaration.EQUAL,
+ pos);
+ }
}
-String VariableDeclaratorId() :
+/**
+ * this will be used by static statement
+ */
+VariableDeclaration VariableDeclarator() :
{
- String expr;
- final StringBuffer buff = new StringBuffer();
+ final AbstractVariable variable;
+ Expression initializer = null;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ variable = VariableDeclaratorId()
+ [
+
+ try {
+ initializer = VariableInitializer()
+ } catch (ParseException e) {
+ errorMessage = "Literal expression expected in variable initializer";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
+ }
+ ]
+ {
+ if (initializer == null) {
+ return new VariableDeclaration(currentSegment,
+ variable,
+ pos,
+ SimpleCharStream.getPosition());
+ }
+ return new VariableDeclaration(currentSegment,
+ variable,
+ initializer,
+ VariableDeclaration.EQUAL,
+ pos);
+ }
+}
+
+/**
+ * A Variable name.
+ * @return the variable name (with suffix)
+ */
+AbstractVariable VariableDeclaratorId() :
+{
+ final Variable var;
+ AbstractVariable expression = null;
+ final int pos = SimpleCharStream.getPosition();
}
{
try {
- expr = Variable()
- {buff.append(expr);}
- ( LOOKAHEAD(2) expr = VariableSuffix()
- {buff.append(expr);}
+ var = Variable()
+ (
+ LOOKAHEAD(2)
+ expression = VariableSuffix(var)
)*
- {return buff.toString();}
+ {
+ if (expression == null) {
+ return var;
+ }
+ return expression;
+ }
} catch (ParseException e) {
errorMessage = "'$' expected for variable identifier";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
throw e;
}
}
-String Variable():
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ */
+Variable Variable():
{
- String expr = null;
+ final StringBuffer buff;
+ Expression expression = null;
final Token token;
+ Variable expr;
+ final int pos;
}
{
- token = [ expr = Expression() ]
+ token = {pos = SimpleCharStream.getPosition()-token.image.length();}
+ [ expression = Expression() ]
{
- if (expr == null) {
- if (currentFunction != null) {
- PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1));
- if (var != null) {
- var.getVariable().setUsed(true);
- }
- }
- return token.image;
+ if (expression == null) {
+ return new Variable(token.image.substring(1),pos,SimpleCharStream.getPosition());
}
- return token + "{" + expr + "}";
+ String s = expression.toStringExpression();
+ buff = new StringBuffer(token.image.length()+s.length()+2);
+ buff.append(token.image);
+ buff.append("{");
+ buff.append(s);
+ buff.append("}");
+ s = buff.toString();
+ return new Variable(s,pos,SimpleCharStream.getPosition());
}
|
- expr = VariableName()
- {return "$" + expr;}
+ {pos = SimpleCharStream.getPosition()-1;}
+ expr = VariableName()
+ {return new Variable(expr,pos,SimpleCharStream.getPosition());}
}
-String VariableName():
+/**
+ * A Variable name (without the $)
+ * @return a variable name String
+ */
+Variable VariableName():
{
-String expr = null;
-final Token token;
+ final StringBuffer buff;
+ String expr;
+ final Variable var;
+ Expression expression = null;
+ final Token token;
+ int pos;
}
{
- expr = Expression()
- {return "{"+expr+"}";}
+
+ {pos = SimpleCharStream.getPosition()-1;}
+ expression = Expression()
+ {expr = expression.toStringExpression();
+ buff = new StringBuffer(expr.length()+2);
+ buff.append("{");
+ buff.append(expr);
+ buff.append("}");
+ pos = SimpleCharStream.getPosition();
+ expr = buff.toString();
+ return new Variable(expr,
+ pos,
+ SimpleCharStream.getPosition());
+
+ }
|
- token = [ expr = Expression() ]
+ token =
+ {pos = SimpleCharStream.getPosition() - token.image.length();}
+ [ expression = Expression() ]
{
- if (expr == null) {
- if (currentFunction != null) {
- PHPVarDeclaration var = currentFunction.getParameter(token.image);
- if (var != null) {
- var.getVariable().setUsed(true);
- }
- }
- return token.image;
+ if (expression == null) {
+ return new Variable(token.image,
+ pos,
+ SimpleCharStream.getPosition());
}
- return token + "{" + expr + "}";
+ expr = expression.toStringExpression();
+ buff = new StringBuffer(token.image.length()+expr.length()+2);
+ buff.append(token.image);
+ buff.append("{");
+ buff.append(expr);
+ buff.append("}");
+ expr = buff.toString();
+ return new Variable(expr,
+ pos,
+ SimpleCharStream.getPosition());
}
|
- expr = VariableName()
+ {pos = SimpleCharStream.getPosition() - 1;}
+ var = VariableName()
{
- if (currentFunction != null) {
- PHPVarDeclaration var = currentFunction.getParameter(expr);
- if (var != null) {
- var.getVariable().setUsed(true);
- }
- }
- return "$" + expr;
+ return new Variable(var,
+ pos,
+ SimpleCharStream.getPosition());
}
|
token =
{
- if (currentFunction != null) {
- PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1));
- if (var != null) {
- var.getVariable().setUsed(true);
- }
- }
- return token.image + expr;
+ pos = SimpleCharStream.getPosition();
+ return new Variable(token.image,
+ pos-token.image.length(),
+ pos);
}
-/*| pas besoin ?
- token = [expr = VariableName()]
- {
- if (expr == null) {
- return token.image;
- }
- return token.image + expr;
- }*/
}
-String VariableInitializer() :
+Expression VariableInitializer() :
{
- final String expr;
+ final Expression expr;
final Token token;
+ final int pos = SimpleCharStream.getPosition();
}
{
expr = Literal()
{return expr;}
|
(token = | token = )
- {return "-" + token.image;}
+ {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
+ pos,
+ SimpleCharStream.getPosition()),
+ OperatorIds.MINUS,
+ pos);}
|
(token = | token = )
- {return "+" + token.image;}
+ {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
+ pos,
+ SimpleCharStream.getPosition()),
+ OperatorIds.PLUS,
+ pos);}
|
expr = ArrayDeclarator()
{return expr;}
|
token =
- {return token.image;}
+ {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
}
-String ArrayVariable() :
+ArrayVariableDeclaration ArrayVariable() :
{
-String expr;
-final StringBuffer buff = new StringBuffer();
+final Expression expr,expr2;
}
{
expr = Expression()
- {buff.append(expr);}
- [ expr = Expression()
- {buff.append("=>").append(expr);}]
- {return buff.toString();}
+ [
+ expr2 = Expression()
+ {return new ArrayVariableDeclaration(expr,expr2);}
+ ]
+ {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
}
-String ArrayInitializer() :
+ArrayVariableDeclaration[] ArrayInitializer() :
{
-String expr;
-final StringBuffer buff = new StringBuffer("(");
+ ArrayVariableDeclaration expr;
+ final ArrayList list = new ArrayList();
}
{
- [ expr = ArrayVariable()
- {buff.append(expr);}
- ( LOOKAHEAD(2) expr = ArrayVariable()
- {buff.append(",").append(expr);}
- )*
- ]
- [ {buff.append(",");}]
+
+ [
+ expr = ArrayVariable()
+ {list.add(expr);}
+ ( LOOKAHEAD(2) expr = ArrayVariable()
+ {list.add(expr);}
+ )*
+ ]
+ [
+ {list.add(null);}
+ ]
{
- buff.append(")");
- return buff.toString();
- }
+ final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
+ list.toArray(vars);
+ return vars;}
}
/**
* A Method Declaration.
* function MetodDeclarator() Block()
*/
-void MethodDeclaration() :
+MethodDeclaration MethodDeclaration() :
{
- final PHPFunctionDeclaration functionDeclaration;
- Token functionToken;
+ final MethodDeclaration functionDeclaration;
+ final Block block;
+ final OutlineableWithChildren seg = currentSegment;
}
{
- functionToken =
+
try {
functionDeclaration = MethodDeclarator()
+ {outlineInfo.addVariable(new String(functionDeclaration.name));}
} catch (ParseException e) {
- if (errorMessage != null) {
- throw e;
- }
+ if (errorMessage != null) throw e;
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
throw e;
}
- {
- if (currentSegment != null) {
- currentSegment.add(functionDeclaration);
- currentSegment = functionDeclaration;
- }
- currentFunction = functionDeclaration;
- }
- Block()
- {
- Hashtable parameters = currentFunction.getParameters();
- Enumeration vars = parameters.elements();
- while (vars.hasMoreElements()) {
- PHPVarDeclaration o = (PHPVarDeclaration) vars.nextElement();
- if (!o.getVariable().isUsed()) {
- try {
- setMarker(fileToParse,
- "Parameter "+o.getVariable().getName()+" is never used in function",
- functionToken.beginLine,
- WARNING,
- "Line " + token.beginLine);
- } catch (CoreException e) {
- PHPeclipsePlugin.log(e);
- }
- }
- }
- currentFunction = null;
- if (currentSegment != null) {
- currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
- }
- }
+ {currentSegment = functionDeclaration;}
+ block = Block()
+ {functionDeclaration.statements = block.statements;
+ currentSegment = seg;
+ return functionDeclaration;}
}
/**
@@ -1005,21 +1153,34 @@ void MethodDeclaration() :
* [&] IDENTIFIER(parameters ...).
* @return a function description for the outline
*/
-PHPFunctionDeclaration MethodDeclarator() :
+MethodDeclaration MethodDeclarator() :
{
final Token identifier;
- final StringBuffer methodDeclaration = new StringBuffer();
+ Token reference = null;
final Hashtable formalParameters;
- final int pos = jj_input_stream.getPosition();
+ final int pos = SimpleCharStream.getPosition();
+ char[] identifierChar = SYNTAX_ERROR_CHAR;
}
{
- [ {methodDeclaration.append("&");} ]
- identifier =
- formalParameters = FormalParameters()
- {
- methodDeclaration.append(identifier);
- return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos,formalParameters);
+ [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;
+ processParseExceptionDebug(e);
}
+ formalParameters = FormalParameters()
+ {MethodDeclaration method = new MethodDeclaration(currentSegment,
+ identifierChar,
+ formalParameters,
+ reference != null,
+ pos,
+ SimpleCharStream.getPosition());
+ return method;}
}
/**
@@ -1028,9 +1189,7 @@ PHPFunctionDeclaration MethodDeclarator() :
*/
Hashtable FormalParameters() :
{
- String expr;
- final StringBuffer buff = new StringBuffer("(");
- PHPVarDeclaration var;
+ VariableDeclaration var;
final Hashtable parameters = new Hashtable();
}
{
@@ -1039,25 +1198,26 @@ Hashtable FormalParameters() :
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
- [ var = FormalParameter()
- {parameters.put(var.getVariable().getName(),var);}
- (
- var = FormalParameter()
- {parameters.put(var.getVariable().getName(),var);}
- )*
- ]
+ [
+ var = FormalParameter()
+ {parameters.put(new String(var.name()),var);}
+ (
+ var = FormalParameter()
+ {parameters.put(new String(var.name()),var);}
+ )*
+ ]
try {
} catch (ParseException e) {
errorMessage = "')' expected";
errorLevel = ERROR;
- errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = jj_input_stream.getPosition() + 1;
- throw e;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseExceptionDebug(e);
}
{return parameters;}
}
@@ -1066,389 +1226,390 @@ Hashtable FormalParameters() :
* A formal parameter.
* $varname[=value] (,$varname[=value])
*/
-PHPVarDeclaration FormalParameter() :
+VariableDeclaration FormalParameter() :
{
- final PHPVarDeclaration variableDeclaration;
+ final VariableDeclaration variableDeclaration;
Token token = null;
}
{
- [token = ] variableDeclaration = VariableDeclarator()
+ [token = ] variableDeclaration = VariableDeclaratorNoSuffix()
{
if (token != null) {
- variableDeclaration.getVariable().setPrefix("@");
+ variableDeclaration.setReference(true);
}
- return variableDeclaration;
- }
+ return variableDeclaration;}
}
-String Type() :
-{}
+ConstantIdentifier Type() :
+{final int pos;}
{
-
- {return "string";}
-|
-
- {return "bool";}
-|
-
- {return "boolean";}
-|
-
- {return "real";}
-|
-
- {return "double";}
-|
-
- {return "float";}
-|
-
- {return "int";}
-|
-
- {return "integer";}
-|
-