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