VST3: fetch midi mappings all at once, use it for note/sound-off
[carla.git] / source / modules / juce_gui_extra / code_editor / juce_XMLCodeTokeniser.cpp
blobedde13e96f6e8fd2eae700829a94b3b698312df5
1 /*
2 ==============================================================================
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
23 ==============================================================================
26 namespace juce
29 XmlTokeniser::XmlTokeniser() {}
30 XmlTokeniser::~XmlTokeniser() {}
32 CodeEditorComponent::ColourScheme XmlTokeniser::getDefaultColourScheme()
34 struct Type
36 const char* name;
37 uint32 colour;
40 const Type types[] =
42 { "Error", 0xffcc0000 },
43 { "Comment", 0xff00aa00 },
44 { "Keyword", 0xff0000cc },
45 { "Operator", 0xff225500 },
46 { "Identifier", 0xff000000 },
47 { "String", 0xff990099 },
48 { "Bracket", 0xff000055 },
49 { "Punctuation", 0xff004400 },
50 { "Preprocessor Text", 0xff660000 }
53 CodeEditorComponent::ColourScheme cs;
55 for (auto& t : types)
56 cs.set (t.name, Colour (t.colour));
58 return cs;
61 template <typename Iterator>
62 static void skipToEndOfXmlDTD (Iterator& source) noexcept
64 bool lastWasQuestionMark = false;
66 for (;;)
68 auto c = source.nextChar();
70 if (c == 0 || (c == '>' && lastWasQuestionMark))
71 break;
73 lastWasQuestionMark = (c == '?');
77 template <typename Iterator>
78 static void skipToEndOfXmlComment (Iterator& source) noexcept
80 juce_wchar last[2] = {};
82 for (;;)
84 auto c = source.nextChar();
86 if (c == 0 || (c == '>' && last[0] == '-' && last[1] == '-'))
87 break;
89 last[1] = last[0];
90 last[0] = c;
94 int XmlTokeniser::readNextToken (CodeDocument::Iterator& source)
96 source.skipWhitespace();
97 auto firstChar = source.peekNextChar();
99 switch (firstChar)
101 case 0: break;
103 case '"':
104 case '\'':
105 CppTokeniserFunctions::skipQuotedString (source);
106 return tokenType_string;
108 case '<':
110 source.skip();
111 source.skipWhitespace();
112 auto nextChar = source.peekNextChar();
114 if (nextChar == '?')
116 source.skip();
117 skipToEndOfXmlDTD (source);
118 return tokenType_preprocessor;
121 if (nextChar == '!')
123 source.skip();
125 if (source.peekNextChar() == '-')
127 source.skip();
129 if (source.peekNextChar() == '-')
131 skipToEndOfXmlComment (source);
132 return tokenType_comment;
137 CppTokeniserFunctions::skipIfNextCharMatches (source, '/');
138 CppTokeniserFunctions::parseIdentifier (source);
139 source.skipWhitespace();
140 CppTokeniserFunctions::skipIfNextCharMatches (source, '/');
141 source.skipWhitespace();
142 CppTokeniserFunctions::skipIfNextCharMatches (source, '>');
143 return tokenType_keyword;
146 case '>':
147 source.skip();
148 return tokenType_keyword;
150 case '/':
151 source.skip();
152 source.skipWhitespace();
153 CppTokeniserFunctions::skipIfNextCharMatches (source, '>');
154 return tokenType_keyword;
156 case '=':
157 case ':':
158 source.skip();
159 return tokenType_operator;
161 default:
162 if (CppTokeniserFunctions::isIdentifierStart (firstChar))
163 CppTokeniserFunctions::parseIdentifier (source);
165 source.skip();
166 break;
169 return tokenType_identifier;
172 } // namespace juce