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
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
23 ==============================================================================
29 XmlTokeniser::XmlTokeniser() {}
30 XmlTokeniser::~XmlTokeniser() {}
32 CodeEditorComponent::ColourScheme
XmlTokeniser::getDefaultColourScheme()
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
;
56 cs
.set (t
.name
, Colour (t
.colour
));
61 template <typename Iterator
>
62 static void skipToEndOfXmlDTD (Iterator
& source
) noexcept
64 bool lastWasQuestionMark
= false;
68 auto c
= source
.nextChar();
70 if (c
== 0 || (c
== '>' && lastWasQuestionMark
))
73 lastWasQuestionMark
= (c
== '?');
77 template <typename Iterator
>
78 static void skipToEndOfXmlComment (Iterator
& source
) noexcept
80 juce_wchar last
[2] = {};
84 auto c
= source
.nextChar();
86 if (c
== 0 || (c
== '>' && last
[0] == '-' && last
[1] == '-'))
94 int XmlTokeniser::readNextToken (CodeDocument::Iterator
& source
)
96 source
.skipWhitespace();
97 auto firstChar
= source
.peekNextChar();
105 CppTokeniserFunctions::skipQuotedString (source
);
106 return tokenType_string
;
111 source
.skipWhitespace();
112 auto nextChar
= source
.peekNextChar();
117 skipToEndOfXmlDTD (source
);
118 return tokenType_preprocessor
;
125 if (source
.peekNextChar() == '-')
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
;
148 return tokenType_keyword
;
152 source
.skipWhitespace();
153 CppTokeniserFunctions::skipIfNextCharMatches (source
, '>');
154 return tokenType_keyword
;
159 return tokenType_operator
;
162 if (CppTokeniserFunctions::isIdentifierStart (firstChar
))
163 CppTokeniserFunctions::parseIdentifier (source
);
169 return tokenType_identifier
;