annotate dmd/Lexer.d @ 135:af1bebfd96a4 dmd2037

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