173
|
1 using System;
|
|
2 using Implab.Components;
|
175
|
3 using Implab.Automaton.RegularExpressions;
|
|
4 using System.Diagnostics;
|
|
5 using Implab.Automaton;
|
173
|
6
|
|
7 namespace Implab.Formats {
|
|
8 public abstract class TextScanner<TTag> : Disposable {
|
|
9
|
175
|
10 int m_maxSymbol;
|
|
11 int[] m_symbolMap;
|
|
12
|
|
13 readonly char[] m_buffer;
|
174
|
14 int m_bufferOffset;
|
175
|
15 int m_bufferSize;
|
173
|
16 int m_tokenLength;
|
174
|
17
|
173
|
18 TTag[] m_tags;
|
|
19
|
175
|
20 protected bool ReadTokenInternal(DFAStateDescriptor<TTag>[] dfa, int state) {
|
|
21 Debug.Assert(dfa != null);
|
174
|
22
|
175
|
23 do {
|
|
24 for (var pos = m_bufferOffset; pos < m_bufferSize; pos++) {
|
|
25 var ch = m_buffer[pos];
|
|
26 state = dfa[state].transitions[m_symbolMap[ch > m_maxSymbol ? m_maxSymbol : ch]];
|
|
27 if (state == DFAConst.UNREACHABLE_STATE)
|
|
28 break;
|
|
29 }
|
|
30 } while (Feed());
|
174
|
31
|
175
|
32 if (dfa[state].final) {
|
173
|
33
|
174
|
34 }
|
|
35
|
173
|
36 }
|
|
37
|
175
|
38 bool Feed() {
|
|
39
|
|
40 }
|
|
41
|
|
42 protected abstract int Read(char[] buffer, int offset, int size);
|
173
|
43
|
|
44 protected TTag[] Tags {
|
|
45 get {
|
|
46 return m_tags;
|
|
47 }
|
|
48 }
|
|
49
|
175
|
50
|
173
|
51 }
|
|
52 }
|
|
53
|