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 2a86a45..e3b05cf 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -48,7 +48,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration; * You can test the parser with the PHPParserTestCase2.java * @author Matthieu Casanova */ -public class PHPParser extends PHPParserSuperclass { +public final class PHPParser extends PHPParserSuperclass { private static IFile fileToParse; @@ -64,7 +64,7 @@ public class PHPParser extends PHPParserSuperclass { public PHPParser() { } - public void setFileToParse(IFile fileToParse) { + public final void setFileToParse(IFile fileToParse) { this.fileToParse = fileToParse; } @@ -73,7 +73,7 @@ public class PHPParser extends PHPParserSuperclass { this.fileToParse = fileToParse; } - public void phpParserTester(String strEval) throws CoreException, ParseException { + public static final void phpParserTester(String strEval) throws CoreException, ParseException { PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING); StringReader stream = new StringReader(strEval); if (jj_input_stream == null) { @@ -83,7 +83,7 @@ public class PHPParser extends PHPParserSuperclass { phpTest(); } - public void htmlParserTester(String strEval) throws CoreException, ParseException { + public static final void htmlParserTester(String strEval) throws CoreException, ParseException { StringReader stream = new StringReader(strEval); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); @@ -92,7 +92,7 @@ public class PHPParser extends PHPParserSuperclass { phpFile(); } - public PHPOutlineInfo parseInfo(Object parent, String s) { + public final PHPOutlineInfo parseInfo(Object parent, String s) { outlineInfo = new PHPOutlineInfo(parent); currentSegment = outlineInfo.getDeclarations(); StringReader stream = new StringReader(s); @@ -201,7 +201,7 @@ public class PHPParser extends PHPParserSuperclass { } } - public void parse(String s) throws CoreException { + public final void parse(String s) throws CoreException { StringReader stream = new StringReader(s); if (jj_input_stream == null) { jj_input_stream = new SimpleCharStream(stream, 1, 1); @@ -236,7 +236,7 @@ public class PHPParser extends PHPParserSuperclass { } } - public void parse() throws ParseException { + public static final void parse() throws ParseException { phpFile(); } } @@ -549,7 +549,15 @@ void phpFile() : {} { try { - ( Php() )* + ( Php() + try { + + } catch (ParseException e) { + errorMessage = "'?>' expected"; + errorLevel = ERROR; + throw e; + } + )* } catch (TokenMgrError e) { errorMessage = e.getMessage(); @@ -568,7 +576,7 @@ void ClassDeclaration() : { PHPClassDeclaration classDeclaration; Token className; - int pos = jj_input_stream.bufpos; + final int pos = jj_input_stream.bufpos; } { className = [ ] @@ -647,7 +655,7 @@ PHPVarDeclaration VariableDeclarator() : { String varName; String varValue = null; - int pos = jj_input_stream.bufpos; + final int pos = jj_input_stream.bufpos; } { varName = VariableDeclaratorId() @@ -672,7 +680,7 @@ PHPVarDeclaration VariableDeclarator() : String VariableDeclaratorId() : { String expr; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { try { @@ -761,7 +769,7 @@ String VariableInitializer() : String ArrayVariable() : { String expr; -StringBuffer buff = new StringBuffer(); +final StringBuffer buff = new StringBuffer(); } { expr = Expression() @@ -774,7 +782,7 @@ StringBuffer buff = new StringBuffer(); String ArrayInitializer() : { String expr = null; -StringBuffer buff = new StringBuffer("("); +final StringBuffer buff = new StringBuffer("("); } { [ expr = ArrayVariable() @@ -814,7 +822,7 @@ PHPFunctionDeclaration MethodDeclarator() : Token identifier; StringBuffer methodDeclaration = new StringBuffer(); String formalParameters; - int pos = jj_input_stream.bufpos; + final int pos = jj_input_stream.bufpos; } { [ {methodDeclaration.append("&");} ] @@ -863,7 +871,7 @@ String FormalParameters() : String FormalParameter() : { PHPVarDeclaration variableDeclaration; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { [ {buff.append("&");}] variableDeclaration = VariableDeclarator() @@ -987,7 +995,7 @@ String ConditionalOrExpression() : String expr; Token operator; String expr2 = null; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = ConditionalAndExpression() @@ -1011,7 +1019,7 @@ String ConditionalAndExpression() : String expr; Token operator; String expr2 = null; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = ConcatExpression() @@ -1034,7 +1042,7 @@ String ConcatExpression() : { String expr; String expr2 = null; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = InclusiveOrExpression() @@ -1057,7 +1065,7 @@ String InclusiveOrExpression() : { String expr; String expr2 = null; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = ExclusiveOrExpression() @@ -1080,7 +1088,7 @@ String ExclusiveOrExpression() : { String expr; String expr2 = null; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = AndExpression() @@ -1101,9 +1109,9 @@ String ExclusiveOrExpression() : String AndExpression() : { - String expr; + final String expr; String expr2 = null; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = EqualityExpression() @@ -1127,7 +1135,7 @@ String EqualityExpression() : String expr; Token operator; String expr2; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = RelationalExpression() @@ -1153,7 +1161,7 @@ String RelationalExpression() : String expr; Token operator; String expr2; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = ShiftExpression() @@ -1172,17 +1180,16 @@ String ShiftExpression() : { String expr; Token operator; - String expr2; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = AdditiveExpression() {buff.append(expr);} ( - (operator = | operator = | operator = ) expr2 = AdditiveExpression() + (operator = | operator = | operator = ) expr = AdditiveExpression() { buff.append(operator.image); - buff.append(expr2); + buff.append(expr); } )* {return buff.toString();} @@ -1192,17 +1199,16 @@ String AdditiveExpression() : { String expr; Token operator; - String expr2; - StringBuffer buff = new StringBuffer(); + final StringBuffer buff = new StringBuffer(); } { expr = MultiplicativeExpression() {buff.append(expr);} ( - ( operator = | operator = ) expr2 = MultiplicativeExpression() + ( operator = | operator = ) expr = MultiplicativeExpression() { buff.append(operator.image); - buff.append(expr2); + buff.append(expr); } )* {return buff.toString();} @@ -1210,17 +1216,17 @@ String AdditiveExpression() : String MultiplicativeExpression() : { - String expr, expr2; + String expr; Token operator; final StringBuffer buff = new StringBuffer();} { expr = UnaryExpression() {buff.append(expr);} ( - ( operator = | operator = | operator = ) expr2 = UnaryExpression() + ( operator = | operator = | operator = ) expr = UnaryExpression() { buff.append(operator.image); - buff.append(expr2); + buff.append(expr); } )* {return buff.toString();} @@ -1312,8 +1318,7 @@ String UnaryExpressionNotPlusMinus() : String CastExpression() : { -String type; -String expr; +final String type, expr; } { type = Type() expr = UnaryExpression() @@ -1361,7 +1366,7 @@ String PrimaryExpression() : String ArrayDeclarator() : { - String expr; + final String expr; } { expr = ArrayInitializer() @@ -1498,7 +1503,7 @@ String expr = null; String ArgumentList() : { String expr; -StringBuffer buff = new StringBuffer(); +final StringBuffer buff = new StringBuffer(); } { expr = Expression() @@ -1581,7 +1586,7 @@ void Statement() : void IncludeStatement() : { String expr; - int pos = jj_input_stream.bufpos; + final int pos = jj_input_stream.bufpos; } { @@ -1647,7 +1652,7 @@ void IncludeStatement() : String PrintExpression() : { - StringBuffer buff = new StringBuffer("print "); + final StringBuffer buff = new StringBuffer("print "); String expr; } { @@ -1778,9 +1783,12 @@ void IfStatement() : * else's to the innermost if statement. The LOOKAHEAD specification * is to tell JavaCC that we know what we are doing. */ -{} { - Condition("if") IfStatement0() + Token token; + final int pos = jj_input_stream.bufpos; +} +{ + token = Condition("if") IfStatement0(pos,pos+token.image.length()) } void Condition(String keyword) : @@ -1803,10 +1811,29 @@ void Condition(String keyword) : } } -void IfStatement0() : -{} +void IfStatement0(int start,int end) : +{ +} { - (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] + (Statement())* (ElseIfStatementColon())* [ElseStatementColon()] + + {try { + setMarker(fileToParse, + "Ugly syntax detected, you should if () {...} instead of if (): ... endif;", + start, + end, + INFO, + "Line " + token.beginLine); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + }} + try { + + } catch (ParseException e) { + errorMessage = "'endif' expected"; + errorLevel = ERROR; + throw e; + } try { } catch (ParseException e) { @@ -1824,12 +1851,6 @@ void ElseIfStatementColon() : Condition("elseif") (Statement())* } -void ElseStatement() : -{} -{ - Statement() -} - void ElseStatementColon() : {} { @@ -1843,15 +1864,35 @@ void ElseIfStatement() : } void WhileStatement() : -{} { - Condition("while") WhileStatement0() + Token token; + final int pos = jj_input_stream.bufpos; +} +{ + token = Condition("while") WhileStatement0(pos,pos + token.image.length()) } -void WhileStatement0() : +void WhileStatement0(final int start, final int end) : {} { - (Statement())* + (Statement())* + {try { + setMarker(fileToParse, + "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;", + start, + end, + INFO, + "Line " + token.beginLine); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + }} + try { + + } catch (ParseException e) { + errorMessage = "'endwhile' expected"; + errorLevel = ERROR; + throw e; + } try { ( | "?>") } catch (ParseException e) { @@ -1879,17 +1920,91 @@ void DoStatement() : void ForeachStatement() : {} { - Variable() Variable() [ Expression() ] Statement() + + try { + + } catch (ParseException e) { + errorMessage = "'(' expected after 'foreach' keyword"; + errorLevel = ERROR; + throw e; + } + try { + Variable() + } catch (ParseException e) { + errorMessage = "variable expected"; + errorLevel = ERROR; + throw e; + } + try { + + } catch (ParseException e) { + errorMessage = "'as' expected"; + errorLevel = ERROR; + throw e; + } + try { + Variable() + } catch (ParseException e) { + errorMessage = "variable expected"; + errorLevel = ERROR; + throw e; + } + [ Expression() ] + try { + + } catch (ParseException e) { + errorMessage = "')' expected after 'foreach' keyword"; + errorLevel = ERROR; + throw e; + } + try { + Statement() + } catch (ParseException e) { + if (errorMessage != null) throw e; + errorMessage = "statement expected"; + errorLevel = ERROR; + throw e; + } } void ForStatement() : -{} { - [ ForInit() ] [ Expression() ] [ ForUpdate() ] +Token token; +final int pos = jj_input_stream.bufpos; +} +{ + token = + try { + + } catch (ParseException e) { + errorMessage = "'(' expected after 'for' keyword"; + errorLevel = ERROR; + throw e; + } + [ ForInit() ] [ Expression() ] [ ForUpdate() ] ( Statement() | - (Statement())* + (Statement())* + { + try { + setMarker(fileToParse, + "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;", + pos, + pos+token.image.length(), + INFO, + "Line " + token.beginLine); + } catch (CoreException e) { + PHPeclipsePlugin.log(e); + } + } + try { + + } catch (ParseException e) { + errorMessage = "'endfor' expected"; + errorLevel = ERROR; + throw e; + } try { } catch (ParseException e) {