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