diff --git a/src/be/jeffcheasey88/peeratcode/parser/Bag.java b/src/be/jeffcheasey88/peeratcode/parser/Bag.java index 51d3de7..4dcd039 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/Bag.java +++ b/src/be/jeffcheasey88/peeratcode/parser/Bag.java @@ -10,6 +10,8 @@ public class Bag{ private Object value; + private String path = ""; + public Bag(){ this.map = new HashMap<>(); } @@ -18,6 +20,14 @@ public class Bag{ return (E) this.value; } + public void addPath(String s){ + path+=s; + } + + public String path(){ + return this.path; + } + public void set(Object value){ System.out.println("bag set "+value); this.value = value; diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index f49df83..9529660 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -18,7 +18,6 @@ import be.jeffcheasey88.peeratcode.parser.TokenValidator; import be.jeffcheasey88.peeratcode.parser.Tokenizer; import be.jeffcheasey88.peeratcode.parser.java.Value.BiValue; import be.jeffcheasey88.peeratcode.parser.java.Value.TriValue; -import be.jeffcheasey88.peeratcode.parser.java.Value.ValueContainer; import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree; import be.jeffcheasey88.peeratcode.parser.state.StateTree; @@ -132,8 +131,8 @@ public class JavaParser extends Parser { System.out.println("----"); //(ab = (cd & 34)) // tokenizer.getTokens().addAll(build("(","ab","=","(","cd","&","34",")",")")); - tokenizer.getTokens().addAll(build("(","ab","=","cd",")")); -// tokenizer.getTokens().addAll(build("(","ab",")")); +// tokenizer.getTokens().addAll(build("(","ab","=","cd",")")); + tokenizer.getTokens().addAll(build("(","ab",")")); value_q0.seed(tokenizer, null); System.out.println("----"); @@ -209,7 +208,13 @@ public class JavaParser extends Parser { BiFunction END_NATIVE_VALUE = (element, validator) -> { System.out.println("\tnative\t"+element); System.out.println("\t"+validator.getBag()); - return new ValueContainer(validator.getBag().get("?").get()); + Value result = validator.getBag().get("?").get(); + if(result.get() != null){ + System.out.println("got "+result.get()); + return result.get(); + } + System.out.println("got "+result); + return result; }; BiFunction END_VALUE = (element, validator) -> { //single value @@ -221,7 +226,10 @@ public class JavaParser extends Parser { BiFunction END_BIVALUE = (element, validator) -> { //create new value from parent & created single value System.out.println("\tbivalue\t"+element); - return null; + Value v = new BiValue((Value)element, validator.getBag().get("?").get()); + Value origin = (Value)element; + origin.switchInto(v); + return v; }; BiFunction END_TRIVALUE = (element, validator) -> { //same but for val ? val : val diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Value.java b/src/be/jeffcheasey88/peeratcode/parser/java/Value.java index cb05059..acb226a 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Value.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Value.java @@ -6,6 +6,8 @@ public class Value extends JavaElement{ private Token token; + private Value value; + protected Value(){} public Value(Token token){ @@ -13,25 +15,17 @@ public class Value extends JavaElement{ System.out.println(this); } - @Override - public String toString(){ - return "[Value="+token+"]"; + public void switchInto(Value value){ + this.value = value; } - public static class ValueContainer extends Value{ - - private Value value; - - public ValueContainer(Value value){ - this.value = value; - System.out.println(this); - } - - @Override - public String toString(){ - return "[ContainerValue="+value+"]"; - } - + public Value get(){ + return this.value; + } + + @Override + public String toString(){ + return "[Value="+token+", val="+((value == null ? "null":value.getClass().getSimpleName()))+"]"; } public static class BiValue extends Value{ diff --git a/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java b/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java index 0cada2c..01db486 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java +++ b/src/be/jeffcheasey88/peeratcode/parser/state/RedirectStateTree.java @@ -22,7 +22,8 @@ public class RedirectStateTree extends StateTree{ Bag localBag = new Bag(); String g = group.apply(currentBag); - System.out.println("redirect "+g); + localBag.addPath(currentBag.path()+"/"+g); + System.out.println("redirect "+localBag.path()); currentBag.set(g, localBag); validator.setBag(localBag); @@ -32,7 +33,7 @@ public class RedirectStateTree extends StateTree{ return false; }); Object builded = redirect.internalSeed(branch, (E) element); - System.out.println("redirect "+g+" builded "+builded); + System.out.println("redirect "+localBag.path()+" builded "+builded); if(builded == null) return null; validator.merge(branch);