Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

148 рядки
4.0 KiB

  1. //
  2. // Lol Engine - VsLol add-in for Visual Studio
  3. //
  4. // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using Microsoft.VisualStudio;
  14. using Microsoft.VisualStudio.Package;
  15. using Microsoft.VisualStudio.TextManager.Interop;
  16. using Microsoft.VisualStudio.OLE.Interop;
  17. namespace lol
  18. {
  19. class LolFxLanguageService : LanguageService
  20. {
  21. public override string GetFormatFilterList()
  22. {
  23. throw new NotImplementedException();
  24. }
  25. public override LanguagePreferences GetLanguagePreferences()
  26. {
  27. if (m_preferences == null)
  28. {
  29. m_preferences = new LanguagePreferences(this.Site,
  30. typeof(LolFxLanguageService).GUID, this.Name);
  31. m_preferences.Init();
  32. }
  33. return m_preferences;
  34. }
  35. public override IScanner GetScanner(IVsTextLines buffer)
  36. {
  37. if (m_scanner == null)
  38. {
  39. m_scanner = new LolFxScanner(buffer);
  40. }
  41. return m_scanner;
  42. }
  43. public override string Name
  44. {
  45. get { return "LolFx"; }
  46. }
  47. public override AuthoringScope ParseSource(ParseRequest req)
  48. {
  49. return new LolFxAuthoringScope();
  50. }
  51. private LanguagePreferences m_preferences;
  52. private LolFxScanner m_scanner;
  53. internal class LolFxScanner : IScanner
  54. {
  55. public LolFxScanner(IVsTextBuffer buffer)
  56. {
  57. m_buffer = buffer;
  58. }
  59. bool IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo tokeninfo, ref int state)
  60. {
  61. while (m_offset < m_source.Length)
  62. {
  63. if (m_source[m_offset] == ' ' || m_source[m_offset] == '\t')
  64. {
  65. ++m_offset;
  66. continue;
  67. }
  68. tokeninfo.StartIndex = m_offset;
  69. tokeninfo.EndIndex = m_offset;
  70. tokeninfo.Type = TokenType.Unknown;
  71. switch (state % 4)
  72. {
  73. case 0: tokeninfo.Color = TokenColor.Number; break;
  74. case 1: tokeninfo.Color = TokenColor.Text; break;
  75. case 2: tokeninfo.Color = TokenColor.Keyword; break;
  76. case 3: tokeninfo.Color = TokenColor.Comment; break;
  77. }
  78. ++m_offset;
  79. ++state;
  80. return true;
  81. }
  82. return false;
  83. }
  84. enum State
  85. {
  86. Default,
  87. CComment,
  88. CppComment,
  89. String,
  90. }
  91. void IScanner.SetSource(string source, int offset)
  92. {
  93. m_source = source;
  94. m_offset = offset;
  95. }
  96. private IVsTextBuffer m_buffer;
  97. string m_source;
  98. int m_offset;
  99. }
  100. internal class LolFxAuthoringScope : AuthoringScope
  101. {
  102. public override string GetDataTipText(int line, int col, out TextSpan span)
  103. {
  104. span = new TextSpan();
  105. return null;
  106. }
  107. public override Declarations GetDeclarations(IVsTextView view,
  108. int line,
  109. int col,
  110. TokenInfo info,
  111. ParseReason reason)
  112. {
  113. return null;
  114. }
  115. public override string Goto(VSConstants.VSStd97CmdID cmd, IVsTextView textView, int line, int col, out TextSpan span)
  116. {
  117. span = new TextSpan();
  118. return null;
  119. }
  120. public override Methods GetMethods(int line, int col, string name)
  121. {
  122. return null;
  123. }
  124. }
  125. }
  126. } /* namespace lol */