annotate Implab/Parsing/Scanner.cs @ 153:b933ec88446e v2

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