annotate dmd/Lexer.d @ 162:438eaa11eed4

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