using System; using System.Collections; using System.Collections.Generic; namespace ScriptConverter.Parser { abstract partial class Lexer { protected static TToken EofToken; static Lexer() { EofToken = null; } protected class OperatorDictionary : IEnumerable { private readonly GenericComparer> _comparer; private Dictionary>> _operatorDictionary; public OperatorDictionary() { _comparer = new GenericComparer>((a, b) => b.Item1.Length - a.Item1.Length); _operatorDictionary = new Dictionary>>(); } public void Add(string op, T type) { List> list; if (!_operatorDictionary.TryGetValue(op[0], out list)) { list = new List>(); _operatorDictionary.Add(op[0], list); } list.Add(Tuple.Create(op, type)); list.Sort(_comparer); } public IEnumerable> Lookup(char ch) { List> list; if (!_operatorDictionary.TryGetValue(ch, out list)) return null; return list; } public IEnumerator GetEnumerator() { throw new NotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } } }