Mercurial > projects > dil
annotate trunk/src/cmd/Generate.d @ 781:d887184efb3c
Improved class TagMap.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Thu, 21 Feb 2008 00:19:15 +0100 |
parents | 8e6fed11bb68 |
children | 57ef69eced96 |
rev | line source |
---|---|
363 | 1 /++ |
2 Author: Aziz Köksal | |
3 License: GPL3 | |
4 +/ | |
5 module cmd.Generate; | |
578
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
6 |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
7 import dil.ast.DefaultVisitor; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
8 import dil.ast.Node, |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
9 dil.ast.Declaration, |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
10 dil.ast.Statement, |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
11 dil.ast.Expression, |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
12 dil.ast.Types; |
596
39fac5531b85
Moved dil.Token to dil.lexer.Token.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
582
diff
changeset
|
13 import dil.lexer.Lexer; |
578
c769bc239006
Moved Parser.d to new package 'parser'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
576
diff
changeset
|
14 import dil.parser.Parser; |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
15 import dil.semantic.Module; |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
752
diff
changeset
|
16 import dil.SourceText; |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
17 import dil.Information; |
779
8e6fed11bb68
Moved Settings.d and SettingsLoader.d to src/.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
771
diff
changeset
|
18 import SettingsLoader; |
8e6fed11bb68
Moved Settings.d and SettingsLoader.d to src/.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
771
diff
changeset
|
19 import Settings; |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
752
diff
changeset
|
20 import common; |
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
752
diff
changeset
|
21 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
22 import tango.io.GrowBuffer; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
23 import tango.io.Print; |
363 | 24 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
25 /// Options for the generate command. |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
26 enum GenOption |
363 | 27 { |
392
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
28 Empty, |
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
29 Tokens = 1, |
363 | 30 Syntax = 1<<1, |
392
bb935c6f9b7a
Applied fixes and improvements to the Lexer class.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
391
diff
changeset
|
31 HTML = 1<<2, |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
32 XML = 1<<3, |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
33 PrintLines = 1<<4 |
363 | 34 } |
35 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
36 /// Executes the command. |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
37 void execute(string filePath, GenOption options, InfoManager infoMan) |
364 | 38 { |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
39 assert(options != GenOption.Empty); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
40 auto mapFilePath = options & GenOption.HTML ? GlobalSettings.htmlMapFile |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
41 : GlobalSettings.xmlMapFile; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
42 auto map = TagMapLoader(infoMan).load(mapFilePath); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
43 auto tags = new TagMap(map); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
44 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
45 if (infoMan.hasInfo) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
46 return; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
47 |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
48 if (options & GenOption.Syntax) |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
49 highlightSyntax(filePath, tags, Stdout, options); |
364 | 50 else |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
51 highlightTokens(filePath, tags, Stdout, options); |
364 | 52 } |
53 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
54 /// Escapes the characters '<', '>' and '&' with named character entities. |
363 | 55 char[] xml_escape(char[] text) |
56 { | |
57 char[] result; | |
58 foreach(c; text) | |
59 switch(c) | |
60 { | |
61 case '<': result ~= "<"; break; | |
62 case '>': result ~= ">"; break; | |
63 case '&': result ~= "&"; break; | |
64 default: result ~= c; | |
65 } | |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
66 if (result.length != text.length) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
67 return result; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
68 // Nothing escaped. Return original text. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
69 delete result; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
70 return text; |
363 | 71 } |
72 | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
73 class TagMap |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
74 { |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
75 string[string] table; |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
76 string[TOK.MAX] tokenTable; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
77 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
78 this(string[string] table) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
79 { |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
80 this.table = table; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
81 Identifier = this["Identifier", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
82 String = this["String", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
83 Char = this["Char", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
84 Number = this["Number", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
85 Keyword = this["Keyword", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
86 LineC = this["LineC", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
87 BlockC = this["BlockC", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
88 NestedC = this["NestedC", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
89 Shebang = this["Shebang", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
90 HLine = this["HLine", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
91 Filespec = this["Filespec", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
92 Illegal = this["Illegal", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
93 Newline = this["Newline", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
94 SpecialToken = this["SpecialToken", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
95 Declaration = this["Declaration", "d"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
96 Statement = this["Statement", "s"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
97 Expression = this["Expression", "e"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
98 Type = this["Type", "t"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
99 Other = this["Other", "o"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
100 EOF = this["EOF", ""]; |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
101 |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
102 foreach (i, tokStr; tokToString) |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
103 if (auto pStr = tokStr in this.table) |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
104 tokenTable[i] = *pStr; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
105 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
106 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
107 string opIndex(string str, string fallback = "") |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
108 { |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
109 auto p = str in table; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
110 if (p) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
111 return *p; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
112 return fallback; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
113 } |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
114 |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
115 string opIndex(TOK tok) |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
116 { |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
117 return tokenTable[tok]; |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
118 } |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
119 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
120 string Identifier, String, Char, Number, Keyword, LineC, BlockC, |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
121 NestedC, Shebang, HLine, Filespec, Illegal, Newline, SpecialToken, |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
122 Declaration, Statement, Expression, Type, Other, EOF; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
123 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
124 /// Returns the tag for the category 'nc'. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
125 string getTag(NodeCategory nc) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
126 { |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
127 string tag; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
128 switch (nc) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
129 { alias NodeCategory NC; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
130 case NC.Declaration: tag = Declaration; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
131 case NC.Statement: tag = Statement; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
132 case NC.Expression: tag = Expression; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
133 case NC.Type: tag = Type; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
134 case NC.Other: tag = Other; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
135 default: assert(0); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
136 } |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
137 return tag; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
138 } |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
139 } |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
140 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
141 /// Find the last occurrence of object in subject. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
142 /// Returns: the index if found, or -1 if not. |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
143 int rfind(char[] subject, char object) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
144 { |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
145 foreach_reverse(i, c; subject) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
146 if (c == object) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
147 return i; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
148 return -1; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
149 } |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
150 |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
151 /// Returns: the short class name of an instance descending from Node. |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
152 char[] getShortClassName(Node node) |
363 | 153 { |
154 static char[][] name_table; | |
155 if (name_table is null) | |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
156 name_table = new char[][NodeKind.max+1]; // Create a new table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
157 // Look up in table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
158 char[] name = name_table[node.kind]; |
363 | 159 if (name !is null) |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
160 return name; // Return cached name. |
363 | 161 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
162 name = node.classinfo.name; // Get the fully qualified name of the class. |
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
163 name = name[rfind(name, '.')+1 .. $]; // Remove package and module name. |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
164 |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
165 uint suffixLength; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
166 switch (node.category) |
363 | 167 { |
168 alias NodeCategory NC; | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
169 case NC.Declaration: |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
170 suffixLength = "Declaration".length; |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
171 break; |
363 | 172 case NC.Statement: |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
173 suffixLength = "Statement".length; |
363 | 174 break; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
175 case NC.Expression: |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
682
diff
changeset
|
176 suffixLength = "Expression".length; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
177 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
178 case NC.Type: |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
179 suffixLength = "Type".length; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
180 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
181 case NC.Other: |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
619
diff
changeset
|
182 break; |
363 | 183 default: |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
619
diff
changeset
|
184 assert(0); |
363 | 185 } |
186 // Remove common suffix. | |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
187 name = name[0 .. $ - suffixLength]; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
188 // Store the name in the table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
189 name_table[node.kind] = name; |
363 | 190 return name; |
191 } | |
192 | |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
193 /// Extended token structure. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
194 struct TokenEx |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
195 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
196 Token* token; /// The lexer token. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
197 Node[] beginNodes; /// beginNodes[n].begin == token |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
198 Node[] endNodes; /// endNodes[n].end == token |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
199 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
200 |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
201 /// Builds an array of TokenEx items. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
202 class TokenExBuilder : DefaultVisitor |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
203 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
204 private TokenEx*[Token*] tokenTable; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
205 |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
206 TokenEx[] build(Node root, Token* first) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
207 { |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
208 auto token = first; |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
209 |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
210 uint count; // Count tokens. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
211 for (; token; token = token.next) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
212 count++; |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
213 // Creat the exact number of TokenEx instances. |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
214 auto toks = new TokenEx[count]; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
215 token = first; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
216 foreach (ref tokEx; toks) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
217 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
218 tokEx.token = token; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
219 if (!token.isWhitespace) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
220 tokenTable[token] = &tokEx; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
221 token = token.next; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
222 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
223 |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
224 super.visitN(root); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
225 tokenTable = null; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
226 return toks; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
227 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
228 |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
229 TokenEx* getTokenEx()(Token* t) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
230 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
231 auto p = t in tokenTable; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
232 assert(p, t.srcText~" is not in tokenTable"); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
233 return *p; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
234 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
235 |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
236 // Override dispatch function. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
237 override Node dispatch(Node n) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
238 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
239 auto begin = n.begin; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
240 if (begin) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
241 { assert(n.end); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
242 auto txbegin = getTokenEx(begin); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
243 auto txend = getTokenEx(n.end); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
244 txbegin.beginNodes ~= n; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
245 txend.endNodes ~= n; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
246 } |
757
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
247 return super.dispatch(n); |
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
248 } |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
249 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
250 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
251 void printErrors(Lexer lx, TagMap tags, Print!(char) print) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
252 { |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
253 foreach (e; lx.errors) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
254 print.format(tags["LexerError"], e.filePath, e.loc, e.col, xml_escape(e.getMsg)); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
255 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
256 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
257 void printErrors(Parser parser, TagMap tags, Print!(char) print) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
258 { |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
259 foreach (e; parser.errors) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
260 print.format(tags["ParserError"], e.filePath, e.loc, e.col, xml_escape(e.getMsg)); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
261 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
262 |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
263 void printLines(uint lines, TagMap tags, Print!(char) print) |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
264 { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
265 auto lineNumberFormat = tags["LineNumber"]; |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
266 for (auto lineNum = 1; lineNum <= lines; lineNum++) |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
267 print.format(lineNumberFormat, lineNum); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
268 } |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
269 |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
270 // void printMultiline(Token* token, TagMap tags, Print!(char) print) |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
271 // { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
272 // } |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
273 |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
274 void highlightSyntax(string filePath, TagMap tags, Print!(char) print, GenOption options) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
275 { |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
752
diff
changeset
|
276 auto parser = new Parser(new SourceText(filePath, true)); |
368 | 277 auto root = parser.start(); |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
598
diff
changeset
|
278 auto lx = parser.lexer; |
363 | 279 |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
280 auto builder = new TokenExBuilder(); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
281 auto tokenExList = builder.build(root, lx.firstToken()); |
363 | 282 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
283 print(tags["DocHead"]); |
363 | 284 if (lx.errors.length || parser.errors.length) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
285 { // Output error messages. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
286 print(tags["CompBegin"]); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
287 printErrors(lx, tags, print); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
288 printErrors(parser, tags, print); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
289 print(tags["CompEnd"]); |
363 | 290 } |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
291 |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
292 if (options & GenOption.PrintLines) |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
293 { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
294 print(tags["LineNumberBegin"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
295 printLines(lx.lineNum, tags, print); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
296 print(tags["LineNumberEnd"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
297 } |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
298 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
299 print(tags["SourceBegin"]); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
300 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
301 auto tagNodeBegin = tags["NodeBegin"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
302 auto tagNodeEnd = tags["NodeEnd"]; |
363 | 303 |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
304 // Iterate over list of tokens. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
305 foreach (ref tokenEx; tokenExList) |
363 | 306 { |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
307 auto token = tokenEx.token; |
363 | 308 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
309 token.ws && print(token.wsChars); // Print preceding whitespace. |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
310 if (token.isWhitespace) { |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
311 printToken(token, tags, print); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
312 continue; |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
313 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
314 // <node> |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
315 foreach (node; tokenEx.beginNodes) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
316 print.format(tagNodeBegin, tags.getTag(node.category), getShortClassName(node)); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
317 // Token text. |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
318 printToken(token, tags, print); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
319 // </node> |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
320 if (options & GenOption.HTML) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
321 foreach_reverse (node; tokenEx.endNodes) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
322 print(tagNodeEnd); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
323 else |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
324 foreach_reverse (node; tokenEx.endNodes) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
325 print.format(tagNodeEnd, tags.getTag(node.category)); |
363 | 326 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
327 print(tags["SourceEnd"]); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
328 print(tags["DocEnd"]); |
363 | 329 } |
330 | |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
331 /// Prints all tokens of a source file using the buffer print. |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
332 void highlightTokens(string filePath, TagMap tags, Print!(char) print, GenOption options) |
363 | 333 { |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
752
diff
changeset
|
334 auto lx = new Lexer(new SourceText(filePath, true)); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
335 lx.scanAll(); |
363 | 336 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
337 print(tags["DocHead"]); |
363 | 338 if (lx.errors.length) |
339 { | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
340 print(tags["CompBegin"]); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
341 printErrors(lx, tags, print); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
342 print(tags["CompEnd"]); |
363 | 343 } |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
344 |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
345 if (options & GenOption.PrintLines) |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
346 { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
347 print(tags["LineNumberBegin"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
348 printLines(lx.lineNum, tags, print); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
349 print(tags["LineNumberEnd"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
350 } |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
351 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
352 print(tags["SourceBegin"]); |
363 | 353 // Traverse linked list and print tokens. |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
354 for (auto token = lx.firstToken(); token; token = token.next) { |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
355 token.ws && print(token.wsChars); // Print preceding whitespace. |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
356 printToken(token, tags, print); |
363 | 357 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
358 print(tags["SourceEnd"]); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
359 print(tags["DocEnd"]); |
363 | 360 } |
361 | |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
362 class TokenHighlighter |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
363 { |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
364 TagMap tags; |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
365 this(InfoManager infoMan, bool useHTML = true) |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
366 { |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
367 auto map = TagMapLoader(infoMan).load(GlobalSettings.htmlMapFile); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
368 tags = new TagMap(map); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
369 } |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
370 |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
371 /// Highlights tokens in a DDoc code section. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
372 /// Returns: a string with the highlighted tokens (in HTML tags.) |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
373 string highlight(string text, string filePath) |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
374 { |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
375 auto buffer = new GrowBuffer(text.length); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
376 auto print = new Print!(char)(Format, buffer); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
377 |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
378 auto lx = new Lexer(new SourceText(filePath, text)); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
379 lx.scanAll(); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
380 |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
381 // Traverse linked list and print tokens. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
382 print("$(D_CODE\n"); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
383 if (lx.errors.length) |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
384 { // Output error messages. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
385 print(tags["CompBegin"]); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
386 printErrors(lx, tags, print); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
387 print(tags["CompEnd"]); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
388 } |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
389 // Traverse linked list and print tokens. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
390 for (auto token = lx.firstToken(); token; token = token.next) { |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
391 token.ws && print(token.wsChars); // Print preceding whitespace. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
392 printToken(token, tags, print); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
393 } |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
394 print("\n)"); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
395 return cast(char[])buffer.slice(); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
396 } |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
397 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
398 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
399 /// Prints a token with tags using the buffer print. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
400 void printToken(Token* token, TagMap tags, Print!(char) print) |
363 | 401 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
668
diff
changeset
|
402 switch(token.kind) |
363 | 403 { |
404 case TOK.Identifier: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
405 print.format(tags.Identifier, token.srcText); |
363 | 406 break; |
407 case TOK.Comment: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
408 string formatStr; |
363 | 409 switch (token.start[1]) |
410 { | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
411 case '/': formatStr = tags.LineC; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
412 case '*': formatStr = tags.BlockC; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
413 case '+': formatStr = tags.NestedC; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
414 default: assert(0); |
363 | 415 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
416 print.format(formatStr, xml_escape(token.srcText)); |
363 | 417 break; |
418 case TOK.String: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
419 print.format(tags.String, xml_escape(token.srcText)); |
363 | 420 break; |
507
996041463028
Removed TOK.WCharLiteral and TOK.DCharLiteral.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
421 case TOK.CharLiteral: |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
422 print.format(tags.Char, xml_escape(token.srcText)); |
363 | 423 break; |
424 case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64, | |
425 TOK.Float32, TOK.Float64, TOK.Float80, | |
426 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
427 print.format(tags.Number, token.srcText); |
363 | 428 break; |
429 case TOK.Shebang: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
430 print.format(tags.Shebang, xml_escape(token.srcText)); |
363 | 431 break; |
432 case TOK.HashLine: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
433 auto formatStr = tags.HLine; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
434 // The text to be inserted into formatStr. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
435 auto buffer = new GrowBuffer; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
436 auto print2 = new Print!(char)(Format, buffer); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
437 |
363 | 438 void printWS(char* start, char* end) |
439 { | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
440 start != end && print2(start[0 .. end - start]); |
363 | 441 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
442 |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
443 auto num = token.tokLineNum; |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
444 if (num is null) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
445 { // Malformed #line |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
446 print.format(formatStr, token.srcText); |
388
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
447 break; |
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
448 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
449 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
450 // Print whitespace between #line and number. |
763
f26f13b5a3a3
Fixed code in scanSpecialTokenSequence().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
761
diff
changeset
|
451 printWS(token.start, num.start); // Prints "#line" as well. |
f26f13b5a3a3
Fixed code in scanSpecialTokenSequence().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
761
diff
changeset
|
452 printToken(num, tags, print2); // Print the number. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
453 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
454 if (auto filespec = token.tokLineFilespec) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
455 { // Print whitespace between number and filespec. |
363 | 456 printWS(num.end, filespec.start); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
457 print2.format(tags.Filespec, xml_escape(filespec.srcText)); |
363 | 458 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
459 // Finally print the whole token. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
460 print.format(formatStr, cast(char[])buffer.slice()); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
461 break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
462 case TOK.Illegal: |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
463 print.format(tags.Illegal, token.srcText()); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
464 break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
465 case TOK.Newline: |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
466 print.format(tags.Newline, token.srcText()); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
467 break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
468 case TOK.EOF: |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
469 print(tags.EOF); |
363 | 470 break; |
471 default: | |
472 if (token.isKeyword()) | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
473 print.format(tags.Keyword, token.srcText); |
363 | 474 else if (token.isSpecialToken) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
475 print.format(tags.SpecialToken, token.srcText); |
363 | 476 else |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
477 print(tags[token.kind]); |
363 | 478 } |
479 } |