diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 1fb427c..55ab148 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -73,6 +73,7 @@ public class JavaParser extends Parser { //- Modifier //- Type //- Value + //- Annotation //- Operation //- Variable //- Function @@ -239,6 +240,22 @@ public class JavaParser extends Parser { return false; }).end((a,b) -> a); + //ANNOTATION + StateTree annotation = new StateTree<>(); + StateTree annotation_name = annotation.then((validator) -> validator.validate((token) -> token.getValue().equals("@"))) + .then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); + annotation_name.then((validator) -> validator.validate((token) -> token.getValue().equals("."))).then(annotation_name); + annotation_name.end((a,b) -> a); + StateTree annotation_begin = annotation_name.then((validator) -> validator.validate((token) -> token.getValue().equals("("))); + StateTree annotation_end = annotation_begin.then((validator) -> validator.validate((token) -> token.getValue().equals(")"))); + annotation_end.end((a,b) -> a); + StateTree annotation_var = annotation_begin.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); + StateTree annotation_value = annotation_var.then((validator) -> validator.validate((token) -> token.getValue().equals("="))) + .then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))); + annotation_value.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(annotation_var); + annotation_value.then(annotation_end); + annotation_begin.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))).then(annotation_end); + StateTree function_container = new StateTree<>(); //OPERATION @@ -313,7 +330,8 @@ public class JavaParser extends Parser { .end((a,b) -> a); //VARIABLE - StateTree variable = new StateTree<>(); + InitialStateTree variable = new InitialStateTree<>(); + variable.multiple(annotation); 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_mod.then(variable_type); @@ -334,7 +352,8 @@ public class JavaParser extends Parser { function_container.then(operation); //FUNCTION - StateTree function = new StateTree<>(); + InitialStateTree function = new InitialStateTree<>(); + function.multiple(annotation); 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); @@ -364,9 +383,9 @@ public class JavaParser extends Parser { function_arg_name.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(function_arg_type); function_arg_name.then(function_end); - - clazz_container.then(variable); + clazz_container.then(function); + clazz_container.then(variable); //CLASS StateTree clazz_ = new StateTree<>(); @@ -436,6 +455,7 @@ public class JavaParser extends Parser { }).end((javafile, bag) -> javafile); main.multiple(pack); main.multiple(importState); + main.multiple(annotation); main.multiple(clazz_);