mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 09:57:59 +01:00
Hackier but more reliable literal() stuff.
This commit is contained in:
@@ -230,7 +230,10 @@ this.lazyRequire("util", ["FailedAssertion", "util"]);
|
||||
|
||||
literal.files = {};
|
||||
literal.locations = {};
|
||||
function literal(/* comment */) {
|
||||
function literal(comment) {
|
||||
if (comment)
|
||||
return /^function.*?\/\*([^]*)\*\/(?:\/\* use strict \*\/)\s*\S$/.exec(comment)[1];
|
||||
|
||||
let { caller } = Components.stack;
|
||||
while (caller && caller.language != 2)
|
||||
caller = caller.caller;
|
||||
|
||||
@@ -1239,14 +1239,14 @@ var Commands = Module("commands", {
|
||||
}
|
||||
},
|
||||
|
||||
nameRegexp: util.regexp(literal(/*
|
||||
nameRegexp: util.regexp(literal(function () /*
|
||||
[^
|
||||
0-9
|
||||
<forbid>
|
||||
]
|
||||
[^ <forbid> ]*
|
||||
*/), "gx", {
|
||||
forbid: util.regexp(String.replace(literal(/*
|
||||
*/$), "gx", {
|
||||
forbid: util.regexp(String.replace(literal(function () /*
|
||||
U0000-U002c // U002d -
|
||||
U002e-U002f
|
||||
U003a-U0040 // U0041-U005a a-z
|
||||
@@ -1269,12 +1269,12 @@ var Commands = Module("commands", {
|
||||
Ufe70-Ufeff // Arabic Presentation Forms-B
|
||||
Uff00-Uffef // Halfwidth and Fullwidth Forms
|
||||
Ufff0-Uffff // Specials
|
||||
*/), /U/g, "\\u"), "x")
|
||||
*/$), /U/g, "\\u"), "x")
|
||||
}),
|
||||
|
||||
validName: Class.Memoize(function validName() util.regexp("^" + this.nameRegexp.source + "$")),
|
||||
|
||||
commandRegexp: Class.Memoize(function commandRegexp() util.regexp(literal(/*
|
||||
commandRegexp: Class.Memoize(function commandRegexp() util.regexp(literal(function () /*
|
||||
^
|
||||
(?P<spec>
|
||||
(?P<prespace> [:\s]*)
|
||||
@@ -1289,7 +1289,7 @@ var Commands = Module("commands", {
|
||||
(?:. | \n)*?
|
||||
)?
|
||||
$
|
||||
*/), "x", {
|
||||
*/$), "x", {
|
||||
name: this.nameRegexp
|
||||
})),
|
||||
|
||||
|
||||
@@ -596,14 +596,14 @@ config.INIT = update(Object.create(config.INIT), config.INIT, {
|
||||
let img = new window.Image;
|
||||
img.src = this.logo || "resource://dactyl-local-content/logo.png";
|
||||
img.onload = util.wrapCallback(function () {
|
||||
highlight.loadCSS(literal(/*
|
||||
highlight.loadCSS(literal(function () /*
|
||||
!Logo {
|
||||
display: inline-block;
|
||||
background: url({src});
|
||||
width: {width}px;
|
||||
height: {height}px;
|
||||
}
|
||||
*/).replace(/\{(.*?)\}/g, (m, m1) => img[m1]));
|
||||
*/$).replace(/\{(.*?)\}/g, (m, m1) => img[m1]));
|
||||
img = null;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -108,7 +108,7 @@ var Help = Module("Help", {
|
||||
{ mimeType: "text/plain;charset=UTF-8" })
|
||||
.responseText;
|
||||
|
||||
let re = util.regexp(UTF8(literal(/*
|
||||
let re = util.regexp(UTF8(literal(function () /*
|
||||
^ (?P<comment> \s* # .*\n)
|
||||
|
||||
| ^ (?P<space> \s*)
|
||||
@@ -124,7 +124,7 @@ var Help = Module("Help", {
|
||||
)
|
||||
|
||||
| (?: ^ [^\S\n]* \n) +
|
||||
*/)), "gmxy");
|
||||
*/$)), "gmxy");
|
||||
|
||||
let betas = util.regexp(/\[((?:b|rc)\d)\]/, "gx");
|
||||
|
||||
|
||||
@@ -229,14 +229,14 @@ var Highlights = Module("Highlight", {
|
||||
return n1 + "[dactyl|highlight~=" + hl + "]";
|
||||
}),
|
||||
|
||||
groupRegexp: util.regexp(literal(/*
|
||||
groupRegexp: util.regexp(literal(function () /*
|
||||
^
|
||||
(\s* (?:\S|\s\S)+ \s+)
|
||||
\{ ([^}]*) \}
|
||||
\s*
|
||||
$
|
||||
*/), "gmx"),
|
||||
sheetRegexp: util.regexp(literal(/*
|
||||
*/$), "gmx"),
|
||||
sheetRegexp: util.regexp(literal(function () /*
|
||||
^\s*
|
||||
!? \*?
|
||||
(?P<group> (?:[^;\s]|\s[^;\s])+ )
|
||||
@@ -245,7 +245,7 @@ var Highlights = Module("Highlight", {
|
||||
(?:; (?P<extends> (?:[^;\s]|\s[^;\s])+ )? )?
|
||||
\s* (?P<css> .*)
|
||||
$
|
||||
*/), "x"),
|
||||
*/$), "x"),
|
||||
// </css>
|
||||
|
||||
/**
|
||||
@@ -328,7 +328,7 @@ var Highlights = Module("Highlight", {
|
||||
commands.add(["hi[ghlight]"],
|
||||
"Set the style of certain display elements",
|
||||
function (args) {
|
||||
let style = literal(/*
|
||||
let style = literal(function () /*
|
||||
;
|
||||
display: inline-block !important;
|
||||
position: static !important;
|
||||
@@ -336,7 +336,7 @@ var Highlights = Module("Highlight", {
|
||||
width: 3em !important; min-width: 3em !important; max-width: 3em !important;
|
||||
height: 1em !important; min-height: 1em !important; max-height: 1em !important;
|
||||
overflow: hidden !important;
|
||||
*/);
|
||||
*/$);
|
||||
let clear = args[0] == "clear";
|
||||
if (clear)
|
||||
args.shift();
|
||||
|
||||
@@ -680,13 +680,13 @@ var IO = Module("io", {
|
||||
}
|
||||
|
||||
rtItems.ftdetect.template = //{{{
|
||||
literal(/*" Vim filetype detection file
|
||||
literal(function () /*" Vim filetype detection file
|
||||
<header>
|
||||
|
||||
au BufNewFile,BufRead *<name>rc*,*.<fileext> set filetype=<name>
|
||||
*/);//}}}
|
||||
*/$);//}}}
|
||||
rtItems.ftplugin.template = //{{{
|
||||
literal(/*" Vim filetype plugin file
|
||||
literal(function () /*" Vim filetype plugin file
|
||||
<header>
|
||||
|
||||
if exists("b:did_ftplugin")
|
||||
@@ -711,9 +711,9 @@ endif
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
*/);//}}}
|
||||
*/$);//}}}
|
||||
rtItems.syntax.template = //{{{
|
||||
literal(/*" Vim syntax file
|
||||
literal(function () /*" Vim syntax file
|
||||
<header>
|
||||
|
||||
if exists("b:current_syntax")
|
||||
@@ -792,7 +792,7 @@ let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim: tw=130 et ts=8 sts=4 sw=4:
|
||||
*/);//}}}
|
||||
*/$);//}}}
|
||||
|
||||
const { options } = modules;
|
||||
|
||||
@@ -1047,7 +1047,7 @@ unlet s:cpo_save
|
||||
};
|
||||
|
||||
completion.addUrlCompleter("file", "Local files", function (context, full) {
|
||||
let match = util.regexp(literal(/*
|
||||
let match = util.regexp(literal(function () /*
|
||||
^
|
||||
(?P<prefix>
|
||||
(?P<proto>
|
||||
@@ -1058,7 +1058,7 @@ unlet s:cpo_save
|
||||
)
|
||||
(?P<path> \/[^\/]* )?
|
||||
$
|
||||
*/), "x").exec(context.filter);
|
||||
*/$), "x").exec(context.filter);
|
||||
if (match) {
|
||||
if (!match.path) {
|
||||
context.key = match.proto;
|
||||
|
||||
@@ -190,7 +190,7 @@ function XMLChannel(uri, contentType, noErrorChannel, unprivileged) {
|
||||
let type = this.channel.contentType;
|
||||
if (/^text\/|[\/+]xml$/.test(type)) {
|
||||
let stream = services.InputStream(channelStream);
|
||||
let [, pre, doctype, url, extra, open, post] = util.regexp(literal(/*
|
||||
let [, pre, doctype, url, extra, open, post] = util.regexp(literal(function () /*
|
||||
^ ([^]*?)
|
||||
(?:
|
||||
(<!DOCTYPE \s+ \S+ \s+) (?:SYSTEM \s+ "([^"]*)" | ((?:[^[>\s]|\s[^[])*))
|
||||
@@ -198,7 +198,7 @@ function XMLChannel(uri, contentType, noErrorChannel, unprivileged) {
|
||||
([^]*)
|
||||
)?
|
||||
$
|
||||
*/), "x").exec(stream.read(4096));
|
||||
*/$), "x").exec(stream.read(4096));
|
||||
this.writes.push(pre);
|
||||
if (doctype) {
|
||||
this.writes.push(doctype + (extra || "") + " [\n");
|
||||
|
||||
@@ -469,7 +469,7 @@ var Styles = Module("Styles", {
|
||||
}
|
||||
},
|
||||
|
||||
propertyPattern: util.regexp(literal(/*
|
||||
propertyPattern: util.regexp(literal(function () /*
|
||||
(?:
|
||||
(?P<preSpace> <space>*)
|
||||
(?P<name> [-a-z]*)
|
||||
@@ -491,14 +491,14 @@ var Styles = Module("Styles", {
|
||||
)?
|
||||
)
|
||||
(?P<postSpace> <space>* (?: ; | $) )
|
||||
*/), "gix",
|
||||
*/$), "gix",
|
||||
{
|
||||
space: /(?: \s | \/\* .*? \*\/ )/,
|
||||
string: /(?:" (?:[^\\"]|\\.)* (?:"|$) | '(?:[^\\']|\\.)* (?:'|$) )/
|
||||
}),
|
||||
|
||||
patterns: memoize({
|
||||
get property() util.regexp(literal(/*
|
||||
get property() util.regexp(literal(function () /*
|
||||
(?:
|
||||
(?P<preSpace> <space>*)
|
||||
(?P<name> [-a-z]*)
|
||||
@@ -509,26 +509,26 @@ var Styles = Module("Styles", {
|
||||
)?
|
||||
)
|
||||
(?P<postSpace> <space>* (?: ; | $) )
|
||||
*/), "gix", this),
|
||||
*/$), "gix", this),
|
||||
|
||||
get function() util.regexp(literal(/*
|
||||
get function() util.regexp(literal(function () /*
|
||||
(?P<function>
|
||||
\s* \( \s*
|
||||
(?: <string> | [^)]* )
|
||||
\s* (?: \) | $)
|
||||
)
|
||||
*/), "gx", this),
|
||||
*/$), "gx", this),
|
||||
|
||||
space: /(?: \s | \/\* .*? \*\/ )/,
|
||||
|
||||
get string() util.regexp(literal(/*
|
||||
get string() util.regexp(literal(function () /*
|
||||
(?P<string>
|
||||
" (?:[^\\"]|\\.)* (?:"|$) |
|
||||
' (?:[^\\']|\\.)* (?:'|$)
|
||||
)
|
||||
*/), "gx", this),
|
||||
*/$), "gx", this),
|
||||
|
||||
get token() util.regexp(literal(/*
|
||||
get token() util.regexp(literal(function () /*
|
||||
(?P<token>
|
||||
(?P<word> [-\w]+)
|
||||
<function>?
|
||||
@@ -538,7 +538,7 @@ var Styles = Module("Styles", {
|
||||
| <space>+
|
||||
| [^;}\s]+
|
||||
)
|
||||
*/), "gix", this)
|
||||
*/$), "gix", this)
|
||||
}),
|
||||
|
||||
/**
|
||||
|
||||
@@ -252,11 +252,11 @@ var Template = Module("Template", {
|
||||
return [tag, { xmlns: "dactyl" }, topic];
|
||||
},
|
||||
linkifyHelp: function linkifyHelp(str, help) {
|
||||
let re = util.regexp(literal(/*
|
||||
let re = util.regexp(literal(function () /*
|
||||
(?P<pre> [/\s]|^)
|
||||
(?P<tag> '[\w-]+' | :(?:[\w-]+!?|!) | (?:._)?<[\w-]+>\w* | \b[a-zA-Z]_(?:[\w[\]]+|.) | \[[\w-;]+\] | E\d{3} )
|
||||
(?= [[\)!,:;./\s]|$)
|
||||
*/), "gx");
|
||||
*/$), "gx");
|
||||
return this.highlightSubstrings(str, (function () {
|
||||
for (let res in re.iterate(str))
|
||||
yield [res.index + res.pre.length, res.tag.length];
|
||||
|
||||
@@ -359,14 +359,14 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
|
||||
let defaults = { lt: "<", gt: ">" };
|
||||
|
||||
let re = util.regexp(literal(/*
|
||||
let re = util.regexp(literal(function () /*
|
||||
([^]*?) // 1
|
||||
(?:
|
||||
(<\{) | // 2
|
||||
(< ((?:[a-z]-)?[a-z-]+?) (?:\[([0-9]+)\])? >) | // 3 4 5
|
||||
(\}>) // 6
|
||||
)
|
||||
*/), "gixy");
|
||||
*/$), "gixy");
|
||||
macro = String(macro);
|
||||
let end = 0;
|
||||
for (let match in re.iterate(macro)) {
|
||||
@@ -749,7 +749,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
*
|
||||
* @returns {XMLHttpRequest}
|
||||
*/
|
||||
httpGet: function httpGet(url, params={}, self) {
|
||||
httpGet: function httpGet(url, params={}, self=null) {
|
||||
if (callable(params))
|
||||
// Deprecated.
|
||||
params = { callback: params.bind(self) };
|
||||
@@ -908,7 +908,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
},
|
||||
|
||||
// ripped from Firefox; modified
|
||||
unsafeURI: Class.Memoize(() => util.regexp(String.replace(literal(/*
|
||||
unsafeURI: Class.Memoize(() => util.regexp(String.replace(literal(function () /*
|
||||
[
|
||||
\s
|
||||
// Invisible characters (bug 452979)
|
||||
@@ -922,7 +922,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
|
||||
// Bidi formatting characters. (RFC 3987 sections 3.2 and 4.1 paragraph 6)
|
||||
U200E U200F U202A U202B U202C U202D U202E
|
||||
]
|
||||
*/), /U/g, "\\u"),
|
||||
*/$), /U/g, "\\u"),
|
||||
"gx")),
|
||||
losslessDecodeURI: function losslessDecodeURI(url) {
|
||||
return url.split("%25").map(function (url) {
|
||||
|
||||
Reference in New Issue
Block a user