annotate Implab.ServiceHost/Unity/TypeReferenceParser.cs @ 281:e0916ddc9950 v3 tip

code cleanup and refactoring
author cin
date Fri, 01 Jun 2018 21:35:24 +0300
parents 6691aff01de1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
1 using System;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
2 using System.Collections.Generic;
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
3 using System.Linq;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
4 using System.Text.RegularExpressions;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
5
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
6 namespace Implab.ServiceHost.Unity {
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
7 internal class TypeReferenceParser {
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
8 enum TokenType {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
9 None,
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
10
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
11 Word,
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
12
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
13 Dot,
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
14
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
15 Comma,
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
16
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
17 OpenList,
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
18
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
19 CloseList,
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
20
277
963b17c275be Refactoring
cin
parents: 269
diff changeset
21 OpenArray,
963b17c275be Refactoring
cin
parents: 269
diff changeset
22
963b17c275be Refactoring
cin
parents: 269
diff changeset
23 CloseArray,
963b17c275be Refactoring
cin
parents: 269
diff changeset
24
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
25 Plus,
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
26
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
27 Eof
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
28 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
29
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
30 readonly Regex _tokens = new Regex(@"\G(?:([\w]+)|\s*([\+\.{},\[\]])\s*)", RegexOptions.Compiled);
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
31
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
32 TokenType m_token;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
33
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
34 string m_tokenValue;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
35
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
36 int m_pos;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
37
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
38 int m_tokenPos;
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
39
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
40 readonly string m_text;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
41
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
42 TokenType Token { get { return m_token; } }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
43
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
44 string TokenValue { get { return m_tokenValue; } }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
45
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
46 int TokenPos { get { return m_tokenPos; } }
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
47
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
48 public TypeReferenceParser(string text) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
49 Safe.ArgumentNotEmpty(text, nameof(text));
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
50 m_text = text;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
51 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
52
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
53 bool ReadToken() {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
54 if (m_pos >= m_text.Length) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
55 m_token = TokenType.Eof;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
56 m_tokenValue = null;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
57 return false;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
58 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
59
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
60 var m = _tokens.Match(m_text, m_pos);
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
61
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
62 if (m.Success) {
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
63 m_tokenPos = m_pos;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
64 m_pos += m.Length;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
65 if (m.Groups[1].Success) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
66 m_token = TokenType.Word;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
67 m_tokenValue = m.Groups[1].Value;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
68 } else if (m.Groups[2].Success) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
69 m_tokenValue = null;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
70 switch (m.Groups[2].Value) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
71 case "{":
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
72 m_token = TokenType.OpenList;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
73 break;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
74 case "}":
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
75 m_token = TokenType.CloseList;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
76 break;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
77 case ".":
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
78 m_token = TokenType.Dot;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
79 break;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
80 case ",":
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
81 m_token = TokenType.Comma;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
82 break;
277
963b17c275be Refactoring
cin
parents: 269
diff changeset
83 case "[":
963b17c275be Refactoring
cin
parents: 269
diff changeset
84 m_token = TokenType.OpenArray;
963b17c275be Refactoring
cin
parents: 269
diff changeset
85 break;
963b17c275be Refactoring
cin
parents: 269
diff changeset
86 case "]":
963b17c275be Refactoring
cin
parents: 269
diff changeset
87 m_token = TokenType.CloseArray;
963b17c275be Refactoring
cin
parents: 269
diff changeset
88 break;
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
89 case "+":
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
90 m_token = TokenType.Plus;
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
91 break;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
92 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
93 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
94 return true;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
95 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
96 throw new FormatException($"Failed to parse '{m_text}' at pos {m_pos}");
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
97 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
98
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
99 public TypeReference Parse() {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
100 var result = ReadTypeReference();
277
963b17c275be Refactoring
cin
parents: 269
diff changeset
101 if (Token != TokenType.Eof)
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
102 ThrowUnexpectedToken();
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
103 return result;
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
104 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
105
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
106 string[] ReadQTypeName() {
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
107 var parts = new List<string>();
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
108
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
109 string current = null;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
110 bool stop = false;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
111 while ((!stop) && ReadToken()) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
112 switch (Token) {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
113 case TokenType.Word:
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
114 if (current != null)
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
115 ThrowUnexpectedToken();
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
116 current = TokenValue;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
117 break;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
118 case TokenType.Dot:
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
119 if (current == null)
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
120 ThrowUnexpectedToken();
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
121 parts.Add(current);
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
122 current = null;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
123 break;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
124 default:
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
125 stop = true;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
126 break;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
127 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
128 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
129 if (current != null)
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
130 parts.Add(current);
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
131
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
132 if (parts.Count == 0)
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
133 return null;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
134
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
135 return parts.ToArray();
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
136 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
137
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
138 string ReadNQTypeName() {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
139 ReadToken();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
140 if (Token != TokenType.Word)
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
141 ThrowUnexpectedToken();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
142 return TokenValue;
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
143 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
144
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
145 TypeReference ReadTypeReference() {
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
146
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
147 var parts = ReadQTypeName();
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
148 if (parts == null)
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
149 return null;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
150
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
151 var genericParameters = ReadGenericParams();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
152
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
153 var typeReference = TypeReference.Create(
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
154 string.Join(".", parts, 0, parts.Length - 1),
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
155 parts[parts.Length - 1],
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
156 genericParameters.Length
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
157 );
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
158
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
159 if (genericParameters.Length > 0 && genericParameters.All(x => x != null))
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
160 typeReference = typeReference.MakeGenericType(genericParameters);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
161
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
162 typeReference = ReadArraySpec(typeReference);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
163
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
164 if(Token == TokenType.Plus)
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
165 return ReadNestedType(typeReference);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
166
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
167 return typeReference;
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
168 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
169
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
170 TypeReference ReadNestedType(TypeReference declaringType) {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
171 var name = ReadNQTypeName();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
172 if(string.IsNullOrEmpty(name))
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
173 throw new FormatException("Nested type name can't be empty");
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
174 ReadToken();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
175
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
176 var genericParameters = ReadGenericParams();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
177
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
178 var typeReference = declaringType.Create(
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
179 name,
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
180 genericParameters.Length
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
181 );
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
182
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
183 if (genericParameters.Length > 0 && genericParameters.All(x => x != null))
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
184 typeReference = typeReference.MakeGenericType(genericParameters);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
185
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
186 typeReference = ReadArraySpec(typeReference);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
187
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
188 if(Token == TokenType.Plus)
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
189 return ReadNestedType(typeReference);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
190
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
191 return typeReference;
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
192 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
193
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
194 TypeReference[] ReadGenericParams() {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
195 if (Token == TokenType.OpenList) {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
196 var genericParameters = ReadTypeReferenceList();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
197 if (Token != TokenType.CloseList)
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
198 ThrowUnexpectedToken();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
199 ReadToken();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
200
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
201 return genericParameters;
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
202 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
203
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
204 return Array.Empty<TypeReference>();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
205 }
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
206
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
207 TypeReference ReadArraySpec(TypeReference typeReference) {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
208 while (Token == TokenType.OpenArray) {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
209 var rank = CountRank();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
210 if (Token != TokenType.CloseArray)
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
211 ThrowUnexpectedToken();
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
212
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
213 typeReference = typeReference.MakeArrayType(rank);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
214
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
215 ReadToken();
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
216 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
217
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
218 return typeReference;
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
219 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
220
278
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
221 int CountRank() {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
222 int rank = 0;
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
223 do {
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
224 rank++;
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
225 } while(ReadToken() && Token == TokenType.Comma);
6691aff01de1 Implab: added XmlDefaultSeializer (SerializersPool is now obsolete)
cin
parents: 277
diff changeset
226 return rank;
277
963b17c275be Refactoring
cin
parents: 269
diff changeset
227 }
963b17c275be Refactoring
cin
parents: 269
diff changeset
228
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
229 TypeReference[] ReadTypeReferenceList() {
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
230 var list = new List<TypeReference>();
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
231
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
232 do {
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
233 var typeReference = ReadTypeReference();
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
234 list.Add(typeReference);
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
235 } while (Token == TokenType.Comma);
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
236
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
237 return list.ToArray();
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
238 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
239
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
240 void ThrowUnexpectedToken() {
268
0be8a6ae8307 Implemented typereference parser
cin
parents: 267
diff changeset
241 throw new FormatException($"Unexpected '{Token}' at pos {TokenPos}: -->{m_text.Substring(TokenPos, Math.Min(m_text.Length - TokenPos, 10))}");
267
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
242 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
243
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
244 }
6b3e5c48131b Working on Unity xml configuration
cin
parents:
diff changeset
245 }