annotate dmd/Lexer.d @ 51:b7d29f613539

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