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