annotate dmd/Lexer.d @ 114:e28b18c23469

added a module dmd.common for commonly used stuff it currently holds code for consistency checking of predefined versions also added a VisualD project file
author Trass3r
date Wed, 01 Sep 2010 18:21:58 +0200
parents 43073c7c7769
children 60bb0fe4563e
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] = "@";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 // For debugging
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 51
diff changeset
502 Token.tochars[TOKerror] = "error";
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 Token.tochars[TOK.TOKdotexp] = "dotexp";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 Token.tochars[TOK.TOKdotti] = "dotti";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 Token.tochars[TOK.TOKdotvar] = "dotvar";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 Token.tochars[TOK.TOKdottype] = "dottype";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 Token.tochars[TOK.TOKsymoff] = "symoff";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 Token.tochars[TOK.TOKarraylength] = "arraylength";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 Token.tochars[TOK.TOKarrayliteral] = "arrayliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 Token.tochars[TOK.TOKassocarrayliteral] = "assocarrayliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 Token.tochars[TOK.TOKstructliteral] = "structliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 Token.tochars[TOK.TOKstring] = "string";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 Token.tochars[TOK.TOKdsymbol] = "symbol";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 Token.tochars[TOK.TOKtuple] = "tuple";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 Token.tochars[TOK.TOKdeclaration] = "declaration";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 Token.tochars[TOK.TOKdottd] = "dottd";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 Token.tochars[TOK.TOKon_scope_exit] = "scope(exit)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 Token.tochars[TOK.TOKon_scope_success] = "scope(success)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 Token.tochars[TOK.TOKon_scope_failure] = "scope(failure)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 static Identifier idPool(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 StringValue* sv = stringtable.update(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 Identifier id = cast(Identifier) sv.ptrvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 if (id is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 sv.ptrvalue = cast(void*)id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 return id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 static Identifier uniqueId(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 static int num;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 return uniqueId(s, ++num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 /*********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 * Create a unique identifier using the prefix s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 static Identifier uniqueId(string s, int num)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 char buffer[32];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 size_t slen = s.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 assert(slen + num.sizeof * 3 + 1 <= buffer.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 int len = sprintf(buffer.ptr, "%.*s%d", s, num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 return idPool(buffer[0..len].idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 TOK nextToken()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 Token *t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 if (token.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 t = token.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 memcpy(&token, t, Token.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 t.next = freelist;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 freelist = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 scan(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 //token.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 return token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 /***********************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576 * Look ahead at next token's value.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 TOK peekNext()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 return peek(&token).value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 TOK peekNext2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 void scan(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 uint lastLine = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 uint linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 t.blockComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 t.lineComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 t.ptr = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 //printf("p = %p, *p = '%c'\n",p,*p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 t.value = TOK.TOKeof; // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 case '\t':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 case '\v':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 case '\f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 if (*p != '\n') // if CR stands by itself
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 case '0': case '1': case '2': case '3': case '4':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 case '5': case '6': case '7': case '8': case '9':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 t.value = number(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 version (CSTRINGS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 t.value = charConstant(t, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 t.value = stringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 if (p[1] == '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 t.value = charConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 else if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 t.value = stringConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 t.value = charConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 case 'r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 case '`':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 t.value = wysiwygStringConstant(t, *p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 t.value = hexStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 case 'q':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 t.value = delimitedStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 else if (p[1] == '{')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 t.value = tokenStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
689
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 t.value = escapeStringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 case '\\': // escaped string literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 { uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 ubyte* pstart = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 } while (*p == '\\');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
720 char* cc = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 memcpy(cc, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 t.ustring = cc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 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
727 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 case 'a': case 'b': case 'c': case 'd': case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 case 'f': case 'g': case 'h': case 'i': case 'j':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 case 'k': case 'm': case 'n': case 'o':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 case 'p': /*case 'q': case 'r':*/ case 's': case 't':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 } else {
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 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 case 'u': case 'v': case 'w': /*case 'x':*/ case 'y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 case 'z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 case 'A': case 'B': case 'C': case 'D': case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 case 'F': case 'G': case 'H': case 'I': case 'J':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 case 'K': case 'M': case 'N': case 'O':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 case 'P': case 'Q': case 'R': case 'S': case 'T':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 case 'U': case 'V': case 'W': case 'X': case 'Y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 case 'Z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 case_ident:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 { ubyte c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 StringValue *sv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 Identifier id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 } while (isidchar(c) || (c & 0x80 && isUniAlpha(decodeUTF())));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 sv = stringtable.update((cast(immutable(char)*)t.ptr)[0.. p - t.ptr]); ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 id = cast(Identifier) sv.ptrvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 if (id is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 { id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 sv.ptrvalue = cast(void*)id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 t.ident = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 t.value = cast(TOK) id.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 anyToken = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 if (*t.ptr == '_') // if special identifier token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 static char date[11+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 static char time[8+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 static char timestamp[24+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 if (!date[0]) // lazy evaluation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 { time_t tm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 char *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 .time(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 p = ctime(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 assert(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 sprintf(date.ptr, "%.6s %.4s", p + 4, p + 20);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 sprintf(time.ptr, "%.8s", p + 11);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 sprintf(timestamp.ptr, "%.24s", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 ///version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 /// if (mod && id == Id.FILE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 /// t.ustring = cast(ubyte*)(loc.filename ? loc.filename : mod.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 /// goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 /// else if (mod && id == Id.LINE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 /// t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 /// t.uns64value = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 /// else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 if (id == Id.DATE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 t.ustring = date.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 else if (id == Id.TIME)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 t.ustring = time.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 else if (id == Id.VENDOR)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 t.ustring = "Digital Mars D".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 else if (id == Id.TIMESTAMP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 t.ustring = timestamp.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 Lstr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 Llen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 t.len = strlen(cast(char*)t.ustring);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 else if (id == Id.VERSIONX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 uint major = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 uint minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 foreach (char cc; global.version_[1..$])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 if (isdigit(cc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 minor = minor * 10 + cc - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 else if (cc == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 major = minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 t.uns64value = major * 1000 + minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 else if (id == Id.EOFX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 // Advance scanner to end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 while (!(*p == 0 || *p == 0x1A))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 //printf("t.value = %d\n",t.value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 t.value = TOK.TOKdivass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 switch (c)
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 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 error("unterminated /* */ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 if (p[-2] == '*' && p - 3 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 else if (doDocComment && t.ptr[2] == '*' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 { // if /** but not /**/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 case '/': // do // style comments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 { ubyte c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 if (p[1] == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 if (doDocComment && t.ptr[2] == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 if (doDocComment && t.ptr[2] == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 int nest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 nest = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 { ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 nest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 if (*p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 if (--nest == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 error("unterminated /+ +/ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 if (doDocComment && t.ptr[2] == '+' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 { // if /++ but not /++/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 default:
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 t.value = TOK.TOKdiv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 if (isdigit(*p))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 { /* Note that we don't allow ._1 and ._ as being
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 * valid floating point numbers.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1059 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1060 t.value = inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1062 else if (p[0] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1063 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1064 if (p[1] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1065 { p += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1066 t.value = TOK.TOKdotdotdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1067 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1068 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1069 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1070 t.value = TOK.TOKslice;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1071 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1072 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1073 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1074 t.value = TOK.TOKdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1075 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 t.value = TOK.TOKandass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 else if (*p == '&')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 t.value = TOK.TOKandand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 t.value = TOK.TOKand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 case '|':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 t.value = TOK.TOKorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 else if (*p == '|')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 t.value = TOK.TOKoror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 t.value = TOK.TOKor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 case '-':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 t.value = TOK.TOKminass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 /// #if 0
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.TOKarrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 /// #endif
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 else if (*p == '-')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 t.value = TOK.TOKminusminus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 t.value = TOK.TOKmin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 t.value = TOK.TOKaddass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 else if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 t.value = TOK.TOKplusplus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 t.value = TOK.TOKadd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 case '<':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 t.value = TOK.TOKle; // <=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 t.value = TOK.TOKshlass; // <<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 t.value = TOK.TOKshl; // <<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 else if (*p == '>')
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.TOKleg; // <>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 t.value = TOK.TOKlg; // <>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 t.value = TOK.TOKlt; // <
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 case '>':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171 t.value = TOK.TOKge; // >=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 t.value = TOK.TOKshrass; // >>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 t.value = TOK.TOKushrass; // >>>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 t.value = TOK.TOKushr; // >>>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 t.value = TOK.TOKshr; // >>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 t.value = TOK.TOKgt; // >
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 case '!':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 t.value = TOK.TOKnotidentity; // !==
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.TOKnotequal; // !=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 t.value = TOK.TOKunord; // !<>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 t.value = TOK.TOKue; // !<>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 else if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 t.value = TOK.TOKug; // !<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 t.value = TOK.TOKuge; // !<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 t.value = TOK.TOKul; // !>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 t.value = TOK.TOKule; // !>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 t.value = TOK.TOKnot; // !
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 t.value = TOK.TOKidentity; // ===
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.TOKequal; // ==
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.TOKassign; // =
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 t.value = TOK.TOKcatass; // ~=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 t.value = TOK.TOKtilde; // ~
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 /*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 #define SINGLE(c,tok) case c: p++; t.value = tok; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 SINGLE('(', TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 SINGLE(')', TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 SINGLE('[', TOKlbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 SINGLE(']', TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 SINGLE('{', TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 SINGLE('}', TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 SINGLE('?', TOKquestion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 SINGLE(',', TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 SINGLE(';', TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 SINGLE(':', TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 SINGLE('$', TOKdollar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 SINGLE('@', TOKat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 #undef SINGLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 #define DOUBLE(c1,tok1,c2,tok2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 case c1: \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 if (*p == c2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 { p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 t.value = tok2; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 } \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 else \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 t.value = tok1; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290 DOUBLE('*', TOKmul, '=', TOKmulass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 DOUBLE('%', TOKmod, '=', TOKmodass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 DOUBLE('^', TOKxor, '=', TOKxorass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 #undef DOUBLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 case '(': p++; t.value = TOK.TOKlparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 case ')': p++; t.value = TOK.TOKrparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 case '[': p++; t.value = TOK.TOKlbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 case ']': p++; t.value = TOK.TOKrbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 case '{': p++; t.value = TOK.TOKlcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 case '}': p++; t.value = TOK.TOKrcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 case '?': p++; t.value = TOK.TOKquestion; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 case ',': p++; t.value = TOK.TOKcomma; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 case ';': p++; t.value = TOK.TOKsemicolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 case ':': p++; t.value = TOK.TOKcolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 case '$': p++; t.value = TOK.TOKdollar; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 case '@': p++; t.value = TOK.TOKat; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 t.value = TOK.TOKmulass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 t.value = TOK.TOKmul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1320 case '%':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 t.value = TOK.TOKmodass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326 t.value = TOK.TOKmod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 case '^':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 t.value = TOK.TOKxorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 t.value = TOK.TOKxor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 case '#':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 pragma_();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346 { ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 // Check for start of unicode identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 if (isUniAlpha(u))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 if (isprint(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 error("unsupported char '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 error("unsupported char 0x%02x", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373 Token* peek(Token* ct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 if (ct.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 t = ct.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 t = new Token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 scan(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 t.next = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 ct.next = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389 Token* peekPastParen(Token* tk)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 //printf("peekPastParen()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 int parens = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 int curlynest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 //tk.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 switch (tk.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 parens++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405 --parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 if (parens)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 curlynest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416 if (--curlynest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 if (curlynest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 * Parse escape sequence.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 uint escapeSequence()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 uint c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 int n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446 int ndigits;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452 case '?':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 Lconsume:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 p++;
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 'a': c = 7; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 case 'b': c = 8; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 case 'f': c = 12; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 case 'n': c = 10; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 case 'r': c = 13; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 case 't': c = 9; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 case 'v': c = 11; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 ndigits = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 ndigits = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 ndigits = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 Lhex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 if (ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 c -= '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487 else if (islower(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 c -= 'a' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 c -= 'A' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 v = v * 16 + c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 if (++n == ndigits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 if (!ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 { error("escape hex sequence has %d hex digits instead of %d", n, ndigits);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 if (ndigits != 2 && !utf_isValidDchar(v))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501 { error("invalid UTF character \\U%08x", v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 v = '?'; // recover with valid UTF character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 error("undefined escape hex sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 case '&': // named character entity
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 for (ubyte* idstart = ++p; true; p++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 case ';':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 c = HtmlNamedEntity(idstart, p - idstart);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 if (c == ~0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519 error("unnamed character entity &%s;", idstart[0..(p - idstart)]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 c = ' ';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 if (isalpha(*p) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 (p != idstart + 1 && isdigit(*p)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 error("unterminated named entity");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 case 0x1A: // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538 c = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 if (isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 v = v * 8 + (c - '0');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 } while (++n < 3 && isoctal(cast(ubyte)c));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 if (c > 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 error("0%03o is larger than a byte", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 error("undefined escape sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 TOK wysiwygStringConstant(Token* t, int tc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1566 uint c;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1567 Loc start = loc;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1568
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1569 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1570 stringbuffer.reset();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1571 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1572 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1573 c = *p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1574 switch (c)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1575 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1576 case '\n':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1577 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1578 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1579
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1580 case '\r':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1581 if (*p == '\n')
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1582 continue; // ignore
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1583 c = '\n'; // treat EndOfLine as \n character
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1584 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1585 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1586
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1587 case 0:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1588 case 0x1A:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1589 error("unterminated string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1590 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1591 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1592 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1593 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1594
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1595 case '"':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1596 case '`':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1597 if (c == tc)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1598 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1599 t.len = stringbuffer.offset;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1600 stringbuffer.writeByte(0);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1601 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1602 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1603 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1604 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1605 return TOKstring;
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 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1608
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1609 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1610 if (c & 0x80)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1611 { p--;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1612 uint u = decodeUTF();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1613 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1614 if (u == PS || u == LS)
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 stringbuffer.writeUTF8(u);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1617 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1618 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1619 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1620 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1621 stringbuffer.writeByte(c);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1622 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1623
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1627 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1628 * Lex hex strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1629 * x"0A ae 34FE BD"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1630 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631 TOK hexStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1633 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1634 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1635 uint n = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1636 uint v;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1637
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1638 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1639 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1640 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1641 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1642 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1643 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1644 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1645 case ' ':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1646 case '\t':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1647 case '\v':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1648 case '\f':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1649 continue; // skip white space
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1650
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1651 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1652 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1653 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1654 // Treat isolated '\r' as if it were a '\n'
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1655 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1656 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1657 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1658
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1659 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1660 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1661 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1662 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1663 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1664 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1665 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1666
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1667 case '"':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1668 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1669 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1670 error("odd number (%d) of hex characters in hex string", n);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1671 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1672 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1673 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1674 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1675 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1676 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1677 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1678 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1679 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1680
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1681 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1682 if (c >= '0' && c <= '9')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1683 c -= '0';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1684 else if (c >= 'a' && c <= 'f')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1685 c -= 'a' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1686 else if (c >= 'A' && c <= 'F')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1687 c -= 'A' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1688 else if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1689 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1690 uint u = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1691 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1692 if (u == PS || u == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1693 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1694 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1695 error("non-hex character \\u%x", u);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1696 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1697 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1698 error("non-hex character '%c'", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1699 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1700 { v = (v << 4) | c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1701 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1702 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1703 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1704 v = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1705 n++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1706 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1707 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1708 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1709 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1710
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1711 version (DMDV2) {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1712 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1713 * Lex delimited strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1714 * q"(foo(xxx))" // "foo(xxx)"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1715 * q"[foo(]" // "foo("
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1716 * q"/foo]/" // "foo]"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1717 * q"HERE
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1718 * foo
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1719 * HERE" // "foo\n"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1720 * Input:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1721 * p is on the "
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1722 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1723 TOK delimitedStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1724 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1725 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1726 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1727 uint delimleft = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1728 uint delimright = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1729 uint nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1730 uint nestcount;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1731 Identifier hereid = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1732 uint blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1733 uint startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1734
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1735 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1736 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1737 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1738 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1739 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1740 //printf("c = '%c'\n", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1741 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1742 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1743 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1744 Lnextline:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1745 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1746 startline = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1747 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1748 { blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1749 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1750 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1751 if (hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1752 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1753 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1754 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1755 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1756 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1757
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1758 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1759 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1760 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1761 c = '\n'; // treat EndOfLine as \n character
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1762 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1763
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1764 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1765 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1766 goto Lerror;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1767
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1768 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1769 if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1770 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1771 c = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1772 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1773 if (c == PS || c == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1774 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1775 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1776 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1777 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1778 if (delimleft == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1779 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1780 delimleft = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1781 nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1782 nestcount = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1783 if (c == '(')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1784 delimright = ')';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1785 else if (c == '{')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1786 delimright = '}';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1787 else if (c == '[')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1788 delimright = ']';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1789 else if (c == '<')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1790 delimright = '>';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1791 else if (isalpha(c) || c == '_' || (c >= 0x80 && isUniAlpha(c)))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1792 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1793 // Start of identifier; must be a heredoc
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1794 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1795 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1796 scan(&t2); // read in heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1797 if (t2.value != TOKidentifier)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1798 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1799 error("identifier expected for heredoc, not %s", t2.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1800 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1801 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1802 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1803 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1804 hereid = t2.ident;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1805 //printf("hereid = '%s'\n", hereid.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1806 blankrol = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1807 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1808 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1809 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1810 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1811 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1812 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1813 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1814 if (isspace(c))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1815 error("delimiter cannot be whitespace");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1816 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1817 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1818 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1819 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1820 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1821 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1822 error("heredoc rest of line should be blank");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1823 blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1824 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1825 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1826 if (nest == 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1827 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1828 if (c == delimleft)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1829 nestcount++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1830 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1831 { nestcount--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1832 if (nestcount == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1833 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1834 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1835 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1836 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1837 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1838 if (startline && isalpha(c) && hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1839 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1840 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1841 ubyte* psave = p;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1842 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1843 scan(&t2); // read in possible heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1844 //printf("endid = '%s'\n", t2.ident.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1845 if (t2.value == TOKidentifier && t2.ident.equals(hereid))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1846 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1847 /* should check that rest of line is blank
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1848 */
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1849 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1850 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1851 p = psave;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1852 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1853 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1854 startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1855 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1856 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1857
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1858 Ldone:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1859 if (*p == '"')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1860 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1861 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1862 error("delimited string must end in %c\"", delimright);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1863 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1864 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1865 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1866 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1867 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1868 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1869 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1870
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1871 Lerror:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1872 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1873 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1874 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1875 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1876 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1879 /**************************************
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1880 * Lex delimited strings:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1881 * q{ foo(xxx) } // " foo(xxx) "
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1882 * q{foo(} // "foo("
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1883 * q{{foo}"}"} // "{foo}"}""
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1884 * Input:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1885 * p is on the q
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1886 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 TOK tokenStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1889 uint nest = 1;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1890 Loc start = loc;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1891 ubyte* pstart = ++p;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1892
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1893 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1894 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1895 Token tok;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1896
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1897 scan(&tok);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1898 switch (tok.value)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1899 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1900 case TOKlcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1901 nest++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1902 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1903
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1904 case TOKrcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1905 if (--nest == 0)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1906 goto Ldone;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1907 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1908
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1909 case TOKeof:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1910 goto Lerror;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1911
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1912 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1913 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1914 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1915 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1916
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1917 Ldone:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1918 t.len = p - 1 - pstart;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1919 char* tmp = cast(char*)GC.malloc(t.len + 1);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1920 memcpy(tmp, pstart, t.len);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1921 tmp[t.len] = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1922 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1923 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1924 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1925
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1926 Lerror:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1927 error("unterminated token string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1928 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1929 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1930 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1931 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1932 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1933 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1934 TOK escapeStringConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1935 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1936 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1937 Loc start = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1938
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1939 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1940 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1941 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1942 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1943 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1944 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1945 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1946 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1947 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1948 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1949 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1950 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1951 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1952 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1953 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1954 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1955 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1956 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1957
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1958 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1959 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1960 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1961 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1962 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1964 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1965 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1966 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1967
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1968 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969 if (*p == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970 continue; // ignore
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1971 c = '\n'; // treat EndOfLine as \n character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1972 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1973 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1974
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1975 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1976 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1977 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1978 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1979 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1980 t.ustring = tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1981 stringPostfix(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1982 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1983
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1984 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1985 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1986 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1987 error("unterminated string constant starting at %s", start.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1988 t.ustring = "".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1989 t.len = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1990 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1991 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1992
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1993 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1994 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1995 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1996 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1997 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1998 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1999 { c = '\n';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2000 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2001 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2002 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2003 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2004 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2005 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2006 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2007 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2008 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2009 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2010
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2011 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2012 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2013
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2014 TOK charConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2015 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2016 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2017 TOK tk = TOKcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2018
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2019 //printf("Lexer.charConstant\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2020 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2021 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2022 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2023 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2024 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2025 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2026 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2027 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2028 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2029 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2030 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2031 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2032 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2033
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2034 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2035 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2036 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2037 tk = TOKdcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2038 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2039
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2040 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2041 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2042 break;
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 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2047 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2048 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2049 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2050 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2051 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2052 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2053 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2054 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2055
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2056 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2057 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2058 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2059 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2060 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2061 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2062 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2063 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2064 if (c < 0xD800 || (c >= 0xE000 && c < 0xFFFE))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2065 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2066 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2067 tk = TOKdcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2068 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2069 t.uns64value = c;
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2073 if (*p != '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2074 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2075 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2076 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2077 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2078 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2079 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2080 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2081
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2082 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2083 * Get postfix of string literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2084 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2085 void stringPostfix(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2086 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2087 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2088 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2089 case 'c':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2090 case 'w':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2091 case 'd':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2092 t.postfix = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2093 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2094 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2095
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2096 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2097 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2098 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2099 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2102 uint wchar_(uint u)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2103 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2104 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2107 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2108 * Read in a number.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2109 * If it's an integer, store it in tok.TKutok.Vlong.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2110 * integers can be decimal, octal or hex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2111 * Handle the suffixes U, UL, LU, L, etc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2112 * If it's double, store it in tok.TKutok.Vdouble.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2113 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2114 * TKnum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2115 * TKdouble,...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2116 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2117
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2118 TOK number(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2119 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2120 // We use a state machine to collect numbers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2121 enum STATE { STATE_initial, STATE_0, STATE_decimal, STATE_octal, STATE_octale,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2122 STATE_hex, STATE_binary, STATE_hex0, STATE_binary0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2123 STATE_hexh, STATE_error };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2124 STATE state;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2125
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2126 enum FLAGS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2128 FLAGS_undefined = 0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2129 FLAGS_decimal = 1, // decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2130 FLAGS_unsigned = 2, // u or U suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2131 FLAGS_long = 4, // l or L suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2132 };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2133
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2134 FLAGS flags = FLAGS.FLAGS_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2135
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2136 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2137 int base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2138 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2139 ubyte *start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2140 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2142 //printf("Lexer.number()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2143 state = STATE.STATE_initial;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2144 base = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2145 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2146 start = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2147 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2149 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2150 switch (state)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2151 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2152 case STATE.STATE_initial: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2153 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2154 state = STATE.STATE_0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2155 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2156 state = STATE.STATE_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2157 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2158
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2159 case STATE.STATE_0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2160 flags = (flags & ~FLAGS.FLAGS_decimal);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2161 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2162 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2163 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2164 case 'H': // 0h
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2165 case 'h':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2166 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2168 case 'X':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2169 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2170 state = STATE.STATE_hex0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2171 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2172
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2173 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2174 if (p[1] == '.') // .. is a separate token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2175 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2176 case 'i':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2177 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2178 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2179 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2180 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2181 case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2182 case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2183 goto case_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2184 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2185 case 'B':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2186 case 'b':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2187 state = STATE.STATE_binary0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2188 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2189
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2190 case '0': case '1': case '2': case '3':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2191 case '4': case '5': case '6': case '7':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2192 state = STATE.STATE_octal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2193 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2194
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2195 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2196 case '8': case '9': case 'A':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2197 case 'C': case 'D': case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2198 case 'a': case 'c': case 'd': case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2199 case_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2200 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2201 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2202 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2203 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2204 state = STATE.STATE_octal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2205 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2206 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2208 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2209 if (p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2210 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2211 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2212
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2213 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2214 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2216 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2218 case STATE.STATE_decimal: // reading decimal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2219 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2221 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2222 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2223 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2224 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2225 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2227 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2228 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2229 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2230 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2231 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2232 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2233 else if (c == 'i' || c == 'f' || c == 'F' ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2234 c == 'e' || c == 'E')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2235 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2236 real_: // It's a real number. Back up and rescan as a real
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2237 p = start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2238 return inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2240 else if (c == 'L' && p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2241 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2242 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2243 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2244 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2245
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2246 case STATE.STATE_hex0: // reading hex number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2247 case STATE.STATE_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2248 if (! ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2250 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2251 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2252 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2253 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2254 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2255 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2256 if (c == 'P' || c == 'p' || c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2257 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2258 if (state == STATE.STATE_hex0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2259 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2260 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2261 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2262 state = STATE.STATE_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2263 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2264
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2265 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2266 hexh:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2267 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2268 case STATE.STATE_hexh: // parse numbers like 0FFh
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2269 if (!ishex(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2270 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2271 if (c == 'H' || c == 'h')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2272 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2273 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2274 base = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2275 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2277 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2279 // Check for something like 1E3 or 0E24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2280 if (memchr(cast(char*)stringbuffer.data, 'E', stringbuffer.offset) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2281 memchr(cast(char*)stringbuffer.data, 'e', stringbuffer.offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2282 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2283 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2284 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2285 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2286 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2287 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2288 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2289
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2290 case STATE.STATE_octal: // reading octal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2291 case STATE.STATE_octale: // reading octal number with non-octal digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2292 if (!isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2293 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2294 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2295 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2296 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2297 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2298 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2300 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2301 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2302 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2303 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2304 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2305 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2306 if (c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2307 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2308 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2309 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2310 state = STATE.STATE_octale;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2311 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2312 else
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 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2317 case STATE.STATE_binary0: // starting binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2318 case STATE.STATE_binary: // reading binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2319 if (c != '0' && c != '1')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2321 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2322 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2323 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2324 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2325 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2326 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2327 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2328 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2329 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2330 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2331 if (state == STATE.STATE_binary0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2332 { error("binary digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2333 state = STATE.STATE_error;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2334 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2336 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2337 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2338 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2339 state = STATE.STATE_binary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2340 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2341
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2342 case STATE.STATE_error: // for error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2343 if (!isdigit(c)) // scan until non-digit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2344 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2345 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2346
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2347 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2348 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2350 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2351 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2352 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2353 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2354 stringbuffer.writeByte(0); // terminate string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2355 if (state == STATE.STATE_octale)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2356 error("Octal digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2357
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2358 ulong n; // unsigned >=64 bit integer type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2360 if (stringbuffer.offset == 2 && (state == STATE.STATE_decimal || state == STATE.STATE_0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2361 n = stringbuffer.data[0] - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2362 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2363 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2364 // Convert string to integer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2365 version (__DMC__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2366 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2367 n = strtoull(cast(char*)stringbuffer.data,null,base);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2368 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2369 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2370 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2371 // Not everybody implements strtoull()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2372 char* p = cast(char*)stringbuffer.data;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2373 int r = 10, d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2375 if (*p == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2377 if (p[1] == 'x' || p[1] == 'X')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2378 p += 2, r = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2379 else if (p[1] == 'b' || p[1] == 'B')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2380 p += 2, r = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2381 else if (isdigit(p[1]))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2382 p += 1, r = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2384
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2385 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2386 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2387 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2388 if (*p >= '0' && *p <= '9')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2389 d = *p - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2390 else if (*p >= 'a' && *p <= 'z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2391 d = *p - 'a' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2392 else if (*p >= 'A' && *p <= 'Z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2393 d = *p - 'A' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2394 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2395 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2396 if (d >= r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2397 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2398 ulong n2 = n * r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2399 //printf("n2 / r = %llx, n = %llx\n", n2/r, n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2400 if (n2 / r != n || n2 + d < n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2401 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2402 error ("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2403 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2404 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2406 n = n2 + d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2407 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2408 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2410 if (n.sizeof > 8 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2411 n > 0xFFFFFFFFFFFFFFFF) // if n needs more than 64 bits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2412 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2413 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2414
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2415 // Parse trailing 'u', 'U', 'l' or 'L' in any combination
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2416 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2417 { FLAGS f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2418
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2419 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2420 { case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2421 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2422 f = FLAGS.FLAGS_unsigned;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2423 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2424
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2425 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2426 if (1 || !global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2427 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2428 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2429 f = FLAGS.FLAGS_long;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2430 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2431 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2432 if (flags & f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2433 error("unrecognized token");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2434 flags = (flags | f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2435 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2436 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2437 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2438 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2439 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2440 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2441
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2442 switch (flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2443 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2444 case FLAGS.FLAGS_undefined:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2445 /* Octal or Hexadecimal constant.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2446 * First that fits: int, uint, long, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2447 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2448 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2449 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2450 else if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2451 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2452 else if (n & 0x80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2453 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2454 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2455 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2456 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2457
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2458 case FLAGS.FLAGS_decimal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2459 /* First that fits: int, long, long long
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2460 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2461 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2462 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2463 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2464 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2465 else if (n & 0xFFFFFFFF80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2466 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2467 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2468 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2469 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2470
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2471 case FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2472 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2473 /* First that fits: uint, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2474 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2475 if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2476 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2477 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2478 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2479 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2480
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2481 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2482 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2483 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2484 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2485 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2486 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2487 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2488 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2489
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2490 case FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2491 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2492 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2493 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2494 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2495 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2496
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2497 case FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2498 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2499 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2500 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2501
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2502 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2503 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2504 printf("%x\n",flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2506 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2507 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2508 t.uns64value = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2509 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2510 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2511
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2512 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2513 * Read in characters, converting them to real.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2514 * Bugs:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2515 * Exponent overflow not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2516 * Too much requested precision is not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2517 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2518 TOK inreal(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2519 in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2520 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2521 assert(*p == '.' || isdigit(*p));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2523 out (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2524 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2525 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2526 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2527 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2528 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2529 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2530 case TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2531 case TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2532 case TOKimaginary80v:
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 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2536 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2539 body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2540 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2541 int dblstate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2542 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2543 char hex; // is this a hexadecimal-floating-constant?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2544 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2545
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2546 //printf("Lexer.inreal()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2547 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2548 dblstate = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2549 hex = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2550 Lnext:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2551 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2552 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2553 // Get next char from input
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2554 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2555 //printf("dblstate = %d, c = '%c'\n", dblstate, c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2556 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2557 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2558 switch (dblstate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2559 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2560 case 0: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2561 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2562 dblstate = 9;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2563 else if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2564 dblstate = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2565 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2566 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2567 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2568
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2569 case 9:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2570 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2571 if (c == 'X' || c == 'x')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2572 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2573 hex++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2574 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2575 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2576 case 1: // digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2577 case 3: // digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2578 case 7: // continuing exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2579 if (!isdigit(c) && !(hex && isxdigit(c)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2580 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2581 if (c == '_')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2582 goto Lnext; // ignore embedded '_'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2583 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2584 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2585 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2586 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2587
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2588 case 2: // no more digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2589 if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2590 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2591 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2592 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2593 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2594 case 4: // no more digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2595 if ((c == 'E' || c == 'e') ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2596 hex && (c == 'P' || c == 'p'))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2597 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2598 dblstate = 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2599 hex = 0; // exponent is always decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2600 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2601 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2602 if (hex)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2603 error("binary-exponent-part required");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2604 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2605
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2606 case 5: // looking immediately to right of E
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2607 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2608 if (c == '-' || c == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2609 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2610 case 6: // 1st exponent digit expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2611 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2612 error("exponent expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2613 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2614 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2615
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2616 case 8: // past end of exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2617 goto done;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2618
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2619 default:
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2620 assert(0, "inreal.dblstate has unexpected value");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2621 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2622 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2623 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2624 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2625 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2626 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2627 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2628
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2629 stringbuffer.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2630
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
2631 version (Windows) { /// && __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2632 char* save = __locale_decpoint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2633 __locale_decpoint = cast(char*)".".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2634 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2635 t.float80value = strtold(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2636
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2637 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2638 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2639 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2640 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2641 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2642 strtof(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2643 result = TOKfloat32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2644 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2645 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2646
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2647 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2648 strtod(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2649 result = TOKfloat64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2650 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2651
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2652 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2653 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2654 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2655 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2656 result = TOKfloat80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2657 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2658 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2659 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2660 if (*p == 'i' || *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2661 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2662 if (!global.params.useDeprecated && *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2663 error("'I' suffix is deprecated, use 'i' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2664 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2665 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2666 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2667 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2668 result = TOKimaginary32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2669 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2670 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2671 result = TOKimaginary64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2672 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2673 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2674 result = TOKimaginary80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2675 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2676 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2677 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2678
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
2679 version (Windows) { ///&& __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2680 __locale_decpoint = save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2681 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2682 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2683 error("number is not representable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2684
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2685 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2686 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2687
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2688 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2689 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2690 error(this.loc, format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2691 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2692
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2693 void error(T...)(Loc loc, string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2694 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2695 if (mod && !global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2696 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2697 string p = loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2698 if (p.length != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2699 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2700
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2701 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2702
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2703 if (global.errors >= 20) // moderate blizzard of cascading messages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2704 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2705 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2706
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2707 global.errors++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2709
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2710 void pragma_()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2711 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2712 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2713 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2714
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2715 /********************************************
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2716 * Decode UTF character.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2717 * Issue error messages for invalid sequences.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2718 * Return decoded character, advance p to last character in UTF sequence.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2719 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2720 uint decodeUTF()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2721 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2722 dchar u;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2723 ubyte c;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2724 ubyte* s = p;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2725 size_t len;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2726 size_t idx;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2727 string msg;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2728
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2729 c = *s;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2730 assert(c & 0x80);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2731
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2732 // Check length of remaining string up to 6 UTF-8 characters
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2733 for (len = 1; len < 6 && s[len]; len++) {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2734 ;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2735 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2736
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2737 idx = 0;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2738 msg = utf_decodeChar(cast(string)s[0..len], &idx, &u);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2739 p += idx - 1;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2740 if (msg)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2741 {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2742 error("%s", msg);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2743 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
2744 return u;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2745 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2746
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2747 void getDocComment(Token* t, uint lineComment)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2748 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2749 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2750 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2751
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2752 static bool isValidIdentifier(string p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2753 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2754 if (p.length == 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2755 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2756 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2757
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2758 if (p[0] >= '0' && p[0] <= '9') { // beware of isdigit() on signed chars
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2759 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2760 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2761
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2762 size_t idx = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2763 while (idx < p.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2764 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2765 dchar dc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2766
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2767 if (utf_decodeChar(p, &idx, &dc) !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2768 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2769 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2770
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2771 if (!((dc >= 0x80 && isUniAlpha(dc)) || isalnum(dc) || dc == '_')) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2772 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2773 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2774 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2775
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2776 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2777 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2778
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2779 /// TODO: use normal string append when GC works
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2780 static string combineComments(const(char)[] c1, const(char)[] c2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2781 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2782 //writef("Lexer.combineComments('%s', '%s')\n", c1, c2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2783
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2784 char[] c = cast(char[]) c2;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2785
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2786 if (c1 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2787 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2788 c = cast(char[]) c1;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2789 if (c2 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2790 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2791 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
2792 size_t len1 = c1.length;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2793 c[0..len1] = c1[];
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2794 c[len1++] = '\n';
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2795 c[len1 .. len1 + c2.length] = c2[];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2796 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2797 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2798
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2799 return cast(string)c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2800 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2801 }