comparison trunk/src/cmd/Generate.d @ 785:57ef69eced96

Added functions isCodeSection() and skipCodeSection(). Added a lot of documentation comments and revised some.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sat, 23 Feb 2008 21:15:56 +0100
parents d887184efb3c
children dcd30b0ba711
comparison
equal deleted inserted replaced
784:939097e0990f 785:57ef69eced96
31 HTML = 1<<2, 31 HTML = 1<<2,
32 XML = 1<<3, 32 XML = 1<<3,
33 PrintLines = 1<<4 33 PrintLines = 1<<4
34 } 34 }
35 35
36 /// Executes the command. 36 /// Executes the generate command.
37 void execute(string filePath, GenOption options, InfoManager infoMan) 37 void execute(string filePath, GenOption options, InfoManager infoMan)
38 { 38 {
39 assert(options != GenOption.Empty); 39 assert(options != GenOption.Empty);
40 auto mapFilePath = options & GenOption.HTML ? GlobalSettings.htmlMapFile 40 auto mapFilePath = options & GenOption.HTML ? GlobalSettings.htmlMapFile
41 : GlobalSettings.xmlMapFile; 41 : GlobalSettings.xmlMapFile;
68 // Nothing escaped. Return original text. 68 // Nothing escaped. Return original text.
69 delete result; 69 delete result;
70 return text; 70 return text;
71 } 71 }
72 72
73 /// Maps tokens to (format) strings.
73 class TagMap 74 class TagMap
74 { 75 {
75 string[string] table; 76 string[string] table;
76 string[TOK.MAX] tokenTable; 77 string[TOK.MAX] tokenTable;
77 78
102 foreach (i, tokStr; tokToString) 103 foreach (i, tokStr; tokToString)
103 if (auto pStr = tokStr in this.table) 104 if (auto pStr = tokStr in this.table)
104 tokenTable[i] = *pStr; 105 tokenTable[i] = *pStr;
105 } 106 }
106 107
108 /// Returns the value for str, or 'fallback' if str is not in the table.
107 string opIndex(string str, string fallback = "") 109 string opIndex(string str, string fallback = "")
108 { 110 {
109 auto p = str in table; 111 auto p = str in table;
110 if (p) 112 if (p)
111 return *p; 113 return *p;
112 return fallback; 114 return fallback;
113 } 115 }
114 116
117 /// Returns the value for tok in O(1) time.
115 string opIndex(TOK tok) 118 string opIndex(TOK tok)
116 { 119 {
117 return tokenTable[tok]; 120 return tokenTable[tok];
118 } 121 }
119 122
123 /// Shortcuts for quick access.
120 string Identifier, String, Char, Number, Keyword, LineC, BlockC, 124 string Identifier, String, Char, Number, Keyword, LineC, BlockC,
121 NestedC, Shebang, HLine, Filespec, Illegal, Newline, SpecialToken, 125 NestedC, Shebang, HLine, Filespec, Illegal, Newline, SpecialToken,
122 Declaration, Statement, Expression, Type, Other, EOF; 126 Declaration, Statement, Expression, Type, Other, EOF;
123 127
124 /// Returns the tag for the category 'nc'. 128 /// Returns the tag for the category 'nc'.
146 if (c == object) 150 if (c == object)
147 return i; 151 return i;
148 return -1; 152 return -1;
149 } 153 }
150 154
151 /// Returns: the short class name of an instance descending from Node. 155 /// Returns the short class name of a class descending from Node.$(BR)
156 /// E.g.: dil.ast.Declarations.ClassDeclaration -> Class
152 char[] getShortClassName(Node node) 157 char[] getShortClassName(Node node)
153 { 158 {
154 static char[][] name_table; 159 static char[][] name_table;
155 if (name_table is null) 160 if (name_table is null)
156 name_table = new char[][NodeKind.max+1]; // Create a new table. 161 name_table = new char[][NodeKind.max+1]; // Create a new table.
269 274
270 // void printMultiline(Token* token, TagMap tags, Print!(char) print) 275 // void printMultiline(Token* token, TagMap tags, Print!(char) print)
271 // { 276 // {
272 // } 277 // }
273 278
279 /// Highlights the syntax in a source file.
274 void highlightSyntax(string filePath, TagMap tags, Print!(char) print, GenOption options) 280 void highlightSyntax(string filePath, TagMap tags, Print!(char) print, GenOption options)
275 { 281 {
276 auto parser = new Parser(new SourceText(filePath, true)); 282 auto parser = new Parser(new SourceText(filePath, true));
277 auto root = parser.start(); 283 auto root = parser.start();
278 auto lx = parser.lexer; 284 auto lx = parser.lexer;
326 } 332 }
327 print(tags["SourceEnd"]); 333 print(tags["SourceEnd"]);
328 print(tags["DocEnd"]); 334 print(tags["DocEnd"]);
329 } 335 }
330 336
331 /// Prints all tokens of a source file using the buffer print. 337 /// Highlights all tokens of a source file.
332 void highlightTokens(string filePath, TagMap tags, Print!(char) print, GenOption options) 338 void highlightTokens(string filePath, TagMap tags, Print!(char) print, GenOption options)
333 { 339 {
334 auto lx = new Lexer(new SourceText(filePath, true)); 340 auto lx = new Lexer(new SourceText(filePath, true));
335 lx.scanAll(); 341 lx.scanAll();
336 342
357 } 363 }
358 print(tags["SourceEnd"]); 364 print(tags["SourceEnd"]);
359 print(tags["DocEnd"]); 365 print(tags["DocEnd"]);
360 } 366 }
361 367
368 /// A token highlighter designed for DDoc.
362 class TokenHighlighter 369 class TokenHighlighter
363 { 370 {
364 TagMap tags; 371 TagMap tags;
365 this(InfoManager infoMan, bool useHTML = true) 372 this(InfoManager infoMan, bool useHTML = true)
366 { 373 {
394 print("\n)"); 401 print("\n)");
395 return cast(char[])buffer.slice(); 402 return cast(char[])buffer.slice();
396 } 403 }
397 } 404 }
398 405
399 /// Prints a token with tags using the buffer print. 406 /// Prints a token to the stream print.
400 void printToken(Token* token, TagMap tags, Print!(char) print) 407 void printToken(Token* token, TagMap tags, Print!(char) print)
401 { 408 {
402 switch(token.kind) 409 switch(token.kind)
403 { 410 {
404 case TOK.Identifier: 411 case TOK.Identifier: