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