From 0a42322ed23cfa4c1ad6e3f48dfcff3af3a9c386 Mon Sep 17 00:00:00 2001 From: magiclu550 <843983728@qq.com> Date: Wed, 8 Jan 2020 16:09:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/wenyan/compiler/WenYanCompilerImpl.java | 4 ++++ src/main/java/cn/wenyan/compiler/WenYanLib.scala | 2 +- .../compiler/streams/FunctionCompileStream.java | 8 +++++++- .../cn/wenyan/compiler/utils/JuDouUtils.scala | 15 ++++++++++----- .../java/cn/wenyan/compiler/utils/Utils.java | 16 +++++++++++++--- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/main/java/cn/wenyan/compiler/WenYanCompilerImpl.java b/src/main/java/cn/wenyan/compiler/WenYanCompilerImpl.java index 541e48b..d6e840a 100644 --- a/src/main/java/cn/wenyan/compiler/WenYanCompilerImpl.java +++ b/src/main/java/cn/wenyan/compiler/WenYanCompilerImpl.java @@ -219,6 +219,7 @@ public String compile(String wenyan){ String result = factory.compile(wenyans)[0]; builder.append("\n").append(result); this.clearCompiled(); + } return builder.toString(); }catch (Exception e){ @@ -289,7 +290,9 @@ public List getNowCompiling() { public void clearCompiled(){ List newWenyans = new ArrayList<>(Arrays.asList(wenyans)); + Utils.removeDuplicateWithOrder(nowCompiling); for(int index:nowCompiling){ + setIndexCode(); newWenyans.set(index,null); } Iterator str = newWenyans.iterator(); @@ -357,6 +360,7 @@ private String[] base(String wenyan){ throw new SyntaxException("此占位符不可存在: {{$numberHASH~}}"); } Map nowMap = new HashMap<>(); + wenyan = JuDouUtils.splitComment(wenyan); wenyan = wenYansToHASH(wenyan,nowMap); wenyan = replaceOnlyString(wenyan,nowMap); wenyan = nameToHASH(wenyan,nowMap); diff --git a/src/main/java/cn/wenyan/compiler/WenYanLib.scala b/src/main/java/cn/wenyan/compiler/WenYanLib.scala index 1b4ee2b..b901970 100644 --- a/src/main/java/cn/wenyan/compiler/WenYanLib.scala +++ b/src/main/java/cn/wenyan/compiler/WenYanLib.scala @@ -38,7 +38,7 @@ object WenYanLib { final val IF_END : String = "if_end" - final val SPLIT : String = "[。!,!,、]" + final val SPLIT : String = "[。!,、]" final val STRING_START : String = "「「" diff --git a/src/main/java/cn/wenyan/compiler/streams/FunctionCompileStream.java b/src/main/java/cn/wenyan/compiler/streams/FunctionCompileStream.java index 84c961c..c83ff62 100644 --- a/src/main/java/cn/wenyan/compiler/streams/FunctionCompileStream.java +++ b/src/main/java/cn/wenyan/compiler/streams/FunctionCompileStream.java @@ -81,7 +81,13 @@ public CompileResult compile(String[] wenyan) { } if(Utils.matches(wenyan[0],WenYanLib.RUN_FUNCTION())){ Utils.inputWenyan(compiler,0); - String name = Utils.getString(WenYanLib.VAR_NAME_FOR(),wenyan[0]).replace("之","."); + String find = Utils.getString(WenYanLib.VAR_NAME_FOR(),wenyan[0]); + String name; + if(find != null) { + name = find.replace("之", "."); + }else{ + name = wenyan[0].substring(wenyan[0].indexOf("施")+1).replace("之", "."); + } StringBuilder builder = new StringBuilder(); builder.append(Utils.getValue(name,stream)).append("("); int end = 0; diff --git a/src/main/java/cn/wenyan/compiler/utils/JuDouUtils.scala b/src/main/java/cn/wenyan/compiler/utils/JuDouUtils.scala index ac547fb..22fd4b5 100644 --- a/src/main/java/cn/wenyan/compiler/utils/JuDouUtils.scala +++ b/src/main/java/cn/wenyan/compiler/utils/JuDouUtils.scala @@ -33,7 +33,7 @@ object JuDouUtils { } } ) - splitComment(builder.toString()) + builder.toString() } def splitWenYan(strings: String) : java.util.List[String] ={ @@ -41,6 +41,7 @@ object JuDouUtils { val list = new util.ArrayList[String]() var builder = new StringBuilder var index = 0 + println(strings) while(index < string.length){ var isAppend = false val s = string(index) @@ -100,13 +101,15 @@ object JuDouUtils { private def getString(target: String): Boolean ={ val patterns = WenYanLib.syntaxs for(p <- patterns){ - if(target.matches(p._2))return true + if(target.matches(p._2)){ + return true + } } false } var patterns = WenYanLib.patterns - private def splitComment(now : String): String ={ + def splitComment(now : String): String ={ var string = now var index = 0 while(index < string.length){ @@ -132,8 +135,10 @@ object JuDouUtils { } //得到index val builder = new StringBuilder(string) - builder.insert(index+1,"。") - string = builder.toString() + if(!string(index+1).toString.matches(WenYanLib.SPLIT)){ + builder.insert(index+1,"。") + string = builder.toString() + } } index+=1 } diff --git a/src/main/java/cn/wenyan/compiler/utils/Utils.java b/src/main/java/cn/wenyan/compiler/utils/Utils.java index 67d77c3..4d1fbde 100644 --- a/src/main/java/cn/wenyan/compiler/utils/Utils.java +++ b/src/main/java/cn/wenyan/compiler/utils/Utils.java @@ -5,8 +5,7 @@ import cn.wenyan.compiler.WenYanLib; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -31,7 +30,6 @@ public static String getString(String patternId,String thing){ } public static void inputWenyan(WenYanCompilerImpl compiler, int wenyanIndex){ - compiler.setIndexCode(); compiler.getNowCompiling().add(wenyanIndex); } @@ -40,6 +38,18 @@ public static String getStringFrom(String patternId,String thing,String start){ return value.substring(value.indexOf(start)+1); } + public static void removeDuplicateWithOrder(List list) { + Set set = new HashSet(); + List newList = new ArrayList(); + for (Iterator iter = list.iterator(); iter.hasNext();) { + Object element = iter.next(); + if (set.add(element)) + newList.add(element); + } + list.clear(); + list.addAll(newList); + } + public static String getStringFrom(String patternId,String thing,String start,String end){ String value = getString(patternId,thing); if(patternId.equals(WenYanLib.STRING())||patternId.equals(WenYanLib.COMMENT())){