WordCollection.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections.Generic;
  2. namespace NTERA.EmuEra.Game.EraEmu.Sub
  3. {
  4. /// <summary>
  5. /// 字句解析結果の保存場所。Listとその現在位置を結びつけるためのもの。
  6. /// 基本的に全てpublicで
  7. /// </summary>
  8. internal sealed class WordCollection
  9. {
  10. public List<Word> Collection = new List<Word>();
  11. public int Pointer;
  12. private static Word nullToken = new NullWord();
  13. public void Add(Word token)
  14. {
  15. Collection.Add(token);
  16. }
  17. public void Add(WordCollection wc)
  18. {
  19. Collection.AddRange(wc.Collection);
  20. }
  21. public void Clear()
  22. {
  23. Collection.Clear();
  24. }
  25. public void ShiftNext() { Pointer++; }
  26. public Word Current
  27. {
  28. get
  29. {
  30. if (Pointer >= Collection.Count)
  31. return nullToken;
  32. return Collection[Pointer];
  33. }
  34. }
  35. public bool EOL => Pointer >= Collection.Count;
  36. public void Insert(Word w)
  37. {
  38. Collection.Insert(Pointer, w);
  39. }
  40. public void InsertRange(WordCollection wc)
  41. {
  42. Collection.InsertRange(Pointer, wc.Collection);
  43. }
  44. public void Remove()
  45. {
  46. Collection.RemoveAt(Pointer);
  47. }
  48. public void SetIsMacro()
  49. {
  50. foreach(Word word in Collection)
  51. {
  52. word.SetIsMacro();
  53. }
  54. }
  55. public WordCollection Clone()
  56. {
  57. WordCollection ret = new WordCollection();
  58. for(int i = 0;i < Collection.Count;i++)
  59. {
  60. ret.Collection.Add(Collection[i]);
  61. }
  62. return ret;
  63. }
  64. public WordCollection Clone(int start, int count)
  65. {
  66. WordCollection ret = new WordCollection();
  67. if (start > Collection.Count)
  68. return ret;
  69. int end = start + count;
  70. if (end > Collection.Count)
  71. end = Collection.Count;
  72. for(int i = start;i < end;i++)
  73. {
  74. ret.Collection.Add(Collection[i]);
  75. }
  76. return ret;
  77. }
  78. }
  79. }