annotate trunk/src/main.d @ 308:3b9fc1e72210

- Indented some cases. Removed case TOK.Catenate.
author aziz
date Tue, 14 Aug 2007 18:35:02 +0000
parents 5f6a173d4ad3
children b4d842b0d2c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
1 /++
8ba2570de175 Initial import.
aziz
parents:
diff changeset
2 Author: Aziz Köksal
249
32d354584b28 - Upgraded license notices to GPL3.
aziz
parents: 213
diff changeset
3 License: GPL3
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
4 +/
8ba2570de175 Initial import.
aziz
parents:
diff changeset
5 module dparser;
69
24db7c5522d5 - Added module Information for compiler messages like warnings, info and errors to the user.
aziz
parents: 66
diff changeset
6 import Parser;
3
4bbce78bfb1e - Added TOK enum.
aziz
parents: 0
diff changeset
7 import Lexer;
4bbce78bfb1e - Added TOK enum.
aziz
parents: 0
diff changeset
8 import Token;
54
e55bd2270f94 - Relocated messages table to a separate module.
aziz
parents: 51
diff changeset
9 import Messages;
3
4bbce78bfb1e - Added TOK enum.
aziz
parents: 0
diff changeset
10 import std.stdio;
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
11 import std.file;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
12 import std.metastrings;
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
13
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
14 import Declarations, SyntaxTree;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
15
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
16 version(D2)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
17 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
18 const VERSION_MAJOR = 2;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
19 const VERSION_MINOR = 0;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
20 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
21 else
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
22 {
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
23 const VERSION_MAJOR = 1;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
24 const VERSION_MINOR = 0;
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
25 }
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
26 const string VERSION = Format!("%s.%s", VERSION_MAJOR, VERSION_MINOR);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
27
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
28 const char[] usageHighlight = "highlight (hl) file.d";
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
29 const string helpMain = `dil v`~VERSION~`
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
30 Copyright (c) 2007 by Aziz Köksal
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
31
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
32 Subcommands:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
33 `~usageHighlight~`
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
34
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
35 Type 'dil help <subcommand>' for more help on a particular subcommand.
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
36
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
37 Compiled with `~__VENDOR__~` `~Format!("v%s.%s", __VERSION__/1000, __VERSION__%1000)~` on `~__TIMESTAMP__~`.
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
38 `;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
39
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
40 void main(char[][] args)
8ba2570de175 Initial import.
aziz
parents:
diff changeset
41 {
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
42 if (args.length <= 1)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
43 return writefln(helpMain);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
44
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
45 string command = args[1];
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
46 switch (command)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
47 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
48 case "hl", "highlight":
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
49 if (args.length == 3)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
50 highlightTokens(args[2]);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
51 break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
52 default:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
53 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
54 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
55
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
56 void parse(string fileName)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
57 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
58 auto sourceText = cast(char[]) std.file.read(fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
59 auto parser = new Parser(sourceText, fileName);
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
60 parser.start();
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 303
diff changeset
61 auto root = parser.parseModule();
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
62
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
63 void print(Node[] decls, char[] indent)
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
64 {
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
65 foreach(decl; decls)
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
66 {
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
67 assert(decl !is null);
303
bc1112f7933d - Added keyword debug to some statements.
aziz
parents: 299
diff changeset
68 writefln(indent, decl.classinfo.name, ": begin=%s end=%s", decl.begin ? decl.begin.srcText : "\33[31mnull\33[0m", decl.end ? decl.end.srcText : "\33[31mnull\33[0m");
299
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
69 print(decl.children, indent ~ " ");
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
70 }
559d5d62e0c1 - Added checks for null before adding member to Node.children.
aziz
parents: 249
diff changeset
71 }
305
df237b3b5f09 - Added class Declarations.
aziz
parents: 303
diff changeset
72 print(root.children, "");
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
73 foreach (error; parser.errors)
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
74 {
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
75 writefln(`%s(%d)P: %s`, parser.lx.fileName, error.loc, error.getMsg);
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
76 }
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
77 }
213
b0ebde88d2d4 - Added members trying, errorCount and prev (for debugging) to Parser.
aziz
parents: 112
diff changeset
78
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
79 char[] xml_escape(char[] text)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
80 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
81 char[] result;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
82 foreach(c; text)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
83 switch(c)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
84 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
85 case '<': result ~= "&lt;"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
86 case '>': result ~= "&gt;"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
87 case '&': result ~= "&amp;"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
88 default: result ~= c;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
89 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
90 return result;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
91 }
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
92
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
93 void highlightTokens(string fileName)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
94 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
95 auto sourceText = cast(char[]) std.file.read(fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
96 auto lx = new Lexer(sourceText, fileName);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
97
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
98 auto token = lx.getTokens();
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
99 char* end = lx.text.ptr;
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
100
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
101 writef(`<?xml version="1.0"?>`
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
102 `<?xml-stylesheet href="format.css" type="text/css"?>`
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
103 `<root>`);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
104 if (lx.errors.length)
51
cadd2bfe686c - Displaying error messages in XML.
aziz
parents: 44
diff changeset
105 {
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
106 writefln("<compilerinfo>");
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
107 foreach (error; lx.errors)
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
108 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
109 writefln(`<error t="%s">%s(%d): %s</error>`, "l", lx.fileName, error.loc, xml_escape(error.getMsg));
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
110 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
111 writefln("</compilerinfo>");
51
cadd2bfe686c - Displaying error messages in XML.
aziz
parents: 44
diff changeset
112 }
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
113 writef(`<sourcetext>`);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
114
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
115 // Traverse linked list and print tokens.
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
116 while (token.type != TOK.EOF)
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
117 {
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
118 token = token.next;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
119
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
120 // Print whitespace between previous and current token.
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
121 if (end != token.start)
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
122 writef("%s", xml_escape(end[0 .. token.start - end]));
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
123
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
124 string srcText = xml_escape(token.srcText);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
125
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
126 switch(token.type)
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
127 {
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
128 case TOK.Identifier:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
129 writef("<i>%s</i>", srcText);
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
130 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
131 case TOK.Comment:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
132 string c;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
133 switch (token.start[1])
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
134 {
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
135 case '/': c = "l"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
136 case '*': c = "b"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
137 case '+': c = "n"; break;
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
138 default:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
139 assert(0);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
140 }
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
141 writef(`<c c="%s">%s</c>`, c, srcText);
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
142 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
143 case TOK.String:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
144 writef("<sl>%s</sl>", srcText);
9
5d6968cc751e - Parsing string and character literals now (rudimentary implementation.)
aziz
parents: 5
diff changeset
145 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
146 case TOK.CharLiteral, TOK.WCharLiteral, TOK.DCharLiteral:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
147 writef("<cl>%s</cl>", srcText);
9
5d6968cc751e - Parsing string and character literals now (rudimentary implementation.)
aziz
parents: 5
diff changeset
148 break;
308
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
149 case TOK.Assign, TOK.Equal,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
150 TOK.Less, TOK.Greater,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
151 TOK.LShiftAssign, TOK.LShift,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
152 TOK.RShiftAssign, TOK.RShift,
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
153 TOK.URShiftAssign, TOK.URShift,
308
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
154 TOK.OrAssign, TOK.OrBinary,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
155 TOK.AndAssign, TOK.AndBinary,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
156 TOK.PlusAssign, TOK.PlusPlus, TOK.Plus,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
157 TOK.MinusAssign, TOK.MinusMinus, TOK.Minus,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
158 TOK.DivAssign, TOK.Div,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
159 TOK.MulAssign, TOK.Mul,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
160 TOK.ModAssign, TOK.Mod,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
161 TOK.XorAssign, TOK.Xor,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
162 TOK.CatAssign,
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
163 TOK.Tilde,
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
164 TOK.Unordered,
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
165 TOK.UorE,
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
166 TOK.UorG,
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
167 TOK.UorGorE,
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
168 TOK.UorL,
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
169 TOK.UorLorE,
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
170 TOK.LorEorG:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
171 writef("<op>%s</op>", srcText);
14
cdf788d8bdaf - Parsing /= now.
aziz
parents: 10
diff changeset
172 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
173 case TOK.LorG:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
174 writef(`<op c="lg">&lt;&gt;</op>`);
39
69b940398d7b - Added unittest to test correct parsing of operator tokens.
aziz
parents: 35
diff changeset
175 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
176 case TOK.LessEqual:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
177 writef(`<op c="le">&lt;=</op>`);
39
69b940398d7b - Added unittest to test correct parsing of operator tokens.
aziz
parents: 35
diff changeset
178 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
179 case TOK.GreaterEqual:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
180 writef(`<op c="ge">&gt;=</op>`);
39
69b940398d7b - Added unittest to test correct parsing of operator tokens.
aziz
parents: 35
diff changeset
181 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
182 case TOK.AndLogical:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
183 writef(`<op c="aa">&amp;&amp;</op>`);
31
94f09f4e988e - Added struct for strings to Token with 'pf' = postfix.
aziz
parents: 30
diff changeset
184 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
185 case TOK.OrLogical:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
186 writef(`<op c="oo">||</op>`);
31
94f09f4e988e - Added struct for strings to Token with 'pf' = postfix.
aziz
parents: 30
diff changeset
187 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
188 case TOK.NotEqual:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
189 writef(`<op c="ne">!=</op>`);
44
5055947e0f98 - Specific operators and comments can be formatted with CSS now.
aziz
parents: 39
diff changeset
190 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
191 case TOK.Not:
307
5f6a173d4ad3 - Don't consider '\!' as an operator when it begins a template argument list.
aziz
parents: 306
diff changeset
192 // Check if this is part of a template instantiation.
5f6a173d4ad3 - Don't consider '\!' as an operator when it begins a template argument list.
aziz
parents: 306
diff changeset
193 // TODO: comments aren't skipped.
5f6a173d4ad3 - Don't consider '\!' as an operator when it begins a template argument list.
aziz
parents: 306
diff changeset
194 if (token.prev.type == TOK.Identifier && token.next.type == TOK.LParen)
5f6a173d4ad3 - Don't consider '\!' as an operator when it begins a template argument list.
aziz
parents: 306
diff changeset
195 goto default;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
196 writef(`<op c="n">!</op>`);
35
c470b9356e35 - Added code for parsing Unordered, UorE, UorG, UorGorE, UorL, UorLorE, NotEqual and Not tokens.
aziz
parents: 33
diff changeset
197 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
198 case TOK.Int32, TOK.Int64, TOK.Uint32, TOK.Uint64,
308
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
199 TOK.Float32, TOK.Float64, TOK.Float80,
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
200 TOK.Imaginary32, TOK.Imaginary64, TOK.Imaginary80:
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
201 writef("<n>%s</n>", srcText);
15
c70c028e47dd - Started implementation of lexing numbers.
aziz
parents: 14
diff changeset
202 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
203 case TOK.LParen, TOK.RParen, TOK.LBracket,
308
3b9fc1e72210 - Indented some cases. Removed case TOK.Catenate.
aziz
parents: 307
diff changeset
204 TOK.RBracket, TOK.LBrace, TOK.RBrace:
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
205 writef("<br>%s</br>", srcText);
20
d6adfbd7c513 - Added code for parsing braces.
aziz
parents: 17
diff changeset
206 break;
306
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
207 default:
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
208 if (token.isKeyword())
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
209 writef("<k>%s</k>", srcText);
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
210 else
9c866aadcb5b - Moved code out of main() to separate functions.
aziz
parents: 305
diff changeset
211 writef("%s", srcText);
5
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
212 }
79b4e8848794 - Started writing XML generator.
aziz
parents: 4
diff changeset
213 end = token.end;
4
92df59b1ec4a - Started implementation of scan().
aziz
parents: 3
diff changeset
214 }
51
cadd2bfe686c - Displaying error messages in XML.
aziz
parents: 44
diff changeset
215 writef("\n</sourcetext>\n</root>");
0
8ba2570de175 Initial import.
aziz
parents:
diff changeset
216 }