parse most part of the Composant Parser
This commit is contained in:
parent
ef587d389f
commit
35110db4e2
5 changed files with 82 additions and 18 deletions
14
java.pc
14
java.pc
|
@ -3,7 +3,7 @@ annotation(
|
|||
{name}= -> name
|
||||
[(](
|
||||
:end,
|
||||
value() -> val
|
||||
value -> val
|
||||
[)]=,
|
||||
:content
|
||||
);
|
||||
|
@ -14,11 +14,11 @@ annotation(
|
|||
value:
|
||||
{name}
|
||||
[=]
|
||||
value(
|
||||
value -> add(value)(
|
||||
:end,
|
||||
[,]
|
||||
:value
|
||||
) -> add(value);
|
||||
);
|
||||
|
||||
end:[)]=
|
||||
)
|
||||
|
@ -34,20 +34,20 @@ class(
|
|||
:class
|
||||
),
|
||||
class:[class],
|
||||
type(
|
||||
type -> name(
|
||||
:end,
|
||||
:implements,
|
||||
:extends
|
||||
) -> name;
|
||||
);
|
||||
implements:[implements](
|
||||
imp:type() -> add(implement)(
|
||||
imp:type -> add(implement)(
|
||||
[,]
|
||||
:imp,
|
||||
:end
|
||||
)
|
||||
)
|
||||
extends:[extends](
|
||||
type() -> extend(
|
||||
type -> extend(
|
||||
:implements,
|
||||
:end
|
||||
)
|
||||
|
|
|
@ -28,7 +28,7 @@ public class Parser<E>{
|
|||
|
||||
//tmp
|
||||
public void build(BufferedWriter writer) throws Exception{
|
||||
Token[] confirmed = new Token[TokenValidator.MAX_VALIDATE+1];
|
||||
Token[] confirmed = new Token[TokenValidator.MAX_VALIDATE];
|
||||
System.arraycopy(tokenizer.getTokens().toArray(), 0, confirmed, 0, confirmed.length);
|
||||
int line = 1;
|
||||
int character = 1;
|
||||
|
|
|
@ -29,8 +29,7 @@ public class TokenValidator{
|
|||
public boolean validate(Function<Token, Boolean> action){
|
||||
if(validated >= this.elements.length) return false;
|
||||
if(action.apply(this.elements[validated])){
|
||||
System.out.println("validate "+elements[validated]);
|
||||
if(validated > MAX_VALIDATE) MAX_VALIDATE = validated;
|
||||
if(validated+1 > MAX_VALIDATE) MAX_VALIDATE = validated+1;
|
||||
this.validated++;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
|||
|
||||
String g = group.apply(currentBag);
|
||||
localBag.addPath(currentBag.path()+"/"+g);
|
||||
System.out.println("redirect "+localBag.path());
|
||||
// System.out.println("redirect "+localBag.path());
|
||||
currentBag.set(g, localBag);
|
||||
validator.setBag(localBag);
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
|||
return false;
|
||||
});
|
||||
Object builded = redirect.internalSeed(branch, (E) element);
|
||||
System.out.println("redirect "+localBag.path()+" builded "+builded);
|
||||
// System.out.println("redirect "+localBag.path()+" builded "+builded);
|
||||
if(builded == null) return null;
|
||||
|
||||
validator.merge(branch);
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.state.generator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.util.List;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.parser.Parser;
|
||||
|
@ -12,6 +16,11 @@ import be.jeffcheasey88.peeratcode.parser.state.generator.ParserComposantGenerat
|
|||
|
||||
public class ParserComposantGenerator {
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
ParserComposantGenerator generator = new ParserComposantGenerator(new BufferedReader(new FileReader(new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-parseur\\java.pc"))));
|
||||
generator.generate();
|
||||
}
|
||||
|
||||
private BufferedReader reader;
|
||||
|
||||
public ParserComposantGenerator(BufferedReader reader){
|
||||
|
@ -28,7 +37,7 @@ public class ParserComposantGenerator {
|
|||
{
|
||||
StateTree<Element> validator = new StateTree<>();
|
||||
StateTree<Element> modifiers = new StateTree<>();
|
||||
modifiers.end(null);
|
||||
modifiers.end((composant, bag) -> composant);
|
||||
StateTree<Element> end = modifiers.then((v) -> v.validate(
|
||||
(t) -> t.getValue().equals("="),
|
||||
(bag,t) -> bag.set("end", true)));
|
||||
|
@ -36,8 +45,8 @@ public class ParserComposantGenerator {
|
|||
(t) -> t.getValue().equals("*"),
|
||||
(bag,t) -> bag.set("loop", true)));
|
||||
loop.then(end);
|
||||
loop.end(null);
|
||||
end.end(null);
|
||||
loop.end((composant, bag) -> composant);
|
||||
end.end((composant, bag) -> composant);
|
||||
|
||||
StateTree<Element> simpleAction = validator
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals("[")))
|
||||
|
@ -52,15 +61,66 @@ public class ParserComposantGenerator {
|
|||
|
||||
StateTree<Element> namedValidator = new StateTree<>();
|
||||
StateTree<Element> leftSide = namedValidator
|
||||
.then(new RedirectStateTree<>(validator, (bag) -> "validator"))
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals("-")) && v.validate((t) -> t.getValue().equals(">")))
|
||||
.then((v) -> v.validate(
|
||||
(t) -> t.getType().equals(TokenType.NAME),
|
||||
(bag, t) -> bag.set(t)));
|
||||
leftSide.end(null);
|
||||
leftSide.end((composant, bag) -> composant);
|
||||
leftSide.then((v) ->
|
||||
v.validate((t) -> t.getValue().equals("(")) &&
|
||||
v.validate((t) -> t.getType().equals(TokenType.NAME), (bag, t) -> bag.set("inside", t)) &&
|
||||
v.validate((t) -> t.getValue().equals(")"))
|
||||
)
|
||||
.end((composant, bag) -> composant);
|
||||
|
||||
StateTree<Element> gotoValidator = new StateTree<>();
|
||||
gotoValidator.then((v) -> v.validate(
|
||||
(t) -> t.getType().equals(TokenType.NAME),
|
||||
(bag, t) -> bag.set(t)))
|
||||
.then((v) -> v.validate((t) -> t.getValue().equals(":")))
|
||||
.end((composant, bag) -> composant);
|
||||
|
||||
StateTree<Element> redirection = new StateTree<>();
|
||||
redirection.then((v) -> v.validate((t) -> t.getType().equals(TokenType.NAME)));
|
||||
redirection.then((v) -> v.validate((t) -> {
|
||||
return t.getType().equals(TokenType.NAME);
|
||||
})).end((composant, bag) -> composant);
|
||||
|
||||
StateTree<Element> methodCall = new StateTree<>();
|
||||
methodCall.then((v) -> v.validate((t) -> t.getValue().equals(":")))
|
||||
.then((v) -> v.validate(
|
||||
(t) -> t.getType().equals(TokenType.NAME),
|
||||
(bag, t) -> bag.set(t)))
|
||||
.end((composant, bag) -> composant);
|
||||
|
||||
StateTree<Element> operations = new StateTree<>();
|
||||
StateTree<Element> operation = new StateTree<>();
|
||||
|
||||
StateTree<Element> op_childs = new StateTree<>();
|
||||
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);
|
||||
|
||||
StateTree<Element> op_validator = operation.then(new RedirectStateTree<>(validator, (bag) -> "?"));
|
||||
op_validator.end((composant, bag) -> composant).then(op_childs);
|
||||
op_validator.then(new RedirectStateTree<>(namedValidator, (bag) -> "?")).end((composant, bag) -> composant).then(op_childs);
|
||||
|
||||
StateTree<Element> op_call = operation.then(new RedirectStateTree<>(methodCall, (bag) -> "?"));
|
||||
op_call.end((composant, bag) -> composant).then(op_childs);
|
||||
op_call.then(new RedirectStateTree<>(namedValidator, (bag) -> "?")).end((composant, bag) -> composant).then(op_childs);
|
||||
|
||||
StateTree<Element> op_redirect = operation.then(new RedirectStateTree<>(redirection, (bag) -> "?"));
|
||||
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);
|
||||
suit.then((v) -> v.validate((t) -> t.getValue().equals(";")))
|
||||
.then(suit).end((composant, bag) -> composant);
|
||||
suit.end((composant, bag) -> composant);
|
||||
|
||||
StateTree<Element> main = new StateTree<>();
|
||||
|
||||
|
@ -68,12 +128,17 @@ public class ParserComposantGenerator {
|
|||
(token) -> token.getType().equals(TokenType.NAME),
|
||||
(bag, token) -> bag.set("name", token)
|
||||
));
|
||||
composant.then(new RedirectStateTree<>(op_childs, (bag) -> "?")).loop();
|
||||
|
||||
|
||||
setTokenizer(new Tokenizer());
|
||||
setStateTree(main);
|
||||
}
|
||||
};
|
||||
|
||||
parser.parse(reader, composant);
|
||||
parser.build(new BufferedWriter(new FileWriter(new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-parseur\\java.out"))));
|
||||
|
||||
return composant;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue