Skip to content

Lua editor: syntax highlighting improvements #3609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions indra/llui/llkeywords.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ LLUIColor LLKeywords::getColorGroup(std::string_view key_in)
return LLUIColorTable::instance().getColor(color_group);
}

void LLKeywords::initialize(LLSD SyntaxXML)
void LLKeywords::initialize(LLSD SyntaxXML, bool luau_language)
{
mSyntax = SyntaxXML;
mLuauLanguage = luau_language;
mLoaded = true;
}

Expand All @@ -235,13 +236,21 @@ void LLKeywords::processTokens()
// Add 'standard' stuff: Quotes, Comments, Strings, Labels, etc. before processing the LLSD
std::string delimiter;
addToken(LLKeywordToken::TT_LABEL, "@", getColorGroup("misc-flow-label"), "Label\nTarget for jump statement", delimiter );
addToken(LLKeywordToken::TT_ONE_SIDED_DELIMITER, "//", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (single-line)\nNon-functional commentary or disabled code", delimiter );
addToken(LLKeywordToken::TT_TWO_SIDED_DELIMITER, "/*", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (multi-line)\nNon-functional commentary or disabled code", "*/" );
addToken(LLKeywordToken::TT_DOUBLE_QUOTATION_MARKS, "\"", LLUIColorTable::instance().getColor("SyntaxLslStringLiteral"), "String literal", "\"" );

// Lua-style comments
addToken(LLKeywordToken::TT_ONE_SIDED_DELIMITER, "--", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (Lua-style single-line)\nNon-functional commentary or disabled code", delimiter);
addToken(LLKeywordToken::TT_TWO_SIDED_DELIMITER, "--[[", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (Lua-style multi-line)\nNon-functional commentary or disabled code", "]]");
if (mLuauLanguage)
{
// Add Lua-style comments
addToken(LLKeywordToken::TT_ONE_SIDED_DELIMITER, "--", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (Lua-style single-line)\nNon-functional commentary or disabled code", delimiter);
addToken(LLKeywordToken::TT_TWO_SIDED_DELIMITER, "--[[", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (Lua-style multi-line)\nNon-functional commentary or disabled code", "]]");
}
else
{
// Add LSL-style comments
addToken(LLKeywordToken::TT_ONE_SIDED_DELIMITER, "//", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (single-line)\nNon-functional commentary or disabled code", delimiter);
addToken(LLKeywordToken::TT_TWO_SIDED_DELIMITER, "/*", LLUIColorTable::instance().getColor("SyntaxLslComment"), "Comment (multi-line)\nNon-functional commentary or disabled code", "*/");
}


LLSD::map_iterator itr = mSyntax.beginMap();
for ( ; itr != mSyntax.endMap(); ++itr)
Expand Down Expand Up @@ -669,7 +678,8 @@ void LLKeywords::findSegments(std::vector<LLTextSegmentPtr>* seg_list, const LLW
if( !iswalnum( prev ) && (prev != '_') )
{
const llwchar* p = cur;
while( iswalnum( *p ) || (*p == '_') )
while( iswalnum( *p ) || (*p == '_')
|| (mLuauLanguage && *p == '.') ) // Allow dots in Lua to pass the functions. For example, "ll.Say()" instead of "llSay()" in LSL
{
p++;
}
Expand Down
3 changes: 2 additions & 1 deletion indra/llui/llkeywords.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class LLKeywords
const LLWString& text,
class LLTextEditor& editor,
LLStyleConstSP style);
void initialize(LLSD SyntaxXML);
void initialize(LLSD SyntaxXML, bool luau_language = false);
void processTokens();

// Add the token as described
Expand Down Expand Up @@ -189,6 +189,7 @@ class LLKeywords

bool mLoaded;
LLSD mSyntax;
bool mLuauLanguage;
word_token_map_t mWordTokenMap;
typedef std::deque<LLKeywordToken*> token_list_t;
token_list_t mLineTokenList;
Expand Down
82 changes: 0 additions & 82 deletions indra/newview/app_settings/keywords_lsl_default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,6 @@
<map>
<key>controls</key>
<map>
<!-- Lua-only keywords -->
<key>and</key>
<map>
<key>tooltip</key>
<string>Logical AND operator. (Lua)</string>
</map>
<key>break</key>
<map>
<key>tooltip</key>
<string>Exits a loop immediately. (Lua)</string>
</map>
<key>elseif</key>
<map>
<key>tooltip</key>
<string>Provides an additional conditional branch in an if–else chain. (Lua)</string>
</map>
<key>end</key>
<map>
<key>tooltip</key>
<string>Terminates a block initiated by if, do, or function. (Lua)</string>
</map>
<key>false</key>
<map>
<key>tooltip</key>
<string>Boolean constant representing false. (Lua)</string>
</map>
<key>function</key>
<map>
<key>tooltip</key>
<string>Declares a function. (Lua)</string>
</map>
<key>goto</key>
<map>
<key>tooltip</key>
<string>Transfers control to a labeled statement. (Lua)</string>
</map>
<key>in</key>
<map>
<key>tooltip</key>
<string>Used in for loops to iterate over elements in a collection. (Lua)</string>
</map>
<key>local</key>
<map>
<key>tooltip</key>
<string>Declares a variable or function with local scope. (Lua)</string>
</map>
<key>nil</key>
<map>
<key>tooltip</key>
<string>Represents a non-existent or undefined value. (Lua)</string>
</map>
<key>not</key>
<map>
<key>tooltip</key>
<string>Logical NOT operator; inverts a boolean value. (Lua)</string>
</map>
<key>or</key>
<map>
<key>tooltip</key>
<string>Logical OR operator. (Lua)</string>
</map>
<key>repeat</key>
<map>
<key>tooltip</key>
<string>Begins a repeat-until loop. (Lua)</string>
</map>
<key>then</key>
<map>
<key>tooltip</key>
<string>Follows an if condition to indicate the start of the consequent block. (Lua)</string>
</map>
<key>true</key>
<map>
<key>tooltip</key>
<string>Boolean constant representing true. (Lua)</string>
</map>
<key>until</key>
<map>
<key>tooltip</key>
<string>Ends a repeat-until loop, specifying the condition to exit. (Lua)</string>
</map>
<!-- LSL keywords -->
<key>do</key>
<map>
<key>tooltip</key>
Expand Down
Loading