LMMS
Loading...
Searching...
No Matches
juce_LuaCodeTokeniser.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
30{
31 static bool isReservedKeyword (String::CharPointerType token, const int tokenLength) noexcept
32 {
33 static const char* const keywords2Char[] =
34 { "if", "or", "in", "do", nullptr };
35
36 static const char* const keywords3Char[] =
37 { "and", "end", "for", "nil", "not", nullptr };
38
39 static const char* const keywords4Char[] =
40 { "then", "true", "else", nullptr };
41
42 static const char* const keywords5Char[] =
43 { "false", "local", "until", "while", "break", nullptr };
44
45 static const char* const keywords6Char[] =
46 { "repeat", "return", "elseif", nullptr};
47
48 static const char* const keywordsOther[] =
49 { "function", "@interface", "@end", "@synthesize", "@dynamic", "@public",
50 "@private", "@property", "@protected", "@class", nullptr };
51
52 const char* const* k;
53
54 switch (tokenLength)
55 {
56 case 2: k = keywords2Char; break;
57 case 3: k = keywords3Char; break;
58 case 4: k = keywords4Char; break;
59 case 5: k = keywords5Char; break;
60 case 6: k = keywords6Char; break;
61
62 default:
63 if (tokenLength < 2 || tokenLength > 16)
64 return false;
65
66 k = keywordsOther;
67 break;
68 }
69
70 for (int i = 0; k[i] != nullptr; ++i)
71 if (token.compare (CharPointer_ASCII (k[i])) == 0)
72 return true;
73
74 return false;
75 }
76
77 template <typename Iterator>
78 static int parseIdentifier (Iterator& source) noexcept
79 {
80 int tokenLength = 0;
81 String::CharPointerType::CharType possibleIdentifier[100] = {};
82 String::CharPointerType possible (possibleIdentifier);
83
84 while (CppTokeniserFunctions::isIdentifierBody (source.peekNextChar()))
85 {
86 auto c = source.nextChar();
87
88 if (tokenLength < 20)
89 possible.write (c);
90
91 ++tokenLength;
92 }
93
94 if (tokenLength > 1 && tokenLength <= 16)
95 {
96 possible.writeNull();
97
98 if (isReservedKeyword (String::CharPointerType (possibleIdentifier), tokenLength))
100 }
101
103 }
104
105 template <typename Iterator>
106 static int readNextToken (Iterator& source)
107 {
108 source.skipWhitespace();
109
110 auto firstChar = source.peekNextChar();
111
112 switch (firstChar)
113 {
114 case 0:
115 break;
116
117 case '0': case '1': case '2': case '3': case '4':
118 case '5': case '6': case '7': case '8': case '9':
119 case '.':
120 {
122
124 {
125 source.skip();
126
127 if (firstChar == '.')
129 }
130
131 return result;
132 }
133
134 case ',':
135 case ';':
136 case ':':
137 source.skip();
139
140 case '(': case ')':
141 case '{': case '}':
142 case '[': case ']':
143 source.skip();
145
146 case '"':
147 case '\'':
150
151 case '+':
152 source.skip();
155
156 case '-':
157 {
158 source.skip();
160
161 if (source.peekNextChar() == '-')
162 {
163 source.skipToEndOfLine();
165 }
166
168 {
171 }
172
173 return result;
174 }
175
176 case '*': case '%':
177 case '=': case '!':
178 source.skip();
181
182 case '?':
183 case '~':
184 source.skip();
186
187 case '<': case '>':
188 case '|': case '&': case '^':
189 source.skip();
193
194 default:
196 return parseIdentifier (source);
197
198 source.skip();
199 break;
200 }
201
203 }
204};
205
206//==============================================================================
209
214
216{
218 {
219 { "Error", Colour (0xffcc0000) },
220 { "Comment", Colour (0xff3c3c3c) },
221 { "Keyword", Colour (0xff0000cc) },
222 { "Operator", Colour (0xff225500) },
223 { "Identifier", Colour (0xff000000) },
224 { "Integer", Colour (0xff880000) },
225 { "Float", Colour (0xff885500) },
226 { "String", Colour (0xff990099) },
227 { "Bracket", Colour (0xff000055) },
228 { "Punctuation", Colour (0xff004400) }
229 };
230
232
233 for (auto& t : types)
234 cs.set (t.name, Colour (t.colour));
235
236 return cs;
237}
238
239} // namespace juce
Definition juce_CharPointer_ASCII.h:38
Definition juce_CodeDocument.h:360
Definition juce_Colour.h:38
int readNextToken(CodeDocument::Iterator &) override
Definition juce_LuaCodeTokeniser.cpp:210
@ tokenType_bracket
Definition juce_LuaCodeTokeniser.h:56
@ tokenType_keyword
Definition juce_LuaCodeTokeniser.h:50
@ tokenType_comment
Definition juce_LuaCodeTokeniser.h:49
@ tokenType_string
Definition juce_LuaCodeTokeniser.h:55
@ tokenType_punctuation
Definition juce_LuaCodeTokeniser.h:57
@ tokenType_error
Definition juce_LuaCodeTokeniser.h:48
@ tokenType_operator
Definition juce_LuaCodeTokeniser.h:51
@ tokenType_identifier
Definition juce_LuaCodeTokeniser.h:52
CodeEditorComponent::ColourScheme getDefaultColourScheme() override
Definition juce_LuaCodeTokeniser.cpp:215
~LuaTokeniser() override
Definition juce_LuaCodeTokeniser.cpp:208
LuaTokeniser()
Definition juce_LuaCodeTokeniser.cpp:207
struct huft * t
Definition inflate.c:943
register unsigned k
Definition inflate.c:946
register unsigned i
Definition inflate.c:1575
Definition carla_juce.cpp:31
Definition juce_CodeEditorComponent.h:228
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 bool isIdentifierBody(const juce_wchar c) noexcept
Definition juce_CPlusPlusCodeTokeniserFunctions.h:42
static void skipQuotedString(Iterator &source) noexcept
Definition juce_CPlusPlusCodeTokeniserFunctions.h:318
static void skipIfNextCharMatches(Iterator &source, const juce_wchar c) noexcept
Definition juce_CPlusPlusCodeTokeniserFunctions.h:394
static int parseNumber(Iterator &source)
Definition juce_CPlusPlusCodeTokeniserFunctions.h:298
Definition juce_LuaCodeTokeniser.cpp:30
static int readNextToken(Iterator &source)
Definition juce_LuaCodeTokeniser.cpp:106
static int parseIdentifier(Iterator &source) noexcept
Definition juce_LuaCodeTokeniser.cpp:78
static bool isReservedKeyword(String::CharPointerType token, const int tokenLength) noexcept
Definition juce_LuaCodeTokeniser.cpp:31
return c
Definition crypt.c:175
int result
Definition process.c:1455