diff options
author | Kris Maglione <maglione.k@gmail.com> | 2011-02-15 13:06:40 -0500 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2011-02-15 13:06:40 -0500 |
commit | 5606b9695704c87406feba251e35cef71c8529b1 (patch) | |
tree | da58e4ab4a678664d3e903c023740157ebe33418 | |
parent | 5d53adcebca4f2bf7df5740c0cc7af65c47a80b5 (diff) | |
download | pentadactyl-5606b9695704c87406feba251e35cef71c8529b1.tar.gz |
Require "x" flag in util.regexp for "extended" regex processing.
-rw-r--r-- | common/components/protocols.js | 2 | ||||
-rw-r--r-- | common/content/abbreviations.js | 4 | ||||
-rw-r--r-- | common/content/dactyl.js | 47 | ||||
-rw-r--r-- | common/modules/commands.jsm | 6 | ||||
-rw-r--r-- | common/modules/highlight.jsm | 4 | ||||
-rw-r--r-- | common/modules/io.jsm | 2 | ||||
-rw-r--r-- | common/modules/styles.jsm | 10 | ||||
-rw-r--r-- | common/modules/template.jsm | 2 | ||||
-rw-r--r-- | common/modules/util.jsm | 16 |
9 files changed, 51 insertions, 42 deletions
diff --git a/common/components/protocols.js b/common/components/protocols.js index e925da69..ac8f0920 100644 --- a/common/components/protocols.js +++ b/common/components/protocols.js @@ -257,7 +257,7 @@ function XMLChannel(uri, contentType) { ([^]*) )? $ - ]]>).exec(stream.read(4096)); + ]]>, "x").exec(stream.read(4096)); this.writes.push(pre); if (doctype) { this.writes.push(doctype + "[\n"); diff --git a/common/content/abbreviations.js b/common/content/abbreviations.js index 462b93ea..0e9a7cb5 100644 --- a/common/content/abbreviations.js +++ b/common/content/abbreviations.js @@ -157,14 +157,14 @@ var Abbreviations = Module("abbreviations", { (^ | \s | <nonkeyword>) (<keyword>+ )$ | // full-id (^ | \s | <keyword> ) (<nonkeyword>+ <keyword>)$ | // end-id (^ | \s ) (\S* <nonkeyword> )$ // non-id - ]]></>, "", params); + ]]></>, "x", params); this._check = util.regexp(<><![CDATA[ ^ (?: <keyword>+ | // full-id <nonkeyword>+ <keyword> | // end-id \S* <nonkeyword> // non-id ) $ - ]]></>, "", params); + ]]></>, "x", params); }, get: deprecated("group.abbrevs.get", { get: function get() this.user.closure.get }), diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 23403eee..933de1b9 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -696,9 +696,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { ) | (?: ^ [^\S\n]* \n) + - ]]>, "gmy"); + ]]>, "gmxy"); - let betas = util.regexp(/\[(b\d)\]/, "g"); + let betas = util.regexp(/\[(b\d)\]/, "gx"); let beta = array(betas.iterate(NEWS)) .map(function (m) m[1]).uniq().slice(-1)[0]; @@ -1240,26 +1240,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { else urls = [str]; - let re = util.regexp(<![CDATA[ - ^ ( - <domain>+ (:\d+)? (/ .*) | - <domain>+ (:\d+) | - <domain>+ \. [a-z0-9]+ | - localhost - ) $ - ]]>, "i", { - domain: util.regexp(String.replace(<![CDATA[ - [^ - U0000-U002c // U002d-U002e --. - U002f // / - // U0030-U0039 0-9 - U003a-U0040 // U0041-U005a a-z - U005b-U0060 // U0061-U007a A-Z - U007b-U007f - ] - ]]>, /U/g, "\\u")) - }); - return urls.map(function (url) { url = url.trim(); @@ -1284,15 +1264,34 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { return searchURL; // If it looks like URL-ish (foo.com/bar), let Gecko figure it out. - if (re.test(url)) + if (this.urlish.test(url)) return util.createURI(url).spec; // Pass it off to the default search engine or, failing // that, let Gecko deal with it as is. return bookmarks.getSearchURL(url, true) || util.createURI(url).spec; - }); + }, this); }, stringToURLArray: deprecated("dactyl.parseURLs", "parseURLs"), + urlish: Class.memoize(function () util.regexp(<![CDATA[ + ^ ( + <domain>+ (:\d+)? (/ .*) | + <domain>+ (:\d+) | + <domain>+ \. [a-z0-9]+ | + localhost + ) $ + ]]>, "ix", { + domain: util.regexp(String.replace(<![CDATA[ + [^ + U0000-U002c // U002d-U002e --. + U002f // / + // U0030-U0039 0-9 + U003a-U0040 // U0041-U005a a-z + U005b-U0060 // U0061-U007a A-Z + U007b-U007f + ] + ]]>, /U/g, "\\u"), "x") + })), pluginFiles: {}, diff --git a/common/modules/commands.jsm b/common/modules/commands.jsm index 4828e978..39ed4c0f 100644 --- a/common/modules/commands.jsm +++ b/common/modules/commands.jsm @@ -1095,7 +1095,7 @@ var Commands = Module("commands", { <forbid> ] [^ <forbid> ]* - ]]>, "g", { + ]]>, "gx", { forbid: util.regexp(String.replace(<![CDATA[ U0000-U002c // U002d - U002e-U002f @@ -1119,7 +1119,7 @@ var Commands = Module("commands", { Ufe70-Ufeff // Arabic Presentation Forms-B Uff00-Uffef // Halfwidth and Fullwidth Forms Ufff0-Uffff // Specials - ]]>, /U/g, "\\u")) + ]]>, /U/g, "\\u"), "x") }), validName: Class.memoize(function () util.regexp("^" + this.nameRegexp.source + "$")), @@ -1137,7 +1137,7 @@ var Commands = Module("commands", { (?:. | \n)*? )? $ - ]]>, "", { + ]]>, "x", { name: this.nameRegexp })), diff --git a/common/modules/highlight.jsm b/common/modules/highlight.jsm index 1c53104f..782b9ca5 100644 --- a/common/modules/highlight.jsm +++ b/common/modules/highlight.jsm @@ -224,7 +224,7 @@ var Highlights = Module("Highlight", { \{ ([^}]*) \} \s* $ - ]]>, "gm"), + ]]>, "gmx"), sheetRegexp: util.regexp(<![CDATA[ ^\s* !? \*? @@ -234,7 +234,7 @@ var Highlights = Module("Highlight", { (?:; (?P<extends> (?:[^;\s]|\s[^;\s])+ )? )? \s* (?P<css> .*) $ - ]]>), + ]]>, "x"), /** * Bulk loads new CSS rules, in the format of, diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 585b8e63..71c72ba2 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -966,7 +966,7 @@ unlet s:cpo_save ) (?P<path> \/[^\/]* )? $ - ]]>).exec(context.filter); + ]]>, "x").exec(context.filter); if (match) { if (!match.path) { context.key = match.proto; diff --git a/common/modules/styles.jsm b/common/modules/styles.jsm index d9da6c68..b83f99dc 100644 --- a/common/modules/styles.jsm +++ b/common/modules/styles.jsm @@ -473,7 +473,7 @@ var Styles = Module("Styles", { )? ) (?P<postSpace> <space>* (?: ; | $) ) - ]]>, "gi", + ]]>, "gix", { space: /(?: \s | \/\* .*? \*\/ )/, string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/ @@ -491,7 +491,7 @@ var Styles = Module("Styles", { )? ) (?P<postSpace> <space>* (?: ; | $) ) - ]]>, "gi", this), + ]]>, "gix", this), get function() util.regexp(<![CDATA[ (?P<function> @@ -499,7 +499,7 @@ var Styles = Module("Styles", { (?: <string> | [^)]* ) \s* (?: \) | $) ) - ]]>, "g", this), + ]]>, "gx", this), space: /(?: \s | \/\* .*? \*\/ )/, @@ -508,7 +508,7 @@ var Styles = Module("Styles", { " (?:[^\\"]|\\.)* (?:"|$) | ' (?:[^\\']|\\.)* (?:'|$) ) - ]]>, "g", this), + ]]>, "gx", this), get token() util.regexp(<![CDATA[ (?P<token> @@ -520,7 +520,7 @@ var Styles = Module("Styles", { | <space>+ | [^;}\s]+ ) - ]]>, "gi", this) + ]]>, "gix", this) }) }, { commands: function (dactyl, modules, window) { diff --git a/common/modules/template.jsm b/common/modules/template.jsm index be1e5ab7..42220bba 100644 --- a/common/modules/template.jsm +++ b/common/modules/template.jsm @@ -349,7 +349,7 @@ var Template = Module("Template", { (?P<pre> [/\s]|^) (?P<tag> '[\w-]+' | :(?:[\w-]+|!) | (?:._)?<[\w-]+> ) (?= [[\)!,;./\s]|$) - ]]>, "g"); + ]]>, "gx"); return this.highlightSubstrings(str, (function () { for (let res in re.iterate(str)) yield [res.index + res.pre.length, res.tag.length]; diff --git a/common/modules/util.jsm b/common/modules/util.jsm index ed47972a..e8b02d41 100644 --- a/common/modules/util.jsm +++ b/common/modules/util.jsm @@ -349,7 +349,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), (< ((?:[a-z]-)?[a-z-]+?) >) | // 3 4 (\}>) // 5 ) - ]]>, "giy"); + ]]>, "gixy"); macro = String(macro); let end = 0; for (let match in re.iterate(macro)) { @@ -1323,14 +1323,21 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), * @returns {RegExp} A custom regexp object. */ regexp: update(function (expr, flags, tokens) { + flags = flags || [k for ([k, v] in Iterator({ g: "global", i: "ignorecase", m: "multiline", y: "sticky" })) + if (expr[v])].join(""); + if (isinstance(expr, ["RegExp"])) expr = expr.source; + // Replace replacement <tokens>. if (tokens) expr = String.replace(expr, /(\(?P)?<(\w+)>/g, function (m, n1, n2) !n1 && set.has(tokens, n2) ? tokens[n2].dactylSource || tokens[n2].source || tokens[n2] : m); - expr = String.replace(expr, /(\\.)|\/\/[^\n]*|\/\*[^]*?\*\/|\s+/gm, function (m, m1) m1 || ""); + // Strip comments and white space. + if (/x/.test(flags)) + expr = String.replace(expr, /(\\.)|\/\/[^\n]*|\/\*[^]*?\*\/|\s+/gm, function (m, m1) m1 || ""); + // Replace (?P<named> parameters) if (/\(\?P</.test(expr)) { var source = expr; let groups = ["wholeMatch"]; @@ -1343,11 +1350,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), var struct = Struct.apply(null, groups); } - let res = update(RegExp(expr, flags), { + let res = update(RegExp(expr, flags.replace("x", "")), { closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "closure")), dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"], iterate: function (str, idx) util.regexp.iterate(this, str, idx) }); + + // Return a struct with properties for named parameters if we + // have them. if (struct) update(res, { exec: function exec() let (match = exec.superapply(this, arguments)) match && struct.fromArray(match), |