This commit is contained in:
Peli de Halleux 2016-01-11 13:54:52 -08:00
Родитель 38eb3be6f3 fece0f0f6b
Коммит a1e6aebe1b
2 изменённых файлов: 33 добавлений и 3 удалений

Просмотреть файл

@ -21,7 +21,12 @@ module TDev.AST.MdDocs {
{
return "\n```" + this.finalize(true) + "\n```\n\n";
}
public comment(s:string)
{
this.op("//").space().write(formatText(s).trim()).nl();
return this
}
}
function formatText(s:string)
@ -31,7 +36,8 @@ module TDev.AST.MdDocs {
{
warnS += "WARN: " + m + "\n"
}
s = s.replace(/\s+/g, " ").trim()
s = s.replace(/^\{([\w\*]+)(:([^{}]*))?\}/g, (full, macro, dummy, arg) => {
if (macro == "sig") {
var m = arg.split(/->/);
@ -48,10 +54,19 @@ module TDev.AST.MdDocs {
warn("cannot find lib action: " + arg)
return full;
}
} else if (macro == "fullsig" || macro == "decl") {
} else if (macro == "decl") {
var d = TDev.Script.things.filter(t => t.getName() == arg)[0]
if (!d) {
warn("no such decl: " + arg)
return full;
}
else
return mkSnippet([d])
} else if (macro == "fullsig") {
warn("unsupported macro: " + macro)
return full;
} else {
warnS += "MACRO: " + macro
return full;
}
})

Просмотреть файл

@ -1734,6 +1734,19 @@ function ts(files:string[])
console.log("out.ts and apis.json written")
}
function mddocs(files:string[])
{
files.forEach(f => {
var t = fs.readFileSync(f, "utf8")
TDev.AST.reset();
TDev.AST.loadScriptAsync((s) => TDev.Promise.as(s == "" ? t : null));
var md = TDev.AST.MdDocs.toMD(TDev.Script)
var mdF = f.replace(/\.td$/, "").replace(/$/, ".md")
fs.writeFileSync(mdF, md)
console.log("written", mdF)
})
}
function featureize(dirs:string[])
{
libroots = JSON.parse(fs.readFileSync("libroots.json", "utf-8"))
@ -2069,6 +2082,8 @@ export function globalInit()
compilerTest();
} else if (process.argv[2] == "ts") {
ts(process.argv.slice(3))
} else if (process.argv[2] == "mddocs") {
mddocs(process.argv.slice(3))
} else {
console.log("invalid usage")
}