annotate Implab/Parsing/Scanner.cs @ 138:f75cfa58e3d4 v2

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