annotate dmd/Lexer.d @ 175:94b6033c07f3

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