mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 22:37:58 +01:00
Require "x" flag in util.regexp for "extended" regex processing.
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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 }),
|
||||
|
||||
@@ -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: {},
|
||||
|
||||
|
||||
@@ -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
|
||||
})),
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
// 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),
|
||||
|
||||
Reference in New Issue
Block a user