X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Futil%2FPreprocessor.java;h=a226731e722ce455326890252cf37a6d178c6037;hp=875416d02888312ae44539322238151c78d90e5e;hb=01732f3955ae92c0520283b44f52d1ec69f9f9f2;hpb=9e124c49a130a702959a55999b1a6c3a3a559997 diff --git a/src/org/ibex/util/Preprocessor.java b/src/org/ibex/util/Preprocessor.java index 875416d..a226731 100644 --- a/src/org/ibex/util/Preprocessor.java +++ b/src/org/ibex/util/Preprocessor.java @@ -7,6 +7,7 @@ package org.ibex.util; +import gnu.regexp.*; import java.util.*; import java.io.*; @@ -29,6 +30,16 @@ import java.io.*; */ public class Preprocessor { + public static String replaceAll(String source, String regexp, String replaceWith) { + try { + RE re = new RE(regexp, 0, RESyntax.RE_SYNTAX_PERL5); + return (String)re.substituteAll(source, replaceWith); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); @@ -191,7 +202,7 @@ PROCESS: if (key != null) { Hashtable hash = byLength[key.length()]; - hash.put(key, (String)hash.get(key) + processLine(trimmed, false).replaceAll("//[^\"]*$", "").trim() + "\n"); + hash.put(key, (String)hash.get(key) + replaceAll(processLine(trimmed, false), "//[^\"]*$", "").trim() + "\n"); } else { out.print(processLine(trimmed, false)); } @@ -264,7 +275,7 @@ PROCESS: ret += tok; i = j - 1; } else if (val instanceof JSFunctionMacro) { - if (s.charAt(j) != '(') { err.add(new Error("open paren must follow macro binding for macro " + tok)); continue; } + if (s.charAt(j) != '(') { ret += tok; i = j - 1; continue; } ret += ((JSFunctionMacro)val).process(s.substring(j+1, s.indexOf(')', j))); i = s.indexOf(')', j); } else { @@ -319,11 +330,11 @@ PROCESS: String bound2 = null; if (unbound2 == null) { bound1 = args; - return expression.replaceAll(unbound1, bound1); + return replaceAll(expression, unbound1, bound1); } else { bound1 = args.substring(0, args.indexOf(',')); bound2 = args.substring(args.indexOf(',') + 1); - return (expression.replaceAll(unbound1, bound1).replaceAll(unbound2, bound2)); + return replaceAll(replaceAll(expression, unbound1, bound1), unbound2, bound2); } } }