From 84cc9d8574e3beb6a08821c9ffda3a173117cfc1 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Mon, 10 Jul 2023 16:07:59 +0200 Subject: [PATCH] [Parse Class] -> Annotations --- .../peeratcode/parser/java/JavaParser.java | 118 +++++++++++------- 1 file changed, 74 insertions(+), 44 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 2b08a30..40cf478 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -82,6 +82,11 @@ public class JavaParser extends Parser { System.out.println("\top"); return javafile; }); + BiFunction + END_ANNOTATION = ((javafile, validator) -> { + System.out.println("ANNOTATION"); + return javafile; + }); public JavaParser(){ Tokenizer tokenizer = new Tokenizer(); @@ -94,27 +99,29 @@ public class JavaParser extends Parser { Function LAMBDA_6 = (v) -> v.validate((t) -> t.getValue().equals(">")); Function LAMBDA_7 = (v) -> v.validate((t) -> t.getValue().equals(",")); Function LAMBDA_8 = (v) -> v.validate((t) -> t.getValue().equals("=")); + Function LAMBDA_10 = (v) -> v.validate((t) -> !t.getValue().equals("")); Function LAMBDA_23 = (v) -> v.validate((t) -> t.getValue().equals("(")); Function LAMBDA_24 = (v) -> v.validate((t) -> t.getValue().equals(")")); Function LAMBDA_25 = (v) -> v.validate((t) -> t.getValue().equals(".")); Function LAMBDA_28 = (v) -> v.validate((t) -> t.getValue().equals("'")); - Function LAMBDA_29 = (v) -> v.validate((t) -> t.getValue().equals("oneChar")); - Function LAMBDA_30 = (v) -> v.validate((t) -> t.getValue().equals("if")); - Function LAMBDA_31 = (v) -> v.validate((t) -> t.getValue().equals("for")); - Function LAMBDA_32 = (v) -> v.validate((t) -> t.getValue().equals("while")); - Function LAMBDA_33 = (v) -> v.validate((t) -> t.getValue().equals("return")); - Function LAMBDA_34 = (v) -> v.validate((t) -> t.getValue().equals("do")); - Function LAMBDA_35 = (v) -> v.validate((t) -> t.getValue().equals("synchronized")); - Function LAMBDA_36 = (v) -> v.validate((t) -> t.getValue().equals("continue")); - Function LAMBDA_37 = (v) -> v.validate((t) -> t.getValue().equals("throw")); - Function LAMBDA_38 = (v) -> v.validate((t) -> t.getValue().equals("break")); - Function LAMBDA_39 = (v) -> v.validate((t) -> t.getValue().equals("try")); - Function LAMBDA_40 = (v) -> v.validate((t) -> t.getValue().equals("{")); - Function LAMBDA_41 = (v) -> v.validate((t) -> t.getValue().equals("}")); - Function LAMBDA_44 = (v) -> v.validate((t) -> t.getValue().equals("throws")); - Function LAMBDA_46 = (v) -> v.validate((t) -> t.getValue().equals("class")); - Function LAMBDA_47 = (v) -> v.validate((t) -> t.getValue().equals("implements")); + Function LAMBDA_29 = (v) -> v.validate((t) -> t.getValue().length() == 1); + Function LAMBDA_30 = (v) -> v.validate((t) -> t.getValue().equals("@")); + Function LAMBDA_32 = (v) -> v.validate((t) -> t.getValue().equals("if")); + Function LAMBDA_33 = (v) -> v.validate((t) -> t.getValue().equals("for")); + Function LAMBDA_34 = (v) -> v.validate((t) -> t.getValue().equals("while")); + Function LAMBDA_35 = (v) -> v.validate((t) -> t.getValue().equals("return")); + Function LAMBDA_36 = (v) -> v.validate((t) -> t.getValue().equals("do")); + Function LAMBDA_37 = (v) -> v.validate((t) -> t.getValue().equals("synchronized")); + Function LAMBDA_38 = (v) -> v.validate((t) -> t.getValue().equals("continue")); + Function LAMBDA_39 = (v) -> v.validate((t) -> t.getValue().equals("throw")); + Function LAMBDA_40 = (v) -> v.validate((t) -> t.getValue().equals("break")); + Function LAMBDA_41 = (v) -> v.validate((t) -> t.getValue().equals("try")); + Function LAMBDA_42 = (v) -> v.validate((t) -> t.getValue().equals("{")); + Function LAMBDA_43 = (v) -> v.validate((t) -> t.getValue().equals("}")); + Function LAMBDA_45 = (v) -> v.validate((t) -> t.getValue().equals("throws")); + Function LAMBDA_47 = (v) -> v.validate((t) -> t.getValue().equals("class")); Function LAMBDA_48 = (v) -> v.validate((t) -> t.getValue().equals("extends")); + Function LAMBDA_49 = (v) -> v.validate((t) -> t.getValue().equals("implements")); StateTree main = new StateTree<>(); StateTree package_q0 = new StateTree<>(); @@ -144,52 +151,68 @@ public class JavaParser extends Parser { type_q1.end(END_TYPE); StateTree value_q0 = value(); + + StateTree annotation_q0 = new StateTree<>(); + StateTree annotation_q2 = annotation_q0.then(LAMBDA_30).then(LAMBDA_name); + StateTree annotation_q4 = annotation_q2.then(LAMBDA_23); + annotation_q4.then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_ANNOTATION); + annotation_q4.then(LAMBDA_24).end(END_ANNOTATION); + StateTree annotation_q7 = annotation_q4.then(LAMBDA_name); + StateTree annotation_q9 = annotation_q7.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")); + annotation_q9.then(LAMBDA_24).end(END_ANNOTATION); + StateTree annotation_q10 = annotation_q9.then(LAMBDA_7); + annotation_q10.then(annotation_q7); + annotation_q2.end(END_ANNOTATION); StateTree variable_q0 = new StateTree<>(); + StateTree variable_q10 = variable_q0.then(new RedirectStateTree<>(modifier_q0,(bag) -> "modifier")); + StateTree variable_q11 = variable_q0.then(new RedirectStateTree<>(annotation_q0,(bag) -> "?")); + variable_q11.then(variable_q10); StateTree variable_q1 = variable_q0.then(new RedirectStateTree<>(type_q0,(bag) -> "type=token")); StateTree variable_q2 = variable_q1.then(LAMBDA_name); StateTree variable_q5 = variable_q2.then(LAMBDA_7); StateTree variable_q7 = variable_q2.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")); variable_q7.then(variable_q5); - variable_q7.then(LAMBDA_1).end(END_VAR); variable_q2.then(LAMBDA_1).end(END_VAR); + variable_q7.then(LAMBDA_1).end(END_VAR); variable_q5.then(variable_q2); - StateTree variable_q10 = variable_q0.then(new RedirectStateTree<>(modifier_q0,(bag) -> "modifier")); variable_q10.then(variable_q1); + variable_q11.then(variable_q1); StateTree operation_q0 = new StateTree<>(); StateTree operation_q1 = operation_q0.then(LAMBDA_name); - operation_q1.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_1).end(END_OP); - operation_q1.then(LAMBDA_25).then(operation_q1); - operation_q0.then(LAMBDA_30).then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_OP); - operation_q0.then(LAMBDA_31).then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_OP); + operation_q1.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_1).end(END_OP); + StateTree operation_q5 = operation_q1.then(LAMBDA_25); + operation_q5.then(operation_q1); operation_q0.then(LAMBDA_32).then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_OP); - operation_q0.then(LAMBDA_33).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_1).end(END_OP); - operation_q0.then(LAMBDA_34).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).end(END_OP); - operation_q0.then(LAMBDA_35).then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_OP); - operation_q0.then(LAMBDA_36).then(LAMBDA_1).end(END_OP); - operation_q0.then(LAMBDA_37).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_1).end(END_OP); + operation_q0.then(LAMBDA_33).then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_OP); + operation_q0.then(LAMBDA_34).then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_OP); + operation_q0.then(LAMBDA_35).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_1).end(END_OP); + operation_q0.then(LAMBDA_36).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).end(END_OP); + operation_q0.then(LAMBDA_37).then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).end(END_OP); operation_q0.then(LAMBDA_38).then(LAMBDA_1).end(END_OP); - operation_q0.then(LAMBDA_39).end(END_OP); + operation_q0.then(LAMBDA_39).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_1).end(END_OP); + operation_q0.then(LAMBDA_40).then(LAMBDA_1).end(END_OP); + operation_q0.then(LAMBDA_41).end(END_OP); StateTree function_q17 = new StateTree<>(); - StateTree function_q18 = function_q17.then(LAMBDA_40); - StateTree function_q19 = function_q18.then(LAMBDA_41); - function_q19.end((func, validator) -> func); - StateTree function_q22 = function_q18.then(new RedirectStateTree<>(operation_q0,(bag) -> "?")); - function_q22.then(function_q19); - StateTree function_q21 = function_q22; + StateTree function_q18 = function_q17.then(LAMBDA_42); + StateTree function_q19 = function_q18.then(LAMBDA_43); + function_q19.end((a,b) -> { System.out.println("\t\tolala"); return a;}); + StateTree function_q21 = function_q18.then(new RedirectStateTree<>(variable_q0,(bag) -> "var")); + StateTree function_q22 = function_q18.then(new RedirectStateTree<>(operation_q0,(bag) -> "op")); function_q21.then(function_q19); + function_q22.then(function_q19); function_q22.then(function_q21); function_q21.then(function_q22); StateTree function_q0 = new StateTree<>(); StateTree function_q1 = function_q0.then(new RedirectStateTree<>(type_q0,(bag) -> "return")); - function_q1.then(LAMBDA_40).end(END_FUNC).then(function_q17); + function_q1.then(LAMBDA_42).end(END_FUNC).then(function_q17); StateTree function_q3 = function_q1.then((v) -> v.validate( (t) -> t.getType().equals(TokenType.NAME), - (bag, t) -> bag.set("name",t))).then(LAMBDA_23); + (bag, token) -> bag.set("name", token))).then(LAMBDA_23); StateTree function_q4 = function_q3.then(LAMBDA_24); - StateTree function_q10 = function_q4.then(LAMBDA_44).then(new RedirectStateTree<>(type_q0,(bag) -> "?")); + StateTree function_q10 = function_q4.then(LAMBDA_45).then(new RedirectStateTree<>(type_q0,(bag) -> "?")); function_q10.end(END_FUNC).then(function_q17); StateTree function_q11 = function_q10.then(LAMBDA_7); function_q11.then(function_q10); @@ -199,7 +222,10 @@ public class JavaParser extends Parser { StateTree function_q6 = function_q3.then(new RedirectStateTree<>(type_q0,(bag) -> "?")); StateTree function_q8 = function_q7.then(LAMBDA_7); function_q8.then(function_q6); - StateTree function_q15 = function_q0.then(new RedirectStateTree<>(modifier_q0,(bag) -> "modifier")); + StateTree function_q15 = function_q0.then(new RedirectStateTree<>(modifier_q0, (bag) -> "?")); + StateTree function_q20 = function_q0.then(new RedirectStateTree<>(annotation_q0,(bag) -> "?")).loop(); + function_q20.then(function_q1); + function_q20.then(function_q15); function_q15.then(function_q1); StateTree class_q16 = new StateTree<>(); @@ -208,23 +234,27 @@ public class JavaParser extends Parser { StateTree class_q19 = class_q16.then(new RedirectStateTree<>(function_q0,(bag) -> "?")); class_q19.then(class_q16); StateTree class_q0 = new StateTree<>(); - StateTree class_q1 = class_q0.then(LAMBDA_46); + StateTree class_q1 = class_q0.then(LAMBDA_47); StateTree class_q2 = class_q1.then(new RedirectStateTree<>(type_q0,(bag) -> "name")); - StateTree class_q9 = class_q2.then(LAMBDA_47); + StateTree class_q7 = class_q2.then(LAMBDA_48).then(new RedirectStateTree<>(type_q0,(bag) -> "extend")); + class_q7.then(LAMBDA_42).end(END_CLASS).then(class_q16); + class_q2.then(LAMBDA_42).end(END_CLASS).then(class_q16); + StateTree class_q9 = class_q2.then(LAMBDA_49); StateTree class_q11 = class_q9.then(new RedirectStateTree<>(type_q0,(bag) -> "implement")); - class_q11.then(LAMBDA_40).end(END_CLASS).then(class_q16); + class_q11.then(LAMBDA_42).end(END_CLASS).then(class_q16); StateTree class_q12 = class_q11.then(LAMBDA_7); class_q12.then(class_q11); - StateTree class_q7 = class_q2.then(LAMBDA_48).then(new RedirectStateTree<>(type_q0,(bag) -> "extend")); class_q7.then(class_q9); - class_q7.then(LAMBDA_40).end(END_CLASS).then(class_q16); - class_q2.then(LAMBDA_40).end(END_CLASS).then(class_q16); + StateTree class_q17 = class_q0.then(new RedirectStateTree<>(annotation_q0,(bag) -> "class_annotation")).loop(); + class_q17.then(class_q1); StateTree class_q3 = class_q0.then(new RedirectStateTree<>(modifier_q0,(bag) -> "modifier")); class_q3.then(class_q1); + class_q17.then(class_q3); main.then(new RedirectStateTree<>(package_q0, (b) -> null)).then(main); main.then(new RedirectStateTree<>(import_q0, (b) -> null)).then(main); main.then(new RedirectStateTree<>(class_q0, (b) -> null)).then(main); + System.out.println((System.currentTimeMillis()-time)+"ms");