Operation -> Else Statement
This commit is contained in:
parent
8f37f9882b
commit
9a19c54e34
4 changed files with 51 additions and 1 deletions
|
@ -38,6 +38,9 @@ public class Function extends OperationContainer{
|
||||||
String zip = generic.clean("{"+matcher.group(5));
|
String zip = generic.clean("{"+matcher.group(5));
|
||||||
String body = generic.unzipOne(zip, (s,p) -> s);
|
String body = generic.unzipOne(zip, (s,p) -> s);
|
||||||
String unzip = body.substring(1, body.indexOf('}'));
|
String unzip = body.substring(1, body.indexOf('}'));
|
||||||
|
System.out.println("----------------------");
|
||||||
|
show(0);
|
||||||
|
System.out.println("----------------------");
|
||||||
parse(unzip, cleaner, generic);
|
parse(unzip, cleaner, generic);
|
||||||
|
|
||||||
return matcher.group(1).length()+generic.unzip(unzip, ((s,p) -> s)).length()+1;
|
return matcher.group(1).length()+generic.unzip(unzip, ((s,p) -> s)).length()+1;
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package be.jeffcheasey88.peeratcode.parser.java.operations;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
|
||||||
|
|
||||||
|
public class ElseOperation extends OperationContainer{
|
||||||
|
|
||||||
|
private static Pattern PATTERN = Pattern.compile("^(\\s*else\\s*).*$");
|
||||||
|
|
||||||
|
public ElseOperation(){}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int parse(String content, CleanerPool cleaner) throws Exception{
|
||||||
|
System.out.println("ELSE STATEMENT");
|
||||||
|
CleanerPool generic = new CleanerPool(
|
||||||
|
new Cleaner("GENERIC_PARENTHESIS",'(',')'),
|
||||||
|
new Cleaner("GENERIC_FUNCTION", '{','}'));
|
||||||
|
content = generic.clean(content);
|
||||||
|
|
||||||
|
Matcher matcher = PATTERN.matcher(content);
|
||||||
|
matcher.matches();
|
||||||
|
|
||||||
|
int index = generic.unzip(matcher.group(1), (s,p) -> s).length();
|
||||||
|
content = generic.unzipOne(content, (s,p) -> s).substring(index);
|
||||||
|
System.out.println("INSIDE "+content);
|
||||||
|
int bodysize;
|
||||||
|
if(content.startsWith("{")){
|
||||||
|
bodysize = content.indexOf('}')+1;
|
||||||
|
content = content.substring(1, bodysize-1);
|
||||||
|
parse(content, cleaner, generic);
|
||||||
|
}else{
|
||||||
|
bodysize = parseOne(content, cleaner, generic);
|
||||||
|
}
|
||||||
|
|
||||||
|
return index+bodysize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(int tab) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ public class IfOperation extends OperationContainer{
|
||||||
private static Pattern PATTERN = Pattern.compile("^(\\s*if\\s*(\\^GENERIC_PARENTHESIS\\d+)).*$");
|
private static Pattern PATTERN = Pattern.compile("^(\\s*if\\s*(\\^GENERIC_PARENTHESIS\\d+)).*$");
|
||||||
|
|
||||||
private String condition; //replace by Operation
|
private String condition; //replace by Operation
|
||||||
private String body;
|
|
||||||
|
|
||||||
public IfOperation(){}
|
public IfOperation(){}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class OperationFactory{
|
||||||
|
|
||||||
this.patterns.put(Pattern.compile("^\\s*return\\s*[^;]*;.*$"), ReturnOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*return\\s*[^;]*;.*$"), ReturnOperation.class);
|
||||||
this.patterns.put(Pattern.compile("^\\s*if\\s*\\^GENERIC_PARENTHESIS\\d+.*$"), IfOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*if\\s*\\^GENERIC_PARENTHESIS\\d+.*$"), IfOperation.class);
|
||||||
|
this.patterns.put(Pattern.compile("^\\s*else\\s*.*$"), ElseOperation.class);
|
||||||
|
|
||||||
this.patterns.put(Pattern.compile("^\\s*([^;=]+;).*$"), MethodCallOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*([^;=]+;).*$"), MethodCallOperation.class);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue