annotate Implab/JSON/JSONParser.cs @ 59:21611344d366

code cleanup
author cin
date Wed, 18 Jun 2014 03:54:02 +0400
parents 7759c80cad95
children 62b440d46313
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
1 using Implab;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
2 using Implab.Parsing;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
3 using System;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
4 using System.Collections.Generic;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
5 using System.Diagnostics;
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
6 using System.IO;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
7 using System.Linq;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
8 using System.Text;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
9 using System.Threading.Tasks;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
10
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
11 namespace Implab.JSON {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
12 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
13 /// internal
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
14 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
15 public struct JSONParserContext {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
16 public string memberName;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
17 public JSONElementContext elementContext;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
18 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
19
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
20 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
21 /// Pull парсер JSON данных.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
22 /// </summary>
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
23 public class JSONParser : DFAutomaton<JSONParserContext>, IDisposable {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
24
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
25 enum MemberContext {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
26 MemberName,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
27 MemberValue
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
28 }
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
29
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
30 static readonly EnumAlphabet<JsonTokenType> _alphabet = EnumAlphabet<JsonTokenType>.FullAlphabet;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
31 static readonly DFAStateDescriptior[] _jsonDFA;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
32 static readonly DFAStateDescriptior[] _objectDFA;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
33 static readonly DFAStateDescriptior[] _arrayDFA;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
34
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
35 static JSONParser() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
36 var jsonExpression = Token.New(JsonTokenType.BeginObject, JsonTokenType.BeginArray).Tag(0);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
37
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
38 var valueExpression = Token.New(JsonTokenType.BeginArray, JsonTokenType.BeginObject, JsonTokenType.Literal, JsonTokenType.Number, JsonTokenType.String);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
39 var memberExpression = Token.New(JsonTokenType.String).Cat(Token.New(JsonTokenType.NameSeparator)).Cat(valueExpression);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
40 var objectExpression = memberExpression
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
41 .Cat(
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
42 Token.New(JsonTokenType.ValueSeparator)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
43 .Cat(memberExpression)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
44 .EClosure()
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
45 )
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
46 .Optional()
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
47 .Cat(Token.New(JsonTokenType.EndObject))
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
48 .Tag(0);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
49 var arrayExpression = valueExpression
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
50 .Cat(
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
51 Token.New(JsonTokenType.ValueSeparator)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
52 .Cat(valueExpression)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
53 .EClosure()
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
54 )
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
55 .Optional()
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
56 .Cat(Token.New(JsonTokenType.EndArray))
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
57 .Tag(0);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
58
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
59 _jsonDFA = BuildDFA(jsonExpression).States;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
60 _objectDFA = BuildDFA(objectExpression).States;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
61 _arrayDFA = BuildDFA(arrayExpression).States;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
62 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
63
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
64 static EDFADefinition<JsonTokenType> BuildDFA(Token expr) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
65 var builder = new DFABuilder();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
66 var dfa = new EDFADefinition<JsonTokenType>(_alphabet);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
67 expr.Accept(builder);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
68
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
69 builder.BuildDFA(dfa);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
70 return dfa;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
71 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
72
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
73 JSONScanner m_scanner;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
74 MemberContext m_memberContext;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
75
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
76 JSONElementType m_elementType;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
77 object m_elementValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
78
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
79 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
80 /// Создает новый парсер на основе строки, содержащей JSON
21611344d366 code cleanup
cin
parents: 57
diff changeset
81 /// </summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
82 /// <param name="text"></param>
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
83 public JSONParser(string text)
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
84 : base(_jsonDFA, INITIAL_STATE, new JSONParserContext { elementContext = JSONElementContext.None, memberName = String.Empty }) {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
85 Safe.ArgumentNotEmpty(text, "text");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
86 m_scanner = new JSONScanner();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
87 m_scanner.Feed(text.ToCharArray());
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
88 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
89
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
90 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
91 /// Создает новый экземпляр парсера, на основе текстового потока.
21611344d366 code cleanup
cin
parents: 57
diff changeset
92 /// </summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
93 /// <param name="reader">Текстовый поток.</param>
21611344d366 code cleanup
cin
parents: 57
diff changeset
94 /// <param name="dispose">Признак того, что парсер должен конролировать время жизни входного потока.</param>
21611344d366 code cleanup
cin
parents: 57
diff changeset
95 public JSONParser(TextReader reader, bool dispose)
21611344d366 code cleanup
cin
parents: 57
diff changeset
96 : base(_jsonDFA, INITIAL_STATE, new JSONParserContext { elementContext = JSONElementContext.None, memberName = String.Empty }) {
21611344d366 code cleanup
cin
parents: 57
diff changeset
97 Safe.ArgumentNotNull(reader, "reader");
21611344d366 code cleanup
cin
parents: 57
diff changeset
98 m_scanner = new JSONScanner();
21611344d366 code cleanup
cin
parents: 57
diff changeset
99 m_scanner.Feed(reader, dispose);
21611344d366 code cleanup
cin
parents: 57
diff changeset
100 }
21611344d366 code cleanup
cin
parents: 57
diff changeset
101
21611344d366 code cleanup
cin
parents: 57
diff changeset
102 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
103 /// Тип текущего элемента на котором стоит парсер.
21611344d366 code cleanup
cin
parents: 57
diff changeset
104 /// </summary>
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
105 public JSONElementType ElementType {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
106 get { return m_elementType; }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
107 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
108
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
109 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
110 /// Имя элемента - имя свойства родительского контейнера. Для элементов массивов и корневого всегда
21611344d366 code cleanup
cin
parents: 57
diff changeset
111 /// пустая строка.
21611344d366 code cleanup
cin
parents: 57
diff changeset
112 /// </summary>
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
113 public string ElementName {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
114 get { return m_context.info.memberName; }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
115 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
116
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
117 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
118 /// Значение элемента. Только для элементов типа <see cref="JSONElementType.Value"/>, для остальных <c>null</c>
21611344d366 code cleanup
cin
parents: 57
diff changeset
119 /// </summary>
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
120 public object ElementValue {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
121 get { return m_elementValue; }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
122 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
123
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
124 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
125 /// Читает слеюудущий объект из потока
21611344d366 code cleanup
cin
parents: 57
diff changeset
126 /// </summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
127 /// <returns><c>true</c> - операция чтения прошла успешно, <c>false</c> - конец данных</returns>
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
128 public bool Read() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
129 if (m_context.current == UNREACHEBLE_STATE)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
130 throw new InvalidOperationException("The parser is in invalid state");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
131 object tokenValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
132 JsonTokenType tokenType;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
133 m_context.info.memberName = String.Empty;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
134 while (m_scanner.ReadToken(out tokenValue, out tokenType)) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
135 Move((int)tokenType);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
136 if (m_context.current == UNREACHEBLE_STATE)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
137 UnexpectedToken(tokenValue, tokenType);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
138 switch (tokenType) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
139 case JsonTokenType.BeginObject:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
140 Switch(
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
141 _objectDFA,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
142 INITIAL_STATE,
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
143 new JSONParserContext {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
144 memberName = m_context.info.memberName,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
145 elementContext = JSONElementContext.Object
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
146 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
147 );
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
148 m_elementValue = null;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
149 m_memberContext = MemberContext.MemberName;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
150 m_elementType = JSONElementType.BeginObject;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
151 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
152 case JsonTokenType.EndObject:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
153 Restore();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
154 m_elementValue = null;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
155 m_elementType = JSONElementType.EndObject;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
156 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
157 case JsonTokenType.BeginArray:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
158 Switch(
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
159 _arrayDFA,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
160 INITIAL_STATE,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
161 new JSONParserContext {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
162 memberName = m_context.info.memberName,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
163 elementContext = JSONElementContext.Array
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
164 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
165 );
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
166 m_elementValue = null;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
167 m_memberContext = MemberContext.MemberValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
168 m_elementType = JSONElementType.BeginArray;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
169 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
170 case JsonTokenType.EndArray:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
171 Restore();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
172 m_elementValue = null;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
173 m_elementType = JSONElementType.EndArray;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
174 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
175 case JsonTokenType.String:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
176 if (m_memberContext == MemberContext.MemberName) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
177 m_context.info.memberName = (string)tokenValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
178 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
179 } else {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
180 m_elementType = JSONElementType.Value;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
181 m_elementValue = tokenValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
182 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
183 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
184 case JsonTokenType.Number:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
185 m_elementType = JSONElementType.Value;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
186 m_elementValue = tokenValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
187 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
188 case JsonTokenType.Literal:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
189 m_elementType = JSONElementType.Value;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
190 m_elementValue = ParseLiteral((string)tokenValue);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
191 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
192 case JsonTokenType.NameSeparator:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
193 m_memberContext = MemberContext.MemberValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
194 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
195 case JsonTokenType.ValueSeparator:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
196 m_memberContext = m_context.info.elementContext == JSONElementContext.Object ? MemberContext.MemberName : MemberContext.MemberValue;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
197 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
198 default:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
199 UnexpectedToken(tokenValue, tokenType);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
200 break;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
201 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
202 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
203 if (m_context.info.elementContext != JSONElementContext.None)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
204 throw new ParserException("Unexpedted end of data");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
205 return false;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
206 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
207
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
208 object ParseLiteral(string literal) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
209 switch (literal) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
210 case "null":
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
211 return null;
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
212 case "false":
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
213 return false;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
214 case "true":
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
215 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
216 default:
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
217 UnexpectedToken(literal, JsonTokenType.Literal);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
218 return null; // avoid compliler error
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
219 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
220 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
221
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
222 void UnexpectedToken(object value, JsonTokenType tokenType) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
223 throw new ParserException(String.Format("Unexpected token {0}: '{1}'", tokenType, value));
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
224 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
225
57
7759c80cad95 minor changes
cin
parents: 55
diff changeset
226
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
227 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
228 /// Признак конца потока
21611344d366 code cleanup
cin
parents: 57
diff changeset
229 /// </summary>
57
7759c80cad95 minor changes
cin
parents: 55
diff changeset
230 public bool EOF {
7759c80cad95 minor changes
cin
parents: 55
diff changeset
231 get {
7759c80cad95 minor changes
cin
parents: 55
diff changeset
232 return m_scanner.EOF;
7759c80cad95 minor changes
cin
parents: 55
diff changeset
233 }
7759c80cad95 minor changes
cin
parents: 55
diff changeset
234 }
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
235
21611344d366 code cleanup
cin
parents: 57
diff changeset
236 protected virtual void Dispose(bool disposing) {
21611344d366 code cleanup
cin
parents: 57
diff changeset
237 if (disposing) {
21611344d366 code cleanup
cin
parents: 57
diff changeset
238 m_scanner.Dispose();
21611344d366 code cleanup
cin
parents: 57
diff changeset
239 }
21611344d366 code cleanup
cin
parents: 57
diff changeset
240 }
21611344d366 code cleanup
cin
parents: 57
diff changeset
241
21611344d366 code cleanup
cin
parents: 57
diff changeset
242 /// <summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
243 /// Освобождает парсер и связанный с ним сканнер.
21611344d366 code cleanup
cin
parents: 57
diff changeset
244 /// </summary>
21611344d366 code cleanup
cin
parents: 57
diff changeset
245 public void Dispose() {
21611344d366 code cleanup
cin
parents: 57
diff changeset
246 Dispose(true);
21611344d366 code cleanup
cin
parents: 57
diff changeset
247 GC.SuppressFinalize(this);
21611344d366 code cleanup
cin
parents: 57
diff changeset
248 }
21611344d366 code cleanup
cin
parents: 57
diff changeset
249
21611344d366 code cleanup
cin
parents: 57
diff changeset
250 ~JSONParser() {
21611344d366 code cleanup
cin
parents: 57
diff changeset
251 Dispose(false);
21611344d366 code cleanup
cin
parents: 57
diff changeset
252 }
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
253 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
254
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
255 }