Mercurial > projects > dil
changeset 55:5887751f8e04
- Relocated ptable to the bottom of the source file.
author | aziz |
---|---|
date | Wed, 27 Jun 2007 18:02:05 +0000 |
parents | e55bd2270f94 |
children | 63af7ddf52e1 |
files | trunk/src/Lexer.d |
diffstat | 1 files changed, 88 insertions(+), 88 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/Lexer.d Wed Jun 27 17:58:00 2007 +0000 +++ b/trunk/src/Lexer.d Wed Jun 27 18:02:05 2007 +0000 @@ -12,94 +12,6 @@ import std.uni; import std.conv; -/// ASCII character properties table. -static const int ptable[256] = [ - 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0,32,32, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -32, 0, 0x2200, 0, 0, 0, 0, 0x2700, 0, 0, 0, 0, 0, 0, 0, 0, - 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 0, 0, 0, 0, 0, 0x3f00, - 0,12,12,12,12,12,12, 8, 8, 8, 8, 8, 8, 8, 8, 8, - 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0x5c00, 0, 0,16, - 0, 0x70c, 0x80c,12,12,12, 0xc0c, 8, 8, 8, 8, 8, 8, 8, 0xa08, 8, - 8, 8, 0xd08, 8, 0x908, 8, 0xb08, 8, 8, 8, 8, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -]; - -enum CProperty -{ - Octal = 1, - Digit = 1<<1, - Hex = 1<<2, - Alpha = 1<<3, - Underscore = 1<<4, - Whitespace = 1<<5 -} - -const uint EVMask = 0xFF00; // Bit mask for escape value - -private alias CProperty CP; -int isoctal(char c) { return ptable[c] & CP.Octal; } -int isdigit(char c) { return ptable[c] & CP.Digit; } -int ishexad(char c) { return ptable[c] & CP.Hex; } -int isalpha(char c) { return ptable[c] & CP.Alpha; } -int isalnum(char c) { return ptable[c] & (CP.Alpha | CP.Digit); } -int isidbeg(char c) { return ptable[c] & (CP.Alpha | CP.Underscore); } -int isident(char c) { return ptable[c] & (CP.Alpha | CP.Underscore | CP.Digit); } -int isspace(char c) { return ptable[c] & CP.Whitespace; } -int char2ev(char c) { return ptable[c] >> 8; /*(ptable[c] & EVMask) >> 8;*/ } - -version(gen_ptable) -static this() -{ - alias ptable p; - // Initialize character properties table. - for (int i; i < p.length; ++i) - { - p[i] = 0; - if ('0' <= i && i <= '7') - p[i] |= CP.Octal; - if ('0' <= i && i <= '9') - p[i] |= CP.Digit; - if (isdigit(i) || 'a' <= i && i <= 'f' || 'A' <= i && i <= 'F') - p[i] |= CP.Hex; - if ('a' <= i && i <= 'z' || 'A' <= i && i <= 'Z') - p[i] |= CP.Alpha; - if (i == '_') - p[i] |= CP.Underscore; - if (i == ' ' || i == '\t' || i == '\v' || i == '\f') - p[i] |= CP.Whitespace; - } - // Store escape sequence values in second byte. - assert(CProperty.max <= ubyte.max, "character property flags and escape value byte overlap."); - p['\''] |= 39 << 8; - p['"'] |= 34 << 8; - p['?'] |= 63 << 8; - p['\\'] |= 92 << 8; - p['a'] |= 7 << 8; - p['b'] |= 8 << 8; - p['f'] |= 12 << 8; - p['n'] |= 10 << 8; - p['r'] |= 13 << 8; - p['t'] |= 9 << 8; - p['v'] |= 11 << 8; - // Print a formatted array literal. - char[] array = "[\n"; - for (int i; i < p.length; ++i) - { - int c = p[i]; - array ~= std.string.format(c>255?" 0x%x,":"%2d,", c, ((i+1) % 16) ? "":"\n"); - } - array[$-2..$] = "\n]"; - writefln(array); -} - const char[3] LS = \u2028; const char[3] PS = \u2029; @@ -1195,3 +1107,91 @@ foreach (i, t; tokens) assert(t.span == toks[i], std.string.format("Lexed '%s' but expected '%s'", t.span, toks[i])); } + +/// ASCII character properties table. +static const int ptable[256] = [ + 0, 0, 0, 0, 0, 0, 0, 0, 0,32, 0,32,32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +32, 0, 0x2200, 0, 0, 0, 0, 0x2700, 0, 0, 0, 0, 0, 0, 0, 0, + 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 0, 0, 0, 0, 0, 0x3f00, + 0,12,12,12,12,12,12, 8, 8, 8, 8, 8, 8, 8, 8, 8, + 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 0, 0x5c00, 0, 0,16, + 0, 0x70c, 0x80c,12,12,12, 0xc0c, 8, 8, 8, 8, 8, 8, 8, 0xa08, 8, + 8, 8, 0xd08, 8, 0x908, 8, 0xb08, 8, 8, 8, 8, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +]; + +enum CProperty +{ + Octal = 1, + Digit = 1<<1, + Hex = 1<<2, + Alpha = 1<<3, + Underscore = 1<<4, + Whitespace = 1<<5 +} + +const uint EVMask = 0xFF00; // Bit mask for escape value + +private alias CProperty CP; +int isoctal(char c) { return ptable[c] & CP.Octal; } +int isdigit(char c) { return ptable[c] & CP.Digit; } +int ishexad(char c) { return ptable[c] & CP.Hex; } +int isalpha(char c) { return ptable[c] & CP.Alpha; } +int isalnum(char c) { return ptable[c] & (CP.Alpha | CP.Digit); } +int isidbeg(char c) { return ptable[c] & (CP.Alpha | CP.Underscore); } +int isident(char c) { return ptable[c] & (CP.Alpha | CP.Underscore | CP.Digit); } +int isspace(char c) { return ptable[c] & CP.Whitespace; } +int char2ev(char c) { return ptable[c] >> 8; /*(ptable[c] & EVMask) >> 8;*/ } + +version(gen_ptable) +static this() +{ + alias ptable p; + // Initialize character properties table. + for (int i; i < p.length; ++i) + { + p[i] = 0; + if ('0' <= i && i <= '7') + p[i] |= CP.Octal; + if ('0' <= i && i <= '9') + p[i] |= CP.Digit; + if (isdigit(i) || 'a' <= i && i <= 'f' || 'A' <= i && i <= 'F') + p[i] |= CP.Hex; + if ('a' <= i && i <= 'z' || 'A' <= i && i <= 'Z') + p[i] |= CP.Alpha; + if (i == '_') + p[i] |= CP.Underscore; + if (i == ' ' || i == '\t' || i == '\v' || i == '\f') + p[i] |= CP.Whitespace; + } + // Store escape sequence values in second byte. + assert(CProperty.max <= ubyte.max, "character property flags and escape value byte overlap."); + p['\''] |= 39 << 8; + p['"'] |= 34 << 8; + p['?'] |= 63 << 8; + p['\\'] |= 92 << 8; + p['a'] |= 7 << 8; + p['b'] |= 8 << 8; + p['f'] |= 12 << 8; + p['n'] |= 10 << 8; + p['r'] |= 13 << 8; + p['t'] |= 9 << 8; + p['v'] |= 11 << 8; + // Print a formatted array literal. + char[] array = "[\n"; + for (int i; i < p.length; ++i) + { + int c = p[i]; + array ~= std.string.format(c>255?" 0x%x,":"%2d,", c, ((i+1) % 16) ? "":"\n"); + } + array[$-2..$] = "\n]"; + writefln(array); +}