1 using System;
2
3 namespace RegExTokens
4 {
5 public const int END = 0;
6
7 public const int LPAREN = 1;
8
9 public const int RPAREN = 2;
10
11 public const int LBRACKET = 3;
12
13 public const int RBRACKET = 4;
14
15 public const int LBRACE = 5;
16
17 public const int RBRACE = 6;
18
19 public const int ALT = 7;
20
21 public const int STAR = 8;
22
23 public const int PLUS = 9;
24
25 public const int QUEST = 10;
26
27 public const int DOT = 11;
28
29 public const int ESCAPE = 12;
30
31 public const int INVERSE = 13;
32
33 public const int MINUS = 14;
34
35 public const int CHAR = 15;
36
37 internal class TokenMap
38 {
39 static TokenMap() :
40 instance(new TokenMap())
41 {
42 }
43 public static TokenMap& Instance()
44 {
45 return *instance;
46 }
47 public int GetTokenId(const ustring& tokenName)
48 {
49 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
50 if (it != tokenIdMap.CEnd())
51 {
52 return it->second;
53 }
54 else
55 {
56 return -1;
57 }
58 }
59 public ustring GetTokenName(int tokenId)
60 {
61 return tokenNameList[tokenId];
62 }
63 public ustring GetTokenInfo(int tokenId)
64 {
65 return tokenInfoList[tokenId];
66 }
67 private TokenMap()
68 {
69 tokenIdMap[u"ALT"] = 7;
70 tokenIdMap[u"CHAR"] = 15;
71 tokenIdMap[u"DOT"] = 11;
72 tokenIdMap[u"ESCAPE"] = 12;
73 tokenIdMap[u"INVERSE"] = 13;
74 tokenIdMap[u"LBRACE"] = 5;
75 tokenIdMap[u"LBRACKET"] = 3;
76 tokenIdMap[u"LPAREN"] = 1;
77 tokenIdMap[u"MINUS"] = 14;
78 tokenIdMap[u"PLUS"] = 9;
79 tokenIdMap[u"QUEST"] = 10;
80 tokenIdMap[u"RBRACE"] = 6;
81 tokenIdMap[u"RBRACKET"] = 4;
82 tokenIdMap[u"RPAREN"] = 2;
83 tokenIdMap[u"STAR"] = 8;
84 tokenNameList.Add(u"END");
85 tokenInfoList.Add(u"end of file");
86 tokenNameList.Add(u"LPAREN");
87 tokenInfoList.Add(u"\'(\'");
88 tokenNameList.Add(u"RPAREN");
89 tokenInfoList.Add(u"\')\'");
90 tokenNameList.Add(u"LBRACKET");
91 tokenInfoList.Add(u"\'[\'");
92 tokenNameList.Add(u"RBRACKET");
93 tokenInfoList.Add(u"\']\'");
94 tokenNameList.Add(u"LBRACE");
95 tokenInfoList.Add(u"\'{\'");
96 tokenNameList.Add(u"RBRACE");
97 tokenInfoList.Add(u"\'}");
98 tokenNameList.Add(u"ALT");
99 tokenInfoList.Add(u"\'|\'");
100 tokenNameList.Add(u"STAR");
101 tokenInfoList.Add(u"\'*\'");
102 tokenNameList.Add(u"PLUS");
103 tokenInfoList.Add(u"\'+\'");
104 tokenNameList.Add(u"QUEST");
105 tokenInfoList.Add(u"\'?\'");
106 tokenNameList.Add(u"DOT");
107 tokenInfoList.Add(u"\'.\'");
108 tokenNameList.Add(u"ESCAPE");
109 tokenInfoList.Add(u"escape");
110 tokenNameList.Add(u"INVERSE");
111 tokenInfoList.Add(u"\'^\'");
112 tokenNameList.Add(u"MINUS");
113 tokenInfoList.Add(u"\'-\'");
114 tokenNameList.Add(u"CHAR");
115 tokenInfoList.Add(u"character");
116 }
117 private static System.UniquePtr<TokenMap> instance;
118 private System.Collections.Map<ustring, int> tokenIdMap;
119 private System.Collections.List<ustring> tokenNameList;
120 private System.Collections.List<ustring> tokenInfoList;
121 }
122
123 public int GetTokenId(const ustring& tokenName)
124 {
125 return TokenMap.Instance().GetTokenId(tokenName);
126 }
127
128 public ustring GetTokenName(int tokenId)
129 {
130 return TokenMap.Instance().GetTokenName(tokenId);
131 }
132
133 public ustring GetTokenInfo(int tokenId)
134 {
135 return TokenMap.Instance().GetTokenInfo(tokenId);
136 }
137 }