1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 08:44:13 +01:00

Allow \c/\C in regexp options and so forth.

This commit is contained in:
Kris Maglione
2011-03-02 14:43:57 -05:00
parent 0f542bc000
commit 66785a8b5f
9 changed files with 45 additions and 25 deletions

View File

@@ -1276,7 +1276,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let urls;
if (options["urlseparator"])
urls = util.splitLiteral(str, RegExp("\\s*" + options["urlseparator"] + "\\s*"));
urls = util.splitLiteral(str, util.regexp("\\s*" + options["urlseparator"] + "\\s*"));
else
urls = [str];

View File

@@ -300,6 +300,8 @@ var EventHive = Class("EventHive", Contexts.Hive, {
* @param {function} callback The function to call when the event is received.
* @param {boolean} capture When true, listen during the capture
* phase, otherwise during the bubbling phase.
* @param {boolean} allowUntrusted When true, allow capturing of
* untrusted events.
*/
listen: function (target, event, callback, capture, allowUntrusted) {
if (!isObject(event))
@@ -821,9 +823,7 @@ var Events = Module("events", {
unknownOk = true;
let out = [];
let re = RegExp("<.*?>?>|[^<]|<(?!.*>)", "g");
let match;
while ((match = re.exec(input))) {
for (let match in util.regexp.iterate(/<.*?>?>|[^<]|<(?!.*>)/g, input)) {
let evt_str = match[0];
let evt_obj = { ctrlKey: false, shiftKey: false, altKey: false, metaKey: false,
keyCode: 0, charCode: 0, type: "keypress" };

View File

@@ -847,8 +847,8 @@ var Hints = Module("hints", {
* hints that match as above.
*/
function wordStartsWithMatcher(hintString, allowWordOverleaping) { //{{{
let hintStrings = tokenize(/\s+/, hintString);
let wordSplitRegexp = RegExp(options["wordseparators"]);
let hintStrings = tokenize(/\s+/, hintString);
let wordSplitRegexp = util.regexp(options["wordseparators"]);
/**
* Match a set of characters to the start of words.

View File

@@ -15,10 +15,6 @@ defineModule("commands", {
use: ["config", "messages", "options", "services", "template"]
}, this);
let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, ""));
let re = RegExp("^(resource://dactyl|" + base + ")\\S+( -> resource://dactyl(?!-content/eval.js)\\S+)?$");
let isDactyl = function isDactyl(frame) re.test(frame.filename);
/**
* A structure representing the options available for a command.
*
@@ -692,7 +688,7 @@ var Commands = Module("commands", {
repeat: null,
add: function add() {
util.assert(isDactyl(Components.stack.caller),
util.assert(util.isDactyl(Components.stack.caller),
"User scripts may not add builtin commands. Please use group.commands.add instead.");
return this.builtin._add.apply(this.builtin, arguments);
},

View File

@@ -903,7 +903,9 @@ var Completion = Module("completion", {
url: function url(context, complete) {
if (this.options["urlseparator"])
var skip = RegExp("^.*" + this.options["urlseparator"] + "\\s*").exec(context.filter);
var skip = util.regexp("^.*" + this.options["urlseparator"] + "\\s*")
.exec(context.filter);
if (skip)
context.advance(skip[0].length);

View File

@@ -406,12 +406,14 @@ var Highlights = Module("Highlight", {
completion: function (dactyl, modules) {
const { completion, config, io } = modules;
completion.colorScheme = function colorScheme(context) {
let extRe = RegExp("\\." + config.fileExtension + "$");
context.title = ["Color Scheme", "Runtime Path"];
context.keys = { text: function (f) f.leafName.replace(RegExp("\\." + config.fileExtension + "$"), ""), description: ".parent.path" };
context.keys = { text: function (f) f.leafName.replace(extRe, ""), description: ".parent.path" };
context.completions = array.flatten(
io.getRuntimeDirectories("colors").map(
function (dir) dir.readDirectory().filter(
function (file) RegExp("\\." + config.fileExtension + "$").test(file.leafName))));
function (file) extRe.test(file.leafName))));
};

View File

@@ -425,7 +425,7 @@ var Option = Class("Option", {
flags = this && this.regexpFlags || "";
let [, bang, val] = /^(!?)(.*)/.exec(value);
let re = RegExp(Option.dequote(val), flags);
let re = util.regexp(Option.dequote(val), flags);
re.bang = bang;
re.result = result !== undefined ? result : !bang;
re.toString = function () Option.unparseRegexp(this, keepQuotes);

View File

@@ -413,7 +413,7 @@ var Styles = Module("Styles", {
if (filter === "*")
var test = function test(uri) true;
else if (!/^(?:[a-z-]+:|[a-z-.]+$)/.test(filter)) {
let re = RegExp(filter);
let re = util.regexp(filter);
test = function test(uri) re.test(uri.spec);
}
else if (/[*]$/.test(filter)) {

View File

@@ -177,20 +177,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
* @returns {RegExp}
*/
charListToRegexp: function charListToRegexp(list, accepted) {
let list = list.replace(/\s+/g, "");
list = list.replace(/\s+/g, "");
// check for chars not in the accepted range
this.assert(RegExp("^[" + accepted + "-]+$").test(list),
"Character list outside the range " + accepted.quote());
"Character list outside the range " + accepted.quote());
// check for illegal ranges
let matches = list.match(RegExp("[" + accepted + "]-[" + accepted + "]", "g"));
if (matches) {
for (let match in values(matches))
this.assert(match[0] <= match[2],
"Invalid character range: " + list.match(match + ".*")[0]);
}
return RegExp("[" + list + "]");
for (let [match] in this.regexp.iterate(/.-./g, list))
this.assert(match.charCodeAt(0) <= match.charCodeAt(2),
"Invalid character range: " + list.slice(list.indexOf(match)))
return RegExp("[" + util.regexp.escape(list) + "]");
},
get chromePackages() {
@@ -822,6 +820,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
bottom: Math.min(r1.bottom, r2.bottom)
}),
/**
* Returns true if the given stack frame resides in Dactyl code.
*
* @param {nsIStackFrame} frame
* @returns {boolean}
*/
isDactyl: Class.memoize(function () {
let base = util.regexp.escape(Components.stack.filename.replace(/[^\/]+$/, ""));
let re = RegExp("^(resource://dactyl|" + base + ")\\S+( -> resource://dactyl(?!-content/eval.js)\\S+)?$");
return function isDactyl(frame) re.test(frame.filename);
}),
/**
* Returns true if *url* is in the domain *domain*.
*
@@ -1340,6 +1350,16 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
if (isinstance(expr, ["RegExp"]))
expr = expr.source;
expr = String.replace(expr, /\\(.)/, function (m, m1) {
if (m1 === "c")
flags = flags.replace(/i/g, "") + "i";
else if (m === "C")
flags = flags.replace(/i/g, "");
else
return m;
return "";
});
// 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);