Parser -> Variable
This commit is contained in:
parent
8d0e9f0ee7
commit
16773beb88
2 changed files with 51 additions and 5 deletions
|
@ -43,6 +43,16 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
public JavaParser(){
|
||||
Tokenizer tokenizer = new Tokenizer();
|
||||
|
||||
//SUMMARY
|
||||
//- Modifier
|
||||
//- Type
|
||||
//- Value
|
||||
//- Variable
|
||||
//- Class
|
||||
//- Import
|
||||
//- Package
|
||||
|
||||
//MODIFIER
|
||||
StateTree<JavaFile> modifier = new StateTree<JavaFile>();
|
||||
modifier.then((validator) -> {
|
||||
boolean mod = false;
|
||||
|
@ -56,6 +66,7 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
return mod;
|
||||
}).end((a,b) -> a);
|
||||
|
||||
//TYPE
|
||||
StateTree<JavaFile> type = new StateTree<JavaFile>();
|
||||
StateTree<JavaFile> type_ = type.then((validator) ->
|
||||
validator.validate(
|
||||
|
@ -82,13 +93,34 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
type_generic_end.then(type_generic_split);
|
||||
type_generic_end.end((a,b) -> a);
|
||||
|
||||
//VALUE
|
||||
|
||||
|
||||
//VARIABLE
|
||||
StateTree<JavaFile> variable = new StateTree<>();
|
||||
StateTree<JavaFile> variable_type = variable.then(new RedirectStateTree<>(type, (global, local) -> global.set("type", local)));
|
||||
variable.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)))
|
||||
.then(variable_type);
|
||||
StateTree<JavaFile> variable_name = variable_type.then((validator) -> validator.validate(
|
||||
(token) -> token.getType().equals(TokenType.NAME),
|
||||
(bag, token) -> bag.set(token)));
|
||||
variable_name.then((validator) -> validator.validate((token) -> token.getValue().equals(";")))
|
||||
.end((a,b) -> new Variable(b));
|
||||
StateTree<JavaFile> variable_split = variable_name.then((validator) -> validator.validate((token) -> token.getValue().equals(",")));
|
||||
variable_split.then(variable_name);
|
||||
variable_name.then((validator) -> validator.validate((token) -> token.getValue().equals("=")));
|
||||
|
||||
StateTree<JavaFile> clazz_container = new StateTree<>();
|
||||
clazz_container.then(variable);
|
||||
|
||||
//CLASS
|
||||
StateTree<JavaFile> clazz_ = new StateTree<>();
|
||||
StateTree<JavaFile> clazz = new StateTree<>();
|
||||
|
||||
StateTree<JavaFile> clazz_base = clazz.then((validator) -> validator.validate((token) -> token.getValue().equals("class")))
|
||||
.then(new RedirectStateTree<>(type, (global, local) -> global.set("name", local.get())));
|
||||
clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.end((javafile, bag) -> new Class(bag));
|
||||
.end((javafile, bag) -> new Class(bag)).multiple(clazz_container);
|
||||
StateTree<JavaFile> clazz_implement = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("implements")));
|
||||
StateTree<JavaFile> clazz_implement_name = clazz_implement.then(new RedirectStateTree<>(type, (global, local) -> {
|
||||
Token token = global.get("implement");
|
||||
|
@ -98,17 +130,18 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
}));
|
||||
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(clazz_implement_name);
|
||||
clazz_implement_name.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.end((javafile, bag) -> new Class(bag));
|
||||
.end((javafile, bag) -> new Class(bag)).multiple(clazz_container);
|
||||
StateTree<JavaFile> clazz_extend = clazz_base.then((validator) -> validator.validate((token) -> token.getValue().equals("extends")))
|
||||
.then(new RedirectStateTree<>(type, (global, local) -> global.set("extend", local)));
|
||||
clazz_extend.then((validator) -> validator.validate((token) -> token.getValue().equals("{")))
|
||||
.end((javafile, bag) -> new Class(bag));
|
||||
.end((javafile, bag) -> new Class(bag)).multiple(clazz_container);
|
||||
clazz_extend.then(clazz_implement);
|
||||
|
||||
|
||||
StateTree<JavaFile> clazz_mod = clazz_.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local)));
|
||||
clazz_mod.then(clazz);
|
||||
|
||||
//IMPORT
|
||||
StateTree<JavaFile> importState = new StateTree<>();
|
||||
importState.then((validator) -> {
|
||||
if(validator.validate(
|
||||
|
@ -132,6 +165,7 @@ public class JavaParser extends Parser<JavaFile> {
|
|||
|
||||
StateTree<JavaFile> main = new StateTree<>();
|
||||
|
||||
//PACKAGE
|
||||
BuilderStateTree<JavaFile, JavaElement> pack = main.then((validator) -> {
|
||||
if(validator.validate(
|
||||
(token) -> token.getValue().equals("package"),
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -32,8 +37,15 @@ class GlobalCover {
|
|||
count++;
|
||||
}
|
||||
}
|
||||
System.out.println("Load time : "+((System.currentTimeMillis()-time)/1000.0)+"s");
|
||||
System.out.printf("%.3f%% ("+validated+") validated in "+count+" files !\n", ((validated/tokens)*100.0));
|
||||
|
||||
time = ((System.currentTimeMillis()-time)/1000);
|
||||
|
||||
String data = "{\"hash\": "+System.currentTimeMillis()+",\"time\": "+time+",\"percentage\": "+String.format("%.3f", ((validated/tokens)*100.0)).replace(",", ".")+",\"validated\": "+validated+",\"files\": "+count+"}";
|
||||
File file = new File("/home/tmp_.txt");
|
||||
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
|
||||
writer.write(data+"\n");
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private List<File> files(File dir){
|
||||
|
|
Loading…
Add table
Reference in a new issue