annotate dmd/Lexer.d @ 73:ef02e2e203c2

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