1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-13 13:25:48 +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

@@ -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
})),

View File

@@ -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,

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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];

View File

@@ -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),