Mercurial > pub > ImplabNet
comparison Implab/Parsing/Scanner.cs @ 158:130781364799 v2
refactoring, code cleanup
author | cin |
---|---|
date | Thu, 18 Feb 2016 14:34:02 +0300 |
parents | 240aa6994018 |
children |
comparison
equal
deleted
inserted
replaced
157:948c015a9011 | 158:130781364799 |
---|---|
37 TextReader m_reader; | 37 TextReader m_reader; |
38 bool m_disposeReader; | 38 bool m_disposeReader; |
39 int m_chunkSize = 1024; // 1k | 39 int m_chunkSize = 1024; // 1k |
40 int m_limit = 10 * 1024 * 1024; // 10Mb | 40 int m_limit = 10 * 1024 * 1024; // 10Mb |
41 | 41 |
42 protected Scanner(CDFADefinition definition) { | 42 protected Scanner(DFAStateDescriptior[] states, int[] alphabet) { |
43 Safe.ArgumentNotNull(definition, "definition"); | 43 Safe.ArgumentNotEmpty(states, "states"); |
44 | 44 Safe.ArgumentNotNull(alphabet, "alphabet"); |
45 m_states = definition.States; | 45 |
46 m_alphabetMap = definition.Alphabet.GetTranslationMap(); | 46 m_states = states; |
47 m_alphabetMap = alphabet; | |
47 | 48 |
48 Feed(new char[0]); | 49 Feed(new char[0]); |
49 } | 50 } |
50 | 51 |
51 /// <summary> | 52 /// <summary> |
127 /// <returns><c>false</c> - достигнут конец данных, токен не прочитан.</returns> | 128 /// <returns><c>false</c> - достигнут конец данных, токен не прочитан.</returns> |
128 protected bool ReadTokenInternal() { | 129 protected bool ReadTokenInternal() { |
129 if (m_pointer >= m_bufferSize) | 130 if (m_pointer >= m_bufferSize) |
130 return false; | 131 return false; |
131 | 132 |
132 m_currentState = m_states[CDFADefinition.INITIAL_STATE]; | 133 m_currentState = m_states[DFADefinition.INITIAL_STATE]; |
133 m_tokenLen = 0; | 134 m_tokenLen = 0; |
134 m_tokenOffset = m_pointer; | 135 m_tokenOffset = m_pointer; |
135 int nextState = CDFADefinition.UNREACHEBLE_STATE; | 136 int nextState; |
136 do { | 137 do { |
137 nextState = m_currentState.transitions[m_previewCode]; | 138 nextState = m_currentState.transitions[m_previewCode]; |
138 if (nextState == CDFADefinition.UNREACHEBLE_STATE) { | 139 if (nextState == DFADefinition.UNREACHEBLE_STATE) { |
139 if (m_currentState.final) | 140 if (m_currentState.final) |
140 return true; | 141 return true; |
141 else | 142 else |
142 throw new ParserException( | 143 throw new ParserException( |
143 String.Format( | 144 String.Format( |