AutoTest -> 94.153% + refractor branch multiple in initial state tree

This commit is contained in:
jeffcheasey88 2023-08-29 08:53:06 +02:00
parent 3aeba124e3
commit 2132defaec
4 changed files with 64 additions and 6 deletions

View file

@ -27,6 +27,13 @@ public class Parser<E>{
this.state.seed(this.tokenizer, container);
}
public final void parse(String line, E container) throws Exception{
this.tokenizer.reset();
this.tokenizer.parse(line);
this.state.seed(this.tokenizer, container);
}
//tmp
public void build(BufferedWriter writer) throws Exception{
Token[] confirmed = new Token[TokenValidator.MAX_VALIDATE];

View file

@ -72,4 +72,37 @@ public class Tokenizer {
if(this.postProcessor != null) this.postProcessor.accept(tokens);
}
public void parse(String line){
if(this.postProcessor != null) this.postProcessor.accept(tokens);
for(int i = 0; i < line.length(); i++){
char c = line.charAt(i);
Token token;
if(Character.isAlphabetic(c) || Character.isDigit(c)){
String value = "";
int j = i;
for(; j < line.length(); j++){
c = line.charAt(j);
if(Character.isAlphabetic(c) || Character.isDigit(c)) value+=c;
else break;
}
token = new Token(1, i+1, value, TokenType.NAME);
i = j-1;
}else if(Character.isWhitespace(c)){
if(!optionSpace) continue;
String value = "";
int j = i;
for(; j < line.length(); j++){
c = line.charAt(j);
if(!Character.isWhitespace(c)) break;
}
token = new Token(1, i+1, value, TokenType.SPACE);
i = j-1;
}else{
token = new Token(1, i+1, ""+c, TokenType.DELIMITER);
}
this.tokens.add(token);
}
}
}

View file

@ -557,10 +557,20 @@ public class JavaParser extends Parser<JavaElement> {
StateTree<JavaElement> function_begin = function_name.then((validator) -> validator.validate((token) -> token.getValue().equals("(")));
StateTree<JavaElement> function_end = function_begin.then((validator) -> validator.validate((token) -> token.getValue().equals(")")));
function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
.end((a,b) -> a)
.end((a,b) -> {
System.out.println("build function "+b);
return a;
})
.multiple(function_container)
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a);
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> {
System.out.println("inside of the function "+b);
return a;
});
function_end.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end((a,b) -> a);
function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("default")))
.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null)))
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
.end((a,b) -> a);
StateTree<JavaElement> function_throws = function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("throws")))
.then(new RedirectStateTree<>(type, (global, local) -> global.set(null)));
@ -642,6 +652,13 @@ public class JavaParser extends Parser<JavaElement> {
InitialStateTree<JavaElement> mult_clazz_container = new InitialStateTree<>();
mult_clazz_container.multiple(clazz_container);
mult_clazz_container.end((a,b) -> a);
StateTree<JavaElement> debug = new StateTree<>();
debug.then((v) -> v.validate((t) -> {
System.out.println("debug "+t);
return false;
}));
//ENUM
StateTree<JavaElement> enums = new StateTree<>();
@ -651,6 +668,7 @@ public class JavaParser extends Parser<JavaElement> {
.end((a,b) -> a)
.unique(enum_value)
.unique(mult_clazz_container)
.unique(debug)
.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a);
StateTree<JavaElement> enum_mod = clazz_.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)));
@ -742,7 +760,7 @@ public class JavaParser extends Parser<JavaElement> {
}
public static void main(String[] args) throws Exception{
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\BotDiscordSql\\src\\be\\jeffcheasey\\challenge\\bot\\parser\\region\\RegionContainer.java");
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\BotDiscordSql\\src\\be\\jeffcheasey\\challenge\\bot\\parser\\RequestType.java");
BufferedReader reader = new BufferedReader(new FileReader(file));

View file

@ -19,14 +19,14 @@ public class InitialStateTree<E> extends StateTree<E>{
BuilderStateTree<E, ?> internalSeed(TokenValidator validator, E element){
BuilderStateTree<E, ?> builded;
for(StateTree<E> state : this.multiple){
TokenValidator branch = validator.branch();
TokenValidator branch;
if(state.checker == null){
while((builded = state.internalSeed(branch, element)) != null){
while((builded = state.internalSeed((branch = validator.branch()), element)) != null){
validator.merge(branch);
builded.build(validator, element);
}
}else{
while(state.checker.apply(branch)){
while(state.checker.apply((branch = validator.branch()))){
builded = state.internalSeed(branch, element);
if(builded == null) break;
validator.merge(branch);