annotate dmd/Lexer.d @ 168:ceed63f310fb

stringtable, stringbuffer and freelist moved to Global
author korDen
date Thu, 30 Sep 2010 12:57:13 +0400
parents fe932c1a9563
children e7769d53e750
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Lexer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.StringTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Module;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Keyword;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.StringValue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.Dchar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Utf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import std.stdio : writeln;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
21 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
22
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import core.stdc.ctype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import core.stdc.stdio;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import core.stdc.time;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import core.stdc.errno;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 enum LS = 0x2028; // UTF line separator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 enum PS = 0x2029; // UTF paragraph separator
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 extern (C) extern
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 __gshared char* __locale_decpoint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
38 bool isUniAlpha(uint u)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
168
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
40 enum ushort table[][2] =
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
41 [
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
42 [ 0x00AA, 0x00AA ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
43 [ 0x00B5, 0x00B5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
44 [ 0x00B7, 0x00B7 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
45 [ 0x00BA, 0x00BA ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
46 [ 0x00C0, 0x00D6 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
47 [ 0x00D8, 0x00F6 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
48 [ 0x00F8, 0x01F5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
49 [ 0x01FA, 0x0217 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
50 [ 0x0250, 0x02A8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
51 [ 0x02B0, 0x02B8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
52 [ 0x02BB, 0x02BB ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
53 [ 0x02BD, 0x02C1 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
54 [ 0x02D0, 0x02D1 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
55 [ 0x02E0, 0x02E4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
56 [ 0x037A, 0x037A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
57 [ 0x0386, 0x0386 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
58 [ 0x0388, 0x038A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
59 [ 0x038C, 0x038C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
60 [ 0x038E, 0x03A1 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
61 [ 0x03A3, 0x03CE ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
62 [ 0x03D0, 0x03D6 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
63 [ 0x03DA, 0x03DA ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
64 [ 0x03DC, 0x03DC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
65 [ 0x03DE, 0x03DE ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
66 [ 0x03E0, 0x03E0 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
67 [ 0x03E2, 0x03F3 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
68 [ 0x0401, 0x040C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
69 [ 0x040E, 0x044F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
70 [ 0x0451, 0x045C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
71 [ 0x045E, 0x0481 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
72 [ 0x0490, 0x04C4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
73 [ 0x04C7, 0x04C8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
74 [ 0x04CB, 0x04CC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
75 [ 0x04D0, 0x04EB ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
76 [ 0x04EE, 0x04F5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
77 [ 0x04F8, 0x04F9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
78 [ 0x0531, 0x0556 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
79 [ 0x0559, 0x0559 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
80 [ 0x0561, 0x0587 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
81 [ 0x05B0, 0x05B9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
82 [ 0x05BB, 0x05BD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
83 [ 0x05BF, 0x05BF ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
84 [ 0x05C1, 0x05C2 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
85 [ 0x05D0, 0x05EA ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
86 [ 0x05F0, 0x05F2 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
87 [ 0x0621, 0x063A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
88 [ 0x0640, 0x0652 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
89 [ 0x0660, 0x0669 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
90 [ 0x0670, 0x06B7 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
91 [ 0x06BA, 0x06BE ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
92 [ 0x06C0, 0x06CE ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
93 [ 0x06D0, 0x06DC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
94 [ 0x06E5, 0x06E8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
95 [ 0x06EA, 0x06ED ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
96 [ 0x06F0, 0x06F9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
97 [ 0x0901, 0x0903 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
98 [ 0x0905, 0x0939 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
99 [ 0x093D, 0x093D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
100 [ 0x093E, 0x094D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
101 [ 0x0950, 0x0952 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
102 [ 0x0958, 0x0963 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
103 [ 0x0966, 0x096F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
104 [ 0x0981, 0x0983 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
105 [ 0x0985, 0x098C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
106 [ 0x098F, 0x0990 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
107 [ 0x0993, 0x09A8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
108 [ 0x09AA, 0x09B0 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
109 [ 0x09B2, 0x09B2 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
110 [ 0x09B6, 0x09B9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
111 [ 0x09BE, 0x09C4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
112 [ 0x09C7, 0x09C8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
113 [ 0x09CB, 0x09CD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
114 [ 0x09DC, 0x09DD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
115 [ 0x09DF, 0x09E3 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
116 [ 0x09E6, 0x09EF ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
117 [ 0x09F0, 0x09F1 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
118 [ 0x0A02, 0x0A02 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
119 [ 0x0A05, 0x0A0A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
120 [ 0x0A0F, 0x0A10 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
121 [ 0x0A13, 0x0A28 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
122 [ 0x0A2A, 0x0A30 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
123 [ 0x0A32, 0x0A33 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
124 [ 0x0A35, 0x0A36 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
125 [ 0x0A38, 0x0A39 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
126 [ 0x0A3E, 0x0A42 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
127 [ 0x0A47, 0x0A48 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
128 [ 0x0A4B, 0x0A4D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
129 [ 0x0A59, 0x0A5C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
130 [ 0x0A5E, 0x0A5E ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
131 [ 0x0A66, 0x0A6F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
132 [ 0x0A74, 0x0A74 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
133 [ 0x0A81, 0x0A83 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
134 [ 0x0A85, 0x0A8B ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
135 [ 0x0A8D, 0x0A8D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
136 [ 0x0A8F, 0x0A91 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
137 [ 0x0A93, 0x0AA8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
138 [ 0x0AAA, 0x0AB0 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
139 [ 0x0AB2, 0x0AB3 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
140 [ 0x0AB5, 0x0AB9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
141 [ 0x0ABD, 0x0AC5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
142 [ 0x0AC7, 0x0AC9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
143 [ 0x0ACB, 0x0ACD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
144 [ 0x0AD0, 0x0AD0 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
145 [ 0x0AE0, 0x0AE0 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
146 [ 0x0AE6, 0x0AEF ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
147 [ 0x0B01, 0x0B03 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
148 [ 0x0B05, 0x0B0C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
149 [ 0x0B0F, 0x0B10 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
150 [ 0x0B13, 0x0B28 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
151 [ 0x0B2A, 0x0B30 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
152 [ 0x0B32, 0x0B33 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
153 [ 0x0B36, 0x0B39 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
154 [ 0x0B3D, 0x0B3D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
155 [ 0x0B3E, 0x0B43 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
156 [ 0x0B47, 0x0B48 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
157 [ 0x0B4B, 0x0B4D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
158 [ 0x0B5C, 0x0B5D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
159 [ 0x0B5F, 0x0B61 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
160 [ 0x0B66, 0x0B6F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
161 [ 0x0B82, 0x0B83 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
162 [ 0x0B85, 0x0B8A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
163 [ 0x0B8E, 0x0B90 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
164 [ 0x0B92, 0x0B95 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
165 [ 0x0B99, 0x0B9A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
166 [ 0x0B9C, 0x0B9C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
167 [ 0x0B9E, 0x0B9F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
168 [ 0x0BA3, 0x0BA4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
169 [ 0x0BA8, 0x0BAA ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
170 [ 0x0BAE, 0x0BB5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
171 [ 0x0BB7, 0x0BB9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
172 [ 0x0BBE, 0x0BC2 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
173 [ 0x0BC6, 0x0BC8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
174 [ 0x0BCA, 0x0BCD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
175 [ 0x0BE7, 0x0BEF ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
176 [ 0x0C01, 0x0C03 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
177 [ 0x0C05, 0x0C0C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
178 [ 0x0C0E, 0x0C10 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
179 [ 0x0C12, 0x0C28 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
180 [ 0x0C2A, 0x0C33 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
181 [ 0x0C35, 0x0C39 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
182 [ 0x0C3E, 0x0C44 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
183 [ 0x0C46, 0x0C48 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
184 [ 0x0C4A, 0x0C4D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
185 [ 0x0C60, 0x0C61 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
186 [ 0x0C66, 0x0C6F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
187 [ 0x0C82, 0x0C83 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
188 [ 0x0C85, 0x0C8C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
189 [ 0x0C8E, 0x0C90 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
190 [ 0x0C92, 0x0CA8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
191 [ 0x0CAA, 0x0CB3 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
192 [ 0x0CB5, 0x0CB9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
193 [ 0x0CBE, 0x0CC4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
194 [ 0x0CC6, 0x0CC8 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
195 [ 0x0CCA, 0x0CCD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
196 [ 0x0CDE, 0x0CDE ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
197 [ 0x0CE0, 0x0CE1 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
198 [ 0x0CE6, 0x0CEF ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
199 [ 0x0D02, 0x0D03 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
200 [ 0x0D05, 0x0D0C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
201 [ 0x0D0E, 0x0D10 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
202 [ 0x0D12, 0x0D28 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
203 [ 0x0D2A, 0x0D39 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
204 [ 0x0D3E, 0x0D43 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
205 [ 0x0D46, 0x0D48 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
206 [ 0x0D4A, 0x0D4D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
207 [ 0x0D60, 0x0D61 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
208 [ 0x0D66, 0x0D6F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
209 [ 0x0E01, 0x0E3A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
210 [ 0x0E40, 0x0E5B ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
211 // { 0x0E50, 0x0E59 },
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
212 [ 0x0E81, 0x0E82 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
213 [ 0x0E84, 0x0E84 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
214 [ 0x0E87, 0x0E88 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
215 [ 0x0E8A, 0x0E8A ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
216 [ 0x0E8D, 0x0E8D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
217 [ 0x0E94, 0x0E97 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
218 [ 0x0E99, 0x0E9F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
219 [ 0x0EA1, 0x0EA3 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
220 [ 0x0EA5, 0x0EA5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
221 [ 0x0EA7, 0x0EA7 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
222 [ 0x0EAA, 0x0EAB ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
223 [ 0x0EAD, 0x0EAE ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
224 [ 0x0EB0, 0x0EB9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
225 [ 0x0EBB, 0x0EBD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
226 [ 0x0EC0, 0x0EC4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
227 [ 0x0EC6, 0x0EC6 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
228 [ 0x0EC8, 0x0ECD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
229 [ 0x0ED0, 0x0ED9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
230 [ 0x0EDC, 0x0EDD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
231 [ 0x0F00, 0x0F00 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
232 [ 0x0F18, 0x0F19 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
233 [ 0x0F20, 0x0F33 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
234 [ 0x0F35, 0x0F35 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
235 [ 0x0F37, 0x0F37 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
236 [ 0x0F39, 0x0F39 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
237 [ 0x0F3E, 0x0F47 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
238 [ 0x0F49, 0x0F69 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
239 [ 0x0F71, 0x0F84 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
240 [ 0x0F86, 0x0F8B ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
241 [ 0x0F90, 0x0F95 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
242 [ 0x0F97, 0x0F97 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
243 [ 0x0F99, 0x0FAD ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
244 [ 0x0FB1, 0x0FB7 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
245 [ 0x0FB9, 0x0FB9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
246 [ 0x10A0, 0x10C5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
247 [ 0x10D0, 0x10F6 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
248 [ 0x1E00, 0x1E9B ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
249 [ 0x1EA0, 0x1EF9 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
250 [ 0x1F00, 0x1F15 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
251 [ 0x1F18, 0x1F1D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
252 [ 0x1F20, 0x1F45 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
253 [ 0x1F48, 0x1F4D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
254 [ 0x1F50, 0x1F57 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
255 [ 0x1F59, 0x1F59 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
256 [ 0x1F5B, 0x1F5B ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
257 [ 0x1F5D, 0x1F5D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
258 [ 0x1F5F, 0x1F7D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
259 [ 0x1F80, 0x1FB4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
260 [ 0x1FB6, 0x1FBC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
261 [ 0x1FBE, 0x1FBE ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
262 [ 0x1FC2, 0x1FC4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
263 [ 0x1FC6, 0x1FCC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
264 [ 0x1FD0, 0x1FD3 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
265 [ 0x1FD6, 0x1FDB ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
266 [ 0x1FE0, 0x1FEC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
267 [ 0x1FF2, 0x1FF4 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
268 [ 0x1FF6, 0x1FFC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
269 [ 0x203F, 0x2040 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
270 [ 0x207F, 0x207F ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
271 [ 0x2102, 0x2102 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
272 [ 0x2107, 0x2107 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
273 [ 0x210A, 0x2113 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
274 [ 0x2115, 0x2115 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
275 [ 0x2118, 0x211D ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
276 [ 0x2124, 0x2124 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
277 [ 0x2126, 0x2126 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
278 [ 0x2128, 0x2128 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
279 [ 0x212A, 0x2131 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
280 [ 0x2133, 0x2138 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
281 [ 0x2160, 0x2182 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
282 [ 0x3005, 0x3007 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
283 [ 0x3021, 0x3029 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
284 [ 0x3041, 0x3093 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
285 [ 0x309B, 0x309C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
286 [ 0x30A1, 0x30F6 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
287 [ 0x30FB, 0x30FC ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
288 [ 0x3105, 0x312C ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
289 [ 0x4E00, 0x9FA5 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
290 [ 0xAC00, 0xD7A3 ],
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
291 ];
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
292
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
293 debug {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
294 for (int i = 0; i < table.length; i++)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
295 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
296 //printf("%x\n", table[i][0]);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
297 assert(table[i][0] <= table[i][1]);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
298 if (i < table.length - 1)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
299 assert(table[i][1] < table[i + 1][0]);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
300 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
301 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
302
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
303 if (u > 0xD7A3)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
304 goto Lisnot;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
305
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
306 // Binary search
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
307 int mid;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
308 int low;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
309 int high;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
310
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
311 low = 0;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
312 high = table.length - 1;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
313 while (low <= high)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
314 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
315 mid = (low + high) >> 1;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
316 if (u < table[mid][0])
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
317 high = mid - 1;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
318 else if (u > table[mid][1])
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
319 low = mid + 1;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
320 else
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
321 goto Lis;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
322 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
323
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
324 Lisnot:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
325 debug {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
326 for (int i = 0; i < table.length; i++)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
327 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
328 assert(u < table[i][0] || u > table[i][1]);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
329 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
330 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
331 return false;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
332
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
333 Lis:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
334 debug {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
335 for (int i = 0; i < table.length; i++)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
336 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
337 if (u >= table[i][0] && u <= table[i][1])
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
338 return 1;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
339 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
340 assert(0); // should have been in table
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
341 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
342 return true;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 class Lexer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 Loc loc; // for error messages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 ubyte* base; // pointer to start of buffer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 ubyte* end; // past end of buffer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 ubyte* p; // current character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 Token token;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 Module mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 int doDocComment; // collect doc comment information
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 int anyToken; // !=0 means seen at least one token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 int commentToken; // !=0 means comments are TOKcomment's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 this(Module mod, ubyte* base, uint begoffset, uint endoffset, int doDocComment, int commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 loc = Loc(mod, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 memset(&token,0,token.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 this.base = base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 this.end = base + endoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 p = base + begoffset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 this.mod = mod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 this.doDocComment = doDocComment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368 this.anyToken = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 this.commentToken = commentToken;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 //initKeywords();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 /* If first line starts with '#!', ignore the line
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 if (p[0] == '#' && p[1] =='!')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 p += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 if (*p == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 loc.linnum = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 static Keyword[] keywords =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 [
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416 // { "", TOK },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 { "this", TOK.TOKthis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 { "super", TOK.TOKsuper },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 { "assert", TOK.TOKassert },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 { "null", TOK.TOKnull },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 { "true", TOK.TOKtrue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 { "false", TOK.TOKfalse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 { "cast", TOK.TOKcast },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 { "new", TOK.TOKnew },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 { "delete", TOK.TOKdelete },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 { "throw", TOK.TOKthrow },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 { "module", TOK.TOKmodule },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 { "pragma", TOK.TOKpragma },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 { "typeof", TOK.TOKtypeof },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 { "typeid", TOK.TOKtypeid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 { "template", TOK.TOKtemplate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 { "void", TOK.TOKvoid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 { "byte", TOK.TOKint8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 { "ubyte", TOK.TOKuns8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 { "short", TOK.TOKint16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 { "ushort", TOK.TOKuns16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 { "int", TOK.TOKint32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 { "uint", TOK.TOKuns32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 { "long", TOK.TOKint64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 { "ulong", TOK.TOKuns64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 { "cent", TOK.TOKcent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 { "ucent", TOK.TOKucent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 { "float", TOK.TOKfloat32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 { "double", TOK.TOKfloat64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 { "real", TOK.TOKfloat80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 { "bool", TOK.TOKbool },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 { "char", TOK.TOKchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 { "wchar", TOK.TOKwchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 { "dchar", TOK.TOKdchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 { "ifloat", TOK.TOKimaginary32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 { "idouble", TOK.TOKimaginary64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 { "ireal", TOK.TOKimaginary80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 { "cfloat", TOK.TOKcomplex32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 { "cdouble", TOK.TOKcomplex64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 { "creal", TOK.TOKcomplex80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 { "delegate", TOK.TOKdelegate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 { "function", TOK.TOKfunction },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 { "is", TOK.TOKis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 { "if", TOK.TOKif },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 { "else", TOK.TOKelse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 { "while", TOK.TOKwhile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 { "for", TOK.TOKfor },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 { "do", TOK.TOKdo },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 { "switch", TOK.TOKswitch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 { "case", TOK.TOKcase },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 { "default", TOK.TOKdefault },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 { "break", TOK.TOKbreak },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 { "continue", TOK.TOKcontinue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 { "synchronized", TOK.TOKsynchronized },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 { "return", TOK.TOKreturn },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 { "goto", TOK.TOKgoto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 { "try", TOK.TOKtry },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 { "catch", TOK.TOKcatch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 { "finally", TOK.TOKfinally },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 { "with", TOK.TOKwith },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 { "asm", TOK.TOKasm },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 { "foreach", TOK.TOKforeach },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 { "foreach_reverse", TOK.TOKforeach_reverse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 { "scope", TOK.TOKscope },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 { "struct", TOK.TOKstruct },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 { "class", TOK.TOKclass },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 { "interface", TOK.TOKinterface },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 { "union", TOK.TOKunion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 { "enum", TOK.TOKenum },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 { "import", TOK.TOKimport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 { "mixin", TOK.TOKmixin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 { "static", TOK.TOKstatic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 { "final", TOK.TOKfinal },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 { "const", TOK.TOKconst },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 { "typedef", TOK.TOKtypedef },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 { "alias", TOK.TOKalias },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 { "override", TOK.TOKoverride },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 { "abstract", TOK.TOKabstract },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 { "volatile", TOK.TOKvolatile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 { "debug", TOK.TOKdebug },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 { "deprecated", TOK.TOKdeprecated },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 { "in", TOK.TOKin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 { "out", TOK.TOKout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 { "inout", TOK.TOKinout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 { "lazy", TOK.TOKlazy },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 { "auto", TOK.TOKauto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 { "align", TOK.TOKalign },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 { "extern", TOK.TOKextern },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 { "private", TOK.TOKprivate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 { "package", TOK.TOKpackage },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 { "protected", TOK.TOKprotected },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 { "public", TOK.TOKpublic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 { "export", TOK.TOKexport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520 { "body", TOK.TOKbody },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 { "invariant", TOK.TOKinvariant },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 { "unittest", TOK.TOKunittest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 { "version", TOK.TOKversion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 //{ "manifest", TOK.TOKmanifest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 // Added after 1.0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 { "ref", TOK.TOKref },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 { "macro", TOK.TOKmacro },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 { "pure", TOK.TOKpure },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530 { "nothrow", TOK.TOKnothrow },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 { "__thread", TOK.TOKtls },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 { "__gshared", TOK.TOKgshared },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 { "__traits", TOK.TOKtraits },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 { "__overloadset", TOK.TOKoverloadset },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 { "__FILE__", TOK.TOKfile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 { "__LINE__", TOK.TOKline },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 { "shared", TOK.TOKshared },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 { "immutable", TOK.TOKimmutable },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541 static Keyword[] keywords =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 [
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 // { "", TOK },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 { "this", TOK.TOKthis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 { "super", TOK.TOKsuper },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 { "assert", TOK.TOKassert },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 { "null", TOK.TOKnull },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 { "true", TOK.TOKtrue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 { "false", TOK.TOKfalse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 { "cast", TOK.TOKcast },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 { "new", TOK.TOKnew },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 { "delete", TOK.TOKdelete },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 { "throw", TOK.TOKthrow },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 { "module", TOK.TOKmodule },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556 { "pragma", TOK.TOKpragma },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 { "typeof", TOK.TOKtypeof },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 { "typeid", TOK.TOKtypeid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 { "template", TOK.TOKtemplate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562 { "void", TOK.TOKvoid },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 { "byte", TOK.TOKint8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 { "ubyte", TOK.TOKuns8 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565 { "short", TOK.TOKint16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 { "ushort", TOK.TOKuns16 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 { "int", TOK.TOKint32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 { "uint", TOK.TOKuns32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 { "long", TOK.TOKint64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570 { "ulong", TOK.TOKuns64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 { "cent", TOK.TOKcent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 { "ucent", TOK.TOKucent, },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 { "float", TOK.TOKfloat32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574 { "double", TOK.TOKfloat64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 { "real", TOK.TOKfloat80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 { "bool", TOK.TOKbool },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 { "char", TOK.TOKchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 { "wchar", TOK.TOKwchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 { "dchar", TOK.TOKdchar },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 { "ifloat", TOK.TOKimaginary32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 { "idouble", TOK.TOKimaginary64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 { "ireal", TOK.TOKimaginary80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 { "cfloat", TOK.TOKcomplex32 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 { "cdouble", TOK.TOKcomplex64 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 { "creal", TOK.TOKcomplex80 },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 { "delegate", TOK.TOKdelegate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 { "function", TOK.TOKfunction },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593 { "is", TOK.TOKis },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 { "if", TOK.TOKif },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 { "else", TOK.TOKelse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 { "while", TOK.TOKwhile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 { "for", TOK.TOKfor },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 { "do", TOK.TOKdo },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 { "switch", TOK.TOKswitch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 { "case", TOK.TOKcase },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 { "default", TOK.TOKdefault },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602 { "break", TOK.TOKbreak },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 { "continue", TOK.TOKcontinue },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 { "synchronized", TOK.TOKsynchronized },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 { "return", TOK.TOKreturn },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 { "goto", TOK.TOKgoto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607 { "try", TOK.TOKtry },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 { "catch", TOK.TOKcatch },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 { "finally", TOK.TOKfinally },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
610 { "with", TOK.TOKwith },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
611 { "asm", TOK.TOKasm },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612 { "foreach", TOK.TOKforeach },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 { "foreach_reverse", TOK.TOKforeach_reverse },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 { "scope", TOK.TOKscope },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 { "struct", TOK.TOKstruct },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 { "class", TOK.TOKclass },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 { "interface", TOK.TOKinterface },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 { "union", TOK.TOKunion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 { "enum", TOK.TOKenum },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 { "import", TOK.TOKimport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 { "mixin", TOK.TOKmixin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 { "static", TOK.TOKstatic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
624 { "final", TOK.TOKfinal },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
625 { "const", TOK.TOKconst },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626 { "typedef", TOK.TOKtypedef },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 { "alias", TOK.TOKalias },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 { "override", TOK.TOKoverride },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 { "abstract", TOK.TOKabstract },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 { "volatile", TOK.TOKvolatile },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 { "debug", TOK.TOKdebug },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 { "deprecated", TOK.TOKdeprecated },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 { "in", TOK.TOKin },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 { "out", TOK.TOKout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 { "inout", TOK.TOKinout },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 { "lazy", TOK.TOKlazy },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 { "auto", TOK.TOKauto },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 { "align", TOK.TOKalign },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 { "extern", TOK.TOKextern },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641 { "private", TOK.TOKprivate },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 { "package", TOK.TOKpackage },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
643 { "protected", TOK.TOKprotected },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 { "public", TOK.TOKpublic },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 { "export", TOK.TOKexport },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647 { "body", TOK.TOKbody },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 { "invariant", TOK.TOKinvariant },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 { "unittest", TOK.TOKunittest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 { "version", TOK.TOKversion },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 //{ "manifest", TOK.TOKmanifest },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
653 // Added after 1.0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 { "ref", TOK.TOKref },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 { "macro", TOK.TOKmacro },
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 static ubyte cmtable[256];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 enum CMoctal = 0x1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 enum CMhex = 0x2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 enum CMidchar = 0x4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 ubyte isoctal (ubyte c) { return cmtable[c] & CMoctal; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665 ubyte ishex (ubyte c) { return cmtable[c] & CMhex; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 ubyte isidchar(ubyte c) { return cmtable[c] & CMidchar; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
667
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 static void cmtable_init()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 for (uint c = 0; c < cmtable.length; c++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 if ('0' <= c && c <= '7')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
673 cmtable[c] |= CMoctal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 if (isdigit(c) || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F'))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675 cmtable[c] |= CMhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 if (isalnum(c) || c == '_')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 cmtable[c] |= CMidchar;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 }
168
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
680
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
681 static StringTable stringtable()
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
682 {
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
683 return global.stringtable;
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
684 }
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
685
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
686 static OutBuffer stringbuffer()
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
687 {
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
688 return global.stringbuffer;
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
689 }
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
690
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 static void initKeywords()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 uint nkeywords = keywords.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 if (global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 nkeywords -= 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 cmtable_init();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 for (uint u = 0; u < nkeywords; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 {
34
544b922227c7 update to work with dmd 2.048
korDen
parents: 8
diff changeset
702 //printf("keyword[%d] = '%.*s'\n",u, keywords[u].name);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 string s = keywords[u].name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 TOK v = keywords[u].value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 StringValue* sv = stringtable.insert(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
706 sv.ptrvalue = cast(void*) new Identifier(sv.lstring.string_, v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 //printf("tochars[%d] = '%s'\n",v, s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 Token.tochars[v] = s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 Token.tochars[TOK.TOKeof] = "EOF";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 Token.tochars[TOK.TOKlcurly] = "{";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 Token.tochars[TOK.TOKrcurly] = "}";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 Token.tochars[TOK.TOKlparen] = "(";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 Token.tochars[TOK.TOKrparen] = ")";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 Token.tochars[TOK.TOKlbracket] = "[";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 Token.tochars[TOK.TOKrbracket] = "]";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719 Token.tochars[TOK.TOKsemicolon] = ";";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 Token.tochars[TOK.TOKcolon] = ":";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 Token.tochars[TOK.TOKcomma] = ",";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 Token.tochars[TOK.TOKdot] = ".";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 Token.tochars[TOK.TOKxor] = "^";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 Token.tochars[TOK.TOKxorass] = "^=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725 Token.tochars[TOK.TOKassign] = "=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 Token.tochars[TOK.TOKconstruct] = "=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 Token.tochars[TOK.TOKblit] = "=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 Token.tochars[TOK.TOKlt] = "<";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 Token.tochars[TOK.TOKgt] = ">";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732 Token.tochars[TOK.TOKle] = "<=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 Token.tochars[TOK.TOKge] = ">=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 Token.tochars[TOK.TOKequal] = "==";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
735 Token.tochars[TOK.TOKnotequal] = "!=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 Token.tochars[TOK.TOKnotidentity] = "!is";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 Token.tochars[TOK.TOKtobool] = "!!";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 Token.tochars[TOK.TOKunord] = "!<>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 Token.tochars[TOK.TOKue] = "!<>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 Token.tochars[TOK.TOKlg] = "<>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 Token.tochars[TOK.TOKleg] = "<>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 Token.tochars[TOK.TOKule] = "!>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744 Token.tochars[TOK.TOKul] = "!>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 Token.tochars[TOK.TOKuge] = "!<";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746 Token.tochars[TOK.TOKug] = "!<=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 Token.tochars[TOK.TOKnot] = "!";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
749 Token.tochars[TOK.TOKtobool] = "!!";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 Token.tochars[TOK.TOKshl] = "<<";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751 Token.tochars[TOK.TOKshr] = ">>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 Token.tochars[TOK.TOKushr] = ">>>";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 Token.tochars[TOK.TOKadd] = "+";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
754 Token.tochars[TOK.TOKmin] = "-";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 Token.tochars[TOK.TOKmul] = "*";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 Token.tochars[TOK.TOKdiv] = "/";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 Token.tochars[TOK.TOKmod] = "%";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 Token.tochars[TOK.TOKslice] = "..";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 Token.tochars[TOK.TOKdotdotdot] = "...";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 Token.tochars[TOK.TOKand] = "&";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 Token.tochars[TOK.TOKandand] = "&&";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
762 Token.tochars[TOK.TOKor] = "|";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 Token.tochars[TOK.TOKoror] = "||";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 Token.tochars[TOK.TOKarray] = "[]";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 Token.tochars[TOK.TOKindex] = "[i]";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 Token.tochars[TOK.TOKaddress] = "&";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 Token.tochars[TOK.TOKstar] = "*";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 Token.tochars[TOK.TOKtilde] = "~";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 Token.tochars[TOK.TOKdollar] = "$";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 Token.tochars[TOK.TOKcast] = "cast";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 Token.tochars[TOK.TOKplusplus] = "++";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 Token.tochars[TOK.TOKminusminus] = "--";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773 Token.tochars[TOK.TOKtype] = "type";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 Token.tochars[TOK.TOKquestion] = "?";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 Token.tochars[TOK.TOKneg] = "-";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776 Token.tochars[TOK.TOKuadd] = "+";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 Token.tochars[TOK.TOKvar] = "var";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 Token.tochars[TOK.TOKaddass] = "+=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
779 Token.tochars[TOK.TOKminass] = "-=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 Token.tochars[TOK.TOKmulass] = "*=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781 Token.tochars[TOK.TOKdivass] = "/=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 Token.tochars[TOK.TOKmodass] = "%=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 Token.tochars[TOK.TOKshlass] = "<<=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
784 Token.tochars[TOK.TOKshrass] = ">>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 Token.tochars[TOK.TOKushrass] = ">>>=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 Token.tochars[TOK.TOKandass] = "&=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 Token.tochars[TOK.TOKorass] = "|=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 Token.tochars[TOK.TOKcatass] = "~=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 Token.tochars[TOK.TOKcat] = "~";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 Token.tochars[TOK.TOKcall] = "call";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 Token.tochars[TOK.TOKidentity] = "is";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
792 Token.tochars[TOK.TOKnotidentity] = "!is";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 Token.tochars[TOK.TOKorass] = "|=";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 Token.tochars[TOK.TOKidentifier] = "identifier";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 Token.tochars[TOK.TOKat] = "@";
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
797 Token.tochars[TOK.TOKpow] = "^^";
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
798 Token.tochars[TOK.TOKpowass] = "^^=";
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
799
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 // For debugging
73
ef02e2e203c2 Updating to dmd2.033
korDen
parents: 51
diff changeset
801 Token.tochars[TOKerror] = "error";
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 Token.tochars[TOK.TOKdotexp] = "dotexp";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 Token.tochars[TOK.TOKdotti] = "dotti";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804 Token.tochars[TOK.TOKdotvar] = "dotvar";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 Token.tochars[TOK.TOKdottype] = "dottype";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 Token.tochars[TOK.TOKsymoff] = "symoff";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
807 Token.tochars[TOK.TOKarraylength] = "arraylength";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 Token.tochars[TOK.TOKarrayliteral] = "arrayliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 Token.tochars[TOK.TOKassocarrayliteral] = "assocarrayliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 Token.tochars[TOK.TOKstructliteral] = "structliteral";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 Token.tochars[TOK.TOKstring] = "string";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 Token.tochars[TOK.TOKdsymbol] = "symbol";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 Token.tochars[TOK.TOKtuple] = "tuple";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 Token.tochars[TOK.TOKdeclaration] = "declaration";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 Token.tochars[TOK.TOKdottd] = "dottd";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 Token.tochars[TOK.TOKon_scope_exit] = "scope(exit)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 Token.tochars[TOK.TOKon_scope_success] = "scope(success)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 Token.tochars[TOK.TOKon_scope_failure] = "scope(failure)";
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 static Identifier idPool(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
822 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 StringValue* sv = stringtable.update(s);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 Identifier id = cast(Identifier) sv.ptrvalue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 if (id is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828 sv.ptrvalue = cast(void*)id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 return id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 static Identifier uniqueId(string s)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 {
168
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
836 return uniqueId(s, ++global.num);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 /*********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840 * Create a unique identifier using the prefix s.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
842 static Identifier uniqueId(string s, int num)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844 char buffer[32];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 size_t slen = s.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 assert(slen + num.sizeof * 3 + 1 <= buffer.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 int len = sprintf(buffer.ptr, "%.*s%d", s, num);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 return idPool(buffer[0..len].idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 TOK nextToken()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 Token *t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 if (token.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 t = token.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 memcpy(&token, t, Token.sizeof);
168
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
861 t.next = global.freelist;
ceed63f310fb stringtable, stringbuffer and freelist moved to Global
korDen
parents: 163
diff changeset
862 global.freelist = t;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 scan(&token);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 //token.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 return token.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 /***********************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874 * Look ahead at next token's value.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 TOK peekNext()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 return peek(&token).value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
881 /***********************
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
882 * Look 2 tokens ahead at value.
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
883 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
884 TOK peekNext2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 {
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
886 Token* t = peek(&token);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
887 return peek(t).value;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 void scan(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 uint lastLine = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 uint linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 t.blockComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 t.lineComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 t.ptr = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 //printf("p = %p, *p = '%c'\n",p,*p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 t.value = TOK.TOKeof; // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 case '\t':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 case '\v':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 case '\f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 if (*p != '\n') // if CR stands by itself
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 case '0': case '1': case '2': case '3': case '4':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 case '5': case '6': case '7': case '8': case '9':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 t.value = number(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 version (CSTRINGS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 t.value = charConstant(t, 0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 t.value = stringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 if (p[1] == '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 t.value = charConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 else if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 t.value = stringConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 t.value = charConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 case 'r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 case '`':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 t.value = wysiwygStringConstant(t, *p);
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 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 t.value = hexStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 case 'q':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 t.value = delimitedStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 else if (p[1] == '{')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 t.value = tokenStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 t.value = escapeStringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997 case '\\': // escaped string literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 { uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 ubyte* pstart = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019 } while (*p == '\\');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1022 char* cc = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 memcpy(cc, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 t.ustring = cc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1028 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
1029 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1035 case 'a': case 'b': case 'c': case 'd': case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 case 'f': case 'g': case 'h': case 'i': case 'j':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 case 'k': case 'm': case 'n': case 'o':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 case 'p': /*case 'q': case 'r':*/ case 's': case 't':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 case 'p': case 'q': /*case 'r':*/ case 's': case 't':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 case 'u': case 'v': case 'w': /*case 'x':*/ case 'y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 case 'z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 case 'A': case 'B': case 'C': case 'D': case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 case 'F': case 'G': case 'H': case 'I': case 'J':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 case 'K': case 'M': case 'N': case 'O':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 case 'P': case 'Q': case 'R': case 'S': case 'T':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 case 'U': case 'V': case 'W': case 'X': case 'Y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 case 'Z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 case_ident:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1053 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1054 ubyte c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1056 while (1)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1057 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1058 c = *++p;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1059 if (isidchar(c))
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1060 continue;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1061 else if (c & 0x80)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1062 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1063 ubyte *s = p;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1064 uint u = decodeUTF();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1065 if (isUniAlpha(u))
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1066 continue;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1067 error("char 0x%04x not allowed in identifier", u);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1068 p = s;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1069 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1070 break;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1071 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1072
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1073 StringValue *sv = stringtable.update((cast(immutable(char)*)t.ptr)[0.. p - t.ptr]);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1074 Identifier id = cast(Identifier) sv.ptrvalue;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1075
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1076 if (id is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1077 { id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1078 sv.ptrvalue = cast(void*)id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1079 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1080 t.ident = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1081 t.value = cast(TOK) id.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 anyToken = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 if (*t.ptr == '_') // if special identifier token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 static char date[11+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 static char time[8+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 static char timestamp[24+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 if (!date[0]) // lazy evaluation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 { time_t tm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 char *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 .time(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094 p = ctime(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 assert(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 sprintf(date.ptr, "%.6s %.4s", p + 4, p + 20);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 sprintf(time.ptr, "%.8s", p + 11);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098 sprintf(timestamp.ptr, "%.24s", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 ///version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 /// if (mod && id == Id.FILE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 /// t.ustring = cast(ubyte*)(loc.filename ? loc.filename : mod.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 /// goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 /// else if (mod && id == Id.LINE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 /// t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 /// t.uns64value = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 /// else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 if (id == Id.DATE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 t.ustring = date.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 else if (id == Id.TIME)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 t.ustring = time.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 else if (id == Id.VENDOR)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 t.ustring = "Digital Mars D".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 else if (id == Id.TIMESTAMP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 t.ustring = timestamp.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 Lstr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 Llen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 t.len = strlen(cast(char*)t.ustring);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 else if (id == Id.VERSIONX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 uint major = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 uint minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 foreach (char cc; global.version_[1..$])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 if (isdigit(cc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 minor = minor * 10 + cc - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 else if (cc == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 major = minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 t.uns64value = major * 1000 + minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 else if (id == Id.EOFX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 // Advance scanner to end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 while (!(*p == 0 || *p == 0x1A))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 //printf("t.value = %d\n",t.value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1177 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1178 t.value = TOK.TOKdivass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1179 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1180
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 error("unterminated /* */ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 if (p[-2] == '*' && p - 3 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1227 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1228 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1229 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 else if (doDocComment && t.ptr[2] == '*' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 { // if /** but not /**/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 case '/': // do // style comments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 { ubyte c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 if (p[1] == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 }
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
1260 if (doDocComment && t.ptr[2] == '/' || t.ptr[2] == '!') // '///' or '//!'
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1266 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1277 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1278 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 }
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
1284 if (doDocComment && t.ptr[2] == '/' || t.ptr[2] == '!') // '///' or '//!'
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1290
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 int nest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 nest = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 { ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 nest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 if (*p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316 if (--nest == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1320
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 error("unterminated /+ +/ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355 if (doDocComment && t.ptr[2] == '+' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356 { // if /++ but not /++/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 t.value = TOK.TOKdiv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 if (isdigit(*p))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 { /* Note that we don't allow ._1 and ._ as being
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372 * valid floating point numbers.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 t.value = inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 else if (p[0] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 if (p[1] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 { p += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 t.value = TOK.TOKdotdotdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 t.value = TOK.TOKslice;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389 t.value = TOK.TOKdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 t.value = TOK.TOKandass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 else if (*p == '&')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 t.value = TOK.TOKandand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403 t.value = TOK.TOKand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 case '|':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 t.value = TOK.TOKorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 else if (*p == '|')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414 t.value = TOK.TOKoror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 t.value = TOK.TOKor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 case '-':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 t.value = TOK.TOKminass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 /// #if 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 /// else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 /// { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 /// t.value = TOK.TOKarrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 /// #endif
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 else if (*p == '-')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 t.value = TOK.TOKminusminus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 t.value = TOK.TOKmin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 t.value = TOK.TOKaddass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446 else if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 t.value = TOK.TOKplusplus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 t.value = TOK.TOKadd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 case '<':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458 t.value = TOK.TOKle; // <=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 t.value = TOK.TOKshlass; // <<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 t.value = TOK.TOKshl; // <<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 t.value = TOK.TOKleg; // <>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 t.value = TOK.TOKlg; // <>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 t.value = TOK.TOKlt; // <
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 case '>':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 t.value = TOK.TOKge; // >=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 t.value = TOK.TOKshrass; // >>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 t.value = TOK.TOKushrass; // >>>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501 t.value = TOK.TOKushr; // >>>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 t.value = TOK.TOKshr; // >>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 t.value = TOK.TOKgt; // >
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 case '!':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 t.value = TOK.TOKnotidentity; // !==
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519 t.value = TOK.TOKnotequal; // !=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 t.value = TOK.TOKunord; // !<>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 t.value = TOK.TOKue; // !<>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 else if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 t.value = TOK.TOKug; // !<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 t.value = TOK.TOKuge; // !<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 t.value = TOK.TOKul; // !>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 t.value = TOK.TOKule; // !>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 t.value = TOK.TOKnot; // !
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 t.value = TOK.TOKidentity; // ===
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 t.value = TOK.TOKequal; // ==
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 t.value = TOK.TOKassign; // =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567 case '~':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 t.value = TOK.TOKcatass; // ~=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 t.value = TOK.TOKtilde; // ~
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1576
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1577 version(DMDV2) {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1578 case '^':
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1579 p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1580 if (*p == '^')
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1581 { p++;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1582 if (*p == '=')
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1583 { p++;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1584 t.value = TOKpowass; // ^^=
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1585 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1586 else
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1587 t.value = TOKpow; // ^^
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1588 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1589 else if (*p == '=')
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1590 { p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1591 t.value = TOKxorass; // ^=
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1592 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1593 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1594 t.value = TOKxor; // ^
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1595 return;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1596 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1597
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1598 /*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1599 #define SINGLE(c,tok) case c: p++; t.value = tok; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1600
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1601 SINGLE('(', TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1602 SINGLE(')', TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1603 SINGLE('[', TOKlbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1604 SINGLE(']', TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1605 SINGLE('{', TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606 SINGLE('}', TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 SINGLE('?', TOKquestion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608 SINGLE(',', TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 SINGLE(';', TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610 SINGLE(':', TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1611 SINGLE('$', TOKdollar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1612 SINGLE('@', TOKat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1613
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1614 #undef SINGLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616 #define DOUBLE(c1,tok1,c2,tok2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617 case c1: \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1618 p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1619 if (*p == c2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1620 { p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621 t.value = tok2; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1622 } \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 else \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 t.value = tok1; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1627 DOUBLE('*', TOKmul, '=', TOKmulass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 DOUBLE('%', TOKmod, '=', TOKmodass)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1629 #if DMDV1
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 DOUBLE('^', TOKxor, '=', TOKxorass)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1631 #endif
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632 #undef DOUBLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1635 case '(': p++; t.value = TOK.TOKlparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1636 case ')': p++; t.value = TOK.TOKrparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1637 case '[': p++; t.value = TOK.TOKlbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1638 case ']': p++; t.value = TOK.TOKrbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 case '{': p++; t.value = TOK.TOKlcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640 case '}': p++; t.value = TOK.TOKrcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641 case '?': p++; t.value = TOK.TOKquestion; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642 case ',': p++; t.value = TOK.TOKcomma; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 case ';': p++; t.value = TOK.TOKsemicolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 case ':': p++; t.value = TOK.TOKcolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 case '$': p++; t.value = TOK.TOKdollar; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1646 case '@': p++; t.value = TOK.TOKat; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1647
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1648 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1649 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1650 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652 t.value = TOK.TOKmulass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1654 t.value = TOK.TOKmul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1655 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1656 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1657
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 case '%':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1660 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1661 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1662 t.value = TOK.TOKmodass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1663 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1664 t.value = TOK.TOKmod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1665 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1666 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1667 version(DMDV1) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1668 case '^':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1669 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1670 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1671 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1672 t.value = TOK.TOKxorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1673 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1674 t.value = TOK.TOKxor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1675 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1676 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1677 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1678 case '#':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1679 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1680 pragma_();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1681 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1682
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1683 default:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1684 { uint c = *p;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1685
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1686 if (c & 0x80)
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1687 { c = decodeUTF();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1689 // Check for start of unicode identifier
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1690 if (isUniAlpha(c))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1691 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1692
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1693 if (c == PS || c == LS)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1694 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1695 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1696 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1697 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1698 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1699 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1700 if (c < 0x80 && isprint(c))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1701 error("unsupported char '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1702 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1703 error("unsupported char 0x%02x", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1704 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1705 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1706 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1707 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1708 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1709 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1710
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1711 Token* peek(Token* ct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1712 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1713 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1714
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1715 if (ct.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1716 t = ct.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1717 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1718 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1719 t = new Token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1720 scan(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1721 t.next = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1722 ct.next = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1723 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1724 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1725 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1726
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1727 Token* peekPastParen(Token* tk)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1728 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1729 //printf("peekPastParen()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1730 int parens = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1731 int curlynest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1732 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1733 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1734 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1735 //tk.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1736 switch (tk.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739 parens++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1740 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1741
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1742 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1743 --parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1744 if (parens)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1745 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1746 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1747 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1748
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1749 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1750 curlynest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1751 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1752
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1753 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1754 if (--curlynest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1755 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1756 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1757
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1758 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1759 if (curlynest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1760 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1761 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1762
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1763 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1764 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1765
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1766 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1767 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1768 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1769 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1770 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1771 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1772
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1773 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1774 * Parse escape sequence.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1775 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1776 uint escapeSequence()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1777 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1778 uint c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1780 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1781 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1782 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1783 int n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1784 int ndigits;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1786 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1787 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1788 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1789 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1790 case '?':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1791 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1792 Lconsume:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1793 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1794 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1795
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1796 case 'a': c = 7; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1797 case 'b': c = 8; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1798 case 'f': c = 12; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1799 case 'n': c = 10; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1800 case 'r': c = 13; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1801 case 't': c = 9; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1802 case 'v': c = 11; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1803
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1804 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1805 ndigits = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1806 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1807 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1808 ndigits = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1809 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1810 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1811 ndigits = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1812 Lhex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1813 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1814 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1815 if (ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1816 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1817 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1818
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1819 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1820 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1821 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1822 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1823 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1824 c -= '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1825 else if (islower(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1826 c -= 'a' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1827 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1828 c -= 'A' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1829 v = v * 16 + c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1830 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1831 if (++n == ndigits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1832 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1833 if (!ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1834 { error("escape hex sequence has %d hex digits instead of %d", n, ndigits);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1835 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1836 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1837 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1838 if (ndigits != 2 && !utf_isValidDchar(v))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1839 { error("invalid UTF character \\U%08x", v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1840 v = '?'; // recover with valid UTF character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1841 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1842 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1844 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1845 error("undefined escape hex sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1846 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1847
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1848 case '&': // named character entity
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1849 for (ubyte* idstart = ++p; true; p++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1850 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1851 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1852 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1853 case ';':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1854 c = HtmlNamedEntity(idstart, p - idstart);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1855 if (c == ~0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1856 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1857 error("unnamed character entity &%s;", idstart[0..(p - idstart)]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1858 c = ' ';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1859 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1860 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1861 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1862
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1863 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1864 if (isalpha(*p) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1865 (p != idstart + 1 && isdigit(*p)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1866 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1867 error("unterminated named entity");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1868 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1869 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1870 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1871 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1872 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1873
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1874 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1875 case 0x1A: // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1876 c = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1879 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1880 if (isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1881 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1882 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1884 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1885 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1886 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 v = v * 8 + (c - '0');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1889 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1890 } while (++n < 3 && isoctal(cast(ubyte)c));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1891 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1892 if (c > 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1893 error("0%03o is larger than a byte", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1894 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1895 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1896 error("undefined escape sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1897 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1898 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1899 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1900 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1901
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1902 TOK wysiwygStringConstant(Token* t, int tc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1903 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1904 uint c;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1905 Loc start = loc;
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 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1908 stringbuffer.reset();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1909 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1910 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1911 c = *p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1912 switch (c)
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 case '\n':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1915 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1916 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1917
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1918 case '\r':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1919 if (*p == '\n')
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1920 continue; // ignore
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1921 c = '\n'; // treat EndOfLine as \n character
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1922 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1923 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1924
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1925 case 0:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1926 case 0x1A:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1927 error("unterminated string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1928 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1929 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1930 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1931 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1932
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1933 case '"':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1934 case '`':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1935 if (c == tc)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1936 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1937 t.len = stringbuffer.offset;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1938 stringbuffer.writeByte(0);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1939 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1940 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1941 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1942 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1943 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1944 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1945 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1946
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1947 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1948 if (c & 0x80)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1949 { p--;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1950 uint u = decodeUTF();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1951 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1952 if (u == PS || u == LS)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1953 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1954 stringbuffer.writeUTF8(u);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1955 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1956 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1957 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1958 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1959 stringbuffer.writeByte(c);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1960 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1961
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1962 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1964
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1965 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1966 * Lex hex strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1967 * x"0A ae 34FE BD"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1968 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969 TOK hexStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1971 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1972 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1973 uint n = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1974 uint v;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1975
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1976 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1977 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1978 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1979 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1980 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1981 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1982 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1983 case ' ':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1984 case '\t':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1985 case '\v':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1986 case '\f':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1987 continue; // skip white space
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1988
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1989 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1990 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1991 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1992 // Treat isolated '\r' as if it were a '\n'
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1993 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1994 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1995 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1996
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1997 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1998 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1999 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2000 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2001 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2002 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2003 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2004
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2005 case '"':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2006 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2007 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2008 error("odd number (%d) of hex characters in hex string", n);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2009 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2010 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2011 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2012 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2013 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2014 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2015 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2016 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2017 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2018
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2019 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2020 if (c >= '0' && c <= '9')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2021 c -= '0';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2022 else if (c >= 'a' && c <= 'f')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2023 c -= 'a' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2024 else if (c >= 'A' && c <= 'F')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2025 c -= 'A' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2026 else if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2027 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2028 uint u = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2029 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2030 if (u == PS || u == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2031 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2032 else
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
2033 error("non-hex character \\u%04x", u);
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2034 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2035 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2036 error("non-hex character '%c'", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2037 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2038 { v = (v << 4) | c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2039 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2040 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2041 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2042 v = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2043 n++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2044 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2045 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2046 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2047 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2048
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2049 version (DMDV2) {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2050 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2051 * Lex delimited strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2052 * q"(foo(xxx))" // "foo(xxx)"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2053 * q"[foo(]" // "foo("
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2054 * q"/foo]/" // "foo]"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2055 * q"HERE
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2056 * foo
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2057 * HERE" // "foo\n"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2058 * Input:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2059 * p is on the "
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2060 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2061 TOK delimitedStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2062 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2063 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2064 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2065 uint delimleft = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2066 uint delimright = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2067 uint nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2068 uint nestcount;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2069 Identifier hereid = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2070 uint blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2071 uint startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2072
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2073 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2074 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2075 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2076 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2077 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2078 //printf("c = '%c'\n", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2079 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2080 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2081 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2082 Lnextline:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2083 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2084 startline = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2085 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2086 { blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2087 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2088 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2089 if (hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2090 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2091 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2092 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2093 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2094 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2095
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2096 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2097 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2098 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2099 c = '\n'; // treat EndOfLine as \n character
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2100 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2101
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2102 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2103 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2104 goto Lerror;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2105
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2106 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2107 if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2108 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2109 c = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2110 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2111 if (c == PS || c == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2112 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2113 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2114 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2115 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2116 if (delimleft == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2117 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2118 delimleft = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2119 nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2120 nestcount = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2121 if (c == '(')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2122 delimright = ')';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2123 else if (c == '{')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2124 delimright = '}';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2125 else if (c == '[')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2126 delimright = ']';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2127 else if (c == '<')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2128 delimright = '>';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2129 else if (isalpha(c) || c == '_' || (c >= 0x80 && isUniAlpha(c)))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2130 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2131 // Start of identifier; must be a heredoc
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2132 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2133 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2134 scan(&t2); // read in heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2135 if (t2.value != TOKidentifier)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2136 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2137 error("identifier expected for heredoc, not %s", t2.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2138 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2139 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2140 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2141 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2142 hereid = t2.ident;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2143 //printf("hereid = '%s'\n", hereid.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2144 blankrol = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2145 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2146 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2147 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2148 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2149 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2150 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2151 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2152 if (isspace(c))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2153 error("delimiter cannot be whitespace");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2154 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2155 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2156 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2157 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2158 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2159 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2160 error("heredoc rest of line should be blank");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2161 blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2162 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2163 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2164 if (nest == 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2165 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2166 if (c == delimleft)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2167 nestcount++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2168 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2169 { nestcount--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2170 if (nestcount == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2171 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2172 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2173 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2174 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2175 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2176 if (startline && isalpha(c) && hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2177 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2178 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2179 ubyte* psave = p;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2180 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2181 scan(&t2); // read in possible heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2182 //printf("endid = '%s'\n", t2.ident.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2183 if (t2.value == TOKidentifier && t2.ident.equals(hereid))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2184 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2185 /* should check that rest of line is blank
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2186 */
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2187 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2188 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2189 p = psave;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2190 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2191 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2192 startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2193 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2194 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2195
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2196 Ldone:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2197 if (*p == '"')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2198 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2199 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2200 error("delimited string must end in %c\"", delimright);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2201 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2202 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2203 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2204 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2205 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2206 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2207 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2208
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2209 Lerror:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2210 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2211 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2212 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2213 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2214 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2215 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2216
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2217 /**************************************
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2218 * Lex delimited strings:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2219 * q{ foo(xxx) } // " foo(xxx) "
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2220 * q{foo(} // "foo("
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2221 * q{{foo}"}"} // "{foo}"}""
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2222 * Input:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2223 * p is on the q
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2224 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2225 TOK tokenStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2226 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2227 uint nest = 1;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2228 Loc start = loc;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2229 ubyte* pstart = ++p;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2230
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2231 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2232 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2233 Token tok;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2234
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2235 scan(&tok);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2236 switch (tok.value)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2237 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2238 case TOKlcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2239 nest++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2240 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2241
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2242 case TOKrcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2243 if (--nest == 0)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2244 goto Ldone;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2245 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2246
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2247 case TOKeof:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2248 goto Lerror;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2249
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2250 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2251 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2252 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2253 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2254
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2255 Ldone:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2256 t.len = p - 1 - pstart;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2257 char* tmp = cast(char*)GC.malloc(t.len + 1);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2258 memcpy(tmp, pstart, t.len);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2259 tmp[t.len] = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2260 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2261 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2262 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2263
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2264 Lerror:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2265 error("unterminated token string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2266 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2267 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2268 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2269 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2270 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2271 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2272 TOK escapeStringConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2273 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2274 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2275 Loc start = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2276
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2277 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2278 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2279 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2280 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2281 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2282 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2283 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2284 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2285 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2286 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2287 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2288 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2289 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2290 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2291 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2292 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2293 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2294 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2296 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2297 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2298 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2299 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2300 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2301 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2302 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2303 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2304 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2305
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2306 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2307 if (*p == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2308 continue; // ignore
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2309 c = '\n'; // treat EndOfLine as \n character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2310 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2311 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2312
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2313 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2314 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2315 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
2316 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2317 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2318 t.ustring = tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2319 stringPostfix(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2320 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2322 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2323 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2324 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2325 error("unterminated string constant starting at %s", start.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2326 t.ustring = "".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2327 t.len = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2328 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2329 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2330
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2331 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2332 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2333 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2334 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2335 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2336 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2337 { c = '\n';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2338 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2339 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2340 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2341 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2342 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2343 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2344 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2345 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2346 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2347 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2348
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2349 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2351
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2352 TOK charConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2353 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2354 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2355 TOK tk = TOKcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2356
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2357 //printf("Lexer.charConstant\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2358 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2359 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2360 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2361 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2362 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2363 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2364 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2365 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2366 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2367 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2368 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2369 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2370 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2371
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2372 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2373 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2374 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2375 tk = TOKdcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2376 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2377
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2378 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2379 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2380 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2381 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2382 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2383 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2384 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2385 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2386 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2387 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2388 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2389 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2390 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2391 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2392 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2393
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2394 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2395 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2396 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2397 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2398 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2399 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2400 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2401 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2402 if (c < 0xD800 || (c >= 0xE000 && c < 0xFFFE))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2403 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2404 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2405 tk = TOKdcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2406 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2407 t.uns64value = c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2408 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2411 if (*p != '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2412 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2413 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2414 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2416 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2417 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2418 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2419
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2420 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2421 * Get postfix of string literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2422 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2423 void stringPostfix(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2424 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2425 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2426 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2427 case 'c':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2428 case 'w':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2429 case 'd':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2430 t.postfix = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2431 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2432 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2433
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2434 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2435 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2436 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2438 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2439
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2440 uint wchar_(uint u)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2441 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2442 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2443 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2444
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2445 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2446 * Read in a number.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2447 * If it's an integer, store it in tok.TKutok.Vlong.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2448 * integers can be decimal, octal or hex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2449 * Handle the suffixes U, UL, LU, L, etc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2450 * If it's double, store it in tok.TKutok.Vdouble.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2451 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2452 * TKnum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2453 * TKdouble,...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2454 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2455
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2456 TOK number(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2457 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2458 // We use a state machine to collect numbers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2459 enum STATE { STATE_initial, STATE_0, STATE_decimal, STATE_octal, STATE_octale,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2460 STATE_hex, STATE_binary, STATE_hex0, STATE_binary0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2461 STATE_hexh, STATE_error };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2462 STATE state;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2463
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2464 enum FLAGS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2465 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2466 FLAGS_undefined = 0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2467 FLAGS_decimal = 1, // decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2468 FLAGS_unsigned = 2, // u or U suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2469 FLAGS_long = 4, // l or L suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2470 };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2471
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2472 FLAGS flags = FLAGS.FLAGS_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2473
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2474 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2475 int base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2476 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2477 ubyte *start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2478 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2479
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2480 //printf("Lexer.number()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2481 state = STATE.STATE_initial;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2482 base = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2483 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2484 start = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2485 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2486 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2487 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2488 switch (state)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2489 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2490 case STATE.STATE_initial: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2491 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2492 state = STATE.STATE_0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2493 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2494 state = STATE.STATE_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2495 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2496
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2497 case STATE.STATE_0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2498 flags = (flags & ~FLAGS.FLAGS_decimal);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2499 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2500 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2501 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2502 case 'H': // 0h
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2503 case 'h':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2504 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2506 case 'X':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2507 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2508 state = STATE.STATE_hex0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2509 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2510
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2511 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2512 if (p[1] == '.') // .. is a separate token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2513 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2514 case 'i':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2515 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2516 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2517 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2518 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2519 case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2520 case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2521 goto case_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2522 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2523 case 'B':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2524 case 'b':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2525 state = STATE.STATE_binary0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2526 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2527
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2528 case '0': case '1': case '2': case '3':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2529 case '4': case '5': case '6': case '7':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2530 state = STATE.STATE_octal;
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 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2534 case '8': case '9': case 'A':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2535 case 'C': case 'D': case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2536 case 'a': case 'c': case 'd': case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2537 case_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2538 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2539 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2540 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2541 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2542 state = STATE.STATE_octal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2543 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2544 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2545
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2546 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2547 if (p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2548 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2549 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2550
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2551 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2552 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2554 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2555
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2556 case STATE.STATE_decimal: // reading decimal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2557 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2558 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2559 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2560 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2561 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2562 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2563 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2564 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2565 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2566 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2567 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2569 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2570 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2571 else if (c == 'i' || c == 'f' || c == 'F' ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2572 c == 'e' || c == 'E')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2573 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2574 real_: // It's a real number. Back up and rescan as a real
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2575 p = start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2576 return inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2577 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2578 else if (c == 'L' && p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2579 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2580 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2581 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2582 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2583
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2584 case STATE.STATE_hex0: // reading hex number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2585 case STATE.STATE_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2586 if (! ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2587 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2588 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2589 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2590 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2591 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2592 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2593 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2594 if (c == 'P' || c == 'p' || c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2595 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2596 if (state == STATE.STATE_hex0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2597 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2598 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2599 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2600 state = STATE.STATE_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2601 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2603 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2604 hexh:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2605 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2606 case STATE.STATE_hexh: // parse numbers like 0FFh
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2607 if (!ishex(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2608 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2609 if (c == 'H' || c == 'h')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2610 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2611 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2612 base = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2613 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2614 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2615 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2616 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2617 // Check for something like 1E3 or 0E24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2618 if (memchr(cast(char*)stringbuffer.data, 'E', stringbuffer.offset) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2619 memchr(cast(char*)stringbuffer.data, 'e', stringbuffer.offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2620 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2621 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2622 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2623 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2624 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2625 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2626 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2627
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2628 case STATE.STATE_octal: // reading octal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2629 case STATE.STATE_octale: // reading octal number with non-octal digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2630 if (!isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2631 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2632 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2633 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2634 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2635 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2636 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2637 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2638 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2639 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2640 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2641 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2642 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2643 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2644 if (c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2645 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2646 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2647 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2648 state = STATE.STATE_octale;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2649 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2650 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2651 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2652 }
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 case STATE.STATE_binary0: // starting binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2656 case STATE.STATE_binary: // reading binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2657 if (c != '0' && c != '1')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2658 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2659 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2660 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2661 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2662 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2663 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2664 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2665 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2666 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2667 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2668 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2669 if (state == STATE.STATE_binary0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2670 { error("binary digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2671 state = STATE.STATE_error;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2672 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2673 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2674 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2675 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2676 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2677 state = STATE.STATE_binary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2678 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2679
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2680 case STATE.STATE_error: // for error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2681 if (!isdigit(c)) // scan until non-digit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2682 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2683 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2684
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2685 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2686 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2687 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2688 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2689 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2690 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2691 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2692 stringbuffer.writeByte(0); // terminate string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2693 if (state == STATE.STATE_octale)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2694 error("Octal digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2695
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2696 ulong n; // unsigned >=64 bit integer type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2697
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2698 if (stringbuffer.offset == 2 && (state == STATE.STATE_decimal || state == STATE.STATE_0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2699 n = stringbuffer.data[0] - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2700 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2701 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2702 // Convert string to integer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2703 version (__DMC__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2704 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2705 n = strtoull(cast(char*)stringbuffer.data,null,base);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2706 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2707 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2708 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2709 // Not everybody implements strtoull()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2710 char* p = cast(char*)stringbuffer.data;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2711 int r = 10, d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2712
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2713 if (*p == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2714 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2715 if (p[1] == 'x' || p[1] == 'X')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2716 p += 2, r = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2717 else if (p[1] == 'b' || p[1] == 'B')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2718 p += 2, r = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2719 else if (isdigit(p[1]))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2720 p += 1, r = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2721 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2722
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2723 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2724 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2725 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2726 if (*p >= '0' && *p <= '9')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2727 d = *p - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2728 else if (*p >= 'a' && *p <= 'z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2729 d = *p - 'a' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2730 else if (*p >= 'A' && *p <= 'Z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2731 d = *p - 'A' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2732 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2733 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2734 if (d >= r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2735 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2736 ulong n2 = n * r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2737 //printf("n2 / r = %llx, n = %llx\n", n2/r, n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2738 if (n2 / r != n || n2 + d < n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2739 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2740 error ("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2741 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2742 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2743
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2744 n = n2 + d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2745 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2746 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2747 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2748 if (n.sizeof > 8 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2749 n > 0xFFFFFFFFFFFFFFFF) // if n needs more than 64 bits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2750 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2751 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2752
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2753 // Parse trailing 'u', 'U', 'l' or 'L' in any combination
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2754 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2755 { FLAGS f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2756
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2757 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2758 { case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2759 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2760 f = FLAGS.FLAGS_unsigned;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2761 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2762
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2763 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2764 if (1 || !global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2765 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2766 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2767 f = FLAGS.FLAGS_long;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2768 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2769 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2770 if (flags & f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2771 error("unrecognized token");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2772 flags = (flags | f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2773 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2774 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2775 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2776 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2777 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2778 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2779
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2780 switch (flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2781 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2782 case FLAGS.FLAGS_undefined:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2783 /* Octal or Hexadecimal constant.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2784 * First that fits: int, uint, long, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2785 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2786 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2787 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2788 else if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2789 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2790 else if (n & 0x80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2791 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2792 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2793 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2794 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2795
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2796 case FLAGS.FLAGS_decimal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2797 /* First that fits: int, long, long long
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2798 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2799 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2800 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2801 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2802 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2803 else if (n & 0xFFFFFFFF80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2804 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2805 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2806 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2807 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2808
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2809 case FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2810 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2811 /* First that fits: uint, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2812 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2813 if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2814 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2815 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2816 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2817 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2818
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2819 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2820 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2821 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2822 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2823 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2824 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2825 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2826 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2827
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2828 case FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2829 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2830 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2831 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2832 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2833 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2834
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2835 case FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2836 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2837 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2838 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2839
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2840 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2841 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2842 printf("%x\n",flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2844 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2845 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2846 t.uns64value = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2847 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2848 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2849
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2850 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2851 * Read in characters, converting them to real.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2852 * Bugs:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2853 * Exponent overflow not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2854 * Too much requested precision is not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2855 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2856 TOK inreal(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2857 in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2858 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2859 assert(*p == '.' || isdigit(*p));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2860 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2861 out (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2862 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2863 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2864 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2865 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2866 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2867 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2868 case TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2869 case TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2870 case TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2871 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2872
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2873 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2874 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2875 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2876 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2877 body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2878 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2879 int dblstate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2880 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2881 char hex; // is this a hexadecimal-floating-constant?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2882 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2883
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2884 //printf("Lexer.inreal()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2885 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2886 dblstate = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2887 hex = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2888 Lnext:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2889 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2890 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2891 // Get next char from input
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2892 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2893 //printf("dblstate = %d, c = '%c'\n", dblstate, c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2894 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2895 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2896 switch (dblstate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2897 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2898 case 0: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2899 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2900 dblstate = 9;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2901 else if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2902 dblstate = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2903 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2904 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2905 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2906
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2907 case 9:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2908 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2909 if (c == 'X' || c == 'x')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2910 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2911 hex++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2912 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2913 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2914 case 1: // digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2915 case 3: // digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2916 case 7: // continuing exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2917 if (!isdigit(c) && !(hex && isxdigit(c)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2918 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2919 if (c == '_')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2920 goto Lnext; // ignore embedded '_'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2921 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2922 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2923 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2924 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2925
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2926 case 2: // no more digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2927 if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2928 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2929 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2930 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2931 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2932 case 4: // no more digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2933 if ((c == 'E' || c == 'e') ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2934 hex && (c == 'P' || c == 'p'))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2935 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2936 dblstate = 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2937 hex = 0; // exponent is always decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2938 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2939 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2940 if (hex)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2941 error("binary-exponent-part required");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2942 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2943
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2944 case 5: // looking immediately to right of E
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2945 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2946 if (c == '-' || c == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2947 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2948 case 6: // 1st exponent digit expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2949 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2950 error("exponent expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2951 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2952 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2953
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2954 case 8: // past end of exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2955 goto done;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2956
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2957 default:
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2958 assert(0, "inreal.dblstate has unexpected value");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2959 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2960 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2961 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2962 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2963 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2964 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2965 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2966
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2967 stringbuffer.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2968
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
2969 version (Windows) { /// && __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2970 char* save = __locale_decpoint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2971 __locale_decpoint = cast(char*)".".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2972 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2973 t.float80value = strtold(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2974
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2975 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2976 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2977 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2978 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2979 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2980 strtof(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2981 result = TOKfloat32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2982 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2983 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2984
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2985 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2986 strtod(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2987 result = TOKfloat64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2988 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2989
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2990 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2991 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2992 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2993 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2994 result = TOKfloat80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2995 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2996 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2997 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2998 if (*p == 'i' || *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2999 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3000 if (!global.params.useDeprecated && *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3001 error("'I' suffix is deprecated, use 'i' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3002 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3003 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3004 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3005 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3006 result = TOKimaginary32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3007 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3008 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3009 result = TOKimaginary64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3010 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3011 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3012 result = TOKimaginary80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3013 break;
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3014 default:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3015 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3016 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3017
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3018 version (Windows) { ///&& __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3019 __locale_decpoint = save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3020 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3021 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3022 error("number is not representable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3023
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3024 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3025 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3026
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3027 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3028 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3029 error(this.loc, format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3030 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3031
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3032 void error(T...)(Loc loc, string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3033 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3034 if (mod && !global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3035 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3036 string p = loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3037 if (p.length != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3038 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3039
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3040 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3041
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3042 if (global.errors >= 20) // moderate blizzard of cascading messages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3043 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3044 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3045
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3046 global.errors++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3047 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3048
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3049 /*********************************************
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3050 * Do pragma.
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3051 * Currently, the only pragma supported is:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3052 * #line linnum [filespec]
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3053 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3054 void pragma_()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3055 {
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3056 Token tok;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3057 int linnum;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3058 string filespec = null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3059 Loc loc = this.loc;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3060
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3061 scan(&tok);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3062 if (tok.value != TOKidentifier || tok.ident != Id.line)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3063 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3064
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3065 scan(&tok);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3066 if (tok.value == TOKint32v || tok.value == TOKint64v)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3067 linnum = cast(int)(tok.uns64value - 1); ///
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3068 else
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3069 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3070
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3071 while (1)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3072 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3073 switch (*p)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3074 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3075 case 0:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3076 case 0x1A:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3077 case '\n':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3078 Lnewline:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3079 this.loc.linnum = linnum;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3080 if (filespec != null)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3081 this.loc.filename = filespec;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3082 return;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3083
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3084 case '\r':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3085 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3086 if (*p != '\n')
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3087 { p--;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3088 goto Lnewline;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3089 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3090 continue;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3091
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3092 case ' ':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3093 case '\t':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3094 case '\v':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3095 case '\f':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3096 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3097 continue; // skip white space
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3098
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3099 case '_':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3100 if (mod && memcmp(p, "__FILE__".ptr, 8) == 0)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3101 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3102 p += 8;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3103 filespec = (loc.filename ? loc.filename : mod.ident.toChars());
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3104 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3105 continue;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3106
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3107 case '"':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3108 if (filespec)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3109 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3110 stringbuffer.reset();
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3111 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3112 while (1)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3113 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3114 uint c;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3115
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3116 c = *p;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3117 switch (c)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3118 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3119 case '\n':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3120 case '\r':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3121 case 0:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3122 case 0x1A:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3123 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3124
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3125 case '"':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3126 stringbuffer.writeByte(0);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3127 filespec = stringbuffer.extractString(); ///
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3128 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3129 break;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3130
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3131 default:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3132 if (c & 0x80)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3133 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3134 uint u = decodeUTF();
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3135 if (u == PS || u == LS)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3136 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3137 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3138 stringbuffer.writeByte(c);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3139 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3140 continue;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3141 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3142 break;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3143 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3144 continue;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3145
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3146 default:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3147 if (*p & 0x80)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3148 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3149 uint u = decodeUTF();
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3150 if (u == PS || u == LS)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3151 goto Lnewline;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3152 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3153 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3154 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3155 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3156
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3157 Lerr:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3158 error(loc, "#line integer [\"filespec\"]\\n expected");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3159 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3160
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3161 /********************************************
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3162 * Decode UTF character.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3163 * Issue error messages for invalid sequences.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3164 * Return decoded character, advance p to last character in UTF sequence.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3165 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3166 uint decodeUTF()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3167 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3168 dchar u;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3169 ubyte c;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3170 ubyte* s = p;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3171 size_t len;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3172 size_t idx;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3173 string msg;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3174
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3175 c = *s;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3176 assert(c & 0x80);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3177
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3178 // Check length of remaining string up to 6 UTF-8 characters
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3179 for (len = 1; len < 6 && s[len]; len++) {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3180 ;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3181 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3182
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3183 idx = 0;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3184 msg = utf_decodeChar(cast(string)s[0..len], &idx, &u);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3185 p += idx - 1;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3186 if (msg)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3187 {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3188 error("%s", msg);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3189 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3190 return u;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3191 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3192
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3193 /***************************************************
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3194 * Parse doc comment embedded between t.ptr and p.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3195 * Remove trailing blanks and tabs from lines.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3196 * Replace all newlines with \n.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3197 * Remove leading comment character from each line.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3198 * Decide if it's a lineComment or a blockComment.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3199 * Append to previous one for this token.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3200 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3201 void getDocComment(Token* t, uint lineComment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3202 {
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3203 /* ct tells us which kind of comment it is: '!', '/', '*', or '+'
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3204 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3205 ubyte ct = t.ptr[2];
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3206
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3207 /* Start of comment text skips over / * *, / + +, or / / /
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3208 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3209 ubyte* q = t.ptr + 3; // start of comment text
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3210
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3211 ubyte* qend = p;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3212 if (ct == '*' || ct == '+')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3213 qend -= 2;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3214
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3215 /* Scan over initial row of ****'s or ++++'s or ////'s
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3216 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3217 for (; q < qend; q++)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3218 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3219 if (*q != ct)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3220 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3221 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3222
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3223 /* Remove trailing row of ****'s or ++++'s
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3224 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3225 if (ct != '/' && ct != '!')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3226 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3227 for (; q < qend; qend--)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3228 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3229 if (qend[-1] != ct)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3230 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3231 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3232 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3233
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3234 /* Comment is now [q .. qend].
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3235 * Canonicalize it into buf[].
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3236 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3237 OutBuffer buf = new OutBuffer;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3238 int linestart = 0;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3239
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3240 for (; q < qend; q++)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3241 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3242 ubyte c = *q;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3243
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3244 switch (c)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3245 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3246 case '*':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3247 case '+':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3248 if (linestart && c == ct)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3249 { linestart = 0;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3250 /* Trim preceding whitespace up to preceding \n
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3251 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3252 while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3253 buf.offset--;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3254 continue;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3255 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3256 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3257
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3258 case ' ':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3259 case '\t':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3260 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3261
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3262 case '\r':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3263 if (q[1] == '\n')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3264 continue; // skip the \r
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3265 goto Lnewline;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3266
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3267 default:
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3268 if (c == 226)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3269 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3270 // If LS or PS
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3271 if (q[1] == 128 &&
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3272 (q[2] == 168 || q[2] == 169))
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3273 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3274 q += 2;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3275 goto Lnewline;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3276 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3277 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3278 linestart = 0;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3279 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3280
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3281 Lnewline:
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3282 c = '\n'; // replace all newlines with \n
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3283 case '\n':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3284 linestart = 1;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3285
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3286 /* Trim trailing whitespace
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3287 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3288 while (buf.offset && (buf.data[buf.offset - 1] == ' ' || buf.data[buf.offset - 1] == '\t'))
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3289 buf.offset--;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3290
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3291 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3292 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3293 buf.writeByte(c);
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3294 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3295
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3296 // Always end with a newline
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3297 if (!buf.offset || buf.data[buf.offset - 1] != '\n')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3298 buf.writeByte('\n');
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3299
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3300 buf.writeByte(0);
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3301
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3302 // It's a line comment if the start of the doc comment comes
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3303 // after other non-whitespace on the same line.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3304 string* dc = (lineComment && anyToken)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3305 ? &t.lineComment
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3306 : &t.blockComment;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3307
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3308 // Combine with previous doc comment, if any
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3309 if (*dc)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3310 *dc = combineComments(*dc, cast(string) buf.data[0 .. buf.size]); // TODO: utf decode etc?
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3311 else
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3312 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3313 auto bufsize = buf.size;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3314 *dc = cast(string) buf.extractData()[0..bufsize];
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3315 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3316 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3317
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3318 /********************************************
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3319 * Combine two document comments into one,
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3320 * separated by a newline.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3321 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3322 static string combineComments(string c1, string c2)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3323 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3324 //printf("Lexer::combineComments('%s', '%s')\n", c1, c2);
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3325
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3326 string c = c2;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3327
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3328 if (c1)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3329 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3330 c = c1;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3331 if (c2)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3332 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3333 size_t len1 = c1.length;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3334 size_t len2 = c2.length;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3335
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3336 c = c1.idup;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3337 if (len1 && c1[$-1] != '\n')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3338 c ~= '\n';
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3339 c ~= c2;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3340 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3341 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3342 return c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3343 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3344
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3345 static bool isValidIdentifier(string p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3346 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3347 if (p.length == 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3348 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3351 if (p[0] >= '0' && p[0] <= '9') { // beware of isdigit() on signed chars
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3352 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3355 size_t idx = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3356 while (idx < p.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3357 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3358 dchar dc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3360 if (utf_decodeChar(p, &idx, &dc) !is null) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3361 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3362 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3363
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3364 if (!((dc >= 0x80 && isUniAlpha(dc)) || isalnum(dc) || dc == '_')) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3365 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3367 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3369 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3371
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3372 /// TODO: use normal string append when GC works
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3373 static string combineComments(const(char)[] c1, const(char)[] c2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3374 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3375 //writef("Lexer.combineComments('%s', '%s')\n", c1, c2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3376
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3377 char[] c = cast(char[]) c2;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3378
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3379 if (c1 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3380 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3381 c = cast(char[]) c1;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3382 if (c2 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3383 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3384 c = cast(char[]) (GC.malloc(c1.length + 1 + c2.length)[0 .. c1.length + 1 + c2.length]);
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3385 size_t len1 = c1.length;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3386 c[0..len1] = c1[];
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3387 c[len1++] = '\n';
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3388 c[len1 .. len1 + c2.length] = c2[];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3389 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3390 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3391
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3392 return cast(string)c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3393 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3394 }