From be289b8d7f00df3b3699e895f776252f77cb7699 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Tue, 30 May 2023 21:35:55 +0200 Subject: [PATCH] Fix Cleaner unzip one, fix logic --- .../peeratcode/parser/java/CleanerPool.java | 13 ++++++++----- .../peeratcode/parser/java/Function.java | 4 ++++ .../java/operations/OperationContainer.java | 1 + .../parser/java/operations/OperationFactory.java | 15 +++------------ 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/CleanerPool.java b/src/be/jeffcheasey88/peeratcode/parser/java/CleanerPool.java index 19f5cc2..888677d 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/CleanerPool.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/CleanerPool.java @@ -36,15 +36,18 @@ public class CleanerPool{ String zip = cleaner.getConstant(key); String modified = modifier.apply(zip, cleaner.getPattern()); if(modified == null) continue; - map.put(key, cleaner.open+zip+cleaner.close); - tmp = matcher.group(1)+cleaner.open+zip+cleaner.close+matcher.group(3); + map.put(key, cleaner.open+modified+cleaner.close); + tmp = matcher.group(1)+cleaner.open+modified+cleaner.close+matcher.group(3); edited = true; } } }while(edited); - - - for(Entry unzip : map.entrySet()) value = value.replaceAll("\\"+unzip.getKey()+"(?([^\\d]|$))", unzip.getValue()+"${e}"); + + String base = value; + for(Entry unzip : map.entrySet()){ + Pattern pattern = Pattern.compile("\\"+unzip.getKey()+"(?([^\\d]|$))"); + if(pattern.matcher(base).find()) value = pattern.matcher(value).replaceAll(unzip.getValue()+"${e}"); + } return value; } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java index 08dbdde..ae5bb5f 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java @@ -34,13 +34,17 @@ public class Function extends OperationContainer{ parameters(matcher.group(3)+";", cleaner); this.exceptions = matcher.group(4).trim(); + System.out.println("body IS {"+matcher.group(5)); CleanerPool generic = new CleanerPool(new Cleaner("GENERIC_FUNCTION", '{', '}')); String zip = generic.clean("{"+matcher.group(5)); + System.out.println("clean it "+zip); String body = generic.unzipOne(zip, (s,p) -> s); String unzip = body.substring(1, body.indexOf('}')); System.out.println("----------Before------------"); show(0); System.out.println("----------------------------"); + + System.out.println("BODY LIKE "+body); parse(unzip, cleaner, generic); System.out.println("----------After------------"); show(0); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationContainer.java b/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationContainer.java index b0de7dc..b8f6924 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationContainer.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationContainer.java @@ -19,6 +19,7 @@ public abstract class OperationContainer extends JavaElement{ } public void parse(String content, CleanerPool global, CleanerPool local) throws Exception{ + System.out.println("RECEIVE CONAINER "+content); content = local.unzip(content, (s,p) -> s); System.out.println("CONTAINER "+content); while(!(content.replaceAll("\\s+", "").isEmpty())) content = internalParse(content, global, local); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java b/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java index c485474..eeab0e6 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operations/OperationFactory.java @@ -32,10 +32,11 @@ public class OperationFactory{ this.patterns.put(Pattern.compile("^\\s*while\\s*\\^GENERIC_PARENTHESIS\\d+.*$"), WhileOperation.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*[^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+;.*$"), MethodCallOperation.class); this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s+[^\\s]+\\s*=\\s*[^;]+;.*$"), Variable.class); this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s*=\\s*[^;]+;.*$"), AssigmentOperation.class); + this.patterns.put(Pattern.compile("^\\s*[^;]+;.*$"), Variable.class); } /* @@ -87,25 +88,15 @@ public class OperationFactory{ private static Pattern UNZIP_EQUALS_RIGHT = Pattern.compile("=(?[^=\\s])"); private String generiqueTypes(String content, CleanerPool cleaner){ - System.out.println("base on "+content); String unzip = cleaner.unzip(content, (value, pattern) -> { - System.out.println("unzip pattern "+pattern); - if(pattern.equals("^GENERIC_FUNCTION")) return null; - if(pattern.equals("^GENERIC_PARENTHESIS")) return null; - System.out.println("let pass "+pattern); + if(pattern.equals("^GENERIC_FUNCTION") || pattern.equals("^GENERIC_PARENTHESIS")) return null; return value.replaceAll("\\s+", ""); }); - System.out.println("generiqueTypes on "+unzip); unzip = UNZIP_STICK.matcher(unzip).replaceAll("${e}"); - System.out.println("g => "+unzip); unzip = UNZIP_MAJ.matcher(unzip).replaceAll("> ${e}"); - System.out.println("g => "+unzip); unzip = UNZIP_ARRAY.matcher(unzip).replaceAll("] ${e}"); - System.out.println("g => "+unzip); unzip = UNZIP_EQUALS_LEFT.matcher(unzip).replaceAll("${e} ="); - System.out.println("g => "+unzip); unzip = UNZIP_EQUALS_RIGHT.matcher(unzip).replaceAll("= ${e}"); - System.out.println("g => "+unzip); return unzip; } }