The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

166 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. XmlTokeniser::XmlTokeniser() {}
  16. XmlTokeniser::~XmlTokeniser() {}
  17. CodeEditorComponent::ColourScheme XmlTokeniser::getDefaultColourScheme()
  18. {
  19. struct Type
  20. {
  21. const char* name;
  22. uint32 colour;
  23. };
  24. const Type types[] =
  25. {
  26. { "Error", 0xffcc0000 },
  27. { "Comment", 0xff00aa00 },
  28. { "Keyword", 0xff0000cc },
  29. { "Operator", 0xff225500 },
  30. { "Identifier", 0xff000000 },
  31. { "String", 0xff990099 },
  32. { "Bracket", 0xff000055 },
  33. { "Punctuation", 0xff004400 },
  34. { "Preprocessor Text", 0xff660000 }
  35. };
  36. CodeEditorComponent::ColourScheme cs;
  37. for (auto& t : types)
  38. cs.set (t.name, Colour (t.colour));
  39. return cs;
  40. }
  41. template <typename Iterator>
  42. static void skipToEndOfXmlDTD (Iterator& source) noexcept
  43. {
  44. bool lastWasQuestionMark = false;
  45. for (;;)
  46. {
  47. auto c = source.nextChar();
  48. if (c == 0 || (c == '>' && lastWasQuestionMark))
  49. break;
  50. lastWasQuestionMark = (c == '?');
  51. }
  52. }
  53. template <typename Iterator>
  54. static void skipToEndOfXmlComment (Iterator& source) noexcept
  55. {
  56. juce_wchar last[2] = {};
  57. for (;;)
  58. {
  59. auto c = source.nextChar();
  60. if (c == 0 || (c == '>' && last[0] == '-' && last[1] == '-'))
  61. break;
  62. last[1] = last[0];
  63. last[0] = c;
  64. }
  65. }
  66. int XmlTokeniser::readNextToken (CodeDocument::Iterator& source)
  67. {
  68. source.skipWhitespace();
  69. auto firstChar = source.peekNextChar();
  70. switch (firstChar)
  71. {
  72. case 0: break;
  73. case '"':
  74. case '\'':
  75. CppTokeniserFunctions::skipQuotedString (source);
  76. return tokenType_string;
  77. case '<':
  78. {
  79. source.skip();
  80. source.skipWhitespace();
  81. auto nextChar = source.peekNextChar();
  82. if (nextChar == '?')
  83. {
  84. source.skip();
  85. skipToEndOfXmlDTD (source);
  86. return tokenType_preprocessor;
  87. }
  88. if (nextChar == '!')
  89. {
  90. source.skip();
  91. if (source.peekNextChar() == '-')
  92. {
  93. source.skip();
  94. if (source.peekNextChar() == '-')
  95. {
  96. skipToEndOfXmlComment (source);
  97. return tokenType_comment;
  98. }
  99. }
  100. }
  101. CppTokeniserFunctions::skipIfNextCharMatches (source, '/');
  102. CppTokeniserFunctions::parseIdentifier (source);
  103. source.skipWhitespace();
  104. CppTokeniserFunctions::skipIfNextCharMatches (source, '/');
  105. source.skipWhitespace();
  106. CppTokeniserFunctions::skipIfNextCharMatches (source, '>');
  107. return tokenType_keyword;
  108. }
  109. case '>':
  110. source.skip();
  111. return tokenType_keyword;
  112. case '/':
  113. source.skip();
  114. source.skipWhitespace();
  115. CppTokeniserFunctions::skipIfNextCharMatches (source, '>');
  116. return tokenType_keyword;
  117. case '=':
  118. case ':':
  119. source.skip();
  120. return tokenType_operator;
  121. default:
  122. if (CppTokeniserFunctions::isIdentifierStart (firstChar))
  123. CppTokeniserFunctions::parseIdentifier (source);
  124. source.skip();
  125. break;
  126. };
  127. return tokenType_identifier;
  128. }
  129. } // namespace juce