Mercurial > projects > dil
comparison trunk/src/Lexer.d @ 0:8ba2570de175
Initial import.
author | aziz |
---|---|
date | Mon, 28 May 2007 19:03:02 +0000 |
parents | |
children | f3cd3bfde4ba |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8ba2570de175 |
---|---|
1 /++ | |
2 Author: Aziz Köksal | |
3 License: GPL2 | |
4 +/ | |
5 module Lexer; | |
6 | |
7 /// ASCII character properties table. | |
8 static const int ptable[256]; | |
9 | |
10 enum CProperty | |
11 { | |
12 Octal = 1 | |
13 Digit = 1<<1, | |
14 Hex = 1<<2, | |
15 Alpha = 1<<3, | |
16 Identifier = 1<<4 | |
17 } | |
18 | |
19 int isoctal(char c) { return ptable[c] & CProperty.Octal; } | |
20 int isdigit(char c) { return ptable[c] & CProperty.Digit; } | |
21 int ishexad(char c) { return ptable[c] & CProperty.Hex; } | |
22 int isalpha(char c) { return ptable[c] & CProperty.Alpha; } | |
23 int isalnum(char c) { return ptable[c] & (CProperty.Alpha | CProperty.Digit); } | |
24 int isident(char c) { return ptable[c] & CProperty.Identifier; } | |
25 | |
26 static this() | |
27 { | |
28 for (int i; i < ptable.length; ++i) | |
29 { | |
30 if ('0' <= i && i <= '7') | |
31 ptable[i] |= CProperty.Octal; | |
32 if ('0' <= i && i <= '9') | |
33 ptable[i] |= CProperty.Digit; | |
34 if (isdigit(i) || 'a' <= i && i <= 'f' || 'A' <= i && i <= 'F') | |
35 ptable[i] |= CProperty.Hex; | |
36 if ('a' <= i && i <= 'z' || 'A' <= i && i <= 'Z') | |
37 ptable[i] |= CProperty.Alpha; | |
38 if (isalnum(i) || i == '_') | |
39 ptable[i] |= Property.Identifier; | |
40 } | |
41 } | |
42 | |
43 class Lexer | |
44 { | |
45 | |
46 } |