annotate dmd/Lexer.d @ 130:60bb0fe4563e

dmdfe 2.037 first main iteration
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Thu, 09 Sep 2010 22:51:44 +0100
parents e28b18c23469
children af1bebfd96a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.StringTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Keyword;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.StringValue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Dchar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Utf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import std.stdio : writeln;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
21 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
22
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import core.stdc.ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import core.stdc.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import core.stdc.time;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import core.stdc.errno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 enum LS = 0x2028; // UTF line separator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 enum PS = 0x2029; // UTF paragraph separator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 extern (C) extern
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 __gshared char* __locale_decpoint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 int isUniAlpha(uint u)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 class Lexer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 static StringTable stringtable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 static OutBuffer stringbuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 static Token* freelist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Loc loc; // for error messages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 ubyte* base; // pointer to start of buffer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 ubyte* end; // past end of buffer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 ubyte* p; // current character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 Token token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 Module mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 int doDocComment; // collect doc comment information
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 int anyToken; // !=0 means seen at least one token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 int commentToken; // !=0 means comments are TOKcomment's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 static this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 stringtable = new StringTable();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 stringbuffer = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 static ~this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 {
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 8
diff changeset
68 //delete stringtable;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 this(Module mod, ubyte* base, uint begoffset, uint endoffset, int doDocComment, int commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 loc = Loc(mod, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 memset(&token,0,token.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 this.base = base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 this.end = base + endoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 p = base + begoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 this.mod = mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 this.doDocComment = doDocComment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 this.anyToken = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 this.commentToken = commentToken;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 //initKeywords();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 /* If first line starts with '#!', ignore the line
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (p[0] == '#' && p[1] =='!')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 p += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 if (*p == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 loc.linnum = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 static Keyword[] keywords =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 [
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 // { "", TOK },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 { "this", TOK.TOKthis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 { "super", TOK.TOKsuper },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 { "assert", TOK.TOKassert },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 { "null", TOK.TOKnull },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 { "true", TOK.TOKtrue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 { "false", TOK.TOKfalse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 { "cast", TOK.TOKcast },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 { "new", TOK.TOKnew },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 { "delete", TOK.TOKdelete },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 { "throw", TOK.TOKthrow },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 { "module", TOK.TOKmodule },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 { "pragma", TOK.TOKpragma },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 { "typeof", TOK.TOKtypeof },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 { "typeid", TOK.TOKtypeid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 { "template", TOK.TOKtemplate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 { "void", TOK.TOKvoid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 { "byte", TOK.TOKint8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 { "ubyte", TOK.TOKuns8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 { "short", TOK.TOKint16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 { "ushort", TOK.TOKuns16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 { "int", TOK.TOKint32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 { "uint", TOK.TOKuns32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 { "long", TOK.TOKint64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 { "ulong", TOK.TOKuns64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 { "cent", TOK.TOKcent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 { "ucent", TOK.TOKucent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 { "float", TOK.TOKfloat32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 { "double", TOK.TOKfloat64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 { "real", TOK.TOKfloat80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 { "bool", TOK.TOKbool },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 { "char", TOK.TOKchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 { "wchar", TOK.TOKwchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 { "dchar", TOK.TOKdchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 { "ifloat", TOK.TOKimaginary32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 { "idouble", TOK.TOKimaginary64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 { "ireal", TOK.TOKimaginary80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 { "cfloat", TOK.TOKcomplex32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 { "cdouble", TOK.TOKcomplex64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 { "creal", TOK.TOKcomplex80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 { "delegate", TOK.TOKdelegate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 { "function", TOK.TOKfunction },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 { "is", TOK.TOKis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 { "if", TOK.TOKif },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 { "else", TOK.TOKelse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 { "while", TOK.TOKwhile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 { "for", TOK.TOKfor },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 { "do", TOK.TOKdo },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 { "switch", TOK.TOKswitch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 { "case", TOK.TOKcase },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 { "default", TOK.TOKdefault },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 { "break", TOK.TOKbreak },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 { "continue", TOK.TOKcontinue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 { "synchronized", TOK.TOKsynchronized },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 { "return", TOK.TOKreturn },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 { "goto", TOK.TOKgoto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 { "try", TOK.TOKtry },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 { "catch", TOK.TOKcatch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 { "finally", TOK.TOKfinally },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 { "with", TOK.TOKwith },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 { "asm", TOK.TOKasm },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 { "foreach", TOK.TOKforeach },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 { "foreach_reverse", TOK.TOKforeach_reverse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 { "scope", TOK.TOKscope },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 { "struct", TOK.TOKstruct },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 { "class", TOK.TOKclass },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 { "interface", TOK.TOKinterface },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 { "union", TOK.TOKunion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 { "enum", TOK.TOKenum },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 { "import", TOK.TOKimport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 { "mixin", TOK.TOKmixin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 { "static", TOK.TOKstatic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 { "final", TOK.TOKfinal },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 { "const", TOK.TOKconst },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 { "typedef", TOK.TOKtypedef },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 { "alias", TOK.TOKalias },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 { "override", TOK.TOKoverride },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 { "abstract", TOK.TOKabstract },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 { "volatile", TOK.TOKvolatile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 { "debug", TOK.TOKdebug },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 { "deprecated", TOK.TOKdeprecated },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 { "in", TOK.TOKin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 { "out", TOK.TOKout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 { "inout", TOK.TOKinout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 { "lazy", TOK.TOKlazy },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 { "auto", TOK.TOKauto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 { "align", TOK.TOKalign },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 { "extern", TOK.TOKextern },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 { "private", TOK.TOKprivate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 { "package", TOK.TOKpackage },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 { "protected", TOK.TOKprotected },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 { "public", TOK.TOKpublic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 { "export", TOK.TOKexport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 { "body", TOK.TOKbody },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 { "invariant", TOK.TOKinvariant },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 { "unittest", TOK.TOKunittest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 { "version", TOK.TOKversion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 //{ "manifest", TOK.TOKmanifest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 // Added after 1.0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 { "ref", TOK.TOKref },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 { "macro", TOK.TOKmacro },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 { "pure", TOK.TOKpure },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 { "nothrow", TOK.TOKnothrow },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 { "__thread", TOK.TOKtls },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 { "__gshared", TOK.TOKgshared },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 { "__traits", TOK.TOKtraits },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 { "__overloadset", TOK.TOKoverloadset },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 { "__FILE__", TOK.TOKfile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 { "__LINE__", TOK.TOKline },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 { "shared", TOK.TOKshared },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 { "immutable", TOK.TOKimmutable },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 static Keyword[] keywords =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 [
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256 // { "", TOK },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
258 { "this", TOK.TOKthis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
259 { "super", TOK.TOKsuper },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 { "assert", TOK.TOKassert },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 { "null", TOK.TOKnull },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 { "true", TOK.TOKtrue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 { "false", TOK.TOKfalse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264 { "cast", TOK.TOKcast },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 { "new", TOK.TOKnew },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266 { "delete", TOK.TOKdelete },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 { "throw", TOK.TOKthrow },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 { "module", TOK.TOKmodule },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
269 { "pragma", TOK.TOKpragma },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 { "typeof", TOK.TOKtypeof },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
271 { "typeid", TOK.TOKtypeid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 { "template", TOK.TOKtemplate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275 { "void", TOK.TOKvoid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 { "byte", TOK.TOKint8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 { "ubyte", TOK.TOKuns8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 { "short", TOK.TOKint16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 { "ushort", TOK.TOKuns16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 { "int", TOK.TOKint32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 { "uint", TOK.TOKuns32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 { "long", TOK.TOKint64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 { "ulong", TOK.TOKuns64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 { "cent", TOK.TOKcent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
285 { "ucent", TOK.TOKucent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 { "float", TOK.TOKfloat32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 { "double", TOK.TOKfloat64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288 { "real", TOK.TOKfloat80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 { "bool", TOK.TOKbool },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 { "char", TOK.TOKchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 { "wchar", TOK.TOKwchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 { "dchar", TOK.TOKdchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295 { "ifloat", TOK.TOKimaginary32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 { "idouble", TOK.TOKimaginary64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 { "ireal", TOK.TOKimaginary80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299 { "cfloat", TOK.TOKcomplex32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 { "cdouble", TOK.TOKcomplex64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 { "creal", TOK.TOKcomplex80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 { "delegate", TOK.TOKdelegate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 { "function", TOK.TOKfunction },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 { "is", TOK.TOKis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 { "if", TOK.TOKif },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 { "else", TOK.TOKelse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 { "while", TOK.TOKwhile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 { "for", TOK.TOKfor },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 { "do", TOK.TOKdo },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 { "switch", TOK.TOKswitch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 { "case", TOK.TOKcase },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 { "default", TOK.TOKdefault },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 { "break", TOK.TOKbreak },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 { "continue", TOK.TOKcontinue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 { "synchronized", TOK.TOKsynchronized },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 { "return", TOK.TOKreturn },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 { "goto", TOK.TOKgoto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 { "try", TOK.TOKtry },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321 { "catch", TOK.TOKcatch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 { "finally", TOK.TOKfinally },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 { "with", TOK.TOKwith },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 { "asm", TOK.TOKasm },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325 { "foreach", TOK.TOKforeach },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 { "foreach_reverse", TOK.TOKforeach_reverse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 { "scope", TOK.TOKscope },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329 { "struct", TOK.TOKstruct },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 { "class", TOK.TOKclass },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 { "interface", TOK.TOKinterface },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 { "union", TOK.TOKunion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 { "enum", TOK.TOKenum },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 { "import", TOK.TOKimport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 { "mixin", TOK.TOKmixin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 { "static", TOK.TOKstatic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 { "final", TOK.TOKfinal },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 { "const", TOK.TOKconst },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 { "typedef", TOK.TOKtypedef },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 { "alias", TOK.TOKalias },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 { "override", TOK.TOKoverride },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 { "abstract", TOK.TOKabstract },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 { "volatile", TOK.TOKvolatile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 { "debug", TOK.TOKdebug },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 { "deprecated", TOK.TOKdeprecated },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 { "in", TOK.TOKin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 { "out", TOK.TOKout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 { "inout", TOK.TOKinout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 { "lazy", TOK.TOKlazy },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 { "auto", TOK.TOKauto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 { "align", TOK.TOKalign },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 { "extern", TOK.TOKextern },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 { "private", TOK.TOKprivate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 { "package", TOK.TOKpackage },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 { "protected", TOK.TOKprotected },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 { "public", TOK.TOKpublic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 { "export", TOK.TOKexport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 { "body", TOK.TOKbody },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 { "invariant", TOK.TOKinvariant },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 { "unittest", TOK.TOKunittest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 { "version", TOK.TOKversion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 //{ "manifest", TOK.TOKmanifest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 // Added after 1.0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 { "ref", TOK.TOKref },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 { "macro", TOK.TOKmacro },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 static ubyte cmtable[256];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 enum CMoctal = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 enum CMhex = 0x2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 enum CMidchar = 0x4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 ubyte isoctal (ubyte c) { return cmtable[c] & CMoctal; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 ubyte ishex (ubyte c) { return cmtable[c] & CMhex; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 ubyte isidchar(ubyte c) { return cmtable[c] & CMidchar; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 static void cmtable_init()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 for (uint c = 0; c < cmtable.length; c++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 if ('0' <= c && c <= '7')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 cmtable[c] |= CMoctal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 if (isdigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 cmtable[c] |= CMhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 if (isalnum(c) || c == '_')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 cmtable[c] |= CMidchar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 static void initKeywords()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 uint nkeywords = keywords.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 if (global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 nkeywords -= 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 cmtable_init();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 for (uint u = 0; u < nkeywords; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 {
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 8
diff changeset
405 //printf("keyword[%d] = '%.*s'\n",u, keywords[u].name);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 string s = keywords[u].name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 TOK v = keywords[u].value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 StringValue* sv = stringtable.insert(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 sv.ptrvalue = cast(void*) new Identifier(sv.lstring.string_, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 //printf("tochars[%d] = '%s'\n",v, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 Token.tochars[v] = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 Token.tochars[TOK.TOKeof] = "EOF";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 Token.tochars[TOK.TOKlcurly] = "{";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 Token.tochars[TOK.TOKrcurly] = "}";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 Token.tochars[TOK.TOKlparen] = "(";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 Token.tochars[TOK.TOKrparen] = ")";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 Token.tochars[TOK.TOKlbracket] = "[";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 Token.tochars[TOK.TOKrbracket] = "]";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 Token.tochars[TOK.TOKsemicolon] = ";";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 Token.tochars[TOK.TOKcolon] = ":";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 Token.tochars[TOK.TOKcomma] = ",";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 Token.tochars[TOK.TOKdot] = ".";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 Token.tochars[TOK.TOKxor] = "^";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 Token.tochars[TOK.TOKxorass] = "^=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 Token.tochars[TOK.TOKassign] = "=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 Token.tochars[TOK.TOKconstruct] = "=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 Token.tochars[TOK.TOKblit] = "=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 Token.tochars[TOK.TOKlt] = "<";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 Token.tochars[TOK.TOKgt] = ">";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 Token.tochars[TOK.TOKle] = "<=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 Token.tochars[TOK.TOKge] = ">=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 Token.tochars[TOK.TOKequal] = "==";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 Token.tochars[TOK.TOKnotequal] = "!=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 Token.tochars[TOK.TOKnotidentity] = "!is";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 Token.tochars[TOK.TOKtobool] = "!!";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 Token.tochars[TOK.TOKunord] = "!<>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 Token.tochars[TOK.TOKue] = "!<>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 Token.tochars[TOK.TOKlg] = "<>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 Token.tochars[TOK.TOKleg] = "<>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 Token.tochars[TOK.TOKule] = "!>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 Token.tochars[TOK.TOKul] = "!>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 Token.tochars[TOK.TOKuge] = "!<";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 Token.tochars[TOK.TOKug] = "!<=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 Token.tochars[TOK.TOKnot] = "!";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 Token.tochars[TOK.TOKtobool] = "!!";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 Token.tochars[TOK.TOKshl] = "<<";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 Token.tochars[TOK.TOKshr] = ">>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 Token.tochars[TOK.TOKushr] = ">>>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 Token.tochars[TOK.TOKadd] = "+";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 Token.tochars[TOK.TOKmin] = "-";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 Token.tochars[TOK.TOKmul] = "*";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 Token.tochars[TOK.TOKdiv] = "/";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 Token.tochars[TOK.TOKmod] = "%";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 Token.tochars[TOK.TOKslice] = "..";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 Token.tochars[TOK.TOKdotdotdot] = "...";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 Token.tochars[TOK.TOKand] = "&";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 Token.tochars[TOK.TOKandand] = "&&";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 Token.tochars[TOK.TOKor] = "|";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 Token.tochars[TOK.TOKoror] = "||";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 Token.tochars[TOK.TOKarray] = "[]";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 Token.tochars[TOK.TOKindex] = "[i]";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 Token.tochars[TOK.TOKaddress] = "&";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 Token.tochars[TOK.TOKstar] = "*";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 Token.tochars[TOK.TOKtilde] = "~";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 Token.tochars[TOK.TOKdollar] = "$";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 Token.tochars[TOK.TOKcast] = "cast";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 Token.tochars[TOK.TOKplusplus] = "++";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 Token.tochars[TOK.TOKminusminus] = "--";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 Token.tochars[TOK.TOKtype] = "type";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 Token.tochars[TOK.TOKquestion] = "?";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 Token.tochars[TOK.TOKneg] = "-";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 Token.tochars[TOK.TOKuadd] = "+";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 Token.tochars[TOK.TOKvar] = "var";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 Token.tochars[TOK.TOKaddass] = "+=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 Token.tochars[TOK.TOKminass] = "-=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 Token.tochars[TOK.TOKmulass] = "*=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 Token.tochars[TOK.TOKdivass] = "/=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 Token.tochars[TOK.TOKmodass] = "%=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 Token.tochars[TOK.TOKshlass] = "<<=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 Token.tochars[TOK.TOKshrass] = ">>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 Token.tochars[TOK.TOKushrass] = ">>>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 Token.tochars[TOK.TOKandass] = "&=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 Token.tochars[TOK.TOKorass] = "|=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 Token.tochars[TOK.TOKcatass] = "~=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 Token.tochars[TOK.TOKcat] = "~";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 Token.tochars[TOK.TOKcall] = "call";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 Token.tochars[TOK.TOKidentity] = "is";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 Token.tochars[TOK.TOKnotidentity] = "!is";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 Token.tochars[TOK.TOKorass] = "|=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 Token.tochars[TOK.TOKidentifier] = "identifier";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 Token.tochars[TOK.TOKat] = "@";
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
500 Token.tochars[TOK.TOKpow] = "^^";
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
501 //Token.tochars[TOK.TOKpowass] = "^^=";
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
502
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 // For debugging
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 51
diff changeset
504 Token.tochars[TOKerror] = "error";
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 Token.tochars[TOK.TOKdotexp] = "dotexp";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 Token.tochars[TOK.TOKdotti] = "dotti";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 Token.tochars[TOK.TOKdotvar] = "dotvar";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 Token.tochars[TOK.TOKdottype] = "dottype";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 Token.tochars[TOK.TOKsymoff] = "symoff";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 Token.tochars[TOK.TOKarraylength] = "arraylength";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 Token.tochars[TOK.TOKarrayliteral] = "arrayliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 Token.tochars[TOK.TOKassocarrayliteral] = "assocarrayliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 Token.tochars[TOK.TOKstructliteral] = "structliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 Token.tochars[TOK.TOKstring] = "string";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 Token.tochars[TOK.TOKdsymbol] = "symbol";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 Token.tochars[TOK.TOKtuple] = "tuple";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 Token.tochars[TOK.TOKdeclaration] = "declaration";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 Token.tochars[TOK.TOKdottd] = "dottd";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 Token.tochars[TOK.TOKon_scope_exit] = "scope(exit)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 Token.tochars[TOK.TOKon_scope_success] = "scope(success)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 Token.tochars[TOK.TOKon_scope_failure] = "scope(failure)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 static Identifier idPool(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 StringValue* sv = stringtable.update(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 Identifier id = cast(Identifier) sv.ptrvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 if (id is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 sv.ptrvalue = cast(void*)id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 return id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 static Identifier uniqueId(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 static int num;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 return uniqueId(s, ++num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 /*********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 * Create a unique identifier using the prefix s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 static Identifier uniqueId(string s, int num)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 char buffer[32];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 size_t slen = s.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 assert(slen + num.sizeof * 3 + 1 <= buffer.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 int len = sprintf(buffer.ptr, "%.*s%d", s, num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 return idPool(buffer[0..len].idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 TOK nextToken()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 Token *t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 if (token.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 t = token.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 memcpy(&token, t, Token.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 t.next = freelist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 freelist = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 scan(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 //token.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 return token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 /***********************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 * Look ahead at next token's value.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 TOK peekNext()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 return peek(&token).value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 TOK peekNext2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 void scan(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 uint lastLine = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 uint linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 t.blockComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 t.lineComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 t.ptr = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 //printf("p = %p, *p = '%c'\n",p,*p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 t.value = TOK.TOKeof; // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 case '\t':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 case '\v':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 case '\f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 if (*p != '\n') // if CR stands by itself
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 case '0': case '1': case '2': case '3': case '4':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 case '5': case '6': case '7': case '8': case '9':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 t.value = number(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 version (CSTRINGS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 t.value = charConstant(t, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 t.value = stringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 if (p[1] == '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 t.value = charConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 else if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 t.value = stringConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 t.value = charConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 case 'r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 case '`':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 t.value = wysiwygStringConstant(t, *p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 t.value = hexStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 case 'q':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 t.value = delimitedStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 else if (p[1] == '{')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 t.value = tokenStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 t.value = escapeStringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 case '\\': // escaped string literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 { uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 ubyte* pstart = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 } while (*p == '\\');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
722 char* cc = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 memcpy(cc, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 t.ustring = cc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 error("Escape String literal %.*s is deprecated, use double quoted string literal \"%.*s\" instead", p - pstart, pstart, p - pstart, pstart);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 case 'a': case 'b': case 'c': case 'd': case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 case 'f': case 'g': case 'h': case 'i': case 'j':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 case 'k': case 'm': case 'n': case 'o':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 case 'p': /*case 'q': case 'r':*/ case 's': case 't':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 case 'p': case 'q': /*case 'r':*/ case 's': case 't':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 case 'u': case 'v': case 'w': /*case 'x':*/ case 'y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 case 'z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 case 'A': case 'B': case 'C': case 'D': case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 case 'F': case 'G': case 'H': case 'I': case 'J':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 case 'K': case 'M': case 'N': case 'O':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 case 'P': case 'Q': case 'R': case 'S': case 'T':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 case 'U': case 'V': case 'W': case 'X': case 'Y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 case 'Z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 case_ident:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 { ubyte c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 StringValue *sv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 } while (isidchar(c) || (c & 0x80 && isUniAlpha(decodeUTF())));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 sv = stringtable.update((cast(immutable(char)*)t.ptr)[0.. p - t.ptr]); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 id = cast(Identifier) sv.ptrvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 if (id is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 { id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 sv.ptrvalue = cast(void*)id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 t.ident = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 t.value = cast(TOK) id.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 anyToken = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 if (*t.ptr == '_') // if special identifier token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 static char date[11+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 static char time[8+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 static char timestamp[24+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 if (!date[0]) // lazy evaluation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 { time_t tm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 char *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 .time(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 p = ctime(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 assert(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 sprintf(date.ptr, "%.6s %.4s", p + 4, p + 20);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 sprintf(time.ptr, "%.8s", p + 11);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 sprintf(timestamp.ptr, "%.24s", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 ///version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 /// if (mod && id == Id.FILE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 /// t.ustring = cast(ubyte*)(loc.filename ? loc.filename : mod.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 /// goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 /// else if (mod && id == Id.LINE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 /// t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 /// t.uns64value = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 /// else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 if (id == Id.DATE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 t.ustring = date.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 else if (id == Id.TIME)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 t.ustring = time.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 else if (id == Id.VENDOR)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 t.ustring = "Digital Mars D".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 else if (id == Id.TIMESTAMP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 t.ustring = timestamp.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 Lstr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 Llen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 t.len = strlen(cast(char*)t.ustring);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 else if (id == Id.VERSIONX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 uint major = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 uint minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 foreach (char cc; global.version_[1..$])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 if (isdigit(cc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 minor = minor * 10 + cc - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 else if (cc == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 major = minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 t.uns64value = major * 1000 + minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 else if (id == Id.EOFX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 // Advance scanner to end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 while (!(*p == 0 || *p == 0x1A))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 //printf("t.value = %d\n",t.value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 t.value = TOK.TOKdivass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 error("unterminated /* */ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 if (p[-2] == '*' && p - 3 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 else if (doDocComment && t.ptr[2] == '*' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 { // if /** but not /**/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 case '/': // do // style comments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 { ubyte c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 if (p[1] == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 if (doDocComment && t.ptr[2] == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 if (doDocComment && t.ptr[2] == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 int nest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 nest = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 { ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 nest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 if (*p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 if (--nest == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 error("unterminated /+ +/ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 if (doDocComment && t.ptr[2] == '+' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 { // if /++ but not /++/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 t.value = TOK.TOKdiv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 if (isdigit(*p))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 { /* Note that we don't allow ._1 and ._ as being
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 * valid floating point numbers.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 t.value = inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 else if (p[0] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 if (p[1] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 { p += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 t.value = TOK.TOKdotdotdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 t.value = TOK.TOKslice;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 t.value = TOK.TOKdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 t.value = TOK.TOKandass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 else if (*p == '&')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 t.value = TOK.TOKandand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 t.value = TOK.TOKand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 case '|':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 t.value = TOK.TOKorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 else if (*p == '|')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 t.value = TOK.TOKoror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 t.value = TOK.TOKor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 case '-':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 t.value = TOK.TOKminass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 /// #if 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 /// else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 /// { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 /// t.value = TOK.TOKarrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 /// #endif
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 else if (*p == '-')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 t.value = TOK.TOKminusminus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 t.value = TOK.TOKmin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 t.value = TOK.TOKaddass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 else if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 t.value = TOK.TOKplusplus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 t.value = TOK.TOKadd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 case '<':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 t.value = TOK.TOKle; // <=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 t.value = TOK.TOKshlass; // <<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 t.value = TOK.TOKshl; // <<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 t.value = TOK.TOKleg; // <>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 t.value = TOK.TOKlg; // <>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166 t.value = TOK.TOKlt; // <
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 case '>':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 t.value = TOK.TOKge; // >=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 t.value = TOK.TOKshrass; // >>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 t.value = TOK.TOKushrass; // >>>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 t.value = TOK.TOKushr; // >>>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 t.value = TOK.TOKshr; // >>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 t.value = TOK.TOKgt; // >
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 case '!':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 t.value = TOK.TOKnotidentity; // !==
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 t.value = TOK.TOKnotequal; // !=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 t.value = TOK.TOKunord; // !<>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 t.value = TOK.TOKue; // !<>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 else if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 t.value = TOK.TOKug; // !<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 t.value = TOK.TOKuge; // !<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 t.value = TOK.TOKul; // !>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 t.value = TOK.TOKule; // !>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 t.value = TOK.TOKnot; // !
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 t.value = TOK.TOKidentity; // ===
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 t.value = TOK.TOKequal; // ==
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 t.value = TOK.TOKassign; // =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 case '~':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 t.value = TOK.TOKcatass; // ~=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 t.value = TOK.TOKtilde; // ~
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1263
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1264 version(DMDV2) {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1265 case '^':
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1266 p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1267 if (*p == '^')
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1268 { p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1269 //static if (false) {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1270 // if (*p == '=')
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1271 // { p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1272 // t.value = TOKpowass; // ^^=
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1273 // }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1274 // else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1275 //}
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1276 t.value = TOKpow; // ^^
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1277 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1278 else if (*p == '=')
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1279 { p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1280 t.value = TOKxorass; // ^=
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1281 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1282 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1283 t.value = TOKxor; // ^
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1284 return;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1285 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1286
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 /*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 #define SINGLE(c,tok) case c: p++; t.value = tok; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290 SINGLE('(', TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 SINGLE(')', TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 SINGLE('[', TOKlbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 SINGLE(']', TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 SINGLE('{', TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 SINGLE('}', TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 SINGLE('?', TOKquestion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 SINGLE(',', TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 SINGLE(';', TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 SINGLE(':', TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 SINGLE('$', TOKdollar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 SINGLE('@', TOKat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 #undef SINGLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 #define DOUBLE(c1,tok1,c2,tok2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 case c1: \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 if (*p == c2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 { p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 t.value = tok2; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 } \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 else \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 t.value = tok1; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 DOUBLE('*', TOKmul, '=', TOKmulass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 DOUBLE('%', TOKmod, '=', TOKmodass)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1318 #if DMDV1
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 DOUBLE('^', TOKxor, '=', TOKxorass)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1320 #endif
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 #undef DOUBLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 case '(': p++; t.value = TOK.TOKlparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 case ')': p++; t.value = TOK.TOKrparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 case '[': p++; t.value = TOK.TOKlbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 case ']': p++; t.value = TOK.TOKrbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 case '{': p++; t.value = TOK.TOKlcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329 case '}': p++; t.value = TOK.TOKrcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 case '?': p++; t.value = TOK.TOKquestion; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331 case ',': p++; t.value = TOK.TOKcomma; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 case ';': p++; t.value = TOK.TOKsemicolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333 case ':': p++; t.value = TOK.TOKcolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 case '$': p++; t.value = TOK.TOKdollar; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 case '@': p++; t.value = TOK.TOKat; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 t.value = TOK.TOKmulass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 t.value = TOK.TOKmul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347 case '%':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 t.value = TOK.TOKmodass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 t.value = TOK.TOKmod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1356 version(DMDV1) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 case '^':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 t.value = TOK.TOKxorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 t.value = TOK.TOKxor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1366 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 case '#':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 pragma_();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373 { ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 // Check for start of unicode identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 if (isUniAlpha(u))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389 if (isprint(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 error("unsupported char '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 error("unsupported char 0x%02x", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 Token* peek(Token* ct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 if (ct.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405 t = ct.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 t = new Token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 scan(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 t.next = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 ct.next = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416 Token* peekPastParen(Token* tk)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 //printf("peekPastParen()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419 int parens = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 int curlynest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 //tk.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 switch (tk.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 parens++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 --parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 if (parens)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 curlynest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 if (--curlynest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 if (curlynest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 * Parse escape sequence.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 uint escapeSequence()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 uint c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 int n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 int ndigits;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 case '?':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 Lconsume:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 case 'a': c = 7; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 case 'b': c = 8; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487 case 'f': c = 12; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 case 'n': c = 10; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 case 'r': c = 13; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 case 't': c = 9; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 case 'v': c = 11; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 ndigits = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 ndigits = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 ndigits = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501 Lhex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 if (ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 c -= '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 else if (islower(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 c -= 'a' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 c -= 'A' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 v = v * 16 + c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 if (++n == ndigits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 if (!ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 { error("escape hex sequence has %d hex digits instead of %d", n, ndigits);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 if (ndigits != 2 && !utf_isValidDchar(v))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 { error("invalid UTF character \\U%08x", v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 v = '?'; // recover with valid UTF character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 error("undefined escape hex sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 case '&': // named character entity
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538 for (ubyte* idstart = ++p; true; p++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 case ';':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 c = HtmlNamedEntity(idstart, p - idstart);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 if (c == ~0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 error("unnamed character entity &%s;", idstart[0..(p - idstart)]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 c = ' ';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 if (isalpha(*p) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 (p != idstart + 1 && isdigit(*p)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556 error("unterminated named entity");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 case 0x1A: // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 c = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 if (isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577 v = v * 8 + (c - '0');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1579 } while (++n < 3 && isoctal(cast(ubyte)c));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 if (c > 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1582 error("0%03o is larger than a byte", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1583 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1584 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1585 error("undefined escape sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1586 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1587 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1588 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1589 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1590
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1591 TOK wysiwygStringConstant(Token* t, int tc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1592 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1593 uint c;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1594 Loc start = loc;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1595
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1596 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1597 stringbuffer.reset();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1598 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1599 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1600 c = *p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1601 switch (c)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1602 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1603 case '\n':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1604 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1605 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1606
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1607 case '\r':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1608 if (*p == '\n')
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1609 continue; // ignore
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1610 c = '\n'; // treat EndOfLine as \n character
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1611 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1612 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1613
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1614 case 0:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1615 case 0x1A:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1616 error("unterminated string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1617 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1618 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1619 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1620 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1621
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1622 case '"':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1623 case '`':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1624 if (c == tc)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1625 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1626 t.len = stringbuffer.offset;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1627 stringbuffer.writeByte(0);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1628 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1629 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1630 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1631 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1632 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1633 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1634 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1635
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1636 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1637 if (c & 0x80)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1638 { p--;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1639 uint u = decodeUTF();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1640 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1641 if (u == PS || u == LS)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1642 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1643 stringbuffer.writeUTF8(u);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1644 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1645 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1646 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1647 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1648 stringbuffer.writeByte(c);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1649 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1650
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1654 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1655 * Lex hex strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1656 * x"0A ae 34FE BD"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1657 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 TOK hexStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1660 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1661 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1662 uint n = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1663 uint v;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1664
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1665 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1666 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1667 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1668 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1669 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1670 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1671 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1672 case ' ':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1673 case '\t':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1674 case '\v':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1675 case '\f':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1676 continue; // skip white space
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1677
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1678 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1679 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1680 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1681 // Treat isolated '\r' as if it were a '\n'
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1682 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1683 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1684 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1685
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1686 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1687 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1688 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1689 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1690 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1691 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1692 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1693
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1694 case '"':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1695 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1696 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1697 error("odd number (%d) of hex characters in hex string", n);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1698 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1699 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1700 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1701 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1702 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1703 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1704 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1705 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1706 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1707
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1708 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1709 if (c >= '0' && c <= '9')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1710 c -= '0';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1711 else if (c >= 'a' && c <= 'f')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1712 c -= 'a' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1713 else if (c >= 'A' && c <= 'F')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1714 c -= 'A' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1715 else if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1716 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1717 uint u = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1718 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1719 if (u == PS || u == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1720 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1721 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1722 error("non-hex character \\u%x", u);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1723 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1724 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1725 error("non-hex character '%c'", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1726 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1727 { v = (v << 4) | c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1728 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1729 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1730 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1731 v = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1732 n++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1733 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1734 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1735 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1736 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 version (DMDV2) {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1739 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1740 * Lex delimited strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1741 * q"(foo(xxx))" // "foo(xxx)"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1742 * q"[foo(]" // "foo("
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1743 * q"/foo]/" // "foo]"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1744 * q"HERE
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1745 * foo
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1746 * HERE" // "foo\n"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1747 * Input:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1748 * p is on the "
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1749 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1750 TOK delimitedStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1751 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1752 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1753 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1754 uint delimleft = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1755 uint delimright = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1756 uint nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1757 uint nestcount;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1758 Identifier hereid = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1759 uint blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1760 uint startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1761
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1762 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1763 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1764 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1765 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1766 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1767 //printf("c = '%c'\n", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1768 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1769 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1770 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1771 Lnextline:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1772 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1773 startline = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1774 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1775 { blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1776 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1777 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1778 if (hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1779 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1780 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1781 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1782 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1783 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1784
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1785 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1786 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1787 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1788 c = '\n'; // treat EndOfLine as \n character
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1789 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1790
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1791 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1792 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1793 goto Lerror;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1794
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1795 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1796 if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1797 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1798 c = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1799 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1800 if (c == PS || c == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1801 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1802 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1803 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1804 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1805 if (delimleft == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1806 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1807 delimleft = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1808 nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1809 nestcount = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1810 if (c == '(')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1811 delimright = ')';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1812 else if (c == '{')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1813 delimright = '}';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1814 else if (c == '[')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1815 delimright = ']';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1816 else if (c == '<')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1817 delimright = '>';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1818 else if (isalpha(c) || c == '_' || (c >= 0x80 && isUniAlpha(c)))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1819 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1820 // Start of identifier; must be a heredoc
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1821 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1822 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1823 scan(&t2); // read in heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1824 if (t2.value != TOKidentifier)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1825 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1826 error("identifier expected for heredoc, not %s", t2.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1827 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1828 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1829 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1830 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1831 hereid = t2.ident;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1832 //printf("hereid = '%s'\n", hereid.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1833 blankrol = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1834 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1835 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1836 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1837 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1838 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1839 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1840 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1841 if (isspace(c))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1842 error("delimiter cannot be whitespace");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1843 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1844 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1845 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1846 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1847 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1848 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1849 error("heredoc rest of line should be blank");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1850 blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1851 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1852 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1853 if (nest == 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1854 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1855 if (c == delimleft)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1856 nestcount++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1857 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1858 { nestcount--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1859 if (nestcount == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1860 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1861 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1862 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1863 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1864 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1865 if (startline && isalpha(c) && hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1866 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1867 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1868 ubyte* psave = p;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1869 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1870 scan(&t2); // read in possible heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1871 //printf("endid = '%s'\n", t2.ident.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1872 if (t2.value == TOKidentifier && t2.ident.equals(hereid))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1873 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1874 /* should check that rest of line is blank
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1875 */
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1876 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1877 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1878 p = psave;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1879 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1880 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1881 startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1882 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1883 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1884
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1885 Ldone:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1886 if (*p == '"')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1887 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1888 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1889 error("delimited string must end in %c\"", delimright);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1890 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1891 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1892 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1893 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1894 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1895 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1896 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1897
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1898 Lerror:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1899 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1900 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1901 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1902 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1903 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1904 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1905
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1906 /**************************************
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1907 * Lex delimited strings:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1908 * q{ foo(xxx) } // " foo(xxx) "
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1909 * q{foo(} // "foo("
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1910 * q{{foo}"}"} // "{foo}"}""
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1911 * Input:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1912 * p is on the q
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1913 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1914 TOK tokenStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1915 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1916 uint nest = 1;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1917 Loc start = loc;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1918 ubyte* pstart = ++p;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1919
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1920 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1921 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1922 Token tok;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1923
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1924 scan(&tok);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1925 switch (tok.value)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1926 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1927 case TOKlcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1928 nest++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1929 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1930
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1931 case TOKrcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1932 if (--nest == 0)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1933 goto Ldone;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1934 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1935
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1936 case TOKeof:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1937 goto Lerror;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1938
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1939 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1940 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1941 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1942 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1943
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1944 Ldone:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1945 t.len = p - 1 - pstart;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1946 char* tmp = cast(char*)GC.malloc(t.len + 1);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1947 memcpy(tmp, pstart, t.len);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1948 tmp[t.len] = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1949 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1950 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1951 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1952
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1953 Lerror:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1954 error("unterminated token string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1955 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1956 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1957 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1958 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1959 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1960 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1961 TOK escapeStringConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1962 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1963 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1964 Loc start = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1965
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1966 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1967 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1968 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1971 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1972 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1973 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1974 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1975 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1976 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1977 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1978 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1979 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1980 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1981 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1982 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1983 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1984
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1985 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1986 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1987 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1988 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1989 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1990 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1991 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1992 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1993 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1994
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1995 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1996 if (*p == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1997 continue; // ignore
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1998 c = '\n'; // treat EndOfLine as \n character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1999 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2000 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2001
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2002 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2003 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2004 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
2005 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2006 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2007 t.ustring = tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2008 stringPostfix(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2009 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2010
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2011 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2012 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2013 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2014 error("unterminated string constant starting at %s", start.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2015 t.ustring = "".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2016 t.len = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2017 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2018 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2019
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2020 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2021 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2022 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2023 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2024 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2025 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2026 { c = '\n';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2027 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2028 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2029 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2030 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2031 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2032 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2033 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2034 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2035 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2036 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2037
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2038 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2039 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2040
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2041 TOK charConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2042 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2043 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2044 TOK tk = TOKcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2045
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2046 //printf("Lexer.charConstant\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2047 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2048 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2049 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2050 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2051 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2052 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2053 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2054 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2055 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2056 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2057 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2058 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2059 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2060
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2061 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2062 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2063 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2064 tk = TOKdcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2065 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2066
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2067 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2068 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2069 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2070 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2071 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2072 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2073 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2074 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2075 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2076 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2077 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2078 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2079 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2080 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2081 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2082
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2083 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2084 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2085 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2086 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2087 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2088 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2089 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2090 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2091 if (c < 0xD800 || (c >= 0xE000 && c < 0xFFFE))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2092 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2093 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2094 tk = TOKdcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2095 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2096 t.uns64value = c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2097 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2098 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2099
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2100 if (*p != '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2101 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2102 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2103 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2104 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2105 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2106 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2108
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2109 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2110 * Get postfix of string literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2111 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2112 void stringPostfix(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2114 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2116 case 'c':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2117 case 'w':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2118 case 'd':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2119 t.postfix = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2120 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2121 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2123 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2124 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2125 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2128
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2129 uint wchar_(uint u)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2131 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2132 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2134 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2135 * Read in a number.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2136 * If it's an integer, store it in tok.TKutok.Vlong.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2137 * integers can be decimal, octal or hex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2138 * Handle the suffixes U, UL, LU, L, etc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2139 * If it's double, store it in tok.TKutok.Vdouble.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2140 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2141 * TKnum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2142 * TKdouble,...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2143 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2145 TOK number(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2146 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2147 // We use a state machine to collect numbers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2148 enum STATE { STATE_initial, STATE_0, STATE_decimal, STATE_octal, STATE_octale,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2149 STATE_hex, STATE_binary, STATE_hex0, STATE_binary0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2150 STATE_hexh, STATE_error };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2151 STATE state;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2152
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2153 enum FLAGS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2155 FLAGS_undefined = 0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2156 FLAGS_decimal = 1, // decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2157 FLAGS_unsigned = 2, // u or U suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2158 FLAGS_long = 4, // l or L suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2159 };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2161 FLAGS flags = FLAGS.FLAGS_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2162
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2163 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2164 int base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2165 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2166 ubyte *start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2167 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2168
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2169 //printf("Lexer.number()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2170 state = STATE.STATE_initial;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2171 base = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2172 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2173 start = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2174 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2175 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2176 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2177 switch (state)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2178 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2179 case STATE.STATE_initial: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2180 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2181 state = STATE.STATE_0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2182 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2183 state = STATE.STATE_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2184 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2185
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2186 case STATE.STATE_0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2187 flags = (flags & ~FLAGS.FLAGS_decimal);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2188 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2189 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2190 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2191 case 'H': // 0h
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2192 case 'h':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2193 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2195 case 'X':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2196 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2197 state = STATE.STATE_hex0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2198 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2199
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2200 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2201 if (p[1] == '.') // .. is a separate token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2202 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2203 case 'i':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2204 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2205 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2206 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2207 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2208 case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2209 case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2210 goto case_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2211 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2212 case 'B':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2213 case 'b':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2214 state = STATE.STATE_binary0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2215 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2216
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2217 case '0': case '1': case '2': case '3':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2218 case '4': case '5': case '6': case '7':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2219 state = STATE.STATE_octal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2220 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2221
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2222 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2223 case '8': case '9': case 'A':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2224 case 'C': case 'D': case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2225 case 'a': case 'c': case 'd': case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2226 case_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2227 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2228 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2230 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2231 state = STATE.STATE_octal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2232 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2233 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2234
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2235 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2236 if (p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2237 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2238 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2239
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2240 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2241 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2242 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2243 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2244
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2245 case STATE.STATE_decimal: // reading decimal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2246 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2247 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2248 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2249 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2250 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2251 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2252 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2254 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2255 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2256 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2258 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2259 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2260 else if (c == 'i' || c == 'f' || c == 'F' ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2261 c == 'e' || c == 'E')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2262 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2263 real_: // It's a real number. Back up and rescan as a real
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2264 p = start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2265 return inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2266 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2267 else if (c == 'L' && p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2268 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2269 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2271 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2272
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2273 case STATE.STATE_hex0: // reading hex number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2274 case STATE.STATE_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2275 if (! ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2276 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2277 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2278 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2279 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2280 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2281 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2282 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2283 if (c == 'P' || c == 'p' || c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2284 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2285 if (state == STATE.STATE_hex0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2286 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2287 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2288 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2289 state = STATE.STATE_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2290 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2291
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2292 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2293 hexh:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2294 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2295 case STATE.STATE_hexh: // parse numbers like 0FFh
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2296 if (!ishex(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2297 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2298 if (c == 'H' || c == 'h')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2299 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2300 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2301 base = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2302 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2304 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2306 // Check for something like 1E3 or 0E24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2307 if (memchr(cast(char*)stringbuffer.data, 'E', stringbuffer.offset) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2308 memchr(cast(char*)stringbuffer.data, 'e', stringbuffer.offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2309 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2310 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2311 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2313 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2314 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2315 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2317 case STATE.STATE_octal: // reading octal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2318 case STATE.STATE_octale: // reading octal number with non-octal digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2319 if (!isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2321 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2322 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2323 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2324 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2325 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2327 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2328 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2329 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2331 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2332 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2333 if (c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2334 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2335 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2336 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2337 state = STATE.STATE_octale;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2339 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2340 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2341 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2342 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2343
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2344 case STATE.STATE_binary0: // starting binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2345 case STATE.STATE_binary: // reading binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2346 if (c != '0' && c != '1')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2348 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2349 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2350 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2351 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2352 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2354 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2355 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2356 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2357 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2358 if (state == STATE.STATE_binary0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2359 { error("binary digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2360 state = STATE.STATE_error;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2361 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2362 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2363 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2364 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2365 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2366 state = STATE.STATE_binary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2367 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2369 case STATE.STATE_error: // for error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2370 if (!isdigit(c)) // scan until non-digit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2371 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2372 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2374 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2375 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2377 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2378 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2379 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2380 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2381 stringbuffer.writeByte(0); // terminate string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2382 if (state == STATE.STATE_octale)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2383 error("Octal digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2385 ulong n; // unsigned >=64 bit integer type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2386
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2387 if (stringbuffer.offset == 2 && (state == STATE.STATE_decimal || state == STATE.STATE_0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2388 n = stringbuffer.data[0] - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2389 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2391 // Convert string to integer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2392 version (__DMC__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2393 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2394 n = strtoull(cast(char*)stringbuffer.data,null,base);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2395 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2396 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2397 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2398 // Not everybody implements strtoull()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2399 char* p = cast(char*)stringbuffer.data;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2400 int r = 10, d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2401
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2402 if (*p == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2403 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2404 if (p[1] == 'x' || p[1] == 'X')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2405 p += 2, r = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2406 else if (p[1] == 'b' || p[1] == 'B')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2407 p += 2, r = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2408 else if (isdigit(p[1]))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2409 p += 1, r = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2411
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2412 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2413 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2414 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2415 if (*p >= '0' && *p <= '9')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2416 d = *p - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2417 else if (*p >= 'a' && *p <= 'z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2418 d = *p - 'a' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2419 else if (*p >= 'A' && *p <= 'Z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2420 d = *p - 'A' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2421 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2422 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2423 if (d >= r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2424 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2425 ulong n2 = n * r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2426 //printf("n2 / r = %llx, n = %llx\n", n2/r, n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2427 if (n2 / r != n || n2 + d < n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2428 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2429 error ("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2430 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2432
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2433 n = n2 + d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2434 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2435 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2436 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2437 if (n.sizeof > 8 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2438 n > 0xFFFFFFFFFFFFFFFF) // if n needs more than 64 bits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2439 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2440 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2441
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2442 // Parse trailing 'u', 'U', 'l' or 'L' in any combination
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2443 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2444 { FLAGS f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2445
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2446 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2447 { case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2448 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2449 f = FLAGS.FLAGS_unsigned;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2450 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2451
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2452 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2453 if (1 || !global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2454 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2455 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2456 f = FLAGS.FLAGS_long;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2457 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2458 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2459 if (flags & f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2460 error("unrecognized token");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2461 flags = (flags | f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2462 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2463 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2464 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2466 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2467 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2468
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2469 switch (flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2470 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2471 case FLAGS.FLAGS_undefined:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2472 /* Octal or Hexadecimal constant.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2473 * First that fits: int, uint, long, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2474 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2475 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2476 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2477 else if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2478 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2479 else if (n & 0x80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2480 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2481 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2482 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2483 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2484
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2485 case FLAGS.FLAGS_decimal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2486 /* First that fits: int, long, long long
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2487 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2488 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2489 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2490 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2491 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2492 else if (n & 0xFFFFFFFF80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2493 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2494 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2495 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2496 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2497
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2498 case FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2499 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2500 /* First that fits: uint, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2501 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2502 if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2503 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2504 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2505 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2506 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2507
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2508 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2509 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2510 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2511 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2512 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2513 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2514 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2515 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2516
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2517 case FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2518 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2519 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2520 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2521 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2522 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2523
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2524 case FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2525 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2526 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2527 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2528
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2529 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2530 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2531 printf("%x\n",flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2532 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2533 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2535 t.uns64value = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2536 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2538
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2539 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2540 * Read in characters, converting them to real.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2541 * Bugs:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2542 * Exponent overflow not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2543 * Too much requested precision is not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2544 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2545 TOK inreal(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2546 in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2547 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2548 assert(*p == '.' || isdigit(*p));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2549 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2550 out (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2551 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2552 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2553 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2554 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2555 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2556 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2557 case TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2558 case TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2559 case TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2560 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2561
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2562 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2563 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2564 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2565 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2566 body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2567 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2568 int dblstate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2569 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2570 char hex; // is this a hexadecimal-floating-constant?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2571 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2573 //printf("Lexer.inreal()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2574 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2575 dblstate = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2576 hex = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2577 Lnext:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2578 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2579 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2580 // Get next char from input
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2581 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2582 //printf("dblstate = %d, c = '%c'\n", dblstate, c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2583 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2584 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2585 switch (dblstate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2586 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2587 case 0: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2588 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2589 dblstate = 9;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2590 else if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2591 dblstate = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2592 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2593 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2594 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2595
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2596 case 9:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2597 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2598 if (c == 'X' || c == 'x')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2599 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2600 hex++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2601 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2602 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2603 case 1: // digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2604 case 3: // digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2605 case 7: // continuing exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2606 if (!isdigit(c) && !(hex && isxdigit(c)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2607 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2608 if (c == '_')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2609 goto Lnext; // ignore embedded '_'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2610 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2611 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2612 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2613 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2614
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2615 case 2: // no more digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2616 if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2617 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2618 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2619 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2620 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2621 case 4: // no more digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2622 if ((c == 'E' || c == 'e') ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2623 hex && (c == 'P' || c == 'p'))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2624 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2625 dblstate = 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2626 hex = 0; // exponent is always decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2627 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2628 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2629 if (hex)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2630 error("binary-exponent-part required");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2631 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2633 case 5: // looking immediately to right of E
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2634 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2635 if (c == '-' || c == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2636 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2637 case 6: // 1st exponent digit expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2638 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2639 error("exponent expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2640 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2641 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2642
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2643 case 8: // past end of exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2644 goto done;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2645
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2646 default:
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2647 assert(0, "inreal.dblstate has unexpected value");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2648 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2649 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2650 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2651 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2652 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2653 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2654 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2655
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2656 stringbuffer.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2657
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
2658 version (Windows) { /// && __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2659 char* save = __locale_decpoint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2660 __locale_decpoint = cast(char*)".".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2661 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2662 t.float80value = strtold(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2664 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2665 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2666 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2667 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2668 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2669 strtof(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2670 result = TOKfloat32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2671 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2672 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2673
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2674 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2675 strtod(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2676 result = TOKfloat64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2677 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2678
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2679 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2680 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2681 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2682 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2683 result = TOKfloat80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2684 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2685 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2686 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2687 if (*p == 'i' || *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2688 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2689 if (!global.params.useDeprecated && *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2690 error("'I' suffix is deprecated, use 'i' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2691 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2692 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2693 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2694 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2695 result = TOKimaginary32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2696 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2697 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2698 result = TOKimaginary64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2699 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2700 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2701 result = TOKimaginary80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2702 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2703 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2704 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2705
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
2706 version (Windows) { ///&& __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2707 __locale_decpoint = save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2709 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2710 error("number is not representable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2711
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2712 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2713 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2714
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2715 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2716 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2717 error(this.loc, format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2718 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2719
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2720 void error(T...)(Loc loc, string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2721 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2722 if (mod && !global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2723 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2724 string p = loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2725 if (p.length != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2726 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2727
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2728 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2729
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2730 if (global.errors >= 20) // moderate blizzard of cascading messages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2731 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2732 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2733
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2734 global.errors++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2735 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2736
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2737 void pragma_()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2738 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2739 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2740 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2741
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2742 /********************************************
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2743 * Decode UTF character.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2744 * Issue error messages for invalid sequences.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2745 * Return decoded character, advance p to last character in UTF sequence.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2746 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2747 uint decodeUTF()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2748 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2749 dchar u;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2750 ubyte c;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2751 ubyte* s = p;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2752 size_t len;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2753 size_t idx;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2754 string msg;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2755
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2756 c = *s;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2757 assert(c & 0x80);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2758
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2759 // Check length of remaining string up to 6 UTF-8 characters
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2760 for (len = 1; len < 6 && s[len]; len++) {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2761 ;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2762 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2763
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2764 idx = 0;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2765 msg = utf_decodeChar(cast(string)s[0..len], &idx, &u);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2766 p += idx - 1;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2767 if (msg)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2768 {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2769 error("%s", msg);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2770 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2771 return u;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2772 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2773
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2774 void getDocComment(Token* t, uint lineComment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2775 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2776 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2777 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2778
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2779 static bool isValidIdentifier(string p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2780 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2781 if (p.length == 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2782 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2783 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2784
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2785 if (p[0] >= '0' && p[0] <= '9') { // beware of isdigit() on signed chars
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2786 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2787 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2788
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2789 size_t idx = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2790 while (idx < p.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2791 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2792 dchar dc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2793
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2794 if (utf_decodeChar(p, &idx, &dc) !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2795 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2796 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2797
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2798 if (!((dc >= 0x80 && isUniAlpha(dc)) || isalnum(dc) || dc == '_')) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2799 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2800 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2801 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2802
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2803 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2804 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2805
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2806 /// TODO: use normal string append when GC works
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2807 static string combineComments(const(char)[] c1, const(char)[] c2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2808 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2809 //writef("Lexer.combineComments('%s', '%s')\n", c1, c2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2810
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2811 char[] c = cast(char[]) c2;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2812
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2813 if (c1 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2814 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2815 c = cast(char[]) c1;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2816 if (c2 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2817 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2818 c = cast(char[]) (GC.malloc(c1.length + 1 + c2.length)[0 .. c1.length + 1 + c2.length]);
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2819 size_t len1 = c1.length;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2820 c[0..len1] = c1[];
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2821 c[len1++] = '\n';
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2822 c[len1 .. len1 + c2.length] = c2[];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2823 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2824 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2825
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2826 return cast(string)c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2827 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2828 }