for(;;)
This commit is contained in:
parent
785079e554
commit
be31006978
2 changed files with 101 additions and 37 deletions
|
@ -536,40 +536,10 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
|
|
||||||
StateTree<JavaElement> operation_for = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("for")))
|
StateTree<JavaElement> 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<JavaElement> operation_for_first_part = new StateTree<>();
|
|
||||||
operation_for.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
|
||||||
.then(operation_for_first_part);
|
|
||||||
StateTree<JavaElement> operation_for_second_part = operation_for_first_part.then((validator) -> validator.validate((token) -> token.getValue().equals(";")));
|
|
||||||
operation_for_first_part.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
|
|
||||||
.then(operation_for_second_part);
|
|
||||||
StateTree<JavaElement> operation_for_index = operation_for_second_part.then((validator) -> validator.validate((token) -> token.getValue().equals(")")));
|
|
||||||
operation_for_index.end((a,b) -> a);
|
|
||||||
operation_for_index.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
|
||||||
.end((a,b) -> a)
|
|
||||||
.multiple(function_container)
|
|
||||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
|
||||||
.end((a,b) -> a);
|
|
||||||
operation_for_second_part.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
|
|
||||||
.then(operation_for_index);
|
|
||||||
operation_for.then(new RedirectStateTree<>(variable, (global, local) -> global.set(null)))
|
|
||||||
.then(operation_for_first_part);
|
|
||||||
StateTree<JavaElement> operation_for_init = operation_for.then(new RedirectStateTree<>(type, (global, local) -> global.set(null)))
|
|
||||||
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)));
|
|
||||||
operation_for_init.then(operation_for_first_part);
|
|
||||||
operation_for.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME)))
|
|
||||||
.then((validator) -> validator.validate((token) -> token.getValue().equals("=")))
|
|
||||||
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
|
|
||||||
.then(operation_for_first_part);
|
|
||||||
StateTree<JavaElement> operation_foreach = operation_for_init.then((validator) -> validator.validate((token) -> token.getValue().equals(":")))
|
|
||||||
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
|
|
||||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")));
|
|
||||||
operation_foreach.end((a,b) -> a);
|
|
||||||
operation_foreach.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
|
||||||
.end((a,b) -> a)
|
|
||||||
.multiple(function_container)
|
|
||||||
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
|
||||||
.end((a,b) -> a);
|
|
||||||
|
|
||||||
|
StateTree<JavaElement> operation_for_first_part = operation_for.then((validator) -> validator.validate((token) -> token.getValue().equals(";")));
|
||||||
|
|
||||||
|
StateTree<JavaElement> operation_for_second_part = operation_for_first_part.then((validator) -> validator.validate((token) -> token.getValue().equals(";")));
|
||||||
|
|
||||||
StateTree<JavaElement> operation_while = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("while")))
|
StateTree<JavaElement> operation_while = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("while")))
|
||||||
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
|
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
|
||||||
|
@ -582,10 +552,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
|
|
||||||
operation_while.then(new RedirectStateTree<>(operation, (global, local) -> global.set(null)))
|
operation_while.then(new RedirectStateTree<>(operation, (global, local) -> global.set(null)))
|
||||||
.end((a,b) -> {
|
.end((a,b) -> a);
|
||||||
System.out.println("JHUGYUFKHJO");
|
|
||||||
return a;
|
|
||||||
});
|
|
||||||
|
|
||||||
operation_while.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
operation_while.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
|
|
97
test/ForCase.java
Normal file
97
test/ForCase.java
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.TokenValidator;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.InitialStateTree;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
||||||
|
|
||||||
|
public class ForCase {
|
||||||
|
|
||||||
|
private static Parser<JavaElement> parser = new Parser<JavaElement>(){
|
||||||
|
{
|
||||||
|
setTokenizer(new Tokenizer());
|
||||||
|
|
||||||
|
InitialStateTree<JavaElement> operation = new InitialStateTree<>();
|
||||||
|
|
||||||
|
StateTree<JavaElement> operation_for = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("for")))
|
||||||
|
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")));
|
||||||
|
|
||||||
|
StateTree<JavaElement> operation_for_first_part = operation_for.then((validator) -> validator.validate((token) -> token.getValue().equals(";")));
|
||||||
|
|
||||||
|
StateTree<JavaElement> operation_for_second_part = operation_for_first_part.then((validator) -> validator.validate((token) -> token.getValue().equals(";")));
|
||||||
|
|
||||||
|
StateTree<JavaElement> operation_for_end = operation_for_second_part.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
|
||||||
|
.end((a,b) -> a);
|
||||||
|
|
||||||
|
setStateTree(operation);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void testCase(String value) throws Exception{
|
||||||
|
TokenValidator.TOKENS = 0;
|
||||||
|
TokenValidator.MAX_VALIDATE = 0;
|
||||||
|
|
||||||
|
parser.parse(value, new JavaElement());
|
||||||
|
|
||||||
|
assertEquals(TokenValidator.TOKENS, TokenValidator.MAX_VALIDATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void empty() throws Exception{
|
||||||
|
testCase("for(;;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case1() throws Exception{
|
||||||
|
testCase("for(i=4;;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case2() throws Exception{
|
||||||
|
testCase("for(i=4,j=3;;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case3() throws Exception{
|
||||||
|
testCase("for(int i=4;;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case4() throws Exception{
|
||||||
|
testCase("for(int i=4,j=3;;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case5() throws Exception{
|
||||||
|
testCase("for(int i;;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case6() throws Exception{
|
||||||
|
testCase("for(int i =0,j;;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case7() throws Exception{
|
||||||
|
testCase("for(;value;)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case8() throws Exception{
|
||||||
|
testCase("for(;;i++)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case9() throws Exception{
|
||||||
|
testCase("for(final int i = 4;;i++)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case10() throws Exception{
|
||||||
|
testCase("for(private static final int i=4,k;value;)");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue