1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-21 22:17:59 +01:00

Require "x" flag in util.regexp for "extended" regex processing.

This commit is contained in:
Kris Maglione
2011-02-15 13:06:40 -05:00
parent 5d53adcebc
commit 5606b96957
9 changed files with 51 additions and 42 deletions

View File

@@ -257,7 +257,7 @@ function XMLChannel(uri, contentType) {
([^]*) ([^]*)
)? )?
$ $
]]>).exec(stream.read(4096)); ]]>, "x").exec(stream.read(4096));
this.writes.push(pre); this.writes.push(pre);
if (doctype) { if (doctype) {
this.writes.push(doctype + "[\n"); this.writes.push(doctype + "[\n");

View File

@@ -157,14 +157,14 @@ var Abbreviations = Module("abbreviations", {
(^ | \s | <nonkeyword>) (<keyword>+ )$ | // full-id (^ | \s | <nonkeyword>) (<keyword>+ )$ | // full-id
(^ | \s | <keyword> ) (<nonkeyword>+ <keyword>)$ | // end-id (^ | \s | <keyword> ) (<nonkeyword>+ <keyword>)$ | // end-id
(^ | \s ) (\S* <nonkeyword> )$ // non-id (^ | \s ) (\S* <nonkeyword> )$ // non-id
]]></>, "", params); ]]></>, "x", params);
this._check = util.regexp(<><![CDATA[ this._check = util.regexp(<><![CDATA[
^ (?: ^ (?:
<keyword>+ | // full-id <keyword>+ | // full-id
<nonkeyword>+ <keyword> | // end-id <nonkeyword>+ <keyword> | // end-id
\S* <nonkeyword> // non-id \S* <nonkeyword> // non-id
) $ ) $
]]></>, "", params); ]]></>, "x", params);
}, },
get: deprecated("group.abbrevs.get", { get: function get() this.user.closure.get }), get: deprecated("group.abbrevs.get", { get: function get() this.user.closure.get }),

View File

@@ -696,9 +696,9 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
) )
| |
(?: ^ [^\S\n]* \n) + (?: ^ [^\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)) let beta = array(betas.iterate(NEWS))
.map(function (m) m[1]).uniq().slice(-1)[0]; .map(function (m) m[1]).uniq().slice(-1)[0];
@@ -1240,26 +1240,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
else else
urls = [str]; 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) { return urls.map(function (url) {
url = url.trim(); url = url.trim();
@@ -1284,15 +1264,34 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
return searchURL; return searchURL;
// If it looks like URL-ish (foo.com/bar), let Gecko figure it out. // 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; return util.createURI(url).spec;
// Pass it off to the default search engine or, failing // Pass it off to the default search engine or, failing
// that, let Gecko deal with it as is. // that, let Gecko deal with it as is.
return bookmarks.getSearchURL(url, true) || util.createURI(url).spec; return bookmarks.getSearchURL(url, true) || util.createURI(url).spec;
}); }, this);
}, },
stringToURLArray: deprecated("dactyl.parseURLs", "parseURLs"), 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: {}, pluginFiles: {},

View File

@@ -1095,7 +1095,7 @@ var Commands = Module("commands", {
<forbid> <forbid>
] ]
[^ <forbid> ]* [^ <forbid> ]*
]]>, "g", { ]]>, "gx", {
forbid: util.regexp(String.replace(<![CDATA[ forbid: util.regexp(String.replace(<![CDATA[
U0000-U002c // U002d - U0000-U002c // U002d -
U002e-U002f U002e-U002f
@@ -1119,7 +1119,7 @@ var Commands = Module("commands", {
Ufe70-Ufeff // Arabic Presentation Forms-B Ufe70-Ufeff // Arabic Presentation Forms-B
Uff00-Uffef // Halfwidth and Fullwidth Forms Uff00-Uffef // Halfwidth and Fullwidth Forms
Ufff0-Uffff // Specials Ufff0-Uffff // Specials
]]>, /U/g, "\\u")) ]]>, /U/g, "\\u"), "x")
}), }),
validName: Class.memoize(function () util.regexp("^" + this.nameRegexp.source + "$")), validName: Class.memoize(function () util.regexp("^" + this.nameRegexp.source + "$")),
@@ -1137,7 +1137,7 @@ var Commands = Module("commands", {
(?:. | \n)*? (?:. | \n)*?
)? )?
$ $
]]>, "", { ]]>, "x", {
name: this.nameRegexp name: this.nameRegexp
})), })),

View File

@@ -224,7 +224,7 @@ var Highlights = Module("Highlight", {
\{ ([^}]*) \} \{ ([^}]*) \}
\s* \s*
$ $
]]>, "gm"), ]]>, "gmx"),
sheetRegexp: util.regexp(<![CDATA[ sheetRegexp: util.regexp(<![CDATA[
^\s* ^\s*
!? \*? !? \*?
@@ -234,7 +234,7 @@ var Highlights = Module("Highlight", {
(?:; (?P<extends> (?:[^;\s]|\s[^;\s])+ )? )? (?:; (?P<extends> (?:[^;\s]|\s[^;\s])+ )? )?
\s* (?P<css> .*) \s* (?P<css> .*)
$ $
]]>), ]]>, "x"),
/** /**
* Bulk loads new CSS rules, in the format of, * Bulk loads new CSS rules, in the format of,

View File

@@ -966,7 +966,7 @@ unlet s:cpo_save
) )
(?P<path> \/[^\/]* )? (?P<path> \/[^\/]* )?
$ $
]]>).exec(context.filter); ]]>, "x").exec(context.filter);
if (match) { if (match) {
if (!match.path) { if (!match.path) {
context.key = match.proto; context.key = match.proto;

View File

@@ -473,7 +473,7 @@ var Styles = Module("Styles", {
)? )?
) )
(?P<postSpace> <space>* (?: ; | $) ) (?P<postSpace> <space>* (?: ; | $) )
]]>, "gi", ]]>, "gix",
{ {
space: /(?: \s | \/\* .*? \*\/ )/, space: /(?: \s | \/\* .*? \*\/ )/,
string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/ string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/
@@ -491,7 +491,7 @@ var Styles = Module("Styles", {
)? )?
) )
(?P<postSpace> <space>* (?: ; | $) ) (?P<postSpace> <space>* (?: ; | $) )
]]>, "gi", this), ]]>, "gix", this),
get function() util.regexp(<![CDATA[ get function() util.regexp(<![CDATA[
(?P<function> (?P<function>
@@ -499,7 +499,7 @@ var Styles = Module("Styles", {
(?: <string> | [^)]* ) (?: <string> | [^)]* )
\s* (?: \) | $) \s* (?: \) | $)
) )
]]>, "g", this), ]]>, "gx", this),
space: /(?: \s | \/\* .*? \*\/ )/, space: /(?: \s | \/\* .*? \*\/ )/,
@@ -508,7 +508,7 @@ var Styles = Module("Styles", {
" (?:[^\\"]|\\.)* (?:"|$) | " (?:[^\\"]|\\.)* (?:"|$) |
' (?:[^\\']|\\.)* (?:'|$) ' (?:[^\\']|\\.)* (?:'|$)
) )
]]>, "g", this), ]]>, "gx", this),
get token() util.regexp(<![CDATA[ get token() util.regexp(<![CDATA[
(?P<token> (?P<token>
@@ -520,7 +520,7 @@ var Styles = Module("Styles", {
| <space>+ | <space>+
| [^;}\s]+ | [^;}\s]+
) )
]]>, "gi", this) ]]>, "gix", this)
}) })
}, { }, {
commands: function (dactyl, modules, window) { commands: function (dactyl, modules, window) {

View File

@@ -349,7 +349,7 @@ var Template = Module("Template", {
(?P<pre> [/\s]|^) (?P<pre> [/\s]|^)
(?P<tag> '[\w-]+' | :(?:[\w-]+|!) | (?:._)?<[\w-]+> ) (?P<tag> '[\w-]+' | :(?:[\w-]+|!) | (?:._)?<[\w-]+> )
(?= [[\)!,;./\s]|$) (?= [[\)!,;./\s]|$)
]]>, "g"); ]]>, "gx");
return this.highlightSubstrings(str, (function () { return this.highlightSubstrings(str, (function () {
for (let res in re.iterate(str)) for (let res in re.iterate(str))
yield [res.index + res.pre.length, res.tag.length]; yield [res.index + res.pre.length, res.tag.length];

View File

@@ -349,7 +349,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
(< ((?:[a-z]-)?[a-z-]+?) >) | // 3 4 (< ((?:[a-z]-)?[a-z-]+?) >) | // 3 4
(\}>) // 5 (\}>) // 5
) )
]]>, "giy"); ]]>, "gixy");
macro = String(macro); macro = String(macro);
let end = 0; let end = 0;
for (let match in re.iterate(macro)) { 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. * @returns {RegExp} A custom regexp object.
*/ */
regexp: update(function (expr, flags, tokens) { 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"])) if (isinstance(expr, ["RegExp"]))
expr = expr.source; expr = expr.source;
// Replace replacement <tokens>.
if (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, /(\(?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)) { if (/\(\?P</.test(expr)) {
var source = expr; var source = expr;
let groups = ["wholeMatch"]; let groups = ["wholeMatch"];
@@ -1343,11 +1350,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
var struct = Struct.apply(null, groups); 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")), closure: Class.Property(Object.getOwnPropertyDescriptor(Class.prototype, "closure")),
dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"], dactylPropertyNames: ["exec", "match", "test", "toSource", "toString", "global", "ignoreCase", "lastIndex", "multiLine", "source", "sticky"],
iterate: function (str, idx) util.regexp.iterate(this, str, idx) iterate: function (str, idx) util.regexp.iterate(this, str, idx)
}); });
// Return a struct with properties for named parameters if we
// have them.
if (struct) if (struct)
update(res, { update(res, {
exec: function exec() let (match = exec.superapply(this, arguments)) match && struct.fromArray(match), exec: function exec() let (match = exec.superapply(this, arguments)) match && struct.fromArray(match),