annotate dmd/Lexer.d @ 192:eb38fdcb3e62 default tip

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