PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/UiException/CSharpParser/CSToken.cs

#
C# | 130 lines | 54 code | 18 blank | 58 comment | 5 complexity | 9b31c1984fd263e86fc446ba6a962798 MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // This is free software licensed under the NUnit license. You may
  3. // obtain a copy of the license at http://nunit.org
  4. // ****************************************************************
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Text;
  8. namespace NUnit.UiException.CodeFormatters
  9. {
  10. /// <summary>
  11. /// This enum indicate the kind of a string sequence.
  12. /// </summary>
  13. public enum ClassificationTag : byte
  14. {
  15. /// <summary>
  16. /// The string refer to C# source code.
  17. /// </summary>
  18. Code = 0, // 0
  19. /// <summary>
  20. /// The string refers to C# keywords.
  21. /// </summary>
  22. Keyword = 1, // 1
  23. /// <summary>
  24. /// The string refers to C# comments.
  25. /// </summary>
  26. Comment = 2, // 2
  27. /// <summary>
  28. /// The string refers to a string/char value.
  29. /// </summary>
  30. String = 3 // 3
  31. }
  32. /// <summary>
  33. /// (formerly named CSToken)
  34. ///
  35. /// Classifies a string and make it falls into one of the categories below:
  36. /// - Code (the value should be interpreted as regular code)
  37. /// - Keyword (the value should be interpreted as a language keyword)
  38. /// - Comment (the value should be interpreted as comments)
  39. /// - String (the value should be interpreted as a string)
  40. /// </summary>
  41. public class ClassifiedToken
  42. {
  43. /// <summary>
  44. /// The string held by this token.
  45. /// </summary>
  46. protected string _text;
  47. /// <summary>
  48. /// The matching tag.
  49. /// </summary>
  50. protected ClassificationTag _tag;
  51. /// <summary>
  52. /// Starting startingPosition of the string.
  53. /// </summary>
  54. protected int _indexStart;
  55. /// <summary>
  56. /// This class cannot be build directly.
  57. /// </summary>
  58. protected ClassifiedToken()
  59. {
  60. // this class requires subclassing
  61. }
  62. /// <summary>
  63. /// Gets the string value.
  64. /// </summary>
  65. public string Text
  66. {
  67. get { return (_text); }
  68. }
  69. /// <summary>
  70. /// Gets the classification value for the string in Text.
  71. /// - Code: Text should be interpreted as regular code,
  72. /// - Keyword: Text should be interpreted as a language keyword,
  73. /// - Comments: Text should be interpreted as comments,
  74. /// - String: Text should be interpreted as a string.
  75. /// </summary>
  76. public ClassificationTag Tag
  77. {
  78. get { return (_tag); }
  79. }
  80. /// <summary>
  81. /// Gets the string's starting startingPosition.
  82. /// </summary>
  83. public int IndexStart
  84. {
  85. get { return (_indexStart); }
  86. }
  87. /// <summary>
  88. /// Returns true if 'obj' is an instance of ClassifiedToken
  89. /// that contains same data that the current instance.
  90. /// </summary>
  91. public override bool Equals(object obj)
  92. {
  93. ClassifiedToken token;
  94. if (obj == null || !(obj is ClassifiedToken))
  95. return (false);
  96. token = obj as ClassifiedToken;
  97. return (Text == token.Text &&
  98. Tag == token.Tag);
  99. }
  100. public override int GetHashCode()
  101. {
  102. return base.GetHashCode();
  103. }
  104. public override string ToString()
  105. {
  106. return (String.Format(
  107. "ClassifiedToken {Text='{0}', Tag={1}}",
  108. Text,
  109. Tag));
  110. }
  111. }
  112. }