mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 09:01:39 -05:00
parsers/exmode.ts: replace macro-generated info with ts-generated info
I tested nearly all ex commands and this didn't seem to break anything.
This commit is contained in:
parent
03953315a8
commit
9ef99b0ab4
3 changed files with 26 additions and 40 deletions
|
@ -14,11 +14,7 @@ export class NumberType implements Type {
|
|||
}
|
||||
|
||||
public convert(argument) {
|
||||
let n = parseInt(argument, 10)
|
||||
if (!Number.isNaN(n)) {
|
||||
return n
|
||||
}
|
||||
n = parseFloat(argument)
|
||||
const n = parseFloat(argument)
|
||||
if (!Number.isNaN(n)) {
|
||||
return n
|
||||
}
|
||||
|
|
|
@ -1368,7 +1368,7 @@ export async function tutor(newtab?: string) {
|
|||
* Display Tridactyl's contributors in order of commits in a user-friendly fashion
|
||||
*/
|
||||
//#background
|
||||
export async function credits(excmd?: string) {
|
||||
export async function credits() {
|
||||
const creditspage = browser.runtime.getURL("static/authors.html")
|
||||
tabopen(creditspage)
|
||||
}
|
||||
|
|
|
@ -1,43 +1,23 @@
|
|||
/** Ex Mode (AKA cmd mode) */
|
||||
|
||||
import { FunctionType } from "../../compiler/types/AllTypes"
|
||||
import { everything as metadata } from "@src/.metadata.generated"
|
||||
import * as convert from "@src/lib/convert"
|
||||
import * as aliases from "@src/lib/aliases"
|
||||
import * as Logging from "@src/lib/logging"
|
||||
import { enumerate, izip } from "@src/lib/itertools"
|
||||
|
||||
const logger = new Logging.Logger("exmode")
|
||||
|
||||
/* Converts numbers, boolean, string[].
|
||||
|
||||
string[] eats all remaining arguments, so it should only be used as a
|
||||
type of the last arg.
|
||||
|
||||
TODO: quoted strings
|
||||
TODO: shell style options
|
||||
TODO: counts
|
||||
*/
|
||||
function convertArgs(params, argv) {
|
||||
const conversions = {
|
||||
number: convert.toNumber,
|
||||
boolean: convert.toBoolean,
|
||||
string: s => s,
|
||||
ModeName: s => s,
|
||||
}
|
||||
|
||||
function convertArgs(types, argv) {
|
||||
const typedArgs = []
|
||||
let type
|
||||
let arg
|
||||
let i
|
||||
for ([type, [i, arg]] of izip(params.values(), enumerate(argv))) {
|
||||
if (type in conversions) {
|
||||
typedArgs.push(conversions[type](arg))
|
||||
} else if (type.includes("|") || ["'", '"'].includes(type[0])) {
|
||||
// Do your own conversions!
|
||||
typedArgs.push(arg)
|
||||
} else if (type === "string[]") {
|
||||
// Eat all remaining arguments
|
||||
return [...typedArgs, ...argv.slice(i)]
|
||||
} else throw new TypeError(`Unknown type: ${type}`)
|
||||
for (let itypes = 0, iargv = 0; itypes < types.length && iargv < argv.length; ++itypes && ++iargv) {
|
||||
const curType = types[itypes]
|
||||
const curArg = argv[iargv]
|
||||
// Special casing arrays because that's why the previous arg conversion code did
|
||||
if (curType.isDotDotDot || curType.kind === "array") {
|
||||
return typedArgs.concat(curType.convert(argv.slice(iargv)))
|
||||
}
|
||||
typedArgs.push(curType.convert(curArg))
|
||||
}
|
||||
return typedArgs
|
||||
}
|
||||
|
@ -61,11 +41,21 @@ export function parser(exstr: string, all_excmds: any): any[] {
|
|||
throw new Error(`Unknwown namespace: ${namespce}.`);
|
||||
}
|
||||
|
||||
// Convert arguments
|
||||
// Convert arguments, but only for ex commands
|
||||
let converted_args
|
||||
if (excmds.cmd_params !== undefined && excmds.cmd_params.has(func)) {
|
||||
if (namespce == "") {
|
||||
let types
|
||||
try {
|
||||
converted_args = convertArgs(excmds.cmd_params.get(func), args)
|
||||
types = (metadata
|
||||
.getFile("src/excmds.ts")
|
||||
.getFunction(funcName)
|
||||
.type as FunctionType)
|
||||
.args
|
||||
} catch (e) {
|
||||
throw `Could not find type information for excmd ${funcName}`
|
||||
}
|
||||
try {
|
||||
converted_args = convertArgs(types, args)
|
||||
} catch (e) {
|
||||
logger.error("Error executing or parsing:", exstr, e)
|
||||
throw e
|
||||
|
|
Loading…
Add table
Reference in a new issue