Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclu550 committed Jan 8, 2020
1 parent 984488d commit 0a42322
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/main/java/cn/wenyan/compiler/WenYanCompilerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -289,7 +290,9 @@ public List<Integer> getNowCompiling() {

public void clearCompiled(){
List<String> newWenyans = new ArrayList<>(Arrays.asList(wenyans));
Utils.removeDuplicateWithOrder(nowCompiling);
for(int index:nowCompiling){
setIndexCode();
newWenyans.set(index,null);
}
Iterator<String> str = newWenyans.iterator();
Expand Down Expand Up @@ -357,6 +360,7 @@ private String[] base(String wenyan){
throw new SyntaxException("此占位符不可存在: {{$numberHASH~}}");
}
Map<String,String> nowMap = new HashMap<>();
wenyan = JuDouUtils.splitComment(wenyan);
wenyan = wenYansToHASH(wenyan,nowMap);
wenyan = replaceOnlyString(wenyan,nowMap);
wenyan = nameToHASH(wenyan,nowMap);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/cn/wenyan/compiler/WenYanLib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "「「"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/cn/wenyan/compiler/utils/JuDouUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ object JuDouUtils {
}
}
)
splitComment(builder.toString())
builder.toString()
}

def splitWenYan(strings: String) : java.util.List[String] ={
val string = strings.replace(" ","")
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)
Expand Down Expand Up @@ -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){
Expand All @@ -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
}
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/cn/wenyan/compiler/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

Expand All @@ -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())){
Expand Down

0 comments on commit 0a42322

Please sign in to comment.