Operations & Functions
This commit is contained in:
parent
2ad831641b
commit
aa51bb95e2
2 changed files with 16 additions and 7 deletions
|
@ -28,7 +28,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception{
|
public static void main(String[] args) throws Exception{
|
||||||
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\be\\jeffcheasey88\\peeratcode\\routes\\Result.java");
|
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-parseur\\src\\be\\jeffcheasey88\\peeratcode\\parser\\java\\JavaParser.java");
|
||||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
|
|
||||||
time = System.currentTimeMillis();
|
time = System.currentTimeMillis();
|
||||||
|
@ -68,6 +68,7 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
int m = getModifier(token.getValue());
|
int m = getModifier(token.getValue());
|
||||||
Integer current = bag.get();
|
Integer current = bag.get();
|
||||||
bag.set(current == null ? m : current+m);
|
bag.set(current == null ? m : current+m);
|
||||||
|
System.out.println("mod "+token);
|
||||||
})) mod = true;
|
})) mod = true;
|
||||||
return mod;
|
return mod;
|
||||||
}).end((a,b) -> a);
|
}).end((a,b) -> a);
|
||||||
|
@ -152,6 +153,8 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
return false;
|
return false;
|
||||||
}).end((a,b) -> a);
|
}).end((a,b) -> a);
|
||||||
|
|
||||||
|
StateTree<JavaElement> function_container = new StateTree<>();
|
||||||
|
|
||||||
//OPERATION
|
//OPERATION
|
||||||
StateTree<JavaElement> operation = new StateTree<>();
|
StateTree<JavaElement> operation = new StateTree<>();
|
||||||
StateTree<JavaElement> operation_name = operation.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME)));
|
StateTree<JavaElement> operation_name = operation.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME)));
|
||||||
|
@ -192,11 +195,17 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("break")))
|
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("break")))
|
||||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("if")))
|
StateTree<JavaElement> operation_if = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("if")))
|
||||||
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
|
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
|
||||||
.then(new RedirectStateTree<>(value, (global, local) -> global.set(null)))
|
.then(new RedirectStateTree<>(value, (global, local) -> global.set(null)))
|
||||||
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
|
.then((validator) -> validator.validate((token) -> token.getValue().equals(")")))
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
|
operation_if.then(operation);
|
||||||
|
operation_if.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||||
|
.then(new RedirectStateTree<>(function_container, (global, local) -> global.set(null)))
|
||||||
|
.then((validator) -> validator.validate((token) -> token.getValue().equals("}")))
|
||||||
|
.end((a,b) -> a);
|
||||||
|
|
||||||
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("for")))
|
operation.then((validator) -> validator.validate((token) -> token.getValue().equals("for")))
|
||||||
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
|
.then((validator) -> validator.validate((token) -> token.getValue().equals("(")))
|
||||||
.then(new RedirectStateTree<>(value, (global, local) -> global.set(null)))
|
.then(new RedirectStateTree<>(value, (global, local) -> global.set(null)))
|
||||||
|
@ -231,18 +240,17 @@ public class JavaParser extends Parser<JavaElement> {
|
||||||
variable_value.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
variable_value.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||||
.end((a,b) -> a);
|
.end((a,b) -> a);
|
||||||
|
|
||||||
StateTree<JavaElement> function_container = new StateTree<>();
|
|
||||||
function_container.then(variable);
|
function_container.then(variable);
|
||||||
function_container.then(operation);
|
function_container.then(operation);
|
||||||
|
|
||||||
//FUNCTION
|
//FUNCTION
|
||||||
StateTree<JavaElement> function = new StateTree<>();
|
StateTree<JavaElement> function = new StateTree<>();
|
||||||
StateTree<JavaElement> function_mod = function.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)));
|
|
||||||
StateTree<JavaElement> function_type = function.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local)));
|
|
||||||
function_mod.then(function_type);
|
|
||||||
BuilderStateTree<JavaElement,JavaElement> function_static = function.then((validator) -> validator.validate((token) -> token.getValue().equals("static")) && validator.validate((token) -> token.getValue().equals("{"))).end((a,b) -> a);
|
BuilderStateTree<JavaElement,JavaElement> function_static = function.then((validator) -> validator.validate((token) -> token.getValue().equals("static")) && validator.validate((token) -> token.getValue().equals("{"))).end((a,b) -> a);
|
||||||
function_static.multiple(function_container);
|
function_static.multiple(function_container);
|
||||||
function_static.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a);
|
function_static.unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a);
|
||||||
|
StateTree<JavaElement> function_mod = function.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)));
|
||||||
|
StateTree<JavaElement> function_type = function.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local)));
|
||||||
|
function_mod.then(function_type);
|
||||||
|
|
||||||
StateTree<JavaElement> function_name = function_type.then((validator) -> validator.validate(
|
StateTree<JavaElement> function_name = function_type.then((validator) -> validator.validate(
|
||||||
(token) -> token.getType().equals(TokenType.NAME),
|
(token) -> token.getType().equals(TokenType.NAME),
|
||||||
|
|
|
@ -23,8 +23,9 @@ public class RedirectStateTree<E, T extends E> extends StateTree<T>{
|
||||||
|
|
||||||
TokenValidator branch = validator.branch();
|
TokenValidator branch = validator.branch();
|
||||||
branch.setBag(localBag);
|
branch.setBag(localBag);
|
||||||
Object builded = redirect.internalSeed(branch, (E) element);
|
BuilderStateTree<E, ?> builded = redirect.internalSeed(branch, (E) element);
|
||||||
if(builded == null) return null;
|
if(builded == null) return null;
|
||||||
|
builded.build(validator, element);
|
||||||
|
|
||||||
this.group.accept(currentBag, localBag);
|
this.group.accept(currentBag, localBag);
|
||||||
branch.setBag(currentBag);
|
branch.setBag(currentBag);
|
||||||
|
|
Loading…
Add table
Reference in a new issue