Mercurial > pub > ImplabNet
diff Implab/Formats/TextScanner.cs @ 177:a0ff6a0e9c44 ref20160224
refactoring
author | cin |
---|---|
date | Wed, 23 Mar 2016 01:42:00 +0300 |
parents | 0c3c69fe225b |
children | d5c5db0335ee |
line wrap: on
line diff
--- a/Implab/Formats/TextScanner.cs Tue Mar 22 18:58:40 2016 +0300 +++ b/Implab/Formats/TextScanner.cs Wed Mar 23 01:42:00 2016 +0300 @@ -1,9 +1,7 @@ using System; using Implab.Components; -using Implab.Automaton.RegularExpressions; using System.Diagnostics; using Implab.Automaton; -using System.IO; using System.Text; namespace Implab.Formats { @@ -18,7 +16,7 @@ int m_tokenLength; /// <summary> - /// Initializes a new instance of the <see cref="Implab.Formats.TextScanner`1"/> class. + /// Initializes a new instance of the <see cref="Implab.Formats.TextScanner"/> class. /// </summary> /// <param name="bufferMax">Buffer max.</param> /// <param name="chunkSize">Chunk size.</param> @@ -30,7 +28,7 @@ } /// <summary> - /// Initializes a new instance of the <see cref="Implab.Formats.TextScanner`1"/> class. + /// Initializes a new instance of the <see cref="Implab.Formats.TextScanner"/> class. /// </summary> /// <param name="buffer">Buffer.</param> protected TextScanner(char[] buffer) { @@ -48,7 +46,9 @@ /// <param name="final">Final states of the automaton.</param> /// <param name="tags">Tags.</param> /// <param name="state">The initial state for the automaton.</param> - internal bool ReadToken<TTag>(int[,] dfa, int[] final, TTag[][] tags, int state, int[] alphabet, out TTag[] tag) { + /// <param name="alphabet"></param> + /// <param name = "tag"></param> + internal bool ReadToken<TTag>(int[,] dfa, bool[] final, TTag[][] tags, int state, int[] alphabet, out TTag[] tag) { Safe.ArgumentNotNull(); m_tokenLength = 0; @@ -58,10 +58,10 @@ // after the next chunk is read the offset in the buffer may change int pos = m_bufferOffset + m_tokenLength; - while(pos < m_bufferSize) { + while (pos < m_bufferSize) { var ch = m_buffer[pos]; - state = dfa[state,ch > maxSymbol ? DFAConst.UNCLASSIFIED_INPUT : alphabet[ch]]; + state = dfa[state, ch > maxSymbol ? DFAConst.UNCLASSIFIED_INPUT : alphabet[ch]]; if (state == DFAConst.UNREACHABLE_STATE) break; @@ -77,16 +77,17 @@ if (final[state]) { tag = tags[state]; return true; - } else { - if (m_bufferOffset == m_bufferSize) { - if (m_tokenLength == 0) //EOF + } + + if (m_bufferOffset == m_bufferSize) { + if (m_tokenLength == 0) //EOF return false; - throw new ParserException(); - } - throw new ParserException(String.Format("Unexpected symbol '{0}'", m_buffer[m_bufferOffset])); + throw new ParserException(); + } + + throw new ParserException(String.Format("Unexpected symbol '{0}'", m_buffer[m_bufferOffset])); - } } protected void Feed(char[] buffer, int offset, int length) { @@ -108,7 +109,7 @@ var size = used + free; if (size > m_bufferMax) - throw new ParserException(String.Format("The buffer limit ({0} Kb) is reached"), m_bufferMax/1024); + throw new ParserException(String.Format("The buffer limit ({0} Kb) is reached", m_bufferMax/1024)); var temp = new char[size];