diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index c8417ce..8f68ce4 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -535,11 +535,38 @@ public class JavaParser extends Parser { .end((a,b) -> a); StateTree operation_for = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("for"))) - .then((validator) -> validator.validate((token) -> token.getValue().equals("("))); - + .then((validator) -> validator.validate((token) -> token.getValue().equals("("))); + StateTree operation_for_first_part = operation_for.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))); + + StateTree operation_for_assign = operation_for.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); + StateTree operation_for_assign_end = operation_for_assign.then((validator) -> validator.validate((token) -> token.getValue().equals("="))) + .then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); + + operation_for_assign.then(operation_for_assign); + operation_for_assign.then(operation_for_first_part); + + + operation_for_assign_end.then((validator) -> validator.validate((token) -> token.getValue().equals(","))) + .then(operation_for_assign); + operation_for_assign_end.then(operation_for_first_part); + + StateTree operation_for_second_part = operation_for_first_part.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))); + + operation_for_first_part.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))) + .then(operation_for_second_part); + + StateTree operation_for_end = operation_for_second_part.then((validator) -> validator.validate((token) -> token.getValue().equals(")"))); + operation_for_end.end((a,b) -> a); + + operation_for_assign.then((validator) -> validator.validate((token) -> token.getValue().equals(":"))) + .then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))) + .then(operation_for_end); + + operation_for_second_part.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))) + .then(operation_for_end); StateTree operation_while = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("while"))) .then((validator) -> validator.validate((token) -> token.getValue().equals("("))) diff --git a/test/ForCase.java b/test/ForCase.java index 2ac45fc..a95e26e 100644 --- a/test/ForCase.java +++ b/test/ForCase.java @@ -45,6 +45,10 @@ public class ForCase { StateTree operation_for_end = operation_for_second_part.then((validator) -> validator.validate((token) -> token.getValue().equals(")"))); operation_for_end.end((a,b) -> a); + operation_for_assign.then((validator) -> validator.validate((token) -> token.getValue().equals(":"))) + .then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))) + .then(operation_for_end); + operation_for_second_part.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))) .then(operation_for_end); @@ -115,4 +119,9 @@ public class ForCase { void case10() throws Exception{ testCase("for(private static final int i=4,k;value;)"); } + + @Test + void case11() throws Exception{ + testCase("for(Test test : tests)"); + } }