One Value
This commit is contained in:
parent
af44fe414f
commit
64f39dc840
4 changed files with 50 additions and 24 deletions
|
@ -19,6 +19,7 @@ public class Bag{
|
|||
}
|
||||
|
||||
public void set(Object value){
|
||||
System.out.println("bag set "+value);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
@ -27,6 +28,7 @@ public class Bag{
|
|||
}
|
||||
|
||||
public void set(String key, Object value){
|
||||
System.out.println("bag set "+key+" -> "+value);
|
||||
this.map.put(key, value);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ 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;
|
||||
|
||||
|
@ -129,8 +130,10 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
StateTree<JavaElement> value_q0 = value(LAMBDA_5, LAMBDA_6, LAMBDA_7, LAMBDA_8, LAMBDA_10, LAMBDA_11, LAMBDA_12, LAMBDA_13, LAMBDA_14, LAMBDA_15, LAMBDA_16, LAMBDA_17, LAMBDA_18, LAMBDA_19, LAMBDA_20, LAMBDA_21, LAMBDA_23, LAMBDA_24, LAMBDA_25, LAMBDA_26, LAMBDA_27, LAMBDA_28, LAMBDA_29);
|
||||
|
||||
System.out.println("----");
|
||||
//(ab = (cd & 3))
|
||||
tokenizer.getTokens().addAll(build("(","ab","=","(","cd","&","34",")",")"));
|
||||
//(ab = (cd & 34))
|
||||
// tokenizer.getTokens().addAll(build("(","ab","=","(","cd","&","34",")",")"));
|
||||
tokenizer.getTokens().addAll(build("(","ab","=","cd",")"));
|
||||
// tokenizer.getTokens().addAll(build("(","ab",")"));
|
||||
value_q0.seed(tokenizer, null);
|
||||
System.out.println("----");
|
||||
|
||||
|
@ -203,25 +206,27 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
Function<TokenValidator, Boolean> LAMBDA_28,
|
||||
Function<TokenValidator, Boolean> LAMBDA_29
|
||||
){
|
||||
BiFunction<JavaElement, TokenValidator, JavaElement> END_NATIVE_VALUE = (element, validator) -> {
|
||||
System.out.println("\tnative\t"+element);
|
||||
System.out.println("\t"+validator.getBag());
|
||||
return new ValueContainer(validator.getBag().<Bag>get("?").get());
|
||||
};
|
||||
BiFunction<JavaElement, TokenValidator, JavaElement> END_VALUE = (element, validator) -> {
|
||||
//single value
|
||||
System.out.println("end value "+validator.getBag());
|
||||
Bag bag = validator.getBag();
|
||||
Value v = new Value(bag);
|
||||
bag.set("result",v);
|
||||
System.out.println("\tvalue\t"+element);
|
||||
Value v = new Value(validator.getBag().get());
|
||||
validator.getBag().set(v);
|
||||
return v;
|
||||
};
|
||||
BiFunction<JavaElement, TokenValidator, JavaElement> END_BIVALUE = (element, validator) -> {
|
||||
//create new value from parent & created single value
|
||||
System.out.println("end bi value "+validator.getBag());
|
||||
Bag bag = validator.getBag();
|
||||
return new BiValue((Value)element, bag.<Bag>get("?").get("result"));
|
||||
System.out.println("\tbivalue\t"+element);
|
||||
return null;
|
||||
};
|
||||
BiFunction<JavaElement, TokenValidator, JavaElement> END_TRIVALUE = (element, validator) -> {
|
||||
//same but for val ? val : val
|
||||
System.out.println("end tri value "+validator.getBag());
|
||||
Bag bag = validator.getBag();
|
||||
return new TriValue(bag);
|
||||
System.out.println("\ttrivalue\t"+element);
|
||||
return new TriValue();
|
||||
};
|
||||
StateTree<JavaElement> value_q0 = new StateTree<>();
|
||||
StateTree<JavaElement> value_q22 = new StateTree<>();
|
||||
|
@ -232,7 +237,7 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
value_q24.then(new RedirectStateTree<>(value_q0,(bag) -> "?")).<JavaElement>end(END_BIVALUE); // <
|
||||
value_q24.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).<JavaElement>end(END_BIVALUE); // <=
|
||||
StateTree<JavaElement> value_q41 = value_q24.then(LAMBDA_5);
|
||||
value_q41.then(new RedirectStateTree<>(value_q0,(bag) -> "?")).<JavaElement>end(END_BIVALUE); // <<
|
||||
value_q41.then(new RedirectStateTree<>(value_q0,(bag) -> "<<")).<JavaElement>end(END_BIVALUE); // <<
|
||||
value_q41.then(LAMBDA_8).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).<JavaElement>end(END_BIVALUE); // <<=
|
||||
StateTree<JavaElement> value_q25 = value_q22.then(LAMBDA_6);
|
||||
value_q25.then(new RedirectStateTree<>(value_q0,(bag) -> "?")).<JavaElement>end(END_BIVALUE); // >
|
||||
|
@ -287,9 +292,9 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
value_q1.<JavaElement>end(END_VALUE).then(value_q22);
|
||||
StateTree<JavaElement> value_q11 = value_q1.then(LAMBDA_25);
|
||||
value_q11.then(value_q1);
|
||||
value_q0.then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).<JavaElement>end(END_VALUE).then(value_q22);
|
||||
value_q0.then(LAMBDA_26).then(LAMBDA_27).then(LAMBDA_26).<JavaElement>end(END_VALUE).then(value_q22);
|
||||
value_q0.then(LAMBDA_28).then(LAMBDA_29).then(LAMBDA_28).<JavaElement>end(END_VALUE).then(value_q22);
|
||||
value_q0.then(LAMBDA_23).then(new RedirectStateTree<>(value_q0,(bag) -> "?")).then(LAMBDA_24).<JavaElement>end(END_NATIVE_VALUE).then(value_q22);
|
||||
value_q0.then(LAMBDA_26).then(LAMBDA_27).then(LAMBDA_26).<JavaElement>end(END_NATIVE_VALUE).then(value_q22);
|
||||
value_q0.then(LAMBDA_28).then(LAMBDA_29).then(LAMBDA_28).<JavaElement>end(END_NATIVE_VALUE).then(value_q22);
|
||||
return value_q0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.java;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.parser.Bag;
|
||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||
|
||||
public class Value extends JavaElement{
|
||||
|
@ -9,9 +8,9 @@ public class Value extends JavaElement{
|
|||
|
||||
protected Value(){}
|
||||
|
||||
public Value(Bag bag){
|
||||
this.token = bag.get();
|
||||
System.out.println("NEW value "+token);
|
||||
public Value(Token token){
|
||||
this.token = token;
|
||||
System.out.println(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +18,22 @@ public class Value extends JavaElement{
|
|||
return "[Value="+token+"]";
|
||||
}
|
||||
|
||||
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 static class BiValue extends Value{
|
||||
|
||||
private Value left;
|
||||
|
@ -27,15 +42,19 @@ public class Value extends JavaElement{
|
|||
public BiValue(Value left, Value right){
|
||||
this.left = left;
|
||||
this.right = right;
|
||||
System.out.println("NEW BiValue "+left+"|"+right);
|
||||
System.out.println(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "[BiValue left="+left+" right="+right+"]";
|
||||
}
|
||||
}
|
||||
|
||||
public static class TriValue extends Value{
|
||||
|
||||
public TriValue(Bag bag){
|
||||
super(bag);
|
||||
public TriValue(){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
|||
return false;
|
||||
});
|
||||
Object builded = redirect.internalSeed(branch, (E) element);
|
||||
// System.out.println("redirect builded "+builded);
|
||||
System.out.println("redirect "+g+" builded "+builded);
|
||||
if(builded == null) return null;
|
||||
|
||||
validator.merge(branch);
|
||||
|
|
Loading…
Add table
Reference in a new issue