LMMS
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
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 '\'':
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);
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
139 source.skipWhitespace();
141 source.skipWhitespace();
143 return tokenType_keyword;
144 }
145
146 case '>':
147 source.skip();
148 return tokenType_keyword;
149
150 case '/':
151 source.skip();
152 source.skipWhitespace();
154 return tokenType_keyword;
155
156 case '=':
157 case ':':
158 source.skip();
159 return tokenType_operator;
160
161 default:
164
165 source.skip();
166 break;
167 };
168
170}
171
172} // namespace juce
Definition juce_CodeDocument.h:360
void skip() noexcept
Definition juce_CodeDocument.cpp:199
juce_wchar peekNextChar() const noexcept
Definition juce_CodeDocument.cpp:227
void skipWhitespace() noexcept
Definition juce_CodeDocument.cpp:287
Definition juce_Colour.h:38
@ tokenType_operator
Definition juce_XMLCodeTokeniser.h:51
@ tokenType_identifier
Definition juce_XMLCodeTokeniser.h:52
@ tokenType_keyword
Definition juce_XMLCodeTokeniser.h:50
@ tokenType_comment
Definition juce_XMLCodeTokeniser.h:49
@ tokenType_string
Definition juce_XMLCodeTokeniser.h:53
@ tokenType_preprocessor
Definition juce_XMLCodeTokeniser.h:56
XmlTokeniser()
Definition juce_XMLCodeTokeniser.cpp:29
CodeEditorComponent::ColourScheme getDefaultColourScheme() override
Definition juce_XMLCodeTokeniser.cpp:32
int readNextToken(CodeDocument::Iterator &) override
Definition juce_XMLCodeTokeniser.cpp:94
~XmlTokeniser() override
Definition juce_XMLCodeTokeniser.cpp:30
struct huft * t
Definition inflate.c:943
static const char * name
Definition pugl.h:1582
Definition carla_juce.cpp:31
static void skipToEndOfXmlComment(Iterator &source) noexcept
Definition juce_XMLCodeTokeniser.cpp:78
static void skipToEndOfXmlDTD(Iterator &source) noexcept
Definition juce_XMLCodeTokeniser.cpp:62
unsigned int uint32
Definition juce_MathsFunctions.h:45
wchar_t juce_wchar
Definition juce_CharacterFunctions.h:42
Definition juce_CodeEditorComponent.h:225
void set(const String &name, Colour colour)
Definition juce_CodeEditorComponent.cpp:1691
static bool isIdentifierStart(const juce_wchar c) noexcept
Definition juce_CPlusPlusCodeTokeniserFunctions.h:36
static void skipQuotedString(Iterator &source) noexcept
Definition juce_CPlusPlusCodeTokeniserFunctions.h:318
static int parseIdentifier(Iterator &source) noexcept
Definition juce_CPlusPlusCodeTokeniserFunctions.h:111
static void skipIfNextCharMatches(Iterator &source, const juce_wchar c) noexcept
Definition juce_CPlusPlusCodeTokeniserFunctions.h:394
return c
Definition crypt.c:175