X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fcom%2Fstevesoft%2Fpat%2FReplaceRule.js;h=c78211d3ed7a82f1c55816f3cf2ebeae9c4ffaf2;hp=5694935825c3b76bc6ca0177df0f50bdbe81b380;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/j2s/com/stevesoft/pat/ReplaceRule.js b/site/j2s/com/stevesoft/pat/ReplaceRule.js index 5694935..c78211d 100644 --- a/site/j2s/com/stevesoft/pat/ReplaceRule.js +++ b/site/j2s/com/stevesoft/pat/ReplaceRule.js @@ -1,203 +1,203 @@ -Clazz.declarePackage ("com.stevesoft.pat"); -Clazz.load (["java.util.Hashtable"], "com.stevesoft.pat.ReplaceRule", ["com.stevesoft.pat.Ctrl", "$.Regex", "$.Transformer", "java.lang.StringBuffer"], function () { -c$ = Clazz.decorateAsClass (function () { -this.next = null; -this.name = null; -Clazz.instantialize (this, arguments); -}, com.stevesoft.pat, "ReplaceRule"); -Clazz.prepareFields (c$, function () { -this.name = this.getClass ().getName (); -}); -Clazz.defineMethod (c$, "clone1", -function () { -return new com.stevesoft.pat.RuleHolder (this); -}); -Clazz.overrideMethod (c$, "clone", -function () { -var x = this.clone1 (); -var xsav = x; -var y = this; -while (y.next != null) { -x.next = y.next.clone1 (); -x.name = y.name; -x = x.next; -y = y.next; -} -return xsav; -}); -c$.add = Clazz.defineMethod (c$, "add", -function (head, adding) { -if (head == null) { -return head = adding; -}head.addRule (adding); -return head; -}, "com.stevesoft.pat.ReplaceRule,com.stevesoft.pat.ReplaceRule"); -Clazz.defineMethod (c$, "add", -function (adding) { -return com.stevesoft.pat.ReplaceRule.add (this, adding); -}, "com.stevesoft.pat.ReplaceRule"); -Clazz.defineMethod (c$, "addRule", -function (r) { -if (this.next == null) { -this.next = r; -} else { -this.next.addRule (r); -}}, "com.stevesoft.pat.ReplaceRule"); -c$.getv = Clazz.defineMethod (c$, "getv", - function () { -if (com.stevesoft.pat.ReplaceRule.getvar != null) { -return com.stevesoft.pat.ReplaceRule.getvar.clone (); -}com.stevesoft.pat.ReplaceRule.getvar = new com.stevesoft.pat.Regex ("(?:\\\\(\\d+)|\\$(?:(\\d+)|(\\w+)|([&\'`])|\\{(?:(\\d+)|([^\n}\\\\]+))})|\\\\([nrbtaef])|\\\\c([\u0000-\uffff])|\\\\x([A-Fa-f0-9]{2})|\\\\([\u0000-\uffff]))", ""); -com.stevesoft.pat.ReplaceRule.getvar.optimize (); -return com.stevesoft.pat.ReplaceRule.getvar; -}); -c$.perlCode = Clazz.defineMethod (c$, "perlCode", -function (s) { -try { -var mf = 0; -var mt = 0; -var gv = com.stevesoft.pat.ReplaceRule.getv (); -var head = null; -var tmp = null; -while (gv.searchFrom (s, mt)) { -var off = com.stevesoft.pat.Regex.BackRefOffset - 1; -mf = gv.matchedFrom (); -if (mf > mt) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule (s.substring (mt, mf))); -}var $var = null; -if (($var = gv.stringMatchedI (1 + off)) != null || ($var = gv.stringMatchedI (2 + off)) != null || ($var = gv.stringMatchedI (5 + off)) != null) { -var d = 0; -for (var i = 0; i < $var.length; i++) { -d = 8 * d + ($var.charCodeAt (i) - 48); -} -if ($var.length == 1) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.BackRefRule (d)); -} else { -head = new com.stevesoft.pat.StringRule ("" + String.fromCharCode (d)); -}} else if (($var = gv.stringMatchedI (10 + off)) != null) { -if ("QELlUu".indexOf ($var) >= 0) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.CodeRule ($var.charAt (0))); -} else { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ($var)); -}} else if (($var = gv.stringMatchedI (3 + off)) != null || ($var = gv.stringMatchedI (4 + off)) != null || ($var = gv.stringMatchedI (6 + off)) != null) { -var arg = ""; -var pc; -if ((pc = $var.indexOf (':')) > 0) { -arg = $var.substring (pc + 1); -$var = $var.substring (0, pc); -}if ($var.equals ("&") || $var.equals ("MATCH")) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.AmpersandRule ()); -} else if ($var.equals ("`") || $var.equals ("PREMATCH")) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.LeftRule ()); -} else if ($var.equals ("'") || $var.equals ("POSTMATCH")) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.RightRule ()); -} else if ($var.equals ("WANT_MORE_TEXT")) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.WantMoreTextReplaceRule ()); -} else if ($var.equals ("POP")) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.PopRule ()); -} else if ($var.startsWith ("+") && (tmp = com.stevesoft.pat.ReplaceRule.defs.get ($var.substring (1))) != null) { -if (Clazz.instanceOf (tmp, com.stevesoft.pat.Regex)) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.PushRule ($var.substring (1), tmp)); -} else if (Clazz.instanceOf (tmp, com.stevesoft.pat.Transformer)) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.PushRule ($var.substring (1), tmp)); -} else { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("${" + $var + "}")); -}} else if ($var.startsWith ("=") && (tmp = com.stevesoft.pat.ReplaceRule.defs.get ($var.substring (1))) != null) { -if (Clazz.instanceOf (tmp, com.stevesoft.pat.Regex)) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.ChangeRule ($var.substring (1), tmp)); -} else if (Clazz.instanceOf (tmp, com.stevesoft.pat.Transformer)) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.ChangeRule ($var.substring (1), tmp)); -} else { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("${" + $var + "}")); -}} else if ((tmp = com.stevesoft.pat.ReplaceRule.defs.get ($var)) != null) { -if (Clazz.instanceOf (tmp, com.stevesoft.pat.ReplaceRule)) { -var alt = (tmp).arg (arg); -if (alt == null) { -alt = (tmp); -}head = com.stevesoft.pat.ReplaceRule.add (head, (alt.clone ())); -}} else { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("${" + $var + "}")); -}} else if (($var = gv.stringMatchedI (7 + off)) != null) { -var c = $var.charAt (0); -if (c == 'n') { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\n")); -} else if (c == 't') { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\t")); -} else if (c == 'r') { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\r")); -} else if (c == 'b') { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\r")); -} else if (c == 'a') { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\u0007")); -} else if (c == 'e') { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\u001b")); -} else if (c == 'f') { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\f")); -}} else if (($var = gv.stringMatchedI (8 + off)) != null) { -var c = $var.charAt (0); -if (c.charCodeAt (0) < com.stevesoft.pat.Ctrl.cmap.length) { -c = com.stevesoft.pat.Ctrl.cmap[c.charCodeAt (0)]; -}head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("" + c)); -} else if (($var = gv.stringMatchedI (9 + off)) != null) { -var d = 16 * com.stevesoft.pat.ReplaceRule.getHexDigit ($var.charAt (0)) + com.stevesoft.pat.ReplaceRule.getHexDigit ($var.charAt (1)); -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("" + String.fromCharCode (d))); -}mt = gv.matchedTo (); -} -if (mt <= s.length) { -head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule (s.substring (mt))); -}return head; -} finally { -} -}, "~S"); -c$.isDefined = Clazz.defineMethod (c$, "isDefined", -function (s) { -return com.stevesoft.pat.ReplaceRule.defs.get (s) != null; -}, "~S"); -c$.define = Clazz.defineMethod (c$, "define", -function (s, r) { -com.stevesoft.pat.ReplaceRule.defs.put (s, r); -}, "~S,com.stevesoft.pat.Regex"); -c$.define = Clazz.defineMethod (c$, "define", -function (s, r) { -com.stevesoft.pat.ReplaceRule.defs.put (s, r); -r.name = s; -}, "~S,com.stevesoft.pat.ReplaceRule"); -c$.define = Clazz.defineMethod (c$, "define", -function (s, t) { -com.stevesoft.pat.ReplaceRule.defs.put (s, t); -}, "~S,com.stevesoft.pat.Transformer"); -c$.undefine = Clazz.defineMethod (c$, "undefine", -function (s) { -com.stevesoft.pat.ReplaceRule.defs.remove (s); -}, "~S"); -Clazz.defineMethod (c$, "toString1", -function () { -return "${" + this.name + "}"; -}); -Clazz.overrideMethod (c$, "toString", -function () { -var sb = new StringBuffer (); -sb.append (this.toString1 ()); -var rr = this.next; -while (rr != null) { -sb.append (rr.toString1 ()); -rr = rr.next; -} -return sb.toString (); -}); -Clazz.defineMethod (c$, "arg", -function (s) { -return null; -}, "~S"); -c$.getHexDigit = Clazz.defineMethod (c$, "getHexDigit", -function (c) { -if (c >= '0' && c <= '9') { -return c.charCodeAt (0) - 48; -}if (c >= 'a' && c <= 'f') { -return c.charCodeAt (0) - 97 + 10; -}return c.charCodeAt (0) - 65 + 10; -}, "~S"); -Clazz.defineStatics (c$, -"getvar", null); -c$.defs = c$.prototype.defs = new java.util.Hashtable (); -}); +Clazz.declarePackage ("com.stevesoft.pat"); +Clazz.load (["java.util.Hashtable"], "com.stevesoft.pat.ReplaceRule", ["com.stevesoft.pat.Ctrl", "$.Regex", "$.Transformer", "java.lang.StringBuffer"], function () { +c$ = Clazz.decorateAsClass (function () { +this.next = null; +this.name = null; +Clazz.instantialize (this, arguments); +}, com.stevesoft.pat, "ReplaceRule"); +Clazz.prepareFields (c$, function () { +this.name = this.getClass ().getName (); +}); +Clazz.defineMethod (c$, "clone1", +function () { +return new com.stevesoft.pat.RuleHolder (this); +}); +Clazz.overrideMethod (c$, "clone", +function () { +var x = this.clone1 (); +var xsav = x; +var y = this; +while (y.next != null) { +x.next = y.next.clone1 (); +x.name = y.name; +x = x.next; +y = y.next; +} +return xsav; +}); +c$.add = Clazz.defineMethod (c$, "add", +function (head, adding) { +if (head == null) { +return head = adding; +}head.addRule (adding); +return head; +}, "com.stevesoft.pat.ReplaceRule,com.stevesoft.pat.ReplaceRule"); +Clazz.defineMethod (c$, "add", +function (adding) { +return com.stevesoft.pat.ReplaceRule.add (this, adding); +}, "com.stevesoft.pat.ReplaceRule"); +Clazz.defineMethod (c$, "addRule", +function (r) { +if (this.next == null) { +this.next = r; +} else { +this.next.addRule (r); +}}, "com.stevesoft.pat.ReplaceRule"); +c$.getv = Clazz.defineMethod (c$, "getv", + function () { +if (com.stevesoft.pat.ReplaceRule.getvar != null) { +return com.stevesoft.pat.ReplaceRule.getvar.clone (); +}com.stevesoft.pat.ReplaceRule.getvar = new com.stevesoft.pat.Regex ("(?:\\\\(\\d+)|\\$(?:(\\d+)|(\\w+)|([&\'`])|\\{(?:(\\d+)|([^\n}\\\\]+))})|\\\\([nrbtaef])|\\\\c([\u0000-\uffff])|\\\\x([A-Fa-f0-9]{2})|\\\\([\u0000-\uffff]))", ""); +com.stevesoft.pat.ReplaceRule.getvar.optimize (); +return com.stevesoft.pat.ReplaceRule.getvar; +}); +c$.perlCode = Clazz.defineMethod (c$, "perlCode", +function (s) { +try { +var mf = 0; +var mt = 0; +var gv = com.stevesoft.pat.ReplaceRule.getv (); +var head = null; +var tmp = null; +while (gv.searchFrom (s, mt)) { +var off = com.stevesoft.pat.Regex.BackRefOffset - 1; +mf = gv.matchedFrom (); +if (mf > mt) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule (s.substring (mt, mf))); +}var $var = null; +if (($var = gv.stringMatchedI (1 + off)) != null || ($var = gv.stringMatchedI (2 + off)) != null || ($var = gv.stringMatchedI (5 + off)) != null) { +var d = 0; +for (var i = 0; i < $var.length; i++) { +d = 8 * d + ($var.charCodeAt (i) - 48); +} +if ($var.length == 1) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.BackRefRule (d)); +} else { +head = new com.stevesoft.pat.StringRule ("" + String.fromCharCode (d)); +}} else if (($var = gv.stringMatchedI (10 + off)) != null) { +if ("QELlUu".indexOf ($var) >= 0) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.CodeRule ($var.charAt (0))); +} else { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ($var)); +}} else if (($var = gv.stringMatchedI (3 + off)) != null || ($var = gv.stringMatchedI (4 + off)) != null || ($var = gv.stringMatchedI (6 + off)) != null) { +var arg = ""; +var pc; +if ((pc = $var.indexOf (':')) > 0) { +arg = $var.substring (pc + 1); +$var = $var.substring (0, pc); +}if ($var.equals ("&") || $var.equals ("MATCH")) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.AmpersandRule ()); +} else if ($var.equals ("`") || $var.equals ("PREMATCH")) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.LeftRule ()); +} else if ($var.equals ("'") || $var.equals ("POSTMATCH")) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.RightRule ()); +} else if ($var.equals ("WANT_MORE_TEXT")) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.WantMoreTextReplaceRule ()); +} else if ($var.equals ("POP")) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.PopRule ()); +} else if ($var.startsWith ("+") && (tmp = com.stevesoft.pat.ReplaceRule.defs.get ($var.substring (1))) != null) { +if (Clazz.instanceOf (tmp, com.stevesoft.pat.Regex)) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.PushRule ($var.substring (1), tmp)); +} else if (Clazz.instanceOf (tmp, com.stevesoft.pat.Transformer)) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.PushRule ($var.substring (1), tmp)); +} else { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("${" + $var + "}")); +}} else if ($var.startsWith ("=") && (tmp = com.stevesoft.pat.ReplaceRule.defs.get ($var.substring (1))) != null) { +if (Clazz.instanceOf (tmp, com.stevesoft.pat.Regex)) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.ChangeRule ($var.substring (1), tmp)); +} else if (Clazz.instanceOf (tmp, com.stevesoft.pat.Transformer)) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.ChangeRule ($var.substring (1), tmp)); +} else { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("${" + $var + "}")); +}} else if ((tmp = com.stevesoft.pat.ReplaceRule.defs.get ($var)) != null) { +if (Clazz.instanceOf (tmp, com.stevesoft.pat.ReplaceRule)) { +var alt = (tmp).arg (arg); +if (alt == null) { +alt = (tmp); +}head = com.stevesoft.pat.ReplaceRule.add (head, (alt.clone ())); +}} else { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("${" + $var + "}")); +}} else if (($var = gv.stringMatchedI (7 + off)) != null) { +var c = $var.charAt (0); +if (c == 'n') { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\n")); +} else if (c == 't') { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\t")); +} else if (c == 'r') { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\r")); +} else if (c == 'b') { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\r")); +} else if (c == 'a') { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\u0007")); +} else if (c == 'e') { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\u001b")); +} else if (c == 'f') { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("\f")); +}} else if (($var = gv.stringMatchedI (8 + off)) != null) { +var c = $var.charAt (0); +if (c.charCodeAt (0) < com.stevesoft.pat.Ctrl.cmap.length) { +c = com.stevesoft.pat.Ctrl.cmap[c.charCodeAt (0)]; +}head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("" + c)); +} else if (($var = gv.stringMatchedI (9 + off)) != null) { +var d = 16 * com.stevesoft.pat.ReplaceRule.getHexDigit ($var.charAt (0)) + com.stevesoft.pat.ReplaceRule.getHexDigit ($var.charAt (1)); +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule ("" + String.fromCharCode (d))); +}mt = gv.matchedTo (); +} +if (mt <= s.length) { +head = com.stevesoft.pat.ReplaceRule.add (head, new com.stevesoft.pat.StringRule (s.substring (mt))); +}return head; +} finally { +} +}, "~S"); +c$.isDefined = Clazz.defineMethod (c$, "isDefined", +function (s) { +return com.stevesoft.pat.ReplaceRule.defs.get (s) != null; +}, "~S"); +c$.define = Clazz.defineMethod (c$, "define", +function (s, r) { +com.stevesoft.pat.ReplaceRule.defs.put (s, r); +}, "~S,com.stevesoft.pat.Regex"); +c$.define = Clazz.defineMethod (c$, "define", +function (s, r) { +com.stevesoft.pat.ReplaceRule.defs.put (s, r); +r.name = s; +}, "~S,com.stevesoft.pat.ReplaceRule"); +c$.define = Clazz.defineMethod (c$, "define", +function (s, t) { +com.stevesoft.pat.ReplaceRule.defs.put (s, t); +}, "~S,com.stevesoft.pat.Transformer"); +c$.undefine = Clazz.defineMethod (c$, "undefine", +function (s) { +com.stevesoft.pat.ReplaceRule.defs.remove (s); +}, "~S"); +Clazz.defineMethod (c$, "toString1", +function () { +return "${" + this.name + "}"; +}); +Clazz.overrideMethod (c$, "toString", +function () { +var sb = new StringBuffer (); +sb.append (this.toString1 ()); +var rr = this.next; +while (rr != null) { +sb.append (rr.toString1 ()); +rr = rr.next; +} +return sb.toString (); +}); +Clazz.defineMethod (c$, "arg", +function (s) { +return null; +}, "~S"); +c$.getHexDigit = Clazz.defineMethod (c$, "getHexDigit", +function (c) { +if (c >= '0' && c <= '9') { +return c.charCodeAt (0) - 48; +}if (c >= 'a' && c <= 'f') { +return c.charCodeAt (0) - 97 + 10; +}return c.charCodeAt (0) - 65 + 10; +}, "~S"); +Clazz.defineStatics (c$, +"getvar", null); +c$.defs = c$.prototype.defs = new java.util.Hashtable (); +});