diff --git a/src/be/jeffcheasey88/peeratcode/parser/Parser.java b/src/be/jeffcheasey88/peeratcode/parser/Parser.java index a72fc2c..9072f03 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/Parser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/Parser.java @@ -27,6 +27,13 @@ public class Parser{ this.state.seed(this.tokenizer, container); } + public final void parse(String line, E container) throws Exception{ + this.tokenizer.reset(); + this.tokenizer.parse(line); + + this.state.seed(this.tokenizer, container); + } + //tmp public void build(BufferedWriter writer) throws Exception{ Token[] confirmed = new Token[TokenValidator.MAX_VALIDATE]; diff --git a/src/be/jeffcheasey88/peeratcode/parser/Tokenizer.java b/src/be/jeffcheasey88/peeratcode/parser/Tokenizer.java index f634694..d1ab30f 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/Tokenizer.java +++ b/src/be/jeffcheasey88/peeratcode/parser/Tokenizer.java @@ -72,4 +72,37 @@ public class Tokenizer { if(this.postProcessor != null) this.postProcessor.accept(tokens); } + public void parse(String line){ + if(this.postProcessor != null) this.postProcessor.accept(tokens); + + for(int i = 0; i < line.length(); i++){ + char c = line.charAt(i); + Token token; + if(Character.isAlphabetic(c) || Character.isDigit(c)){ + String value = ""; + int j = i; + for(; j < line.length(); j++){ + c = line.charAt(j); + if(Character.isAlphabetic(c) || Character.isDigit(c)) value+=c; + else break; + } + token = new Token(1, i+1, value, TokenType.NAME); + i = j-1; + }else if(Character.isWhitespace(c)){ + if(!optionSpace) continue; + String value = ""; + int j = i; + for(; j < line.length(); j++){ + c = line.charAt(j); + if(!Character.isWhitespace(c)) break; + } + token = new Token(1, i+1, value, TokenType.SPACE); + i = j-1; + }else{ + token = new Token(1, i+1, ""+c, TokenType.DELIMITER); + } + this.tokens.add(token); + } + } + } \ No newline at end of file diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 807de3f..fa0842d 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -557,10 +557,20 @@ public class JavaParser extends Parser { StateTree function_begin = function_name.then((validator) -> validator.validate((token) -> token.getValue().equals("("))); StateTree function_end = function_begin.then((validator) -> validator.validate((token) -> token.getValue().equals(")"))); function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("{"))) - .end((a,b) -> a) + .end((a,b) -> { + System.out.println("build function "+b); + return a; + }) .multiple(function_container) - .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a); + .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> { + System.out.println("inside of the function "+b); + return a; + }); function_end.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end((a,b) -> a); + function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("default"))) + .then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))) + .then((validator) -> validator.validate((token) -> token.getValue().equals(";"))) + .end((a,b) -> a); StateTree function_throws = function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("throws"))) .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); @@ -642,6 +652,13 @@ public class JavaParser extends Parser { InitialStateTree mult_clazz_container = new InitialStateTree<>(); mult_clazz_container.multiple(clazz_container); + mult_clazz_container.end((a,b) -> a); + + StateTree debug = new StateTree<>(); + debug.then((v) -> v.validate((t) -> { + System.out.println("debug "+t); + return false; + })); //ENUM StateTree enums = new StateTree<>(); @@ -651,6 +668,7 @@ public class JavaParser extends Parser { .end((a,b) -> a) .unique(enum_value) .unique(mult_clazz_container) + .unique(debug) .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a); StateTree enum_mod = clazz_.then(new RedirectStateTree<>(modifier, (global, local) -> global.set("modifier", local))); @@ -742,7 +760,7 @@ public class JavaParser extends Parser { } public static void main(String[] args) throws Exception{ - File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\BotDiscordSql\\src\\be\\jeffcheasey\\challenge\\bot\\parser\\region\\RegionContainer.java"); + File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\BotDiscordSql\\src\\be\\jeffcheasey\\challenge\\bot\\parser\\RequestType.java"); BufferedReader reader = new BufferedReader(new FileReader(file)); diff --git a/src/be/jeffcheasey88/peeratcode/parser/state/InitialStateTree.java b/src/be/jeffcheasey88/peeratcode/parser/state/InitialStateTree.java index b427335..701f114 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/state/InitialStateTree.java +++ b/src/be/jeffcheasey88/peeratcode/parser/state/InitialStateTree.java @@ -19,14 +19,14 @@ public class InitialStateTree extends StateTree{ BuilderStateTree internalSeed(TokenValidator validator, E element){ BuilderStateTree builded; for(StateTree state : this.multiple){ - TokenValidator branch = validator.branch(); + TokenValidator branch; if(state.checker == null){ - while((builded = state.internalSeed(branch, element)) != null){ + while((builded = state.internalSeed((branch = validator.branch()), element)) != null){ validator.merge(branch); builded.build(validator, element); } }else{ - while(state.checker.apply(branch)){ + while(state.checker.apply((branch = validator.branch()))){ builded = state.internalSeed(branch, element); if(builded == null) break; validator.merge(branch);