annotate Implab/Parsing/Scanner.cs @ 159:5558e43c79bb v2

minor fix
author cin
date Thu, 18 Feb 2016 16:06:14 +0300
parents 130781364799
children
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 System;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
3 using System.Collections.Generic;
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
4 using System.IO;
152
240aa6994018 component model refactoring
cin
parents: 79
diff changeset
5 using Implab.Components;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
6
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
7 namespace Implab.Parsing {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
8 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
9 /// Базовый класс для разбора потока входных символов на токены.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
10 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
11 /// <remarks>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
12 /// Сканнер имеет внутри буффер с симолами входного текста, по которому перемещаются два
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
13 /// указателя, начала и конца токена, при перемещении искользуется ДКА для определения
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
14 /// конца токена и допустимости текущего символа.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
15 /// </remarks>
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
16 public abstract class Scanner : Disposable {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
17 struct ScannerConfig {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
18 public DFAStateDescriptior[] states;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
19 public int[] alphabetMap;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
20 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
21
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
22 Stack<ScannerConfig> m_defs = new Stack<ScannerConfig>();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
23
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
24 DFAStateDescriptior[] m_states;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
25 int[] m_alphabetMap;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
26
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
27 protected DFAStateDescriptior m_currentState;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
28 int m_previewCode;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
29
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
30 protected int m_tokenLen = 0;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
31 protected int m_tokenOffset;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
32
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
33 protected char[] m_buffer;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
34 protected int m_bufferSize;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
35 protected int m_pointer;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
36
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
37 TextReader m_reader;
21611344d366 code cleanup
cin
parents: 57
diff changeset
38 bool m_disposeReader;
21611344d366 code cleanup
cin
parents: 57
diff changeset
39 int m_chunkSize = 1024; // 1k
21611344d366 code cleanup
cin
parents: 57
diff changeset
40 int m_limit = 10 * 1024 * 1024; // 10Mb
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
41
158
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
42 protected Scanner(DFAStateDescriptior[] states, int[] alphabet) {
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
43 Safe.ArgumentNotEmpty(states, "states");
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
44 Safe.ArgumentNotNull(alphabet, "alphabet");
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
45
158
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
46 m_states = states;
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
47 m_alphabetMap = alphabet;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
48
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
49 Feed(new char[0]);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
50 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
51
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
52 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
53 /// Заполняет входными данными буффер.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
54 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
55 /// <param name="data">Данные для обработки.</param>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
56 /// <remarks>Копирование данных не происходит, переданный массив используется в
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
57 /// качестве входного буффера.</remarks>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
58 public void Feed(char[] data) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
59 Safe.ArgumentNotNull(data, "data");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
60
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
61 Feed(data, data.Length);
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 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
65 /// Заполняет буффур чтения входными данными.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
66 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
67 /// <param name="data">Данные для обработки.</param>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
68 /// <param name="length">Длина данных для обработки.</param>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
69 /// <remarks>Копирование данных не происходит, переданный массив используется в
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
70 /// качестве входного буффера.</remarks>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
71 public void Feed(char[] data, int length) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
72 Safe.ArgumentNotNull(data, "data");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
73 Safe.ArgumentInRange(length, 0, data.Length, "length");
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
74 AssertNotDisposed();
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
75
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
76 m_pointer = -1;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
77 m_buffer = data;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
78 m_bufferSize = length;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
79 Shift();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
80 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
81
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
82 public void Feed(TextReader reader, bool dispose) {
21611344d366 code cleanup
cin
parents: 57
diff changeset
83 Safe.ArgumentNotNull(reader, "reader");
21611344d366 code cleanup
cin
parents: 57
diff changeset
84 AssertNotDisposed();
21611344d366 code cleanup
cin
parents: 57
diff changeset
85
21611344d366 code cleanup
cin
parents: 57
diff changeset
86 if (m_reader != null && m_disposeReader)
21611344d366 code cleanup
cin
parents: 57
diff changeset
87 m_reader.Dispose();
21611344d366 code cleanup
cin
parents: 57
diff changeset
88
21611344d366 code cleanup
cin
parents: 57
diff changeset
89 m_reader = reader;
21611344d366 code cleanup
cin
parents: 57
diff changeset
90 m_disposeReader = dispose;
21611344d366 code cleanup
cin
parents: 57
diff changeset
91 m_pointer = -1;
21611344d366 code cleanup
cin
parents: 57
diff changeset
92 m_buffer = new char[m_chunkSize];
21611344d366 code cleanup
cin
parents: 57
diff changeset
93 m_bufferSize = 0;
21611344d366 code cleanup
cin
parents: 57
diff changeset
94 Shift();
21611344d366 code cleanup
cin
parents: 57
diff changeset
95 }
21611344d366 code cleanup
cin
parents: 57
diff changeset
96
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
97 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
98 /// Получает текущий токен в виде строки.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
99 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
100 /// <returns></returns>
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
101 protected string GetTokenValue() {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
102 return new String(m_buffer, m_tokenOffset, m_tokenLen);
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
103 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
104
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
105 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
106 /// Метки текущего токена, которые были назначены в регулярном выражении.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
107 /// </summary>
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
108 protected int[] TokenTags {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
109 get {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
110 return m_currentState.tag;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
111 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
112 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
113
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
114 /// <summary>
57
7759c80cad95 minor changes
cin
parents: 55
diff changeset
115 /// Признак конца данных
7759c80cad95 minor changes
cin
parents: 55
diff changeset
116 /// </summary>
7759c80cad95 minor changes
cin
parents: 55
diff changeset
117 public bool EOF {
7759c80cad95 minor changes
cin
parents: 55
diff changeset
118 get {
7759c80cad95 minor changes
cin
parents: 55
diff changeset
119 return m_pointer >= m_bufferSize;
7759c80cad95 minor changes
cin
parents: 55
diff changeset
120 }
7759c80cad95 minor changes
cin
parents: 55
diff changeset
121 }
7759c80cad95 minor changes
cin
parents: 55
diff changeset
122
7759c80cad95 minor changes
cin
parents: 55
diff changeset
123 /// <summary>
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
124 /// Читает следующий токен, при этом <see cref="m_tokenOffset"/> указывает на начало токена,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
125 /// <see cref="m_tokenLen"/> на длину токена, <see cref="m_buffer"/> - массив символов, в
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
126 /// котором находится токен.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
127 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
128 /// <returns><c>false</c> - достигнут конец данных, токен не прочитан.</returns>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
129 protected bool ReadTokenInternal() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
130 if (m_pointer >= m_bufferSize)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
131 return false;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
132
158
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
133 m_currentState = m_states[DFADefinition.INITIAL_STATE];
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
134 m_tokenLen = 0;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
135 m_tokenOffset = m_pointer;
158
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
136 int nextState;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
137 do {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
138 nextState = m_currentState.transitions[m_previewCode];
158
130781364799 refactoring, code cleanup
cin
parents: 152
diff changeset
139 if (nextState == DFADefinition.UNREACHEBLE_STATE) {
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
140 if (m_currentState.final)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
141 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
142 else
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
143 throw new ParserException(
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
144 String.Format(
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
145 "Unexpected symbol '{0}', at pos {1}",
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
146 m_buffer[m_pointer],
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
147 Position
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
148 )
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
149 );
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
150 } else {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
151 m_currentState = m_states[nextState];
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
152 m_tokenLen++;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
153 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
154
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
155 } while (Shift());
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
156
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
157 // END OF DATA
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
158 if (!m_currentState.final)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
159 throw new ParserException("Unexpected end of data");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
160
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
161 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
162 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
163
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
164
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
165 bool Shift() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
166 m_pointer++;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
167
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
168 if (m_pointer >= m_bufferSize) {
60
10c7337d29e7 +JSONXmlReaderOptions
cin
parents: 59
diff changeset
169 if (!ReadNextChunk())
10c7337d29e7 +JSONXmlReaderOptions
cin
parents: 59
diff changeset
170 return false;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
171 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
172
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
173 m_previewCode = m_alphabetMap[m_buffer[m_pointer]];
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
174
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
175 return true;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
176 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
177
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
178 bool ReadNextChunk() {
21611344d366 code cleanup
cin
parents: 57
diff changeset
179 if (m_reader == null)
21611344d366 code cleanup
cin
parents: 57
diff changeset
180 return false;
21611344d366 code cleanup
cin
parents: 57
diff changeset
181
21611344d366 code cleanup
cin
parents: 57
diff changeset
182 // extend buffer if nesessary
21611344d366 code cleanup
cin
parents: 57
diff changeset
183 if (m_pointer + m_chunkSize > m_buffer.Length) {
21611344d366 code cleanup
cin
parents: 57
diff changeset
184 // trim unused buffer head
21611344d366 code cleanup
cin
parents: 57
diff changeset
185 var size = m_tokenLen + m_chunkSize;
21611344d366 code cleanup
cin
parents: 57
diff changeset
186 if (size >= m_limit)
21611344d366 code cleanup
cin
parents: 57
diff changeset
187 throw new ParserException(String.Format("Input buffer {0} bytes limit exceeded", m_limit));
21611344d366 code cleanup
cin
parents: 57
diff changeset
188 var temp = new char[size];
21611344d366 code cleanup
cin
parents: 57
diff changeset
189 Array.Copy(m_buffer, m_tokenOffset, temp, 0, m_tokenLen);
21611344d366 code cleanup
cin
parents: 57
diff changeset
190 m_pointer -= m_tokenOffset;
21611344d366 code cleanup
cin
parents: 57
diff changeset
191 m_bufferSize -= m_tokenOffset;
21611344d366 code cleanup
cin
parents: 57
diff changeset
192 m_tokenOffset = 0;
21611344d366 code cleanup
cin
parents: 57
diff changeset
193 m_buffer = temp;
21611344d366 code cleanup
cin
parents: 57
diff changeset
194 }
21611344d366 code cleanup
cin
parents: 57
diff changeset
195
21611344d366 code cleanup
cin
parents: 57
diff changeset
196 var read = m_reader.Read(m_buffer, m_tokenLen, m_chunkSize);
21611344d366 code cleanup
cin
parents: 57
diff changeset
197 if (read == 0)
21611344d366 code cleanup
cin
parents: 57
diff changeset
198 return false;
21611344d366 code cleanup
cin
parents: 57
diff changeset
199
21611344d366 code cleanup
cin
parents: 57
diff changeset
200 m_bufferSize += read;
21611344d366 code cleanup
cin
parents: 57
diff changeset
201
21611344d366 code cleanup
cin
parents: 57
diff changeset
202 return true;
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
203 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
204
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
205 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
206 /// Позиция сканнера во входном буфере
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
207 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
208 public int Position {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
209 get {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
210 return m_pointer + 1;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
211 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
212 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
213
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
214 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
215 /// Преключает внутренний ДКА на указанный, позволяет реализовать подобие захватывающей
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
216 /// группировки.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
217 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
218 /// <param name="states">Таблица состояний нового ДКА</param>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
219 /// <param name="alphabet">Таблица входных символов для нового ДКА</param>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
220 protected void Switch(DFAStateDescriptior[] states, int[] alphabet) {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
221 Safe.ArgumentNotNull(states, "dfa");
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
222
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
223 m_defs.Push(new ScannerConfig {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
224 states = m_states,
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
225 alphabetMap = m_alphabetMap
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
226 });
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
227
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
228 m_states = states;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
229 m_alphabetMap = alphabet;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
230
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
231 m_previewCode = m_alphabetMap[m_buffer[m_pointer]];
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
232 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
233
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
234 /// <summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
235 /// Восстанавливает предыдущей ДКА сканнера.
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
236 /// </summary>
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
237 protected void Restore() {
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
238 if (m_defs.Count == 0)
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
239 throw new InvalidOperationException();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
240 var prev = m_defs.Pop();
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
241 m_states = prev.states;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
242 m_alphabetMap = prev.alphabetMap;
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
243 m_previewCode = m_alphabetMap[m_buffer[m_pointer]];
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
244 }
59
21611344d366 code cleanup
cin
parents: 57
diff changeset
245
21611344d366 code cleanup
cin
parents: 57
diff changeset
246 protected override void Dispose(bool disposing) {
21611344d366 code cleanup
cin
parents: 57
diff changeset
247 if (disposing) {
21611344d366 code cleanup
cin
parents: 57
diff changeset
248 if (m_reader != null && m_disposeReader)
21611344d366 code cleanup
cin
parents: 57
diff changeset
249 m_reader.Dispose();
21611344d366 code cleanup
cin
parents: 57
diff changeset
250 m_buffer = null;
21611344d366 code cleanup
cin
parents: 57
diff changeset
251 m_bufferSize = 0;
21611344d366 code cleanup
cin
parents: 57
diff changeset
252 m_pointer = 0;
21611344d366 code cleanup
cin
parents: 57
diff changeset
253 m_tokenLen = 0;
21611344d366 code cleanup
cin
parents: 57
diff changeset
254 m_tokenOffset = 0;
21611344d366 code cleanup
cin
parents: 57
diff changeset
255 }
21611344d366 code cleanup
cin
parents: 57
diff changeset
256 base.Dispose(disposing);
21611344d366 code cleanup
cin
parents: 57
diff changeset
257 }
55
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
258 }
c0bf853aa04f Added initial JSON support
cin
parents:
diff changeset
259 }