Mercurial > projects > dil
comparison trunk/src/dil/lexer/Funcs.d @ 715:b6c6baa41267
Moved character properties table to dil.lexer.Funcs.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Thu, 31 Jan 2008 15:58:10 +0100 |
parents | 9e811db780a6 |
children | 5e3ef1b2011c |
comparison
equal
deleted
inserted
replaced
714:140469ecb90e | 715:b6c6baa41267 |
---|---|
78 return '\n'; | 78 return '\n'; |
79 } | 79 } |
80 } | 80 } |
81 return 0; | 81 return 0; |
82 } | 82 } |
83 | |
84 /// ASCII character properties table. | |
85 static const int ptable[256] = [ | |
86 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0,32,32, 0, 0, 0, | |
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
88 32, 0, 0x2200, 0, 0, 0, 0, 0x2700, 0, 0, 0, 0, 0, 0, 0, 0, | |
89 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 0, 0, 0, 0, 0, 0x3f00, | |
90 0,12,12,12,12,12,12, 8, 8, 8, 8, 8, 8, 8, 8, 8, | |
91 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0x5c00, 0, 0,16, | |
92 0, 0x70c, 0x80c,12,12,12, 0xc0c, 8, 8, 8, 8, 8, 8, 8, 0xa08, 8, | |
93 8, 8, 0xd08, 8, 0x908, 8, 0xb08, 8, 8, 8, 8, 0, 0, 0, 0, 0, | |
94 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
95 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
96 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
97 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
98 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
99 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
100 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
101 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
102 ]; | |
103 | |
104 enum CProperty | |
105 { | |
106 Octal = 1, | |
107 Digit = 1<<1, | |
108 Hex = 1<<2, | |
109 Alpha = 1<<3, | |
110 Underscore = 1<<4, | |
111 Whitespace = 1<<5 | |
112 } | |
113 | |
114 const uint EVMask = 0xFF00; // Bit mask for escape value | |
115 | |
116 private alias CProperty CP; | |
117 int isoctal(char c) { return ptable[c] & CP.Octal; } | |
118 int isdigit(char c) { return ptable[c] & CP.Digit; } | |
119 int ishexad(char c) { return ptable[c] & CP.Hex; } | |
120 int isalpha(char c) { return ptable[c] & CP.Alpha; } | |
121 int isalnum(char c) { return ptable[c] & (CP.Alpha | CP.Digit); } | |
122 int isidbeg(char c) { return ptable[c] & (CP.Alpha | CP.Underscore); } | |
123 int isident(char c) { return ptable[c] & (CP.Alpha | CP.Underscore | CP.Digit); } | |
124 int isspace(char c) { return ptable[c] & CP.Whitespace; } | |
125 int char2ev(char c) { return ptable[c] >> 8; /*(ptable[c] & EVMask) >> 8;*/ } | |
126 int isascii(uint c) { return c < 128; } | |
127 | |
128 version(gen_ptable) | |
129 static this() | |
130 { | |
131 alias ptable p; | |
132 assert(p.length == 256); | |
133 // Initialize character properties table. | |
134 for (int i; i < p.length; ++i) | |
135 { | |
136 p[i] = 0; // Reset | |
137 if ('0' <= i && i <= '7') | |
138 p[i] |= CP.Octal; | |
139 if ('0' <= i && i <= '9') | |
140 p[i] |= CP.Digit | CP.Hex; | |
141 if ('a' <= i && i <= 'f' || 'A' <= i && i <= 'F') | |
142 p[i] |= CP.Hex; | |
143 if ('a' <= i && i <= 'z' || 'A' <= i && i <= 'Z') | |
144 p[i] |= CP.Alpha; | |
145 if (i == '_') | |
146 p[i] |= CP.Underscore; | |
147 if (i == ' ' || i == '\t' || i == '\v' || i == '\f') | |
148 p[i] |= CP.Whitespace; | |
149 } | |
150 // Store escape sequence values in second byte. | |
151 assert(CProperty.max <= ubyte.max, "character property flags and escape value byte overlap."); | |
152 p['\''] |= 39 << 8; | |
153 p['"'] |= 34 << 8; | |
154 p['?'] |= 63 << 8; | |
155 p['\\'] |= 92 << 8; | |
156 p['a'] |= 7 << 8; | |
157 p['b'] |= 8 << 8; | |
158 p['f'] |= 12 << 8; | |
159 p['n'] |= 10 << 8; | |
160 p['r'] |= 13 << 8; | |
161 p['t'] |= 9 << 8; | |
162 p['v'] |= 11 << 8; | |
163 // Print a formatted array literal. | |
164 char[] array = "[\n"; | |
165 foreach (i, c; ptable) | |
166 { | |
167 array ~= Format((c>255?" 0x{0:x},":"{0,2},"), c) ~ (((i+1) % 16) ? "":"\n"); | |
168 } | |
169 array[$-2..$] = "\n]"; | |
170 Stdout(array).newline; | |
171 } |