From aa51bb95e2f3d7f8672f027915307cb847e8a83b Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Wed, 19 Jul 2023 17:30:31 +0200 Subject: [PATCH] Operations & Functions --- .../peeratcode/parser/java/JavaParser.java | 20 +++++++++++++------ .../parser/state/RedirectStateTree.java | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 704a014..808db05 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -28,7 +28,7 @@ public class JavaParser extends Parser { } 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 { 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 { return false; }).end((a,b) -> a); + StateTree function_container = new StateTree<>(); + //OPERATION StateTree operation = new StateTree<>(); StateTree operation_name = operation.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); @@ -192,11 +195,17 @@ public class JavaParser extends Parser { 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 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 { variable_value.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))) .end((a,b) -> a); - StateTree function_container = new StateTree<>(); function_container.then(variable); function_container.then(operation); //FUNCTION StateTree function = new StateTree<>(); - StateTree function_mod = function.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local))); - StateTree function_type = function.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local))); - function_mod.then(function_type); BuilderStateTree 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 function_mod = function.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local))); + StateTree function_type = function.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local))); + function_mod.then(function_type); StateTree function_name = function_type.then((validator) -> validator.validate( (token) -> token.getType().equals(TokenType.NAME), diff --git a/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java b/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java index e9779c2..98264c2 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java +++ b/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java @@ -23,8 +23,9 @@ public class RedirectStateTree extends StateTree{ TokenValidator branch = validator.branch(); branch.setBag(localBag); - Object builded = redirect.internalSeed(branch, (E) element); + BuilderStateTree builded = redirect.internalSeed(branch, (E) element); if(builded == null) return null; + builded.build(validator, element); this.group.accept(currentBag, localBag); branch.setBag(currentBag);