Add jake task for generating Markdown language spec

This commit is contained in:
Anders Hejlsberg 2014-09-26 14:36:18 -07:00
parent 72ac68cb26
commit deedaf9c1b
5 changed files with 40 additions and 14 deletions

View File

@ -2,6 +2,7 @@
var fs = require("fs");
var path = require("path");
var child_process = require("child_process");
// Variables
var compilerDirectory = "src/compiler/";
@ -9,6 +10,7 @@ var servicesDirectory = "src/services/";
var harnessDirectory = "src/harness/";
var libraryDirectory = "src/lib/";
var scriptsDirectory = "scripts/";
var docDirectory = "doc/";
var builtDirectory = "built/";
var builtLocalDirectory = "built/local/";
@ -260,6 +262,38 @@ task("clean", function() {
jake.rmRf(builtDirectory);
});
// Generate Markdown spec
var word2mdJs = path.join(scriptsDirectory, "word2md.js");
var word2mdTs = path.join(scriptsDirectory, "word2md.ts");
var specWord = path.join(docDirectory, "TypeScript Language Specification.docx");
var specMd = path.join(docDirectory, "spec.md");
var headerMd = path.join(docDirectory, "header.md");
file(word2mdTs);
// word2md script
compileFile(word2mdJs,
[word2mdTs],
[word2mdTs],
[],
false);
// The generated spec.md; built for the 'generate-spec' task
file(specMd, [word2mdJs, specWord], function () {
jake.cpR(headerMd, specMd, {silent: true});
var specWordFullPath = path.resolve(specWord);
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" >>' + specMd;
console.log(cmd);
child_process.exec(cmd, function () {
complete();
});
}, {async: true})
desc("Generates a Markdown version of the Language Specification");
task("generate-spec", [specMd])
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
desc("Makes a new LKG out of the built js files");
task("LKG", libraryTargets, function() {

View File

@ -1354,7 +1354,7 @@ Object type literals are the primary form of type literals and are described in
As the table above illustrates, an array type literal is shorthand for a reference to the generic interface type Array in the global module, a function type literal is shorthand for an object type containing a single call signature, and a constructor type literal is shorthand for an object type containing a single construct signature. Note that function and constructor types with multiple call or construct signatures cannot be written as function or constructor type literals but must instead be written as object type literals.
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an A*rrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the Array<T> notation. For example, the type
In order to avoid grammar ambiguities, array type literals permit only a restricted set of notations for the element type. Specifically, an *ArrayType* cannot start with a *FunctionType* or *ConstructorType*. To use one of those forms for the element type, an array type must be written using the Array<T> notation. For example, the type
```TypeScript
() => string[]

View File

@ -1,11 +1,3 @@
// word2md - Word to Markdown conversion tool
//
// word2md converts a Microsoft Word document to Markdown formatted text. The tool uses the
// Word Automation APIs to start an instance of Word and access the contents of the document
// being converted. The tool must be run using the cscript.exe script host and requires Word
// to be installed on the target machine. The name of the document to convert must be specified
// as a command line argument and the resulting Markdown is written to standard output. The
// tool recognizes the specific Word styles used in the TypeScript Language Specification.
var sys = (function () {
var args = [];
for (var i = 0; i < WScript.Arguments.length; i++) {
@ -163,9 +155,9 @@ function convertDocumentToMarkdown(doc) {
writeBlockEnd();
}
findReplace("", { font: { subscript: true } }, "<sub>^&</sub>", { font: { subscript: false } });
findReplace("", { style: "Code Fragment" }, "`^&`", { style: -66 /* default font */ });
findReplace("", { style: "Production" }, "*^&*", { style: -66 /* default font */ });
findReplace("", { style: "Terminal" }, "`^&`", { style: -66 /* default font */ });
findReplace("", { style: "Code Fragment" }, "`^&`", { style: -66 });
findReplace("", { style: "Production" }, "*^&*", { style: -66 });
findReplace("", { style: "Terminal" }, "`^&`", { style: -66 });
findReplace("", { font: { bold: true, italic: true } }, "***^&***", { font: { bold: false, italic: false } });
findReplace("", { font: { italic: true } }, "*^&*", { font: { italic: false } });
doc.fields.toggleShowCodes();

View File

@ -97,7 +97,7 @@ module Word {
}
export interface Fields extends Collection<Field> {
toggleShowCodes();
toggleShowCodes(): void;
}
export interface Document {
@ -138,7 +138,7 @@ function convertDocumentToMarkdown(doc: Word.Document): string {
var tableCellIndex: number;
var columnAlignment: number[] = [];
function setProperties(target: {}, properties: {}) {
function setProperties(target: any, properties: any) {
for (var name in properties) {
if (properties.hasOwnProperty(name)) {
var value = properties[name];