Capture all tokens from composant parser
This commit is contained in:
parent
35110db4e2
commit
c8c92687e8
3 changed files with 29 additions and 18 deletions
10
java.pc
10
java.pc
|
@ -33,7 +33,7 @@ class(
|
|||
mod:modifier(
|
||||
:class
|
||||
),
|
||||
class:[class],
|
||||
class:[class]
|
||||
type -> name(
|
||||
:end,
|
||||
:implements,
|
||||
|
@ -45,13 +45,13 @@ class(
|
|||
:imp,
|
||||
:end
|
||||
)
|
||||
)
|
||||
);
|
||||
extends:[extends](
|
||||
type -> extend(
|
||||
:implements,
|
||||
:end
|
||||
)
|
||||
:end,
|
||||
:implements
|
||||
)
|
||||
);
|
||||
|
||||
end:[{]=
|
||||
)
|
||||
|
|
|
@ -28,10 +28,6 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
|||
validator.setBag(localBag);
|
||||
|
||||
TokenValidator branch = validator.branch();
|
||||
branch.validate((t) -> {
|
||||
System.out.println(t);
|
||||
return false;
|
||||
});
|
||||
Object builded = redirect.internalSeed(branch, (E) element);
|
||||
// System.out.println("redirect "+localBag.path()+" builded "+builded);
|
||||
if(builded == null) return null;
|
||||
|
|
|
@ -5,9 +5,12 @@ import java.io.BufferedWriter;
|
|||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||
import be.jeffcheasey88.peeratcode.parser.Token;
|
||||
import be.jeffcheasey88.peeratcode.parser.TokenType;
|
||||
import be.jeffcheasey88.peeratcode.parser.Tokenizer;
|
||||
import be.jeffcheasey88.peeratcode.parser.state.RedirectStateTree;
|
||||
|
@ -50,11 +53,11 @@ public class ParserComposantGenerator {
|
|||
|
||||
StateTree<Element> simpleAction = validator
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals("[")))
|
||||
.then((v) -> v.validate((t) -> true, (bag, t) -> bag.set(t)))
|
||||
.then((v) -> v.validate((t) -> !t.getValue().equals("]"), (bag, t) -> bag.set(t))).loop()
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals("]")));
|
||||
StateTree<Element> customAction = validator
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals("{")))
|
||||
.then((v) -> v.validate((t) -> true, (bag, t) -> bag.set(t)))
|
||||
.then((v) -> v.validate((t) -> !t.getValue().equals("}"), (bag, t) -> bag.set(t))).loop()
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals("}")));
|
||||
simpleAction.then(modifiers);
|
||||
customAction.then(modifiers);
|
||||
|
@ -99,7 +102,13 @@ public class ParserComposantGenerator {
|
|||
op_childs.then((v) -> v.validate((t) -> t.getValue().equals("(")))
|
||||
.then(new RedirectStateTree<>(operations, (bag) -> "?"))
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals(")")))
|
||||
.end((composant, bag) -> composant);
|
||||
.end((composant, bag) -> {
|
||||
System.out.println("\t"+bag);
|
||||
return composant;
|
||||
});
|
||||
|
||||
operation.then(new RedirectStateTree<>(gotoValidator, (bag) -> "?"))
|
||||
.then(operations);
|
||||
|
||||
StateTree<Element> op_validator = operation.then(new RedirectStateTree<>(validator, (bag) -> "?"));
|
||||
op_validator.end((composant, bag) -> composant).then(op_childs);
|
||||
|
@ -113,8 +122,6 @@ public class ParserComposantGenerator {
|
|||
op_redirect.end((composant, bag) -> composant).then(op_childs);
|
||||
op_redirect.then(new RedirectStateTree<>(namedValidator, (bag) -> "?")).end((composant, bag) -> composant).then(op_childs);
|
||||
|
||||
operation.then(new RedirectStateTree<>(gotoValidator, (bag) -> "?")).then(operations);
|
||||
|
||||
StateTree<Element> suit = operations.then(new RedirectStateTree<>(operation, (bag) -> "?")).loop();
|
||||
suit.then((v) -> v.validate((t) -> t.getValue().equals(",")))
|
||||
.then(suit).end((composant, bag) -> composant);
|
||||
|
@ -126,9 +133,14 @@ public class ParserComposantGenerator {
|
|||
|
||||
StateTree<Element> composant = main.then((v) -> v.validate(
|
||||
(token) -> token.getType().equals(TokenType.NAME),
|
||||
(bag, token) -> bag.set("name", token)
|
||||
(bag, token) -> bag.set(token)
|
||||
));
|
||||
composant.then(new RedirectStateTree<>(op_childs, (bag) -> "?")).loop();
|
||||
composant.then(new RedirectStateTree<>(op_childs, (bag) -> "content"))
|
||||
.end((element, bag) -> {
|
||||
System.out.println(bag);
|
||||
return element;
|
||||
})
|
||||
.then(composant);
|
||||
|
||||
|
||||
setTokenizer(new Tokenizer());
|
||||
|
@ -150,12 +162,15 @@ public class ParserComposantGenerator {
|
|||
|
||||
public static class SynthaxeComposant extends Element{
|
||||
|
||||
private List<Composant> composants;
|
||||
private Map<String, Composant> composants;
|
||||
|
||||
public SynthaxeComposant(){
|
||||
|
||||
this.composants = new HashMap<>();
|
||||
}
|
||||
|
||||
void register(String name, Composant composant){
|
||||
this.composants.put(name, composant);
|
||||
}
|
||||
|
||||
public static class Composant extends Element{
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue