Capture base validator
This commit is contained in:
parent
c8c92687e8
commit
da9bb2df4d
1 changed files with 63 additions and 45 deletions
|
@ -9,6 +9,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.Bag;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Parser;
|
import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||||
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||||
|
@ -16,6 +17,8 @@ import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
||||||
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;
|
||||||
import be.jeffcheasey88.peeratcode.parser.state.generator.ParserComposantGenerator.Element.SynthaxeComposant;
|
import be.jeffcheasey88.peeratcode.parser.state.generator.ParserComposantGenerator.Element.SynthaxeComposant;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.generator.ParserComposantGenerator.Element.SynthaxeComposant.Composant.NamedElement;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.state.generator.ParserComposantGenerator.Element.SynthaxeComposant.Composant.Validator;
|
||||||
|
|
||||||
public class ParserComposantGenerator {
|
public class ParserComposantGenerator {
|
||||||
|
|
||||||
|
@ -40,7 +43,11 @@ public class ParserComposantGenerator {
|
||||||
{
|
{
|
||||||
StateTree<Element> validator = new StateTree<>();
|
StateTree<Element> validator = new StateTree<>();
|
||||||
StateTree<Element> modifiers = new StateTree<>();
|
StateTree<Element> modifiers = new StateTree<>();
|
||||||
modifiers.end((composant, bag) -> composant);
|
modifiers.end((composant, bag) -> {
|
||||||
|
Element result = new Validator(bag);
|
||||||
|
bag.set(result);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
StateTree<Element> end = modifiers.then((v) -> v.validate(
|
StateTree<Element> end = modifiers.then((v) -> v.validate(
|
||||||
(t) -> t.getValue().equals("="),
|
(t) -> t.getValue().equals("="),
|
||||||
(bag,t) -> bag.set("end", true)));
|
(bag,t) -> bag.set("end", true)));
|
||||||
|
@ -48,17 +55,25 @@ public class ParserComposantGenerator {
|
||||||
(t) -> t.getValue().equals("*"),
|
(t) -> t.getValue().equals("*"),
|
||||||
(bag,t) -> bag.set("loop", true)));
|
(bag,t) -> bag.set("loop", true)));
|
||||||
loop.then(end);
|
loop.then(end);
|
||||||
loop.end((composant, bag) -> composant);
|
loop.end((composant, bag) -> {
|
||||||
end.end((composant, bag) -> composant);
|
Element result = new Validator(bag);
|
||||||
|
bag.set(result);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
end.end((composant, bag) -> {
|
||||||
|
Element result = new Validator(bag);
|
||||||
|
bag.set(result);
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
StateTree<Element> simpleAction = validator
|
StateTree<Element> simpleAction = validator
|
||||||
.then((v) -> v.validate((t) -> t.getValue().equals("[")))
|
.then((v) -> v.validate((t) -> t.getValue().equals("[")))
|
||||||
.then((v) -> v.validate((t) -> !t.getValue().equals("]"), (bag, t) -> bag.set(t))).loop()
|
.then((v) -> v.validate((t) -> !t.getValue().equals("]"), (bag, t) -> bag.set(t))).loop()
|
||||||
.then((v) -> v.validate((t) -> t.getValue().equals("]")));
|
.then((v) -> v.validate((t) -> t.getValue().equals("]"), (bag, t) -> bag.set("type", "simple")));
|
||||||
StateTree<Element> customAction = validator
|
StateTree<Element> customAction = validator
|
||||||
.then((v) -> v.validate((t) -> t.getValue().equals("{")))
|
.then((v) -> v.validate((t) -> t.getValue().equals("{")))
|
||||||
.then((v) -> v.validate((t) -> !t.getValue().equals("}"), (bag, t) -> bag.set(t))).loop()
|
.then((v) -> v.validate((t) -> !t.getValue().equals("}"), (bag, t) -> bag.set(t))).loop()
|
||||||
.then((v) -> v.validate((t) -> t.getValue().equals("}")));
|
.then((v) -> v.validate((t) -> t.getValue().equals("}"), (bag, t) -> bag.set("type", "custom")));
|
||||||
simpleAction.then(modifiers);
|
simpleAction.then(modifiers);
|
||||||
customAction.then(modifiers);
|
customAction.then(modifiers);
|
||||||
|
|
||||||
|
@ -68,13 +83,13 @@ public class ParserComposantGenerator {
|
||||||
.then((v) -> v.validate(
|
.then((v) -> v.validate(
|
||||||
(t) -> t.getType().equals(TokenType.NAME),
|
(t) -> t.getType().equals(TokenType.NAME),
|
||||||
(bag, t) -> bag.set(t)));
|
(bag, t) -> bag.set(t)));
|
||||||
leftSide.end((composant, bag) -> composant);
|
leftSide.end((composant, bag) -> new NamedElement(bag));
|
||||||
leftSide.then((v) ->
|
leftSide.then((v) ->
|
||||||
v.validate((t) -> t.getValue().equals("(")) &&
|
v.validate((t) -> t.getValue().equals("(")) &&
|
||||||
v.validate((t) -> t.getType().equals(TokenType.NAME), (bag, t) -> bag.set("inside", t)) &&
|
v.validate((t) -> t.getType().equals(TokenType.NAME), (bag, t) -> bag.set("inside", t)) &&
|
||||||
v.validate((t) -> t.getValue().equals(")"))
|
v.validate((t) -> t.getValue().equals(")"))
|
||||||
)
|
)
|
||||||
.end((composant, bag) -> composant);
|
.end((composant, bag) -> new NamedElement(bag));
|
||||||
|
|
||||||
StateTree<Element> gotoValidator = new StateTree<>();
|
StateTree<Element> gotoValidator = new StateTree<>();
|
||||||
gotoValidator.then((v) -> v.validate(
|
gotoValidator.then((v) -> v.validate(
|
||||||
|
@ -100,7 +115,9 @@ public class ParserComposantGenerator {
|
||||||
|
|
||||||
StateTree<Element> op_childs = new StateTree<>();
|
StateTree<Element> op_childs = new StateTree<>();
|
||||||
op_childs.then((v) -> v.validate((t) -> t.getValue().equals("(")))
|
op_childs.then((v) -> v.validate((t) -> t.getValue().equals("(")))
|
||||||
.then(new RedirectStateTree<>(operations, (bag) -> "?"))
|
.then(new RedirectStateTree<>(operations, (bag) -> {
|
||||||
|
return "operations";
|
||||||
|
}))
|
||||||
.then((v) -> v.validate((t) -> t.getValue().equals(")")))
|
.then((v) -> v.validate((t) -> t.getValue().equals(")")))
|
||||||
.end((composant, bag) -> {
|
.end((composant, bag) -> {
|
||||||
System.out.println("\t"+bag);
|
System.out.println("\t"+bag);
|
||||||
|
@ -110,19 +127,22 @@ public class ParserComposantGenerator {
|
||||||
operation.then(new RedirectStateTree<>(gotoValidator, (bag) -> "?"))
|
operation.then(new RedirectStateTree<>(gotoValidator, (bag) -> "?"))
|
||||||
.then(operations);
|
.then(operations);
|
||||||
|
|
||||||
StateTree<Element> op_validator = operation.then(new RedirectStateTree<>(validator, (bag) -> "?"));
|
StateTree<Element> op_validator = operation.then(new RedirectStateTree<>(validator, (bag) -> "validator"));
|
||||||
op_validator.end((composant, bag) -> composant).then(op_childs);
|
op_validator.end((composant, bag) -> {
|
||||||
op_validator.then(new RedirectStateTree<>(namedValidator, (bag) -> "?")).end((composant, bag) -> composant).then(op_childs);
|
System.out.println("+\t"+bag);
|
||||||
|
return composant;
|
||||||
|
}).then(op_childs);
|
||||||
|
op_validator.then(new RedirectStateTree<>(namedValidator, (bag) -> "namedValidator")).end((composant, bag) -> composant).then(op_childs);
|
||||||
|
|
||||||
StateTree<Element> op_call = operation.then(new RedirectStateTree<>(methodCall, (bag) -> "?"));
|
StateTree<Element> op_call = operation.then(new RedirectStateTree<>(methodCall, (bag) -> "methodCall"));
|
||||||
op_call.end((composant, bag) -> composant).then(op_childs);
|
op_call.end((composant, bag) -> composant).then(op_childs);
|
||||||
op_call.then(new RedirectStateTree<>(namedValidator, (bag) -> "?")).end((composant, bag) -> composant).then(op_childs);
|
op_call.then(new RedirectStateTree<>(namedValidator, (bag) -> "namedValidator")).end((composant, bag) -> composant).then(op_childs);
|
||||||
|
|
||||||
StateTree<Element> op_redirect = operation.then(new RedirectStateTree<>(redirection, (bag) -> "?"));
|
StateTree<Element> op_redirect = operation.then(new RedirectStateTree<>(redirection, (bag) -> "redirection"));
|
||||||
op_redirect.end((composant, bag) -> composant).then(op_childs);
|
op_redirect.end((composant, bag) -> composant).then(op_childs);
|
||||||
op_redirect.then(new RedirectStateTree<>(namedValidator, (bag) -> "?")).end((composant, bag) -> composant).then(op_childs);
|
op_redirect.then(new RedirectStateTree<>(namedValidator, (bag) -> "namedValidator")).end((composant, bag) -> composant).then(op_childs);
|
||||||
|
|
||||||
StateTree<Element> suit = operations.then(new RedirectStateTree<>(operation, (bag) -> "?")).loop();
|
StateTree<Element> suit = operations.then(new RedirectStateTree<>(operation, (bag) -> "operation")).loop();
|
||||||
suit.then((v) -> v.validate((t) -> t.getValue().equals(",")))
|
suit.then((v) -> v.validate((t) -> t.getValue().equals(",")))
|
||||||
.then(suit).end((composant, bag) -> composant);
|
.then(suit).end((composant, bag) -> composant);
|
||||||
suit.then((v) -> v.validate((t) -> t.getValue().equals(";")))
|
suit.then((v) -> v.validate((t) -> t.getValue().equals(";")))
|
||||||
|
@ -190,18 +210,39 @@ public class ParserComposantGenerator {
|
||||||
private boolean end;
|
private boolean end;
|
||||||
private boolean loop;
|
private boolean loop;
|
||||||
|
|
||||||
public Validator(){
|
public Validator(Bag bag){
|
||||||
|
String type = bag.get("type");
|
||||||
|
action = bag.<Token>get().getValue();
|
||||||
|
if(type.equals("simple")){
|
||||||
|
action = '['+action+']';
|
||||||
|
}else{
|
||||||
|
action = '{'+action+'}';
|
||||||
|
}
|
||||||
|
this.end = (bag.get("end") != null);
|
||||||
|
this.loop = (bag.get("loop") != null);
|
||||||
|
System.out.println(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return action+((loop ? "*":""))+((end ? "=":""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NamedValidator extends Validator{
|
public static class NamedElement extends Element{
|
||||||
|
|
||||||
private String logic;
|
private String logic;
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
public NamedValidator(){
|
public NamedElement(Bag bag){
|
||||||
|
Token inside = bag.get("inside");
|
||||||
|
if(inside != null){
|
||||||
|
this.logic = bag.<Token>get().getValue();
|
||||||
|
this.name = inside.getValue();
|
||||||
|
}else{
|
||||||
|
this.name = bag.<Token>get().getValue();
|
||||||
|
}
|
||||||
|
System.out.println(logic+"("+name+")");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -210,20 +251,7 @@ public class ParserComposantGenerator {
|
||||||
|
|
||||||
private String target;
|
private String target;
|
||||||
|
|
||||||
public Redirection(){
|
public Redirection(){}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class NamedRedirection extends Redirection{
|
|
||||||
|
|
||||||
private String logic;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public NamedRedirection(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,16 +265,6 @@ public class ParserComposantGenerator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NamedComposantCall extends ComposantCall{
|
|
||||||
|
|
||||||
private String logic;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public NamedComposantCall(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue