diff --git a/src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java b/src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java index 0cb5bb5..6241a17 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java +++ b/src/be/jeffcheasey88/peeratcode/parser/state/generator/ParserComposantGenerator.java @@ -110,6 +110,8 @@ public class ParserComposantGenerator { StateTree operations = new StateTree<>(); StateTree operation = new StateTree<>(); + StateTree sub_operations = new StateTree<>(); + StateTree gotoValidator = new StateTree<>(); gotoValidator.then((v) -> v.validate( (t) -> t.getType().equals(TokenType.NAME), @@ -123,7 +125,7 @@ public class ParserComposantGenerator { parent.currentDeclared = comp; return parent; - }).then(new RedirectStateTree<>(operations, (bag) -> { + }).then(new RedirectStateTree<>(sub_operations, (bag) -> { return "operations"; })) .end((composant, bag) -> { @@ -265,6 +267,63 @@ public class ParserComposantGenerator { return composant; }); + + StateTree sub_suit = sub_operations.then(new RedirectStateTree<>(operation, (bag) -> { + Integer count = bag.get("count"); + if(count == null) count = 0; + bag.set("count", count+1); + return "operation"+count; + })).loop(); + sub_suit.then((v) -> v.validate((t) -> t.getValue().equals(","))) + .end((composant, bag) -> { + Composant current = (Composant)composant; + if(current.currentDeclared != null) current = current.currentDeclared; + MultipleWayComposant way = current.current; + + int count = bag.get("count"); + LinkedComposant linked = new LinkedComposant(); + for(int i = 0; i < count; i++){ + Bag op = bag.get("operation"+i); + if(op.get() == null) continue; + linked.elements.add(op.get()); + } + way.elements.add(linked); + return composant; + }).then(suit); + sub_suit.then((v) -> v.validate((t) -> t.getValue().equals(";"))) + .end((composant, bag) -> { + Composant current = (Composant)composant; + if(current.currentDeclared != null) current = current.currentDeclared; + MultipleWayComposant way = current.current; + + int count = bag.get("count"); + LinkedComposant linked = new LinkedComposant(); + for(int i = 0; i < count; i++){ + Bag op = bag.get("operation"+i); + if(op.get() == null) continue; + linked.elements.add(op.get()); + } + way.elements.add(linked); + current.include(); + return composant; + }); + sub_suit.end((composant, bag) -> { + Composant current = (Composant)composant; + if(current.currentDeclared != null) current = current.currentDeclared; + MultipleWayComposant way = current.current; + + int count = bag.get("count"); + LinkedComposant linked = new LinkedComposant(); + for(int i = 0; i < count; i++){ + Bag op = bag.get("operation"+i); + if(op.get() == null) continue; + linked.elements.add(op.get()); + } + way.elements.add(linked); + current.include(); + return composant; + }); + StateTree main = new StateTree<>(); StateTree composant = main.then((v) -> v.validate(