From 4564f52c4c5b5bde34d12c626ba3444b283c3b54 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Wed, 19 Jul 2023 14:31:12 +0200 Subject: [PATCH] Parser -> Function signature --- .../peeratcode/parser/java/JavaParser.java | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index ef636d8..0ac8a2c 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -48,6 +48,7 @@ public class JavaParser extends Parser { //- Type //- Value //- Variable + //- Function //- Class //- Import //- Package @@ -148,9 +149,9 @@ public class JavaParser extends Parser { //VARIABLE StateTree variable = new StateTree<>(); + StateTree variable_mod = variable.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local))); StateTree variable_type = variable.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local))); - variable.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local))) - .then(variable_type); + variable_mod.then(variable_type); StateTree variable_name = variable_type.then((validator) -> validator.validate( (token) -> token.getType().equals(TokenType.NAME), (bag, token) -> bag.set(token))); @@ -164,8 +165,33 @@ public class JavaParser extends Parser { variable_value.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))) .end((a,b) -> a); + //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); + function.then((validator) -> validator.validate((token) -> token.getValue().equals("static"))).end((a,b) -> a); + StateTree function_name = function_type.then((validator) -> validator.validate( + (token) -> token.getType().equals(TokenType.NAME), + (bag, token) -> bag.set(token))); + StateTree function_begin = function_name.then((validator) -> validator.validate((token) -> token.getValue().equals("("))); + StateTree function_end = function_begin.then((validator) -> validator.validate((token) -> token.getValue().equals(")"))); + function_end.end((a,b) -> a); + + StateTree function_throws = function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("throws"))) + .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); + function_throws.end((a,b) -> a); + function_throws.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(function_throws); + + + StateTree function_arg_type = function_begin.then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); + StateTree function_arg_name = function_arg_type.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); + function_arg_name.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(function_arg_type); + function_arg_name.then(function_end); + StateTree clazz_container = new StateTree<>(); clazz_container.then(variable); + clazz_container.then(function); //CLASS StateTree clazz_ = new StateTree<>();