StateTree -> Fix signle case AFTER multiple case
This commit is contained in:
parent
3256c1986e
commit
a0b096745a
2 changed files with 24 additions and 22 deletions
|
@ -12,6 +12,7 @@ import java.util.List;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Parser;
|
import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.BuilderStateTree;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
import be.jeffcheasey88.peeratcode.parser.state.StateTree;
|
||||||
|
|
||||||
public class JavaParser extends Parser<JavaFile> {
|
public class JavaParser extends Parser<JavaFile> {
|
||||||
|
@ -36,6 +37,7 @@ public class JavaParser extends Parser<JavaFile> {
|
||||||
public JavaParser(){
|
public JavaParser(){
|
||||||
Tokenizer tokenizer = new Tokenizer();
|
Tokenizer tokenizer = new Tokenizer();
|
||||||
|
|
||||||
|
StateTree<JavaFile> clazz = new StateTree<>();
|
||||||
|
|
||||||
StateTree<JavaFile> importState = new StateTree<>();
|
StateTree<JavaFile> importState = new StateTree<>();
|
||||||
importState.then((validator) -> {
|
importState.then((validator) -> {
|
||||||
|
@ -60,7 +62,7 @@ public class JavaParser extends Parser<JavaFile> {
|
||||||
|
|
||||||
StateTree<JavaFile> main = new StateTree<>();
|
StateTree<JavaFile> main = new StateTree<>();
|
||||||
|
|
||||||
main.then((validator) -> {
|
BuilderStateTree<JavaFile, JavaElement> pack = main.then((validator) -> {
|
||||||
if(validator.validate(
|
if(validator.validate(
|
||||||
(token) -> token.getValue().equals("package"),
|
(token) -> token.getValue().equals("package"),
|
||||||
(bag, token) -> bag.set(new LinkedList<>()))){
|
(bag, token) -> bag.set(new LinkedList<>()))){
|
||||||
|
@ -73,8 +75,9 @@ public class JavaParser extends Parser<JavaFile> {
|
||||||
return validator.validate((token) -> token.getValue().equals(";"));
|
return validator.validate((token) -> token.getValue().equals(";"));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}).<JavaElement>end((javafile, bag) -> javafile.setPackage(bag))
|
}).<JavaElement>end((javafile, bag) -> javafile.setPackage(bag));
|
||||||
.multiple(importState);
|
pack.multiple(importState);
|
||||||
|
pack.thenNoChild(clazz);
|
||||||
|
|
||||||
|
|
||||||
System.out.println((System.currentTimeMillis()-time)+"ms");
|
System.out.println((System.currentTimeMillis()-time)+"ms");
|
||||||
|
|
|
@ -35,6 +35,24 @@ public class BuilderStateTree<E, B> extends StateTree<B>{
|
||||||
}
|
}
|
||||||
|
|
||||||
void internalSeedNoChilds(TokenValidator validator, E element){
|
void internalSeedNoChilds(TokenValidator validator, E element){
|
||||||
|
if(multiple != null){
|
||||||
|
TokenValidator branch = validator.branch();
|
||||||
|
if(multiple.checker == null){
|
||||||
|
BuilderStateTree<E, ?> builded;
|
||||||
|
while((builded = multiple.internalSeed(branch, element)) != null){
|
||||||
|
validator.merge(branch);
|
||||||
|
builded.build(validator, element);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
while(multiple.checker.apply(branch)){
|
||||||
|
BuilderStateTree<E, ?> builded = multiple.internalSeed(branch, element);
|
||||||
|
if(builded != null){
|
||||||
|
validator.merge(branch);
|
||||||
|
builded.build(validator, element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for(StateTree<E> child : this.childs){
|
for(StateTree<E> child : this.childs){
|
||||||
TokenValidator branch = validator.branch();
|
TokenValidator branch = validator.branch();
|
||||||
if(child.checker == null){
|
if(child.checker == null){
|
||||||
|
@ -55,25 +73,6 @@ public class BuilderStateTree<E, B> extends StateTree<B>{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(multiple != null){
|
|
||||||
TokenValidator branch = validator.branch();
|
|
||||||
if(multiple.checker == null){
|
|
||||||
BuilderStateTree<E, ?> builded;
|
|
||||||
while((builded = multiple.internalSeed(branch, element)) != null){
|
|
||||||
validator.merge(branch);
|
|
||||||
builded.build(validator, element);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
while(multiple.checker.apply(branch)){
|
|
||||||
BuilderStateTree<E, ?> builded = multiple.internalSeed(branch, element);
|
|
||||||
if(builded != null){
|
|
||||||
validator.merge(branch);
|
|
||||||
builded.build(validator, element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends StateTree<E>> StateTree<E> thenNoChild(StateTree<E> child){
|
public <T extends StateTree<E>> StateTree<E> thenNoChild(StateTree<E> child){
|
||||||
|
|
Loading…
Add table
Reference in a new issue