X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index 46fb115..2a86a45 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -202,7 +202,11 @@ public class PHPParser extends PHPParserSuperclass { } public void parse(String s) throws CoreException { - ReInit(new StringReader(s)); + StringReader stream = new StringReader(s); + if (jj_input_stream == null) { + jj_input_stream = new SimpleCharStream(stream, 1, 1); + } + ReInit(stream); try { parse(); } catch (ParseException e) { @@ -356,6 +360,8 @@ MORE : | < TRUE: "true" > | < WHILE: "while" > | < ENDWHILE : "endwhile" > +| +| | | } @@ -487,6 +493,7 @@ MORE : | =" > | " > | | | @@ -566,13 +573,17 @@ void ClassDeclaration() : { className = [ ] { - classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos); - currentSegment.add(classDeclaration); - currentSegment = classDeclaration; + if (currentSegment != null) { + classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos); + currentSegment.add(classDeclaration); + currentSegment = classDeclaration; + } } ClassBody() { - currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + if (currentSegment != null) { + currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + } } } @@ -610,10 +621,18 @@ void FieldDeclaration() : } { variableDeclaration = VariableDeclarator() - {currentSegment.add(variableDeclaration);} + { + if (currentSegment != null) { + currentSegment.add(variableDeclaration); + } + } ( - variableDeclaration = VariableDeclarator() - {currentSegment.add(variableDeclaration);} + variableDeclaration = VariableDeclarator() + { + if (currentSegment != null) { + currentSegment.add(variableDeclaration); + } + } )* try { @@ -777,12 +796,16 @@ void MethodDeclaration() : { functionDeclaration = MethodDeclarator() { - currentSegment.add(functionDeclaration); - currentSegment = functionDeclaration; + if (currentSegment != null) { + currentSegment.add(functionDeclaration); + currentSegment = functionDeclaration; + } } Block() { - currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + if (currentSegment != null) { + currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + } } } @@ -1111,6 +1134,7 @@ String EqualityExpression() : {buff.append(expr);} ( ( operator = + | operator = | operator = | operator = | operator = @@ -1562,7 +1586,11 @@ void IncludeStatement() : { expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1573,7 +1601,11 @@ void IncludeStatement() : | expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1584,7 +1616,11 @@ void IncludeStatement() : | expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1595,7 +1631,11 @@ void IncludeStatement() : | expr = Expression() - {currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));} + { + if (currentSegment != null) { + currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr)); + } + } try { ( | "?>") } catch (ParseException e) { @@ -1740,7 +1780,7 @@ void IfStatement() : */ {} { - Condition("if") Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) Statement() ] + Condition("if") IfStatement0() } void Condition(String keyword) : @@ -1763,6 +1803,39 @@ void Condition(String keyword) : } } +void IfStatement0() : +{} +{ + (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] + try { + + } catch (ParseException e) { + errorMessage = "';' expected 'endif' keyword"; + errorLevel = ERROR; + throw e; + } +| + Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) Statement() ] +} + +void ElseIfStatementColon() : +{} +{ + Condition("elseif") (Statement())* +} + +void ElseStatement() : +{} +{ + Statement() +} + +void ElseStatementColon() : +{} +{ + (Statement())* +} + void ElseIfStatement() : {} { @@ -1782,7 +1855,7 @@ void WhileStatement0() : try { ( | "?>") } catch (ParseException e) { - errorMessage = "';' expected"; + errorMessage = "';' expected after 'endwhile' keyword"; errorLevel = ERROR; throw e; } @@ -1812,7 +1885,19 @@ void ForeachStatement() : void ForStatement() : {} { - [ ForInit() ] [ Expression() ] [ ForUpdate() ] Statement() + [ ForInit() ] [ Expression() ] [ ForUpdate() ] + ( + Statement() + | + (Statement())* + try { + + } catch (ParseException e) { + errorMessage = "';' expected 'endfor' keyword"; + errorLevel = ERROR; + throw e; + } + ) } void ForInit() :