1 using System;
2
3
4
5 namespace ProjectFileTokens
6 {
7 public const int END = 0;
8
9 public const int PROJECT = 1;
10
11 public const int SOURCE = 2;
12
13 public const int ID = 3;
14
15 public const int FILEPATH = 4;
16
17 public const int DOT = 5;
18
19 public const int SEMICOLON = 6;
20
21 public const int RULES = 7;
22
23 internal class TokenMap
24 {
25 static TokenMap() :
26 instance(new TokenMap())
27 {
28 }
29 public static TokenMap& Instance()
30 {
31 return *instance;
32 }
33 public int GetTokenId(const ustring& tokenName)
34 {
35 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
36 if (it != tokenIdMap.CEnd())
37 {
38 return it->second;
39 }
40 else
41 {
42 return -1;
43 }
44 }
45 public ustring GetTokenName(int tokenId)
46 {
47 return tokenNameList[tokenId];
48 }
49 public ustring GetTokenInfo(int tokenId)
50 {
51 return tokenInfoList[tokenId];
52 }
53 private TokenMap()
54 {
55 tokenIdMap[u"DOT"] = 5;
56 tokenIdMap[u"FILEPATH"] = 4;
57 tokenIdMap[u"ID"] = 3;
58 tokenIdMap[u"PROJECT"] = 1;
59 tokenIdMap[u"RULES"] = 7;
60 tokenIdMap[u"SEMICOLON"] = 6;
61 tokenIdMap[u"SOURCE"] = 2;
62 tokenNameList.Add(u"END");
63 tokenInfoList.Add(u"end of file");
64 tokenNameList.Add(u"PROJECT");
65 tokenInfoList.Add(u"'project'");
66 tokenNameList.Add(u"SOURCE");
67 tokenInfoList.Add(u"'source'");
68 tokenNameList.Add(u"ID");
69 tokenInfoList.Add(u"identifier");
70 tokenNameList.Add(u"FILEPATH");
71 tokenInfoList.Add(u"file path");
72 tokenNameList.Add(u"DOT");
73 tokenInfoList.Add(u"'.'");
74 tokenNameList.Add(u"SEMICOLON");
75 tokenInfoList.Add(u"';'");
76 tokenNameList.Add(u"RULES");
77 tokenInfoList.Add(u"'rules'");
78 }
79 private static System.UniquePtr<TokenMap> instance;
80 private System.Collections.Map<ustring, int> tokenIdMap;
81 private System.Collections.List<ustring> tokenNameList;
82 private System.Collections.List<ustring> tokenInfoList;
83 }
84 public int GetTokenId(const ustring& tokenName)
85 {
86 return TokenMap.Instance().GetTokenId(tokenName);
87 }
88
89 public ustring GetTokenName(int tokenId)
90 {
91 return TokenMap.Instance().GetTokenName(tokenId);
92 }
93
94 public ustring GetTokenInfo(int tokenId)
95 {
96 return TokenMap.Instance().GetTokenInfo(tokenId);
97 }
98 }