Mercurial > projects > dil
annotate src/cmd/Generate.d @ 806:bcb74c9b895c
Moved out files in the trunk folder to the root.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sun, 09 Mar 2008 00:12:19 +0100 |
parents | trunk/src/cmd/Generate.d@dcd30b0ba711 |
children |
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 | |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
36 /// Executes the generate 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 | |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
73 /// Maps tokens to (format) strings. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
74 class TagMap |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
75 { |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
76 string[string] table; |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
77 string[TOK.MAX] tokenTable; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
78 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
79 this(string[string] table) |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
80 { |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
81 this.table = table; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
82 Identifier = this["Identifier", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
83 String = this["String", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
84 Char = this["Char", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
85 Number = this["Number", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
86 Keyword = this["Keyword", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
87 LineC = this["LineC", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
88 BlockC = this["BlockC", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
89 NestedC = this["NestedC", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
90 Shebang = this["Shebang", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
91 HLine = this["HLine", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
92 Filespec = this["Filespec", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
93 Illegal = this["Illegal", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
94 Newline = this["Newline", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
95 SpecialToken = this["SpecialToken", "{0}"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
96 Declaration = this["Declaration", "d"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
97 Statement = this["Statement", "s"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
98 Expression = this["Expression", "e"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
99 Type = this["Type", "t"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
100 Other = this["Other", "o"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
101 EOF = this["EOF", ""]; |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
102 |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
103 foreach (i, tokStr; tokToString) |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
104 if (auto pStr = tokStr in this.table) |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
105 tokenTable[i] = *pStr; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
106 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
107 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
108 /// Returns the value for str, or 'fallback' if str is not in the table. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
109 string opIndex(string str, string fallback = "") |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
110 { |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
111 auto p = str in table; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
112 if (p) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
113 return *p; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
114 return fallback; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
115 } |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
116 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
117 /// Returns the value for tok in O(1) time. |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
118 string opIndex(TOK tok) |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
119 { |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
120 return tokenTable[tok]; |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
121 } |
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
122 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
123 /// Shortcuts for quick access. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
124 string Identifier, String, Char, Number, Keyword, LineC, BlockC, |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
125 NestedC, Shebang, HLine, Filespec, Illegal, Newline, SpecialToken, |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
126 Declaration, Statement, Expression, Type, Other, EOF; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
127 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
128 /// Returns the tag for the category 'nc'. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
129 string getTag(NodeCategory nc) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
130 { |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
131 string tag; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
132 switch (nc) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
133 { alias NodeCategory NC; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
134 case NC.Declaration: tag = Declaration; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
135 case NC.Statement: tag = Statement; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
136 case NC.Expression: tag = Expression; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
137 case NC.Type: tag = Type; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
138 case NC.Other: tag = Other; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
139 default: assert(0); |
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 return tag; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
142 } |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
143 } |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
144 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
145 /// Find the last occurrence of object in subject. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
146 /// 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
|
147 int rfind(char[] subject, char object) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
148 { |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
149 foreach_reverse(i, c; subject) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
150 if (c == object) |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
151 return i; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
152 return -1; |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
153 } |
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
154 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
155 /// Returns the short class name of a class descending from Node.$(BR) |
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
156 /// E.g.: dil.ast.Declarations.ClassDeclaration -> Class |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
157 char[] getShortClassName(Node node) |
363 | 158 { |
159 static char[][] name_table; | |
160 if (name_table is null) | |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
161 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
|
162 // Look up in table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
163 char[] name = name_table[node.kind]; |
363 | 164 if (name !is null) |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
165 return name; // Return cached name. |
363 | 166 |
582
724603deed37
Added comments and renamed a few variables.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
581
diff
changeset
|
167 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
|
168 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
|
169 |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
170 uint suffixLength; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
171 switch (node.category) |
363 | 172 { |
173 alias NodeCategory NC; | |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
174 case NC.Declaration: |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
175 suffixLength = "Declaration".length; |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
176 break; |
363 | 177 case NC.Statement: |
682
7541c64fc423
Renamed FunctionBody, CatchBody and FinallyBody.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
681
diff
changeset
|
178 suffixLength = "Statement".length; |
363 | 179 break; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
180 case NC.Expression: |
695
170ddcdc9711
Renamed VoidInitializer, ArrayInitializer and StructInitializer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
682
diff
changeset
|
181 suffixLength = "Expression".length; |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
182 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
183 case NC.Type: |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
184 suffixLength = "Type".length; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
185 break; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
186 case NC.Other: |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
619
diff
changeset
|
187 break; |
363 | 188 default: |
640
05645f5613c1
Added an error message.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
619
diff
changeset
|
189 assert(0); |
363 | 190 } |
191 // Remove common suffix. | |
581
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
192 name = name[0 .. $ - suffixLength]; |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
193 // Store the name in the table. |
61f9784aaf2a
Improved function getShortClassName().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
580
diff
changeset
|
194 name_table[node.kind] = name; |
363 | 195 return name; |
196 } | |
197 | |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
198 /// Extended token structure. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
199 struct TokenEx |
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 Token* token; /// The lexer token. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
202 Node[] beginNodes; /// beginNodes[n].begin == token |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
203 Node[] endNodes; /// endNodes[n].end == token |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
204 } |
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 /// Builds an array of TokenEx items. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
207 class TokenExBuilder : DefaultVisitor |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
208 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
209 private TokenEx*[Token*] tokenTable; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
210 |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
211 TokenEx[] build(Node root, Token* first) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
212 { |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
213 auto token = first; |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
214 |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
215 uint count; // Count tokens. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
216 for (; token; token = token.next) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
217 count++; |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
218 // Creat the exact number of TokenEx instances. |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
219 auto toks = new TokenEx[count]; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
220 token = first; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
221 foreach (ref tokEx; toks) |
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 tokEx.token = token; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
224 if (!token.isWhitespace) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
225 tokenTable[token] = &tokEx; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
226 token = token.next; |
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 super.visitN(root); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
230 tokenTable = null; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
231 return toks; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
232 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
233 |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
234 TokenEx* getTokenEx()(Token* t) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
235 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
236 auto p = t in tokenTable; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
237 assert(p, t.srcText~" is not in tokenTable"); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
238 return *p; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
239 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
240 |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
241 // Override dispatch function. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
242 override Node dispatch(Node n) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
243 { |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
244 auto begin = n.begin; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
245 if (begin) |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
246 { assert(n.end); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
247 auto txbegin = getTokenEx(begin); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
248 auto txend = getTokenEx(n.end); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
249 txbegin.beginNodes ~= n; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
250 txend.endNodes ~= n; |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
251 } |
757
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
252 return super.dispatch(n); |
e4b60543c5e8
Revised methods in class Visitor.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
755
diff
changeset
|
253 } |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
254 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
255 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
256 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
|
257 { |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
258 foreach (e; lx.errors) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
259 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
|
260 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
261 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
262 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
|
263 { |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
264 foreach (e; parser.errors) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
265 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
|
266 } |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
267 |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
268 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
|
269 { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
270 auto lineNumberFormat = tags["LineNumber"]; |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
271 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
|
272 print.format(lineNumberFormat, lineNum); |
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 |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
275 // 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
|
276 // { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
277 // } |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
278 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
279 /// Highlights the syntax in a source file. |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
280 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
|
281 { |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
752
diff
changeset
|
282 auto parser = new Parser(new SourceText(filePath, true)); |
368 | 283 auto root = parser.start(); |
619
933cd8d24467
Renamed Parser.lx to Parser.lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
598
diff
changeset
|
284 auto lx = parser.lexer; |
363 | 285 |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
286 auto builder = new TokenExBuilder(); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
287 auto tokenExList = builder.build(root, lx.firstToken()); |
363 | 288 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
289 print(tags["DocHead"]); |
363 | 290 if (lx.errors.length || parser.errors.length) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
291 { // Output error messages. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
292 print(tags["CompBegin"]); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
293 printErrors(lx, tags, print); |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
294 printErrors(parser, tags, print); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
295 print(tags["CompEnd"]); |
363 | 296 } |
771
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 if (options & GenOption.PrintLines) |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
299 { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
300 print(tags["LineNumberBegin"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
301 printLines(lx.lineNum, tags, print); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
302 print(tags["LineNumberEnd"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
303 } |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
304 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
305 print(tags["SourceBegin"]); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
306 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
307 auto tagNodeBegin = tags["NodeBegin"]; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
308 auto tagNodeEnd = tags["NodeEnd"]; |
363 | 309 |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
310 // Iterate over list of tokens. |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
311 foreach (ref tokenEx; tokenExList) |
363 | 312 { |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
313 auto token = tokenEx.token; |
363 | 314 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
315 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
|
316 if (token.isWhitespace) { |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
317 printToken(token, tags, print); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
318 continue; |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
319 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
320 // <node> |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
321 foreach (node; tokenEx.beginNodes) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
322 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
|
323 // Token text. |
391
33b566df6af4
Migrated project to Tango.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
390
diff
changeset
|
324 printToken(token, tags, print); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
325 // </node> |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
326 if (options & GenOption.HTML) |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
327 foreach_reverse (node; tokenEx.endNodes) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
328 print(tagNodeEnd); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
329 else |
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
330 foreach_reverse (node; tokenEx.endNodes) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
331 print.format(tagNodeEnd, tags.getTag(node.category)); |
363 | 332 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
333 print(tags["SourceEnd"]); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
334 print(tags["DocEnd"]); |
363 | 335 } |
336 | |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
337 /// Highlights all tokens of a source file. |
771
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
338 void highlightTokens(string filePath, TagMap tags, Print!(char) print, GenOption options) |
363 | 339 { |
755
90668b83ae5e
Introduced new module dil.SourceText and class SourceText.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
752
diff
changeset
|
340 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
|
341 lx.scanAll(); |
363 | 342 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
343 print(tags["DocHead"]); |
363 | 344 if (lx.errors.length) |
345 { | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
346 print(tags["CompBegin"]); |
752
51e9dfe27f20
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
709
diff
changeset
|
347 printErrors(lx, tags, print); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
348 print(tags["CompEnd"]); |
363 | 349 } |
771
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 if (options & GenOption.PrintLines) |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
352 { |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
353 print(tags["LineNumberBegin"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
354 printLines(lx.lineNum, tags, print); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
355 print(tags["LineNumberEnd"]); |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
356 } |
ef9bee5a2d61
Command 'generate' can print line numbers now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
763
diff
changeset
|
357 |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
358 print(tags["SourceBegin"]); |
363 | 359 // 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
|
360 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
|
361 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
|
362 printToken(token, tags, print); |
363 | 363 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
364 print(tags["SourceEnd"]); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
365 print(tags["DocEnd"]); |
363 | 366 } |
367 | |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
368 /// A token highlighter designed for DDoc. |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
369 class TokenHighlighter |
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 TagMap tags; |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
372 this(InfoManager infoMan, bool useHTML = true) |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
373 { |
800
dcd30b0ba711
Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
785
diff
changeset
|
374 string filePath = GlobalSettings.htmlMapFile; |
dcd30b0ba711
Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
785
diff
changeset
|
375 if (!useHTML) |
dcd30b0ba711
Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
785
diff
changeset
|
376 filePath = GlobalSettings.xmlMapFile; |
dcd30b0ba711
Added --xml option to command 'ddoc'.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
785
diff
changeset
|
377 auto map = TagMapLoader(infoMan).load(filePath); |
761
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
378 tags = new TagMap(map); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
379 } |
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 /// 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
|
382 /// 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
|
383 string highlight(string text, string filePath) |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
384 { |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
385 auto buffer = new GrowBuffer(text.length); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
386 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
|
387 |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
388 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
|
389 lx.scanAll(); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
390 |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
391 // Traverse linked list and print tokens. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
392 print("$(D_CODE\n"); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
393 if (lx.errors.length) |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
394 { // Output error messages. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
395 print(tags["CompBegin"]); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
396 printErrors(lx, tags, print); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
397 print(tags["CompEnd"]); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
398 } |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
399 // Traverse linked list and print tokens. |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
400 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
|
401 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
|
402 printToken(token, tags, print); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
403 } |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
404 print("\n)"); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
405 return cast(char[])buffer.slice(); |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
406 } |
307905dadf5d
DDoc code sections are highlighted now.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
759
diff
changeset
|
407 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
408 |
785
57ef69eced96
Added functions isCodeSection() and skipCodeSection().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
781
diff
changeset
|
409 /// Prints a token to the stream print. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
410 void printToken(Token* token, TagMap tags, Print!(char) print) |
363 | 411 { |
679
ff6971637f88
Renamed Token member type to kind.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
668
diff
changeset
|
412 switch(token.kind) |
363 | 413 { |
414 case TOK.Identifier: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
415 print.format(tags.Identifier, token.srcText); |
363 | 416 break; |
417 case TOK.Comment: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
418 string formatStr; |
363 | 419 switch (token.start[1]) |
420 { | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
421 case '/': formatStr = tags.LineC; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
422 case '*': formatStr = tags.BlockC; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
423 case '+': formatStr = tags.NestedC; break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
424 default: assert(0); |
363 | 425 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
426 print.format(formatStr, xml_escape(token.srcText)); |
363 | 427 break; |
428 case TOK.String: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
429 print.format(tags.String, xml_escape(token.srcText)); |
363 | 430 break; |
507
996041463028
Removed TOK.WCharLiteral and TOK.DCharLiteral.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
485
diff
changeset
|
431 case TOK.CharLiteral: |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
432 print.format(tags.Char, xml_escape(token.srcText)); |
363 | 433 break; |
434 case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64, | |
435 TOK.Float32, TOK.Float64, TOK.Float80, | |
436 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
437 print.format(tags.Number, token.srcText); |
363 | 438 break; |
439 case TOK.Shebang: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
440 print.format(tags.Shebang, xml_escape(token.srcText)); |
363 | 441 break; |
442 case TOK.HashLine: | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
443 auto formatStr = tags.HLine; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
444 // The text to be inserted into formatStr. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
445 auto buffer = new GrowBuffer; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
446 auto print2 = new Print!(char)(Format, buffer); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
447 |
363 | 448 void printWS(char* start, char* end) |
449 { | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
450 start != end && print2(start[0 .. end - start]); |
363 | 451 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
452 |
485
ea8c7459f1c4
Changed a lot of things in the Lexer.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
422
diff
changeset
|
453 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
|
454 if (num is null) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
455 { // Malformed #line |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
456 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
|
457 break; |
ae154eceba65
Applied some fixes to scanning and printing #line tokens.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
379
diff
changeset
|
458 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
459 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
460 // Print whitespace between #line and number. |
763
f26f13b5a3a3
Fixed code in scanSpecialTokenSequence().
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
761
diff
changeset
|
461 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
|
462 printToken(num, tags, print2); // Print the number. |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
463 |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
464 if (auto filespec = token.tokLineFilespec) |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
465 { // Print whitespace between number and filespec. |
363 | 466 printWS(num.end, filespec.start); |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
467 print2.format(tags.Filespec, xml_escape(filespec.srcText)); |
363 | 468 } |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
469 // Finally print the whole token. |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
470 print.format(formatStr, cast(char[])buffer.slice()); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
471 break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
472 case TOK.Illegal: |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
473 print.format(tags.Illegal, token.srcText()); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
474 break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
475 case TOK.Newline: |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
476 print.format(tags.Newline, token.srcText()); |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
477 break; |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
478 case TOK.EOF: |
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
479 print(tags.EOF); |
363 | 480 break; |
481 default: | |
482 if (token.isKeyword()) | |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
483 print.format(tags.Keyword, token.srcText); |
363 | 484 else if (token.isSpecialToken) |
759
9c47f377ca0b
Revised module cmd.Generate.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
757
diff
changeset
|
485 print.format(tags.SpecialToken, token.srcText); |
363 | 486 else |
781
d887184efb3c
Improved class TagMap.
Aziz K?ksal <aziz.koeksal@gmail.com>
parents:
779
diff
changeset
|
487 print(tags[token.kind]); |
363 | 488 } |
489 } |