JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_XMLCodeTokeniser.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
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.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29XmlTokeniser::XmlTokeniser() {}
30XmlTokeniser::~XmlTokeniser() {}
31
33{
34 struct Type
35 {
36 const char* name;
37 uint32 colour;
38 };
39
40 const Type types[] =
41 {
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 }
51 };
52
54
55 for (auto& t : types)
56 cs.set (t.name, Colour (t.colour));
57
58 return cs;
59}
60
61template <typename Iterator>
62static void skipToEndOfXmlDTD (Iterator& source) noexcept
63{
64 bool lastWasQuestionMark = false;
65
66 for (;;)
67 {
68 auto c = source.nextChar();
69
70 if (c == 0 || (c == '>' && lastWasQuestionMark))
71 break;
72
73 lastWasQuestionMark = (c == '?');
74 }
75}
76
77template <typename Iterator>
78static void skipToEndOfXmlComment (Iterator& source) noexcept
79{
80 juce_wchar last[2] = {};
81
82 for (;;)
83 {
84 auto c = source.nextChar();
85
86 if (c == 0 || (c == '>' && last[0] == '-' && last[1] == '-'))
87 break;
88
89 last[1] = last[0];
90 last[0] = c;
91 }
92}
93
95{
96 source.skipWhitespace();
97 auto firstChar = source.peekNextChar();
98
99 switch (firstChar)
100 {
101 case 0: break;
102
103 case '"':
104 case '\'':
105 CppTokeniserFunctions::skipQuotedString (source);
106 return tokenType_string;
107
108 case '<':
109 {
110 source.skip();
111 source.skipWhitespace();
112 auto nextChar = source.peekNextChar();
113
114 if (nextChar == '?')
115 {
116 source.skip();
117 skipToEndOfXmlDTD (source);
118 return tokenType_preprocessor;
119 }
120
121 if (nextChar == '!')
122 {
123 source.skip();
124
125 if (source.peekNextChar() == '-')
126 {
127 source.skip();
128
129 if (source.peekNextChar() == '-')
130 {
131 skipToEndOfXmlComment (source);
132 return tokenType_comment;
133 }
134 }
135 }
136
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;
144 }
145
146 case '>':
147 source.skip();
148 return tokenType_keyword;
149
150 case '/':
151 source.skip();
152 source.skipWhitespace();
153 CppTokeniserFunctions::skipIfNextCharMatches (source, '>');
154 return tokenType_keyword;
155
156 case '=':
157 case ':':
158 source.skip();
159 return tokenType_operator;
160
161 default:
162 if (CppTokeniserFunctions::isIdentifierStart (firstChar))
163 CppTokeniserFunctions::parseIdentifier (source);
164
165 source.skip();
166 break;
167 };
168
169 return tokenType_identifier;
170}
171
172} // namespace juce
Iterates the text in a CodeDocument.
void skip() noexcept
Advances the position by one character.
juce_wchar peekNextChar() const noexcept
Reads the next character without moving the current position.
void skipWhitespace() noexcept
Skips over any whitespace characters until the next character is non-whitespace.
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
CodeEditorComponent::ColourScheme getDefaultColourScheme() override
Returns a suggested syntax highlighting colour scheme.
int readNextToken(CodeDocument::Iterator &) override
Reads the next token from the source and returns its token type.
JUCE Namespace.
wchar_t juce_wchar
A platform-independent 32-bit unicode character type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
Defines a syntax highlighting colour scheme.