Operations & Functions

This commit is contained in:
jeffcheasey88 2023-07-19 17:30:31 +02:00
parent 2ad831641b
commit aa51bb95e2
2 changed files with 16 additions and 7 deletions

View file

@ -28,7 +28,7 @@ public class JavaParser extends Parser<JavaElement> {
}
public static void main(String[] args) throws Exception{
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\be\\jeffcheasey88\\peeratcode\\routes\\Result.java");
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-parseur\\src\\be\\jeffcheasey88\\peeratcode\\parser\\java\\JavaParser.java");
BufferedReader reader = new BufferedReader(new FileReader(file));
time = System.currentTimeMillis();
@ -68,6 +68,7 @@ public class JavaParser extends Parser<JavaElement> {
int m = getModifier(token.getValue());
Integer current = bag.get();
bag.set(current == null ? m : current+m);
System.out.println("mod "+token);
})) mod = true;
return mod;
}).end((a,b) -> a);
@ -152,6 +153,8 @@ public class JavaParser extends Parser<JavaElement> {
return false;
}).end((a,b) -> a);
StateTree<JavaElement> function_container = new StateTree<>();
//OPERATION
StateTree<JavaElement> operation = new StateTree<>();
StateTree<JavaElement> operation_name = operation.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME)));
@ -192,11 +195,17 @@ public class JavaParser extends Parser<JavaElement> {
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("break")))
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
.end((a,b) -> a);
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("if")))
StateTree<JavaElement> operation_if = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("if")))
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
.then(new RedirectStateTree<>(value, (global, local) -> global.set(null)))
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
.end((a,b) -> a);
operation_if.then(operation);
operation_if.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
.then(new RedirectStateTree<>(function_container, (global, local) -> global.set(null)))
.then((validator) -> validator.validate((token) -> token.getValue().equals("}")))
.end((a,b) -> a);
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("for")))
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
.then(new RedirectStateTree<>(value, (global, local) -> global.set(null)))
@ -231,18 +240,17 @@ public class JavaParser extends Parser<JavaElement> {
variable_value.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
.end((a,b) -> a);
StateTree<JavaElement> function_container = new StateTree<>();
function_container.then(variable);
function_container.then(operation);
//FUNCTION
StateTree<JavaElement> function = new StateTree<>();
StateTree<JavaElement> function_mod = function.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)));
StateTree<JavaElement> function_type = function.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local)));
function_mod.then(function_type);
BuilderStateTree<JavaElement,JavaElement> function_static = function.then((validator) -> validator.validate((token) -> token.getValue().equals("static")) && validator.validate((token) -> token.getValue().equals("{"))).end((a,b) -> a);
function_static.multiple(function_container);
function_static.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a);
StateTree<JavaElement> function_mod = function.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)));
StateTree<JavaElement> function_type = function.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local)));
function_mod.then(function_type);
StateTree<JavaElement> function_name = function_type.then((validator) -> validator.validate(
(token) -> token.getType().equals(TokenType.NAME),

View file

@ -23,8 +23,9 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
TokenValidator branch = validator.branch();
branch.setBag(localBag);
Object builded = redirect.internalSeed(branch, (E) element);
BuilderStateTree<E, ?> builded = redirect.internalSeed(branch, (E) element);
if(builded == null) return null;
builded.build(validator, element);
this.group.accept(currentBag, localBag);
branch.setBag(currentBag);