mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 10:47:58 +01:00
Add inordinate number of quoting styles, none of which, save one, are acually accessible
This commit is contained in:
@@ -164,6 +164,8 @@ function Commands() //{{{
|
|||||||
return NaN;
|
return NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QUOTE_STYLE = "vimperator";
|
||||||
|
|
||||||
const quoteMap = {
|
const quoteMap = {
|
||||||
"\n": "n",
|
"\n": "n",
|
||||||
"\t": "t"
|
"\t": "t"
|
||||||
@@ -298,92 +300,63 @@ function Commands() //{{{
|
|||||||
},
|
},
|
||||||
|
|
||||||
// returns [count, parsed_argument]
|
// returns [count, parsed_argument]
|
||||||
parseArg: function getNextArg(str)
|
parseArg: function parseArg(str)
|
||||||
{
|
{
|
||||||
var stringDelimiter = null;
|
let arg = "";
|
||||||
var escapeNext = false;
|
let quote = null;
|
||||||
|
let len = str.length;
|
||||||
|
|
||||||
var arg = "";
|
while (str.length && !/^\s/.test(str))
|
||||||
|
|
||||||
outer:
|
|
||||||
for (let i = 0; i < str.length; i++)
|
|
||||||
{
|
{
|
||||||
inner:
|
let res;
|
||||||
switch (str[i])
|
|
||||||
|
switch (QUOTE_STYLE)
|
||||||
{
|
{
|
||||||
case '"':
|
case "vim-sucks":
|
||||||
case "'":
|
if (res = str.match = str.match(/^()((?:[^\\\s]|\\.)+)((?:\\$)?)/))
|
||||||
if (escapeNext)
|
arg += res[2].replace(/\\(.)/g, "$1");
|
||||||
{
|
|
||||||
escapeNext = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
switch (stringDelimiter)
|
|
||||||
{
|
|
||||||
case str[i]:
|
|
||||||
stringDelimiter = null;
|
|
||||||
continue outer;
|
|
||||||
case null:
|
|
||||||
stringDelimiter = str[i];
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// \ is an escape key for non quoted or "-quoted strings
|
case "vimperator":
|
||||||
// for '-quoted strings it is taken literally, apart from \' and \\
|
if (res = str.match(/^()((?:[^\\\s"']|\\.)+)((?:\\$)?)/))
|
||||||
case "\\":
|
arg += res[2].replace(/\\(.)/g, "$1");
|
||||||
if (escapeNext)
|
else if (res = str.match(/^(")((?:[^\\"]|\\.)*)("?)/))
|
||||||
{
|
arg += eval(res[0] + (res[3] ? "" : '"'));
|
||||||
escapeNext = false;
|
else if (res = str.match(/^(')((?:[^\\']|\\.)*)('?)/))
|
||||||
break;
|
arg += res[2].replace(/\\(.)/g, function (n0, n1) /[\\']/.test(n1) ? n1 : n0);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// in non-quoted strings, only escape "\\" and "\ ", otherwise drop "\\"
|
|
||||||
if (!stringDelimiter && str[i + 1] != "\\" && str[i + 1] != " ")
|
|
||||||
continue outer;
|
|
||||||
// in single quoted strings, only escape "\\" and "\'", otherwise keep "\\"
|
|
||||||
if (stringDelimiter == "'" && str[i + 1] != "\\" && str[i + 1] != "'")
|
|
||||||
break;
|
|
||||||
escapeNext = true;
|
|
||||||
continue outer;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case "rc-ish":
|
||||||
if (stringDelimiter == "'")
|
if (res = str.match = str.match(/^()((?:[^\\\s"']|\\.)+)((?:\\$)?)/))
|
||||||
{
|
arg += res[2].replace(/\\(.)/g, "$1");
|
||||||
escapeNext = false;
|
else if (res = str.match(/^(")((?:[^\\"]|\\.)*)("?)/))
|
||||||
break;
|
arg += eval(res[0] + (res[3] ? "" : '"'));
|
||||||
}
|
else if (res = str.match(/^(')((?:[^']|'')*)('?)/))
|
||||||
if (escapeNext)
|
arg += res[2].replace("''", "'", "g");
|
||||||
{
|
break;
|
||||||
escapeNext = false;
|
|
||||||
switch (str[i])
|
case "pythonesque":
|
||||||
{
|
if (res = str.match = str.match(/^()((?:[^\\\s"']|\\.)+)((?:\\$)?)/))
|
||||||
case "n": arg += "\n"; break;
|
arg += res[2].replace(/\\(.)/g, "$1");
|
||||||
case "t": arg += "\t"; break;
|
else if (res = str.match(/^(""")((?:.?.?[^"])*)((?:""")?)/))
|
||||||
default:
|
arg += res[2];
|
||||||
break inner; // this makes "a\fb" -> afb; wanted or should we return ab? --mst
|
else if (res = str.match(/^(")((?:[^\\"]|\\.)*)("?)/))
|
||||||
}
|
arg += eval(res[0] + (res[3] ? "" : '"'));
|
||||||
continue outer;
|
else if (res = str.match(/^(')((?:[^\\']|\\.)*)('?)/))
|
||||||
}
|
arg += res[2].replace(/\\(.)/g, function (n0, n1) /[\\']/.test(n1) ? n1 : n0);
|
||||||
else if (stringDelimiter != '"' && /\s/.test(str[i]))
|
|
||||||
{
|
|
||||||
return [i, arg];
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
arg += str[i];
|
|
||||||
|
if (!res)
|
||||||
|
break;
|
||||||
|
if (!res[3])
|
||||||
|
quote = res[1];
|
||||||
|
if (!res[1])
|
||||||
|
quote = res[3];
|
||||||
|
str = str.substr(res[0].length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add parsing of a " comment here:
|
return [len - str.length, arg, quote];
|
||||||
if (stringDelimiter)
|
|
||||||
return [str.length, arg, stringDelimiter];
|
|
||||||
if (escapeNext)
|
|
||||||
return [str.length, arg, "\\"];
|
|
||||||
else
|
|
||||||
return [str.length, arg];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// in '-quoted strings, only ' and \ itself are escaped
|
// in '-quoted strings, only ' and \ itself are escaped
|
||||||
@@ -506,6 +479,8 @@ function Commands() //{{{
|
|||||||
if (sep == "=" || /\s/.test(sep) && opt[1] != this.OPTION_NOARG)
|
if (sep == "=" || /\s/.test(sep) && opt[1] != this.OPTION_NOARG)
|
||||||
{
|
{
|
||||||
[count, arg, quote] = getNextArg(sub.substr(optname.length + 1));
|
[count, arg, quote] = getNextArg(sub.substr(optname.length + 1));
|
||||||
|
if (quote == "\\" && !complete)
|
||||||
|
return liberator.echoerr("Trailing \\");
|
||||||
|
|
||||||
// if we add the argument to an option after a space, it MUST not be empty
|
// if we add the argument to an option after a space, it MUST not be empty
|
||||||
if (sep != "=" && !quote && arg.length == 0)
|
if (sep != "=" && !quote && arg.length == 0)
|
||||||
@@ -595,6 +570,9 @@ function Commands() //{{{
|
|||||||
|
|
||||||
// if not an option, treat this token as an argument
|
// if not an option, treat this token as an argument
|
||||||
var [count, arg, quote] = getNextArg(sub);
|
var [count, arg, quote] = getNextArg(sub);
|
||||||
|
if (quote == "\\" && !complete)
|
||||||
|
return liberator.echoerr("Trailing \\");
|
||||||
|
|
||||||
if (complete)
|
if (complete)
|
||||||
{
|
{
|
||||||
args.quote = complQuote[quote] || complQuote[""];
|
args.quote = complQuote[quote] || complQuote[""];
|
||||||
|
|||||||
Reference in New Issue
Block a user