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 23b070d..f82c7cd 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,9 +61,6 @@ public final class PHPParser extends PHPParserSuperclass {
private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
static PHPOutlineInfo outlineInfo;
- public static MethodDeclaration currentFunction;
- 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 */
@@ -71,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
@@ -83,12 +83,6 @@ public final class PHPParser extends PHPParserSuperclass {
private static AstNode[] nodes;
/** The cursor in expression stack. */
private static int nodePtr;
- private static VariableDeclaration[] variableDeclarationStack;
- private static int variableDeclarationPtr;
- private static Statement[] statementStack;
- private static int statementPtr;
- private static ElseIf[] elseIfStack;
- private static int elseIfPtr;
public final void setFileToParse(final IFile fileToParse) {
this.fileToParse = fileToParse;
@@ -107,11 +101,7 @@ public final class PHPParser extends PHPParserSuperclass {
*/
private static final void init() {
nodes = new AstNode[AstStackIncrement];
- statementStack = new Statement[AstStackIncrement];
- elseIfStack = new ElseIf[AstStackIncrement];
nodePtr = -1;
- statementPtr = -1;
- elseIfPtr = -1;
htmlStart = 0;
}
@@ -119,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;
@@ -132,83 +122,10 @@ public final class PHPParser extends PHPParserSuperclass {
}
}
- private static final void pushOnVariableDeclarationStack(VariableDeclaration var) {
- try {
- variableDeclarationStack[++variableDeclarationPtr] = var;
- } catch (IndexOutOfBoundsException e) {
- int oldStackLength = variableDeclarationStack.length;
- VariableDeclaration[] oldStack = variableDeclarationStack;
- variableDeclarationStack = new VariableDeclaration[oldStackLength + AstStackIncrement];
- System.arraycopy(oldStack, 0, variableDeclarationStack, 0, oldStackLength);
- variableDeclarationPtr = oldStackLength;
- variableDeclarationStack[variableDeclarationPtr] = var;
- }
- }
-
- private static final void pushOnStatementStack(Statement statement) {
- try {
- statementStack[++statementPtr] = statement;
- } catch (IndexOutOfBoundsException e) {
- int oldStackLength = statementStack.length;
- Statement[] oldStack = statementStack;
- statementStack = new Statement[oldStackLength + AstStackIncrement];
- System.arraycopy(oldStack, 0, statementStack, 0, oldStackLength);
- statementPtr = oldStackLength;
- statementStack[statementPtr] = statement;
- }
- }
-
- private static final void pushOnElseIfStack(ElseIf elseIf) {
- try {
- elseIfStack[++elseIfPtr] = elseIf;
- } catch (IndexOutOfBoundsException e) {
- int oldStackLength = elseIfStack.length;
- ElseIf[] oldStack = elseIfStack;
- elseIfStack = new ElseIf[oldStackLength + AstStackIncrement];
- System.arraycopy(oldStack, 0, elseIfStack, 0, oldStackLength);
- elseIfPtr = oldStackLength;
- elseIfStack[elseIfPtr] = elseIf;
- }
- }
-
- public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
- PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
- final StringReader stream = new StringReader(strEval);
- if (jj_input_stream == null) {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
- }
- ReInit(new StringReader(strEval));
- init();
- 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);
- init();
- phpFile();
- } catch (FileNotFoundException e) {
- e.printStackTrace(); //To change body of catch statement use Options | File Templates.
- }
- }
-
- public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
- final StringReader stream = new StringReader(strEval);
- if (jj_input_stream == null) {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
- }
- ReInit(stream);
- init();
- phpFile();
- }
-
public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
- currentSegment = new PHPDocument(parent);
- outlineInfo = new PHPOutlineInfo(parent);
+ 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);
@@ -217,9 +134,11 @@ public final class PHPParser extends PHPParserSuperclass {
init();
try {
parse();
- phpDocument = new PHPDocument(null);
- phpDocument.nodes = nodes;
- PHPeclipsePlugin.log(1,phpDocument.toString());
+ 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);
}
@@ -235,7 +154,7 @@ 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);
@@ -251,8 +170,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 {
@@ -270,31 +189,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,
@@ -377,13 +271,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).toCharArray();
+ 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();
}
@@ -424,34 +337,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
}
@@ -484,6 +393,7 @@ MORE :
|
|
|
+|
|
| ">
|
@@ -549,8 +459,8 @@ MORE :
{
|
-|
-|
+|
+|
|
|
|
@@ -569,55 +479,31 @@ MORE :
/* 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 */
@@ -689,15 +575,7 @@ MORE :
TOKEN :
{
- < DOLLAR_ID: >
-}
-
-void phpTest() :
-{}
-{
- Php()
-
- {PHPParser.createNewHTMLCode();}
+ >
}
void phpFile() :
@@ -705,7 +583,7 @@ void phpFile() :
{
try {
(PhpBlock())*
-
+ {PHPParser.createNewHTMLCode();}
} catch (TokenMgrError e) {
PHPeclipsePlugin.log(e);
errorStart = SimpleCharStream.getPosition();
@@ -723,18 +601,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;
+ processParseException(e);
}
}
@@ -757,7 +637,7 @@ PHPEchoBlock phpEchoBlock() :
{
final Expression expr;
final int pos = SimpleCharStream.getPosition();
- PHPEchoBlock echoBlock;
+ final PHPEchoBlock echoBlock;
}
{
expr = Expression() [ ]
@@ -776,44 +656,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 = 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;
+ processParseException(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;
+ 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);
}
@@ -827,7 +711,7 @@ ClassDeclaration ClassDeclaration() :
return classDeclaration;}
}
-void ClassBody(ClassDeclaration classDeclaration) :
+void ClassBody(final ClassDeclaration classDeclaration) :
{}
{
try {
@@ -835,8 +719,8 @@ void ClassBody(ClassDeclaration classDeclaration) :
} catch (ParseException e) {
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;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
throw e;
}
( ClassBodyDeclaration(classDeclaration) )*
@@ -845,8 +729,8 @@ void ClassBody(ClassDeclaration classDeclaration) :
} catch (ParseException e) {
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;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
throw e;
}
}
@@ -854,14 +738,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() {classDeclaration.addMethod(method);}
-| field = FieldDeclaration() {classDeclaration.addVariable(field);}
+| field = FieldDeclaration() {classDeclaration.addField(field);}
}
/**
@@ -870,42 +754,41 @@ 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 {
} 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;
+ processParseException(e);
}
{list = new VariableDeclaration[arrayList.size()];
arrayList.toArray(list);
return new FieldDeclaration(list,
pos,
- SimpleCharStream.getPosition());}
+ SimpleCharStream.getPosition(),
+ currentSegment);}
}
VariableDeclaration VariableDeclarator() :
{
- final String varName, varValue;
+ final String varName;
Expression initializer = null;
- final int pos = jj_input_stream.getPosition();
+ final int pos = SimpleCharStream.getPosition();
}
{
varName = VariableDeclaratorId()
@@ -916,8 +799,8 @@ VariableDeclaration VariableDeclarator() :
} 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;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
throw e;
}
]
@@ -926,7 +809,7 @@ VariableDeclaration VariableDeclarator() :
return new VariableDeclaration(currentSegment,
varName.toCharArray(),
pos,
- jj_input_stream.getPosition());
+ SimpleCharStream.getPosition());
}
return new VariableDeclaration(currentSegment,
varName.toCharArray(),
@@ -941,32 +824,39 @@ 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;
- 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;
}
}
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ */
String Variable():
{
final StringBuffer buff;
@@ -977,13 +867,13 @@ 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();
}
|
@@ -991,18 +881,22 @@ String Variable():
{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;
}
{
expression = Expression()
- {buff = new StringBuffer('{');
+ {buff = new StringBuffer("{");
buff.append(expression.toStringExpression());
- buff.append('}');
+ buff.append("}");
return buff.toString();}
|
token = [ expression = Expression() ]
@@ -1011,15 +905,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();
}
@@ -1060,7 +954,7 @@ Expression VariableInitializer() :
ArrayVariableDeclaration ArrayVariable() :
{
-Expression expr,expr2;
+final Expression expr,expr2;
}
{
expr = Expression()
@@ -1085,7 +979,7 @@ ArrayVariableDeclaration[] ArrayInitializer() :
[ {list.add(null);}]
{
- ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
+ final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
list.toArray(vars);
return vars;}
}
@@ -1097,40 +991,27 @@ ArrayVariableDeclaration[] ArrayInitializer() :
MethodDeclaration MethodDeclaration() :
{
final MethodDeclaration functionDeclaration;
- Token functionToken;
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;
- }
+ {currentSegment = functionDeclaration;}
block = Block()
- {
- functionDeclaration.statements = block.statements;
- currentFunction = null;
- if (currentSegment != null) {
- currentSegment = (OutlineableWithChildren) currentSegment.getParent();
- }
- return functionDeclaration;
- }
+ {functionDeclaration.statements = block.statements;
+ currentSegment = seg;
+ return functionDeclaration;}
}
/**
@@ -1144,17 +1025,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());}
}
/**
@@ -1163,8 +1054,6 @@ MethodDeclaration MethodDeclarator() :
*/
Hashtable FormalParameters() :
{
- String expr;
- final StringBuffer buff = new StringBuffer("(");
VariableDeclaration var;
final Hashtable parameters = new Hashtable();
}
@@ -1174,9 +1063,9 @@ 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;
+ processParseException(e);
}
[ var = FormalParameter()
{parameters.put(new String(var.name),var);}
@@ -1190,9 +1079,9 @@ Hashtable FormalParameters() :
} 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;
+ processParseException(e);
}
{return parameters;}
}
@@ -1219,37 +1108,38 @@ 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);}
|