Two Value

This commit is contained in:
jeffcheasey88 2023-07-09 12:07:30 +02:00
parent 64f39dc840
commit 9bf924ecb8
4 changed files with 37 additions and 24 deletions

View file

@ -10,6 +10,8 @@ public class Bag{
private Object value; private Object value;
private String path = "";
public Bag(){ public Bag(){
this.map = new HashMap<>(); this.map = new HashMap<>();
} }
@ -18,6 +20,14 @@ public class Bag{
return (E) this.value; return (E) this.value;
} }
public void addPath(String s){
path+=s;
}
public String path(){
return this.path;
}
public void set(Object value){ public void set(Object value){
System.out.println("bag set "+value); System.out.println("bag set "+value);
this.value = value; this.value = value;

View file

@ -18,7 +18,6 @@ import be.jeffcheasey88.peeratcode.parser.TokenValidator;
import be.jeffcheasey88.peeratcode.parser.Tokenizer; import be.jeffcheasey88.peeratcode.parser.Tokenizer;
import be.jeffcheasey88.peeratcode.parser.java.Value.BiValue; import be.jeffcheasey88.peeratcode.parser.java.Value.BiValue;
import be.jeffcheasey88.peeratcode.parser.java.Value.TriValue; 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.RedirectStateTree;
import be.jeffcheasey88.peeratcode.parser.state.StateTree; import be.jeffcheasey88.peeratcode.parser.state.StateTree;
@ -132,8 +131,8 @@ public class JavaParser extends Parser<JavaFile> {
System.out.println("----"); System.out.println("----");
//(ab = (cd & 34)) //(ab = (cd & 34))
// tokenizer.getTokens().addAll(build("(","ab","=","(","cd","&","34",")",")")); // tokenizer.getTokens().addAll(build("(","ab","=","(","cd","&","34",")",")"));
tokenizer.getTokens().addAll(build("(","ab","=","cd",")")); // tokenizer.getTokens().addAll(build("(","ab","=","cd",")"));
// tokenizer.getTokens().addAll(build("(","ab",")")); tokenizer.getTokens().addAll(build("(","ab",")"));
value_q0.seed(tokenizer, null); value_q0.seed(tokenizer, null);
System.out.println("----"); System.out.println("----");
@ -209,7 +208,13 @@ public class JavaParser extends Parser<JavaFile> {
BiFunction<JavaElement, TokenValidator, JavaElement> END_NATIVE_VALUE = (element, validator) -> { BiFunction<JavaElement, TokenValidator, JavaElement> END_NATIVE_VALUE = (element, validator) -> {
System.out.println("\tnative\t"+element); System.out.println("\tnative\t"+element);
System.out.println("\t"+validator.getBag()); System.out.println("\t"+validator.getBag());
return new ValueContainer(validator.getBag().<Bag>get("?").get()); Value result = validator.getBag().<Bag>get("?").get();
if(result.get() != null){
System.out.println("got "+result.get());
return result.get();
}
System.out.println("got "+result);
return result;
}; };
BiFunction<JavaElement, TokenValidator, JavaElement> END_VALUE = (element, validator) -> { BiFunction<JavaElement, TokenValidator, JavaElement> END_VALUE = (element, validator) -> {
//single value //single value
@ -221,7 +226,10 @@ public class JavaParser extends Parser<JavaFile> {
BiFunction<JavaElement, TokenValidator, JavaElement> END_BIVALUE = (element, validator) -> { BiFunction<JavaElement, TokenValidator, JavaElement> END_BIVALUE = (element, validator) -> {
//create new value from parent & created single value //create new value from parent & created single value
System.out.println("\tbivalue\t"+element); System.out.println("\tbivalue\t"+element);
return null; Value v = new BiValue((Value)element, validator.getBag().<Bag>get("?").get());
Value origin = (Value)element;
origin.switchInto(v);
return v;
}; };
BiFunction<JavaElement, TokenValidator, JavaElement> END_TRIVALUE = (element, validator) -> { BiFunction<JavaElement, TokenValidator, JavaElement> END_TRIVALUE = (element, validator) -> {
//same but for val ? val : val //same but for val ? val : val

View file

@ -6,6 +6,8 @@ public class Value extends JavaElement{
private Token token; private Token token;
private Value value;
protected Value(){} protected Value(){}
public Value(Token token){ public Value(Token token){
@ -13,25 +15,17 @@ public class Value extends JavaElement{
System.out.println(this); System.out.println(this);
} }
@Override public void switchInto(Value value){
public String toString(){
return "[Value="+token+"]";
}
public static class ValueContainer extends Value{
private Value value;
public ValueContainer(Value value){
this.value = value; this.value = value;
System.out.println(this); }
public Value get(){
return this.value;
} }
@Override @Override
public String toString(){ public String toString(){
return "[ContainerValue="+value+"]"; return "[Value="+token+", val="+((value == null ? "null":value.getClass().getSimpleName()))+"]";
}
} }
public static class BiValue extends Value{ public static class BiValue extends Value{

View file

@ -22,7 +22,8 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
Bag localBag = new Bag(); Bag localBag = new Bag();
String g = group.apply(currentBag); 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); currentBag.set(g, localBag);
validator.setBag(localBag); validator.setBag(localBag);
@ -32,7 +33,7 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
return false; return false;
}); });
Object builded = redirect.internalSeed(branch, (E) element); 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; if(builded == null) return null;
validator.merge(branch); validator.merge(branch);