##// END OF EJS Templates
sync
sync

File last commit:

r174:983df35b3ca1 ref20160224
r175:96a89dcb4060 ref20160224
Show More
BufferScanner.cs
62 lines | 1.6 KiB | text/x-csharp | CSharpLexer
cin
Working on text scanner
r173 using System;
using Implab.Automaton.RegularExpressions;
using Implab.Automaton;
cin
sync
r174 using System.Diagnostics;
cin
Working on text scanner
r173
namespace Implab.Formats {
public struct BufferScanner<TTag> {
readonly DFAStateDescriptor<TTag>[] m_dfa;
int m_state;
cin
sync
r174 int m_pos;
cin
Working on text scanner
r173
cin
sync
r174 public BufferScanner(DFAStateDescriptor<TTag>[] dfa, int initialState) {
cin
Working on text scanner
r173 m_dfa = dfa;
m_state = initialState;
}
public int Position {
cin
sync
r174 get { return m_pos; }
cin
Working on text scanner
r173 }
/// <summary>
/// Scan this instance.
/// </summary>
/// <returns><c>true</c> - additional data required</returns>
cin
sync
r174 public bool Scan(int[] buffer, int position, int length) {
var hi = position + length;
m_pos = position;
while (position < hi) {
var next = m_dfa[m_state].transitions[buffer[position]];
cin
Working on text scanner
r173 if (next == DFAConst.UNREACHABLE_STATE) {
if (m_dfa[m_state].final)
return false;
throw new ParserException(
String.Format(
cin
sync
r174 "Unexpected symbol"
cin
Working on text scanner
r173 )
);
}
cin
sync
r174 m_pos++;
cin
Working on text scanner
r173 m_state = next;
}
return true;
}
public void Eof() {
if (!m_dfa[m_state].final)
throw new ParserException(
String.Format(
cin
sync
r174 "Unexpected EOF"
cin
Working on text scanner
r173 )
);
}
public TTag[] GetTokenTags() {
return m_dfa[m_state].tags;
}
}
}