annotate dmd/Lexer.d @ 163:fe932c1a9563

*.interpret functions implemenation
author korDen
date Thu, 23 Sep 2010 13:55:20 +0400
parents 438eaa11eed4
children ceed63f310fb
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
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
887 /***********************
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
888 * Look 2 tokens ahead at value.
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
889 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890 TOK peekNext2()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 {
163
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
892 Token* t = peek(&token);
fe932c1a9563 *.interpret functions implemenation
korDen
parents: 162
diff changeset
893 return peek(t).value;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896 void scan(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 uint lastLine = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 uint linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 t.blockComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902 t.lineComment = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 t.ptr = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 //printf("p = %p, *p = '%c'\n",p,*p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
910 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 t.value = TOK.TOKeof; // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 case ' ':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915 case '\t':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 case '\v':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 case '\f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 if (*p != '\n') // if CR stands by itself
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 continue; // skip white space
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932 case '0': case '1': case '2': case '3': case '4':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 case '5': case '6': case '7': case '8': case '9':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 t.value = number(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 version (CSTRINGS) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 t.value = charConstant(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 '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 t.value = stringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 if (p[1] == '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 t.value = charConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
952 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
954 else if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 t.value = stringConstant(t, 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962 t.value = charConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
963 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 case 'r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 case '`':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
970 t.value = wysiwygStringConstant(t, *p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
971 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 if (p[1] != '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 t.value = hexStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 case 'q':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982 if (p[1] == '"')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 t.value = delimitedStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
986 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
987 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
988 else if (p[1] == '{')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
989 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
990 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
991 t.value = tokenStringConstant(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
992 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
993 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
994 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
995 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
996 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
997
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
998 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
999 t.value = escapeStringConstant(t,0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1000 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1001 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1002 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1003 case '\\': // escaped string literal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1004 { uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1005 ubyte* pstart = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1006
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1007 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1008 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1009 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1010 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1011 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1012 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1013 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1014 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1015 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1016 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1017 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1018 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1019
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1020 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1021 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1022 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1023 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1024 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1025 } while (*p == '\\');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1026 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1027 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
1028 char* cc = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1029 memcpy(cc, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1030 t.ustring = cc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1031 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1032 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1033 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1034 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
1035 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1036 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1037 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1038 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1039 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1040 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1041 case 'a': case 'b': case 'c': case 'd': case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1042 case 'f': case 'g': case 'h': case 'i': case 'j':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1043 case 'k': case 'm': case 'n': case 'o':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1044 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1045 case 'p': /*case 'q': case 'r':*/ case 's': case 't':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1046 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1047 case 'p': case 'q': /*case 'r':*/ case 's': case 't':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1048 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1049 case 'u': case 'v': case 'w': /*case 'x':*/ case 'y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1050 case 'z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1051 case 'A': case 'B': case 'C': case 'D': case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1052 case 'F': case 'G': case 'H': case 'I': case 'J':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1053 case 'K': case 'M': case 'N': case 'O':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1054 case 'P': case 'Q': case 'R': case 'S': case 'T':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1055 case 'U': case 'V': case 'W': case 'X': case 'Y':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1056 case 'Z':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1057 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1058 case_ident:
135
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 ubyte c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1061
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1062 while (1)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1063 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1064 c = *++p;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1065 if (isidchar(c))
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1066 continue;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1067 else if (c & 0x80)
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1068 {
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1069 ubyte *s = p;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1070 uint u = decodeUTF();
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1071 if (isUniAlpha(u))
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1072 continue;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1073 error("char 0x%04x not allowed in identifier", u);
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1074 p = s;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1075 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1076 break;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1077 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1078
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1079 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
1080 Identifier id = cast(Identifier) sv.ptrvalue;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1081
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1082 if (id is null)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1083 { id = new Identifier(sv.lstring.string_, TOK.TOKidentifier);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1084 sv.ptrvalue = cast(void*)id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1085 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1086 t.ident = id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1087 t.value = cast(TOK) id.value;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1088 anyToken = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1089 if (*t.ptr == '_') // if special identifier token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1090 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1091 static char date[11+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1092 static char time[8+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1093 static char timestamp[24+1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1094
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1095 if (!date[0]) // lazy evaluation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1096 { time_t tm;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1097 char *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1098
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1099 .time(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1100 p = ctime(&tm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1101 assert(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1102 sprintf(date.ptr, "%.6s %.4s", p + 4, p + 20);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1103 sprintf(time.ptr, "%.8s", p + 11);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1104 sprintf(timestamp.ptr, "%.24s", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1105 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1106
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1107 ///version (DMDV1) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1108 /// if (mod && id == Id.FILE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1109 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1110 /// t.ustring = cast(ubyte*)(loc.filename ? loc.filename : mod.ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1111 /// goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1112 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1113 /// else if (mod && id == Id.LINE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1114 /// {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1115 /// t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1116 /// t.uns64value = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1117 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1118 /// else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1119 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1120 if (id == Id.DATE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1121 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1122 t.ustring = date.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1123 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1124 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1125 else if (id == Id.TIME)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1126 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1127 t.ustring = time.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1128 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1129 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1130 else if (id == Id.VENDOR)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1131 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1132 t.ustring = "Digital Mars D".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1133 goto Lstr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1135 else if (id == Id.TIMESTAMP)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1137 t.ustring = timestamp.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1138 Lstr:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1139 t.value = TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1140 Llen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1141 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1142 t.len = strlen(cast(char*)t.ustring);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1143 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1144 else if (id == Id.VERSIONX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1145 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1146 uint major = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1147 uint minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1149 foreach (char cc; global.version_[1..$])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1150 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1151 if (isdigit(cc))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1152 minor = minor * 10 + cc - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1153 else if (cc == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1154 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1155 major = minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1156 minor = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1157 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1158 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1159 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1160 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1161 t.value = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1162 t.uns64value = major * 1000 + minor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1163 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1164 ///version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1165 else if (id == Id.EOFX)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1167 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1168 // Advance scanner to end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1169 while (!(*p == 0 || *p == 0x1A))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1170 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1171 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1172 ///}
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1173 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1174 //printf("t.value = %d\n",t.value);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1175 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1176 }
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 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1181 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1182 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1183 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1184 t.value = TOK.TOKdivass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1185 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1187 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1188 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1189 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1190 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1191 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1192 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1194 ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1195 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1196 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1197 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1198 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1199
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1200 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1201 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1202 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1203 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1205 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1206 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1207 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1208 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1209 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1210
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1211 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1212 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1213 error("unterminated /* */ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1214 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1215 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1216 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1217
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1218 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1219 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1220 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1221 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1222 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1223 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1224 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1225 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1226 }
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 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1230 if (p[-2] == '*' && p - 3 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1231 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1232 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1233 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1234 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1235 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1236 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1237 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1238 else if (doDocComment && t.ptr[2] == '*' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1239 { // if /** but not /**/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1240 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1241 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1242 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1243
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1244 case '/': // do // style comments
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1245 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1246 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1247 { ubyte c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1248 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1249 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1250 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1251 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1253 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1254 if (p[1] == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1255 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1256 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1257
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1258 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1259 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1260 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1261 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1262 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1263 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1264 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1265 }
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
1266 if (doDocComment && t.ptr[2] == '/' || t.ptr[2] == '!') // '///' or '//!'
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1267 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1268 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1269 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1270 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1271
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1272 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1273 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1274 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1275 if (u == PS || u == LS)
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 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1279 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1280 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1281 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1282
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1283 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1284 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1285 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1286 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1287 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1288 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1289 }
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
1290 if (doDocComment && t.ptr[2] == '/' || t.ptr[2] == '!') // '///' or '//!'
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1291 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1292
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1293 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1294 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1295 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1296
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1297 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1298 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1299 int nest;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1300
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1301 linnum = loc.linnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1302 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1303 nest = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1304 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1305 { ubyte c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1306 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1307 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1308 case '/':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1309 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1310 if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1311 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1312 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1313 nest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1314 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1315 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1316
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1317 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1318 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1319 if (*p == '/')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1320 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1321 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1322 if (--nest == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1323 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1324 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1325 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1326
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1327 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1328 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1329 if (*p != '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1330 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1331 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1332
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1333 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1334 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1335 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1336 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1337
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1338 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1339 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1340 error("unterminated /+ +/ comment");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1341 p = end;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1342 t.value = TOK.TOKeof;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1343 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1344
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1345 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1346 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1347 { uint u = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1348 if (u == PS || u == LS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1349 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1351 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1352 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1354 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1355 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1356 if (commentToken)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1357 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1358 t.value = TOK.TOKcomment;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1359 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1361 if (doDocComment && t.ptr[2] == '+' && p - 4 != t.ptr)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1362 { // if /++ but not /++/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1363 getDocComment(t, lastLine == linnum);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1364 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1365 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1366 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1367
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1368 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1369 break; ///
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1370 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1371 t.value = TOK.TOKdiv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1372 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1373
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1374 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1375 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1376 if (isdigit(*p))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1377 { /* Note that we don't allow ._1 and ._ as being
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1378 * valid floating point numbers.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1379 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1380 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1381 t.value = inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1382 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1383 else if (p[0] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1384 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1385 if (p[1] == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1386 { p += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1387 t.value = TOK.TOKdotdotdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1388 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1389 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1390 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1391 t.value = TOK.TOKslice;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1392 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1393 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1394 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1395 t.value = TOK.TOKdot;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1396 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1397
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1398 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1399 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1400 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1401 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1402 t.value = TOK.TOKandass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1403 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1404 else if (*p == '&')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1405 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1406 t.value = TOK.TOKandand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1407 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1408 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1409 t.value = TOK.TOKand;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1410 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1411
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1412 case '|':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1413 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1414 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1415 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1416 t.value = TOK.TOKorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1417 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1418 else if (*p == '|')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1419 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1420 t.value = TOK.TOKoror;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1422 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1423 t.value = TOK.TOKor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1424 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1426 case '-':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1427 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1428 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1429 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1430 t.value = TOK.TOKminass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1431 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1432 /// #if 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1433 /// else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1434 /// { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1435 /// t.value = TOK.TOKarrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1436 /// }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1437 /// #endif
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1438 else if (*p == '-')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1439 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1440 t.value = TOK.TOKminusminus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1441 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1442 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1443 t.value = TOK.TOKmin;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1444 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1445
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1446 case '+':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1447 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1448 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1449 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1450 t.value = TOK.TOKaddass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1451 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1452 else if (*p == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1453 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1454 t.value = TOK.TOKplusplus;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1455 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1456 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1457 t.value = TOK.TOKadd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1458 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1459
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1460 case '<':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1461 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1462 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1463 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1464 t.value = TOK.TOKle; // <=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1465 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1466 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1467 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1468 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1469 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1470 t.value = TOK.TOKshlass; // <<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1471 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1472 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1473 t.value = TOK.TOKshl; // <<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1474 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1475 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1476 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1477 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1478 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1479 t.value = TOK.TOKleg; // <>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1480 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1481 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1482 t.value = TOK.TOKlg; // <>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1483 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1484 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1485 t.value = TOK.TOKlt; // <
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1486 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1487
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1488 case '>':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1489 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1490 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1491 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1492 t.value = TOK.TOKge; // >=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1493 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1494 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1495 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1496 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1497 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1498 t.value = TOK.TOKshrass; // >>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1499 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1500 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1501 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1502 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1503 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1504 t.value = TOK.TOKushrass; // >>>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1505 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1506 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1507 t.value = TOK.TOKushr; // >>>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1508 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1509 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1510 t.value = TOK.TOKshr; // >>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1512 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1513 t.value = TOK.TOKgt; // >
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1514 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1515
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1516 case '!':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1517 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1518 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1519 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1520 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1521 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1522 t.value = TOK.TOKnotidentity; // !==
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1523 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1524 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1525 t.value = TOK.TOKnotequal; // !=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1526 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1527 else if (*p == '<')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1528 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1529 if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1530 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1531 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1532 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1533 t.value = TOK.TOKunord; // !<>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1534 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1535 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1536 t.value = TOK.TOKue; // !<>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1537 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1538 else if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1539 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1540 t.value = TOK.TOKug; // !<=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1541 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1542 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1543 t.value = TOK.TOKuge; // !<
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1544 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1545 else if (*p == '>')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1546 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1547 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1548 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1549 t.value = TOK.TOKul; // !>=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1550 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1551 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1552 t.value = TOK.TOKule; // !>
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1553 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1554 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1555 t.value = TOK.TOKnot; // !
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1556 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1557
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1558 case '=':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1559 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1560 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1561 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1562 if (*p == '=' && global.params.Dversion == 1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1563 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1564 t.value = TOK.TOKidentity; // ===
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1565 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1566 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1567 t.value = TOK.TOKequal; // ==
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1568 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1569 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1570 t.value = TOK.TOKassign; // =
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1571 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1572
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1573 case '~':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1574 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1575 if (*p == '=')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1576 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1577 t.value = TOK.TOKcatass; // ~=
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1578 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1579 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1580 t.value = TOK.TOKtilde; // ~
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1581 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1582
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1583 version(DMDV2) {
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1584 case '^':
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1585 p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1586 if (*p == '^')
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1587 { p++;
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1588 if (*p == '=')
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1589 { p++;
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1590 t.value = TOKpowass; // ^^=
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1591 }
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1592 else
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1593 t.value = TOKpow; // ^^
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 if (*p == '=')
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1596 { p++;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1597 t.value = TOKxorass; // ^=
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 else
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1600 t.value = TOKxor; // ^
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1601 return;
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1602 }
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1603
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1604 /*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1605 #define SINGLE(c,tok) case c: p++; t.value = tok; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1606
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1607 SINGLE('(', TOKlparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1608 SINGLE(')', TOKrparen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1609 SINGLE('[', TOKlbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1610 SINGLE(']', TOKrbracket)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1611 SINGLE('{', TOKlcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1612 SINGLE('}', TOKrcurly)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1613 SINGLE('?', TOKquestion)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1614 SINGLE(',', TOKcomma)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1615 SINGLE(';', TOKsemicolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1616 SINGLE(':', TOKcolon)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1617 SINGLE('$', TOKdollar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1618 SINGLE('@', TOKat)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1619
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1620 #undef SINGLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1621
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1622 #define DOUBLE(c1,tok1,c2,tok2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1623 case c1: \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1624 p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1625 if (*p == c2) \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1626 { p++; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1627 t.value = tok2; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1628 } \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1629 else \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1630 t.value = tok1; \
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1631 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1632
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1633 DOUBLE('*', TOKmul, '=', TOKmulass)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1634 DOUBLE('%', TOKmod, '=', TOKmodass)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1635 #if DMDV1
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1636 DOUBLE('^', TOKxor, '=', TOKxorass)
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1637 #endif
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1638 #undef DOUBLE
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1639 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1640
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1641 case '(': p++; t.value = TOK.TOKlparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1642 case ')': p++; t.value = TOK.TOKrparen; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1643 case '[': p++; t.value = TOK.TOKlbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1644 case ']': p++; t.value = TOK.TOKrbracket; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1645 case '{': p++; t.value = TOK.TOKlcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1646 case '}': p++; t.value = TOK.TOKrcurly; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1647 case '?': p++; t.value = TOK.TOKquestion; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1648 case ',': p++; t.value = TOK.TOKcomma; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1649 case ';': p++; t.value = TOK.TOKsemicolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1650 case ':': p++; t.value = TOK.TOKcolon; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1651 case '$': p++; t.value = TOK.TOKdollar; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1652 case '@': p++; t.value = TOK.TOKat; return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1653
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1654 case '*':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1655 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1656 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1657 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1658 t.value = TOK.TOKmulass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1659 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1660 t.value = TOK.TOKmul;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1661 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1662 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1663
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1664 case '%':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1665 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1666 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1667 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1668 t.value = TOK.TOKmodass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1669 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1670 t.value = TOK.TOKmod;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1671 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1672 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1673 version(DMDV1) {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1674 case '^':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1675 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1676 if (*p == '=') {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1677 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1678 t.value = TOK.TOKxorass;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1679 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1680 t.value = TOK.TOKxor;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1681 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1682 return;
130
60bb0fe4563e dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
1683 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1684 case '#':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1685 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1686 pragma_();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1687 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1688
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1689 default:
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1690 { uint c = *p;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1691
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1692 if (c & 0x80)
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1693 { c = decodeUTF();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1694
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1695 // Check for start of unicode identifier
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1696 if (isUniAlpha(c))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1697 goto case_ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1698
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1699 if (c == PS || c == LS)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1700 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1701 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1702 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1703 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1704 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1705 }
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
1706 if (c < 0x80 && isprint(c))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1707 error("unsupported char '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1708 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1709 error("unsupported char 0x%02x", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1710 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1711 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1712 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1713 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1714 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1715 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1716
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1717 Token* peek(Token* ct)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1718 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1719 Token* t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1720
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1721 if (ct.next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1722 t = ct.next;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1723 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1724 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1725 t = new Token();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1726 scan(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1727 t.next = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1728 ct.next = t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1729 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1730 return t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1731 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1732
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1733 Token* peekPastParen(Token* tk)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1734 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1735 //printf("peekPastParen()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1736 int parens = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1737 int curlynest = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1738 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1739 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1740 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1741 //tk.print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1742 switch (tk.value)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1743 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1744 case TOK.TOKlparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1745 parens++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1746 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1747
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1748 case TOK.TOKrparen:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1749 --parens;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1750 if (parens)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1751 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1752 tk = peek(tk);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1753 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1754
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1755 case TOK.TOKlcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1756 curlynest++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1757 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1758
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1759 case TOK.TOKrcurly:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1760 if (--curlynest >= 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1761 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1762 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1763
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1764 case TOK.TOKsemicolon:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1765 if (curlynest)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1766 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1767 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1768
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1769 case TOK.TOKeof:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1770 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1771
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1772 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1773 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1774 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1775 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1776 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1777 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1778
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1779 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1780 * Parse escape sequence.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1781 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1782 uint escapeSequence()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1783 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1784 uint c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1786 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1787 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1788 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1789 int n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1790 int ndigits;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1791
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1792 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1793 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1794 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1795 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1796 case '?':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1797 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1798 Lconsume:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1799 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1800 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1801
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1802 case 'a': c = 7; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1803 case 'b': c = 8; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1804 case 'f': c = 12; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1805 case 'n': c = 10; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1806 case 'r': c = 13; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1807 case 't': c = 9; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1808 case 'v': c = 11; goto Lconsume;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1809
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1810 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1811 ndigits = 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1812 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1813 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1814 ndigits = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1815 goto Lhex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1816 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1817 ndigits = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1818 Lhex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1819 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1820 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1821 if (ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1822 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1823 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1824
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1825 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1826 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1827 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1828 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1829 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1830 c -= '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1831 else if (islower(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1832 c -= 'a' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1833 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1834 c -= 'A' - 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1835 v = v * 16 + c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1836 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1837 if (++n == ndigits)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1838 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1839 if (!ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1840 { error("escape hex sequence has %d hex digits instead of %d", n, ndigits);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1841 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1842 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1843 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1844 if (ndigits != 2 && !utf_isValidDchar(v))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1845 { error("invalid UTF character \\U%08x", v);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1846 v = '?'; // recover with valid UTF character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1847 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1848 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1849 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1850 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1851 error("undefined escape hex sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1852 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1853
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1854 case '&': // named character entity
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1855 for (ubyte* idstart = ++p; true; p++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1856 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1857 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1858 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1859 case ';':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1860 c = HtmlNamedEntity(idstart, p - idstart);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1861 if (c == ~0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1862 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1863 error("unnamed character entity &%s;", idstart[0..(p - idstart)]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1864 c = ' ';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1865 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1866 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1867 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1868
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1869 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1870 if (isalpha(*p) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1871 (p != idstart + 1 && isdigit(*p)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1872 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1873 error("unterminated named entity");
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 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1877 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1878 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1879
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1880 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1881 case 0x1A: // end of file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1882 c = '\\';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1883 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1884
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1885 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1886 if (isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1887 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1888 uint v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1889
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1890 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1891 v = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1892 do
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1893 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1894 v = v * 8 + (c - '0');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1895 c = *++p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1896 } while (++n < 3 && isoctal(cast(ubyte)c));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1897 c = v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1898 if (c > 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1899 error("0%03o is larger than a byte", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1900 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1901 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1902 error("undefined escape sequence \\%c\n",c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1903 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1904 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1905 return c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1906 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1907
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1908 TOK wysiwygStringConstant(Token* t, int tc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1909 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1910 uint c;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1911 Loc start = loc;
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 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1914 stringbuffer.reset();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1915 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1916 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1917 c = *p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1918 switch (c)
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 '\n':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1921 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1922 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1923
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1924 case '\r':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1925 if (*p == '\n')
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1926 continue; // ignore
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1927 c = '\n'; // treat EndOfLine as \n character
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1928 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1929 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1930
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1931 case 0:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1932 case 0x1A:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1933 error("unterminated string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1934 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1935 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1936 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1937 return TOKstring;
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 case '"':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1940 case '`':
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1941 if (c == tc)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1942 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1943 t.len = stringbuffer.offset;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1944 stringbuffer.writeByte(0);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1945 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1946 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1947 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1948 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1949 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1950 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1951 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1952
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1953 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1954 if (c & 0x80)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1955 { p--;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1956 uint u = decodeUTF();
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1957 p++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1958 if (u == PS || u == LS)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1959 loc.linnum++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1960 stringbuffer.writeUTF8(u);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1961 continue;
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 break;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1964 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1965 stringbuffer.writeByte(c);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1966 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
1967
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1968 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1969 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1970
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1971 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1972 * Lex hex strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1973 * x"0A ae 34FE BD"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1974 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1975 TOK hexStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1976 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1977 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1978 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1979 uint n = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1980 uint v;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1981
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1982 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1983 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1984 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1985 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1986 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1987 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1988 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1989 case ' ':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1990 case '\t':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1991 case '\v':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1992 case '\f':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1993 continue; // skip white space
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1994
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1995 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1996 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1997 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1998 // Treat isolated '\r' as if it were a '\n'
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
1999 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2000 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2001 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2002
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2003 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2004 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2005 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2006 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2007 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2008 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2009 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2010
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2011 case '"':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2012 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2013 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2014 error("odd number (%d) of hex characters in hex string", n);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2015 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2016 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2017 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2018 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2019 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2020 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2021 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2022 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2023 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2024
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2025 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2026 if (c >= '0' && c <= '9')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2027 c -= '0';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2028 else if (c >= 'a' && c <= 'f')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2029 c -= 'a' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2030 else if (c >= 'A' && c <= 'F')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2031 c -= 'A' - 10;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2032 else if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2033 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2034 uint u = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2035 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2036 if (u == PS || u == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2037 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2038 else
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 130
diff changeset
2039 error("non-hex character \\u%04x", u);
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2040 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2041 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2042 error("non-hex character '%c'", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2043 if (n & 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2044 { v = (v << 4) | c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2045 stringbuffer.writeByte(v);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2046 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2047 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2048 v = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2049 n++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2050 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2051 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2052 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2053 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2054
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2055 version (DMDV2) {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2056 /**************************************
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2057 * Lex delimited strings:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2058 * q"(foo(xxx))" // "foo(xxx)"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2059 * q"[foo(]" // "foo("
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2060 * q"/foo]/" // "foo]"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2061 * q"HERE
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2062 * foo
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2063 * HERE" // "foo\n"
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2064 * Input:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2065 * p is on the "
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2066 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2067 TOK delimitedStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2068 {
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2069 uint c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2070 Loc start = loc;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2071 uint delimleft = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2072 uint delimright = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2073 uint nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2074 uint nestcount;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2075 Identifier hereid = null;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2076 uint blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2077 uint startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2078
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2079 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2080 stringbuffer.reset();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2081 while (1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2082 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2083 c = *p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2084 //printf("c = '%c'\n", c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2085 switch (c)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2086 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2087 case '\n':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2088 Lnextline:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2089 loc.linnum++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2090 startline = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2091 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2092 { blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2093 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2094 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2095 if (hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2096 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2097 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2098 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2099 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2100 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2101
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2102 case '\r':
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2103 if (*p == '\n')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2104 continue; // ignore
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2105 c = '\n'; // treat EndOfLine as \n character
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2106 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2107
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2108 case 0:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2109 case 0x1A:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2110 goto Lerror;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2111
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2112 default:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2113 if (c & 0x80)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2114 { p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2115 c = decodeUTF();
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2116 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2117 if (c == PS || c == LS)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2118 goto Lnextline;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2119 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2120 break;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2121 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2122 if (delimleft == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2123 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2124 delimleft = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2125 nest = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2126 nestcount = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2127 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 (c == '[')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2132 delimright = ']';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2133 else if (c == '<')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2134 delimright = '>';
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2135 else if (isalpha(c) || c == '_' || (c >= 0x80 && isUniAlpha(c)))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2136 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2137 // Start of identifier; must be a heredoc
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2138 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2139 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2140 scan(&t2); // read in heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2141 if (t2.value != TOKidentifier)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2142 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2143 error("identifier expected for heredoc, not %s", t2.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2144 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2145 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2146 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2147 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2148 hereid = t2.ident;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2149 //printf("hereid = '%s'\n", hereid.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2150 blankrol = 1;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2151 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2152 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2153 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2154 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2155 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2156 delimright = c;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2157 nest = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2158 if (isspace(c))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2159 error("delimiter cannot be whitespace");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2160 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2161 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2162 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2163 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2164 if (blankrol)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2165 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2166 error("heredoc rest of line should be blank");
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2167 blankrol = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2168 continue;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2169 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2170 if (nest == 1)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2171 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2172 if (c == delimleft)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2173 nestcount++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2174 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2175 { nestcount--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2176 if (nestcount == 0)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2177 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2178 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2179 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2180 else if (c == delimright)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2181 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2182 if (startline && isalpha(c) && hereid)
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2183 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2184 Token t2;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2185 ubyte* psave = p;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2186 p--;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2187 scan(&t2); // read in possible heredoc identifier
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2188 //printf("endid = '%s'\n", t2.ident.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2189 if (t2.value == TOKidentifier && t2.ident.equals(hereid))
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2190 {
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2191 /* should check that rest of line is blank
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2192 */
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2193 goto Ldone;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2194 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2195 p = psave;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2196 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2197 stringbuffer.writeUTF8(c);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2198 startline = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2199 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2200 }
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2201
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2202 Ldone:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2203 if (*p == '"')
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2204 p++;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2205 else
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2206 error("delimited string must end in %c\"", delimright);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2207 t.len = stringbuffer.offset;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2208 stringbuffer.writeByte(0);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2209 void* mem = malloc(stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2210 memcpy(mem, stringbuffer.data, stringbuffer.offset);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2211 t.ustring = cast(const(char)*)mem;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2212 stringPostfix(t);
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2213 return TOKstring;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2214
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2215 Lerror:
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2216 error("unterminated string constant starting at %s", start.toChars());
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2217 t.ustring = "".ptr;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2218 t.len = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2219 t.postfix = 0;
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 49
diff changeset
2220 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2221 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2222
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2223 /**************************************
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2224 * Lex delimited strings:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2225 * q{ foo(xxx) } // " foo(xxx) "
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2226 * q{foo(} // "foo("
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2227 * q{{foo}"}"} // "{foo}"}""
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2228 * Input:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2229 * p is on the q
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2230 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2231 TOK tokenStringConstant(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2232 {
8
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2233 uint nest = 1;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2234 Loc start = loc;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2235 ubyte* pstart = ++p;
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 while (true)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2238 {
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2239 Token tok;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2240
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2241 scan(&tok);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2242 switch (tok.value)
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 TOKlcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2245 nest++;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2246 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2247
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2248 case TOKrcurly:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2249 if (--nest == 0)
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2250 goto Ldone;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2251 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2252
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2253 case TOKeof:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2254 goto Lerror;
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 default:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2257 continue;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2258 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2259 }
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2260
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2261 Ldone:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2262 t.len = p - 1 - pstart;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2263 char* tmp = cast(char*)GC.malloc(t.len + 1);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2264 memcpy(tmp, pstart, t.len);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2265 tmp[t.len] = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2266 t.ustring = tmp;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2267 stringPostfix(t);
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2268 return TOKstring;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2269
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2270 Lerror:
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2271 error("unterminated token string constant starting at %s", start.toChars());
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2272 t.ustring = "".ptr;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2273 t.len = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2274 t.postfix = 0;
d42cd5917df4 wysiwyg strings, alias this, templates, TypeSlice implementation
dkoroskin <>
parents: 4
diff changeset
2275 return TOKstring;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2276 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2277 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2278 TOK escapeStringConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2279 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2280 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2281 Loc start = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2282
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2283 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2284 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2285 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2286 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2287 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2288 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2289 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2290 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2291 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2292 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2293 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2294 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2295 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2296 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2297 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2298 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2299 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2300 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2301
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2302 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2303 c = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2304 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2305 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2306 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2307 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2308 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2309 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2310 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2311
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2312 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2313 if (*p == '\n')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2314 continue; // ignore
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2315 c = '\n'; // treat EndOfLine as \n character
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2316 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2317 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2318
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2319 case '"':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2320 t.len = stringbuffer.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2321 stringbuffer.writeByte(0);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
2322 char* tmp = cast(char*)GC.malloc(stringbuffer.offset);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2323 memcpy(tmp, stringbuffer.data, stringbuffer.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2324 t.ustring = tmp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2325 stringPostfix(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2326 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2327
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2328 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2329 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2330 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2331 error("unterminated string constant starting at %s", start.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2332 t.ustring = "".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2333 t.len = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2334 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2335 return TOK.TOKstring;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2336
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2337 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2338 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2339 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2340 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2341 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2342 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2343 { c = '\n';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2344 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2345 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2346 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2347 stringbuffer.writeUTF8(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2348 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2350 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2351 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2352 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2354
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2355 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2356 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2357
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2358 TOK charConstant(Token* t, int wide)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2359 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2360 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2361 TOK tk = TOKcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2363 //printf("Lexer.charConstant\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2364 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2365 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2366 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2367 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2368 version (TEXTUAL_ASSEMBLY_OUT) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2369 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2370 case '\\':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2371 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2372 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2373 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2374 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2375 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2376 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2377
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2378 case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2379 case '&':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2380 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2381 tk = TOKdcharv;
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 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2385 t.uns64value = escapeSequence();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2386 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2387 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2388 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2389 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2390 case '\n':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2391 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2392 loc.linnum++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2393 case '\r':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2394 case 0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2395 case 0x1A:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2396 case '\'':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2397 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2398 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2400 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2401 if (c & 0x80)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2402 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2403 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2404 c = decodeUTF();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2405 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2406 if (c == LS || c == PS)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2407 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2408 if (c < 0xD800 || (c >= 0xE000 && c < 0xFFFE))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2409 tk = TOKwcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2410 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2411 tk = TOKdcharv;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2412 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2413 t.uns64value = c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2414 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2415 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2417 if (*p != '\'')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2418 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2419 error("unterminated character constant");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2420 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2421 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2422 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2423 return tk;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2425
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2426 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2427 * Get postfix of string literal.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2428 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2429 void stringPostfix(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2430 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2431 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2432 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2433 case 'c':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2434 case 'w':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2435 case 'd':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2436 t.postfix = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2437 p++;
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 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2441 t.postfix = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2442 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2443 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2444 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2445
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2446 uint wchar_(uint u)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2447 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2448 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2449 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2450
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2451 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2452 * Read in a number.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2453 * If it's an integer, store it in tok.TKutok.Vlong.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2454 * integers can be decimal, octal or hex
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2455 * Handle the suffixes U, UL, LU, L, etc.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2456 * If it's double, store it in tok.TKutok.Vdouble.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2457 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2458 * TKnum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2459 * TKdouble,...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2460 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2461
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2462 TOK number(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2463 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2464 // We use a state machine to collect numbers
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2465 enum STATE { STATE_initial, STATE_0, STATE_decimal, STATE_octal, STATE_octale,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2466 STATE_hex, STATE_binary, STATE_hex0, STATE_binary0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2467 STATE_hexh, STATE_error };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2468 STATE state;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2469
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2470 enum FLAGS
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2471 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2472 FLAGS_undefined = 0,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2473 FLAGS_decimal = 1, // decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2474 FLAGS_unsigned = 2, // u or U suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2475 FLAGS_long = 4, // l or L suffix
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2476 };
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2477
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2478 FLAGS flags = FLAGS.FLAGS_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2479
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2480 int i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2481 int base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2482 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2483 ubyte *start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2484 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2485
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2486 //printf("Lexer.number()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2487 state = STATE.STATE_initial;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2488 base = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2489 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2490 start = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2491 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2492 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2493 c = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2494 switch (state)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2495 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2496 case STATE.STATE_initial: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2497 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2498 state = STATE.STATE_0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2499 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2500 state = STATE.STATE_decimal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2501 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2503 case STATE.STATE_0:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2504 flags = (flags & ~FLAGS.FLAGS_decimal);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2505 switch (c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2506 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2507 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2508 case 'H': // 0h
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2509 case 'h':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2510 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2511 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2512 case 'X':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2513 case 'x':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2514 state = STATE.STATE_hex0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2515 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2516
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2517 case '.':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2518 if (p[1] == '.') // .. is a separate token
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2519 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2520 case 'i':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2521 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2522 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2523 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2524 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2525 case 'E':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2526 case 'e':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2527 goto case_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2528 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2529 case 'B':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2530 case 'b':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2531 state = STATE.STATE_binary0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2532 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2533
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2534 case '0': case '1': case '2': case '3':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2535 case '4': case '5': case '6': case '7':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2536 state = STATE.STATE_octal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2537 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2538
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2539 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2540 case '8': case '9': case 'A':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2541 case 'C': case 'D': case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2542 case 'a': case 'c': case 'd': case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2543 case_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2544 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2545 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2546 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2547 case '_':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2548 state = STATE.STATE_octal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2549 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2550 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2551
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2552 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2553 if (p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2554 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2555 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2557 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2558 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2559 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2560 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2561
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2562 case STATE.STATE_decimal: // reading decimal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2563 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2564 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2565 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2566 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2567 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2568 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2569 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2570 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2571 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2572 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2573 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2574 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2575 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2576 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2577 else if (c == 'i' || c == 'f' || c == 'F' ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2578 c == 'e' || c == 'E')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2579 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2580 real_: // It's a real number. Back up and rescan as a real
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2581 p = start;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2582 return inreal(t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2583 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2584 else if (c == 'L' && p[1] == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2585 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2586 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2587 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2588 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2590 case STATE.STATE_hex0: // reading hex number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2591 case STATE.STATE_hex:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2592 if (! ishex(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2593 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2594 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2595 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2596 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2597 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2598 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2599 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2600 if (c == 'P' || c == 'p' || c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2601 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2602 if (state == STATE.STATE_hex0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2603 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2604 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2605 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2606 state = STATE.STATE_hex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2607 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2608
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2609 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2610 hexh:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2611 state = STATE.STATE_hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2612 case STATE.STATE_hexh: // parse numbers like 0FFh
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2613 if (!ishex(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2614 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2615 if (c == 'H' || c == 'h')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2616 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2617 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2618 base = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2619 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2620 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2621 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2622 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2623 // Check for something like 1E3 or 0E24
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2624 if (memchr(cast(char*)stringbuffer.data, 'E', stringbuffer.offset) ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2625 memchr(cast(char*)stringbuffer.data, 'e', stringbuffer.offset))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2626 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2627 error("Hex digit expected, not '%c'", c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2628 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2629 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2630 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2631 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2632 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2633
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2634 case STATE.STATE_octal: // reading octal number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2635 case STATE.STATE_octale: // reading octal number with non-octal digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2636 if (!isoctal(cast(ubyte)c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2637 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2638 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2639 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2640 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2641 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2642 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2643 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2644 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2645 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2646 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2647 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2648 if (c == '.' && p[1] != '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2649 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2650 if (c == 'i')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2651 goto real_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2652 if (isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2653 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2654 state = STATE.STATE_octale;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2655 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2656 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2657 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2658 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2659 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2660
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2661 case STATE.STATE_binary0: // starting binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2662 case STATE.STATE_binary: // reading binary number
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2663 if (c != '0' && c != '1')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2664 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2665 version (ZEROH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2666 if (ishex(c)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2667 || c == 'H' || c == 'h'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2668 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2669 goto hexh;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2670 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2671 if (c == '_') // ignore embedded _
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2672 { p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2673 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2674 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2675 if (state == STATE.STATE_binary0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2676 { error("binary digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2677 state = STATE.STATE_error;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2678 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2679 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2680 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2681 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2682 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2683 state = STATE.STATE_binary;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2684 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2685
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2686 case STATE.STATE_error: // for error recovery
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2687 if (!isdigit(c)) // scan until non-digit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2688 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2689 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2690
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2691 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2692 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2693 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2694 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2695 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2696 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2697 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2698 stringbuffer.writeByte(0); // terminate string
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2699 if (state == STATE.STATE_octale)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2700 error("Octal digit expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2701
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2702 ulong n; // unsigned >=64 bit integer type
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2703
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2704 if (stringbuffer.offset == 2 && (state == STATE.STATE_decimal || state == STATE.STATE_0))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2705 n = stringbuffer.data[0] - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2706 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2707 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2708 // Convert string to integer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2709 version (__DMC__) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2710 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2711 n = strtoull(cast(char*)stringbuffer.data,null,base);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2712 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2713 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2714 } else {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2715 // Not everybody implements strtoull()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2716 char* p = cast(char*)stringbuffer.data;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2717 int r = 10, d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2718
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2719 if (*p == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2720 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2721 if (p[1] == 'x' || p[1] == 'X')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2722 p += 2, r = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2723 else if (p[1] == 'b' || p[1] == 'B')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2724 p += 2, r = 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2725 else if (isdigit(p[1]))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2726 p += 1, r = 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2727 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2728
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2729 n = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2730 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2731 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2732 if (*p >= '0' && *p <= '9')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2733 d = *p - '0';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2734 else if (*p >= 'a' && *p <= 'z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2735 d = *p - 'a' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2736 else if (*p >= 'A' && *p <= 'Z')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2737 d = *p - 'A' + 10;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2738 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2739 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2740 if (d >= r)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2741 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2742 ulong n2 = n * r;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2743 //printf("n2 / r = %llx, n = %llx\n", n2/r, n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2744 if (n2 / r != n || n2 + d < n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2745 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2746 error ("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2747 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2748 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2749
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2750 n = n2 + d;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2751 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2752 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2753 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2754 if (n.sizeof > 8 &&
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2755 n > 0xFFFFFFFFFFFFFFFF) // if n needs more than 64 bits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2756 error("integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2757 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2758
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2759 // Parse trailing 'u', 'U', 'l' or 'L' in any combination
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2760 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2761 { FLAGS f;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2762
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2763 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2764 { case 'U':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2765 case 'u':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2766 f = FLAGS.FLAGS_unsigned;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2767 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2768
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2769 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2770 if (1 || !global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2771 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2772 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2773 f = FLAGS.FLAGS_long;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2774 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2775 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2776 if (flags & f)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2777 error("unrecognized token");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2778 flags = (flags | f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2779 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2780 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2781 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2782 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2783 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2784 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2785
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2786 switch (flags)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2787 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2788 case FLAGS.FLAGS_undefined:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2789 /* Octal or Hexadecimal constant.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2790 * First that fits: int, uint, long, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2791 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2792 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2793 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2794 else if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2795 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2796 else if (n & 0x80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2797 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2798 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2799 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2800 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2801
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2802 case FLAGS.FLAGS_decimal:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2803 /* First that fits: int, long, long long
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2804 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2805 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2806 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2807 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2808 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2809 else if (n & 0xFFFFFFFF80000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2810 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2811 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2812 result = TOK.TOKint32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2813 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2814
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2815 case FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2816 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2817 /* First that fits: uint, ulong
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2818 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2819 if (n & 0xFFFFFFFF00000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2820 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2821 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2822 result = TOK.TOKuns32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2823 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2824
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2825 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2826 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2827 { error("signed integer overflow");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2828 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2829 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2830 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2831 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2832 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2833
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2834 case FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2835 if (n & 0x8000000000000000)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2836 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2837 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2838 result = TOK.TOKint64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2839 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2840
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2841 case FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2842 case FLAGS.FLAGS_decimal | FLAGS.FLAGS_unsigned | FLAGS.FLAGS_long:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2843 result = TOK.TOKuns64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2844 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2845
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2846 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2847 debug {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2848 printf("%x\n",flags);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2849 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2850 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2851 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2852 t.uns64value = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2853 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2854 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2855
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2856 /**************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2857 * Read in characters, converting them to real.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2858 * Bugs:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2859 * Exponent overflow not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2860 * Too much requested precision is not detected.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2861 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2862 TOK inreal(Token* t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2863 in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2864 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2865 assert(*p == '.' || isdigit(*p));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2866 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2867 out (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2868 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2869 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2870 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2871 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2872 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2873 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2874 case TOKimaginary32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2875 case TOKimaginary64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2876 case TOKimaginary80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2877 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2878
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2879 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2880 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2881 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2882 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2883 body
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2884 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2885 int dblstate;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2886 uint c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2887 char hex; // is this a hexadecimal-floating-constant?
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2888 TOK result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2889
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2890 //printf("Lexer.inreal()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2891 stringbuffer.reset();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2892 dblstate = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2893 hex = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2894 Lnext:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2895 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2896 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2897 // Get next char from input
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2898 c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2899 //printf("dblstate = %d, c = '%c'\n", dblstate, c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2900 while (true)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2901 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2902 switch (dblstate)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2903 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2904 case 0: // opening state
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2905 if (c == '0')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2906 dblstate = 9;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2907 else if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2908 dblstate = 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2909 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2910 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2911 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2912
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2913 case 9:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2914 dblstate = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2915 if (c == 'X' || c == 'x')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2916 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2917 hex++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2918 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2919 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2920 case 1: // digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2921 case 3: // digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2922 case 7: // continuing exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2923 if (!isdigit(c) && !(hex && isxdigit(c)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2924 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2925 if (c == '_')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2926 goto Lnext; // ignore embedded '_'
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2927 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2928 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2929 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2930 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2931
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2932 case 2: // no more digits to left of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2933 if (c == '.')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2934 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2935 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2936 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2937 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2938 case 4: // no more digits to right of .
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2939 if ((c == 'E' || c == 'e') ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2940 hex && (c == 'P' || c == 'p'))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2941 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2942 dblstate = 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2943 hex = 0; // exponent is always decimal
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2944 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2945 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2946 if (hex)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2947 error("binary-exponent-part required");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2948 goto done;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2949
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2950 case 5: // looking immediately to right of E
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2951 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2952 if (c == '-' || c == '+')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2953 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2954 case 6: // 1st exponent digit expected
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2955 if (!isdigit(c))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2956 error("exponent expected");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2957 dblstate++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2958 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2959
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2960 case 8: // past end of exponent digits
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2961 goto done;
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2962
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2963 default:
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
2964 assert(0, "inreal.dblstate has unexpected value");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2965 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2966 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2967 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2968 stringbuffer.writeByte(c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2969 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2970 done:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2971 p--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2972
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2973 stringbuffer.writeByte(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2974
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
2975 version (Windows) { /// && __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2976 char* save = __locale_decpoint;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2977 __locale_decpoint = cast(char*)".".ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2978 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2979 t.float80value = strtold(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2980
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2981 errno = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2982 switch (*p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2983 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2984 case 'F':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2985 case 'f':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2986 strtof(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2987 result = TOKfloat32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2988 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2989 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2990
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2991 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2992 strtod(cast(char*)stringbuffer.data, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2993 result = TOKfloat64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2994 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2995
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2996 case 'l':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2997 if (!global.params.useDeprecated)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2998 error("'l' suffix is deprecated, use 'L' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2999 case 'L':
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3000 result = TOKfloat80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3001 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3002 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3003 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3004 if (*p == 'i' || *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3005 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3006 if (!global.params.useDeprecated && *p == 'I')
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3007 error("'I' suffix is deprecated, use 'i' instead");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3008 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3009 switch (result)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3010 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3011 case TOKfloat32v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3012 result = TOKimaginary32v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3013 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3014 case TOKfloat64v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3015 result = TOKimaginary64v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3016 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3017 case TOKfloat80v:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3018 result = TOKimaginary80v;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3019 break;
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3020 default:
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3021 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3022 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3023
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 79
diff changeset
3024 version (Windows) { ///&& __DMC__
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3025 __locale_decpoint = save;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3026 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3027 if (errno == ERANGE)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3028 error("number is not representable");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3029
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3030 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3031 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3032
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3033 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3034 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3035 error(this.loc, format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3036 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3037
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3038 void error(T...)(Loc loc, string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3039 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3040 if (mod && !global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3041 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3042 string p = loc.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3043 if (p.length != 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3044 writef("%s: ", p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3045
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3046 writefln(format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3047
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3048 if (global.errors >= 20) // moderate blizzard of cascading messages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3049 fatal();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3050 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3051
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3052 global.errors++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3053 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3054
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3055 /*********************************************
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3056 * Do pragma.
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3057 * Currently, the only pragma supported is:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3058 * #line linnum [filespec]
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3059 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3060 void pragma_()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3061 {
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3062 Token tok;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3063 int linnum;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3064 string filespec = null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3065 Loc loc = this.loc;
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 != TOKidentifier || tok.ident != Id.line)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3069 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3070
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3071 scan(&tok);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3072 if (tok.value == TOKint32v || tok.value == TOKint64v)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3073 linnum = cast(int)(tok.uns64value - 1); ///
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3074 else
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3075 goto Lerr;
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 while (1)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3078 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3079 switch (*p)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3080 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3081 case 0:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3082 case 0x1A:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3083 case '\n':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3084 Lnewline:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3085 this.loc.linnum = linnum;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3086 if (filespec != null)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3087 this.loc.filename = filespec;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3088 return;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3089
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3090 case '\r':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3091 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3092 if (*p != '\n')
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3093 { p--;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3094 goto Lnewline;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3095 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3096 continue;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3097
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3098 case ' ':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3099 case '\t':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3100 case '\v':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3101 case '\f':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3102 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3103 continue; // skip white space
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3104
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3105 case '_':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3106 if (mod && memcmp(p, "__FILE__".ptr, 8) == 0)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3107 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3108 p += 8;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3109 filespec = (loc.filename ? loc.filename : mod.ident.toChars());
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3110 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3111 continue;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3112
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3113 case '"':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3114 if (filespec)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3115 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3116 stringbuffer.reset();
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3117 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3118 while (1)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3119 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3120 uint c;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3121
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3122 c = *p;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3123 switch (c)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3124 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3125 case '\n':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3126 case '\r':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3127 case 0:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3128 case 0x1A:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3129 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3130
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3131 case '"':
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3132 stringbuffer.writeByte(0);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3133 filespec = stringbuffer.extractString(); ///
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3134 p++;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3135 break;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3136
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3137 default:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3138 if (c & 0x80)
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 uint u = decodeUTF();
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3141 if (u == PS || u == LS)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3142 goto Lerr;
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 stringbuffer.writeByte(c);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3145 p++;
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 break;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3149 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3150 continue;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3151
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3152 default:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3153 if (*p & 0x80)
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 uint u = decodeUTF();
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3156 if (u == PS || u == LS)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3157 goto Lnewline;
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 goto Lerr;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3160 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3161 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3163 Lerr:
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 157
diff changeset
3164 error(loc, "#line integer [\"filespec\"]\\n expected");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3165 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3166
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3167 /********************************************
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3168 * Decode UTF character.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3169 * Issue error messages for invalid sequences.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3170 * Return decoded character, advance p to last character in UTF sequence.
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3171 */
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3172 uint decodeUTF()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3173 {
49
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3174 dchar u;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3175 ubyte c;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3176 ubyte* s = p;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3177 size_t len;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3178 size_t idx;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3179 string msg;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3180
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3181 c = *s;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3182 assert(c & 0x80);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3183
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3184 // Check length of remaining string up to 6 UTF-8 characters
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3185 for (len = 1; len < 6 && s[len]; len++) {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3186 ;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3187 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3188
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3189 idx = 0;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3190 msg = utf_decodeChar(cast(string)s[0..len], &idx, &u);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3191 p += idx - 1;
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3192 if (msg)
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3193 {
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3194 error("%s", msg);
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3195 }
0aa7d1437ada AttribDeclaration.oneMember
korDen
parents: 34
diff changeset
3196 return u;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3197 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3198
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3199 /***************************************************
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3200 * Parse doc comment embedded between t.ptr and p.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3201 * Remove trailing blanks and tabs from lines.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3202 * Replace all newlines with \n.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3203 * Remove leading comment character from each line.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3204 * Decide if it's a lineComment or a blockComment.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3205 * Append to previous one for this token.
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 void getDocComment(Token* t, uint lineComment)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3208 {
157
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3209 /* ct tells us which kind of comment it is: '!', '/', '*', 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 ct = t.ptr[2];
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 /* Start of comment text skips over / * *, / + +, or / / /
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3214 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3215 ubyte* q = t.ptr + 3; // start of comment text
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 ubyte* qend = p;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3218 if (ct == '*' || ct == '+')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3219 qend -= 2;
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 /* Scan over initial row of ****'s or ++++'s or ////'s
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3222 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3223 for (; q < qend; q++)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3224 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3225 if (*q != ct)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3226 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3227 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3228
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3229 /* Remove trailing row of ****'s or ++++'s
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 (ct != '/' && ct != '!')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3232 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3233 for (; q < qend; qend--)
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 if (qend[-1] != ct)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3236 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3237 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3238 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3239
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3240 /* Comment is now [q .. qend].
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3241 * Canonicalize it into buf[].
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3242 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3243 OutBuffer buf = new OutBuffer;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3244 int linestart = 0;
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 for (; q < qend; q++)
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 ubyte c = *q;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3249
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3250 switch (c)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3251 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3252 case '*':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3253 case '+':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3254 if (linestart && c == ct)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3255 { linestart = 0;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3256 /* Trim preceding whitespace up to preceding \n
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 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
3259 buf.offset--;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3260 continue;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3261 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3262 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 ' ':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3265 case '\t':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3266 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3267
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3268 case '\r':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3269 if (q[1] == '\n')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3270 continue; // skip the \r
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3271 goto Lnewline;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3272
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3273 default:
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3274 if (c == 226)
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 // If LS or PS
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3277 if (q[1] == 128 &&
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3278 (q[2] == 168 || q[2] == 169))
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 q += 2;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3281 goto Lnewline;
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 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3284 linestart = 0;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3285 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3286
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3287 Lnewline:
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3288 c = '\n'; // replace all newlines with \n
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3289 case '\n':
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3290 linestart = 1;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3291
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3292 /* Trim trailing whitespace
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3293 */
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3294 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
3295 buf.offset--;
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 break;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3298 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3299 buf.writeByte(c);
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3300 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3301
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3302 // Always end with a newline
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3303 if (!buf.offset || buf.data[buf.offset - 1] != '\n')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3304 buf.writeByte('\n');
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3305
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3306 buf.writeByte(0);
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3307
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3308 // 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
3309 // after other non-whitespace on the same line.
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3310 string* dc = (lineComment && anyToken)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3311 ? &t.lineComment
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3312 : &t.blockComment;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3313
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3314 // Combine with previous doc comment, if any
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3315 if (*dc)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3316 *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
3317 else
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 auto bufsize = buf.size;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3320 *dc = cast(string) buf.extractData()[0..bufsize];
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3321 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3322 }
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 /********************************************
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3325 * Combine two document comments into one,
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3326 * separated by a newline.
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 static string combineComments(string c1, string 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 //printf("Lexer::combineComments('%s', '%s')\n", c1, c2);
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 string c = c2;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3333
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3334 if (c1)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3335 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3336 c = c1;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3337 if (c2)
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3338 {
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3339 size_t len1 = c1.length;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3340 size_t len2 = c2.length;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3341
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3342 c = c1.idup;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3343 if (len1 && c1[$-1] != '\n')
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3344 c ~= '\n';
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3345 c ~= c2;
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3346 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3347 }
b7b61140701d * added all missing default cases in switch statements
trass3r
parents: 135
diff changeset
3348 return c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3349 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3350
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3351 static bool isValidIdentifier(string p)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3352 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3353 if (p.length == 0) {
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 if (p[0] >= '0' && p[0] <= '9') { // beware of isdigit() on signed chars
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3358 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3359 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3360
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3361 size_t idx = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3362 while (idx < p.length)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3363 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3364 dchar dc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3366 if (utf_decodeChar(p, &idx, &dc) !is null) {
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 if (!((dc >= 0x80 && isUniAlpha(dc)) || isalnum(dc) || dc == '_')) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3371 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3372 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3373 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3374
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3375 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3376 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3377
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3378 /// TODO: use normal string append when GC works
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3379 static string combineComments(const(char)[] c1, const(char)[] c2)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3380 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3381 //writef("Lexer.combineComments('%s', '%s')\n", c1, c2);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3382
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3383 char[] c = cast(char[]) c2;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3384
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3385 if (c1 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3386 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3387 c = cast(char[]) c1;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3388 if (c2 !is null)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3389 {
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3390 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
3391 size_t len1 = c1.length;
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3392 c[0..len1] = c1[];
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3393 c[len1++] = '\n';
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3394 c[len1 .. len1 + c2.length] = c2[];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3395 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3396 }
79
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3397
43073c7c7769 updated to 2.035
Trass3r
parents: 73
diff changeset
3398 return cast(string)c;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3399 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
3400 }