From ef587d389fd1ef5b8a599e28e162f7fbd89fab45 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Tue, 11 Jul 2023 22:50:52 +0200 Subject: [PATCH] Base Generator by composant --- java.pc | 85 +++++++++ .../generator/ParserComposantGenerator.java | 173 ++++++++++++++++++ 2 files changed, 258 insertions(+) create mode 100644 java.pc create mode 100644 src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java diff --git a/java.pc b/java.pc new file mode 100644 index 0000000..8570ea5 --- /dev/null +++ b/java.pc @@ -0,0 +1,85 @@ +annotation( + [@] + {name}= -> name + [(]( + :end, + value() -> val + [)]=, + :content + ); + + content: + :value -> values + [)]=; + value: + {name} + [=] + value( + :end, + [,] + :value + ) -> add(value); + + end:[)]= +) + +modifier({modifier}*= -> concat(mod)) + +class( + annotation( + :mod, + :class + ), + mod:modifier( + :class + ), + class:[class], + type( + :end, + :implements, + :extends + ) -> name; + implements:[implements]( + imp:type() -> add(implement)( + [,] + :imp, + :end + ) + ) + extends:[extends]( + type() -> extend( + :implements, + :end + ) + ) + + end:[{]= +) + +import( + [import]( + :static, + :normal + ); + static:[static]( + :normal + ); + normal:[!;]* -> concat(import) + [;]=; + + import, + class +) + +package( + [package] + [!;]* -> concat(package) + [;]=; + + import, + class +) + +main( + package +) \ No newline at end of file diff --git a/src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java b/src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java new file mode 100644 index 0000000..d75d999 --- /dev/null +++ b/src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java @@ -0,0 +1,173 @@ +package be.jeffcheasey88.peeratcode.parser.state.generator; + +import java.io.BufferedReader; +import java.util.List; + +import be.jeffcheasey88.peeratcode.parser.Parser; +import be.jeffcheasey88.peeratcode.parser.TokenType; +import be.jeffcheasey88.peeratcode.parser.Tokenizer; +import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree; +import be.jeffcheasey88.peeratcode.parser.state.StateTree; +import be.jeffcheasey88.peeratcode.parser.state.generator.ParserComposantGenerator.Element.SynthaxeComposant; + +public class ParserComposantGenerator { + + private BufferedReader reader; + + public ParserComposantGenerator(BufferedReader reader){ + this.reader = reader; + } + + public void generate() throws Exception{ + SynthaxeComposant synthax = load(); + } + + private SynthaxeComposant load() throws Exception{ + SynthaxeComposant composant = new SynthaxeComposant(); + Parser parser = new Parser(){ + { + StateTree validator = new StateTree<>(); + StateTree modifiers = new StateTree<>(); + modifiers.end(null); + StateTree end = modifiers.then((v) -> v.validate( + (t) -> t.getValue().equals("="), + (bag,t) -> bag.set("end", true))); + StateTree loop = modifiers.then((v) -> v.validate( + (t) -> t.getValue().equals("*"), + (bag,t) -> bag.set("loop", true))); + loop.then(end); + loop.end(null); + end.end(null); + + StateTree simpleAction = validator + .then((v) -> v.validate((t) -> t.getValue().equals("["))) + .then((v) -> v.validate((t) -> true, (bag, t) -> bag.set(t))) + .then((v) -> v.validate((t) -> t.getValue().equals("]"))); + StateTree customAction = validator + .then((v) -> v.validate((t) -> t.getValue().equals("{"))) + .then((v) -> v.validate((t) -> true, (bag, t) -> bag.set(t))) + .then((v) -> v.validate((t) -> t.getValue().equals("}"))); + simpleAction.then(modifiers); + customAction.then(modifiers); + + StateTree namedValidator = new StateTree<>(); + StateTree leftSide = namedValidator + .then(new RedirectStateTree<>(validator, (bag) -> "validator")) + .then((v) -> v.validate((t) -> t.getValue().equals("-")) && v.validate((t) -> t.getValue().equals(">"))) + .then((v) -> v.validate( + (t) -> t.getType().equals(TokenType.NAME), + (bag, t) -> bag.set(t))); + leftSide.end(null); + + StateTree redirection = new StateTree<>(); + redirection.then((v) -> v.validate((t) -> t.getType().equals(TokenType.NAME))); + + StateTree main = new StateTree<>(); + + StateTree composant = main.then((v) -> v.validate( + (token) -> token.getType().equals(TokenType.NAME), + (bag, token) -> bag.set("name", token) + )); + + setTokenizer(new Tokenizer()); + setStateTree(main); + } + }; + + return composant; + } + + public static class Element{ + + public Element(){ + + } + + public static class SynthaxeComposant extends Element{ + + private List composants; + + public SynthaxeComposant(){ + + } + + + public static class Composant extends Element{ + + private String title; + + private List path; + private List declared; + private List next; + + public Composant(){ + + } + + public static class Validator extends Element{ + + private String action; + private boolean end; + private boolean loop; + + public Validator(){ + + } + } + + public static class NamedValidator extends Validator{ + + private String logic; + private String name; + + public NamedValidator(){ + + } + + } + + public static class Redirection extends Element{ + + private String target; + + public Redirection(){ + + } + + } + + public static class NamedRedirection extends Redirection{ + + private String logic; + private String name; + + public NamedRedirection(){ + + } + + } + + public static class ComposantCall extends Element{ + + private String name; + + public ComposantCall(){ + + } + + } + + public static class NamedComposantCall extends ComposantCall{ + + private String logic; + private String name; + + public NamedComposantCall(){ + + } + + } + } + } + } +}