A TextMate grammar for LSL (Linden Scripting Language) syntax highlighting in editors that support TextMate grammars, including Visual Studio Code, Sublime Text, and Atom.
LSL (Linden Scripting Language) is the programming language used to create interactive content in Second Life. This grammar provides comprehensive syntax highlighting for LSL scripts, including:
- Keywords: Control flow statements (
if,else,for,while,return, etc.) - Data Types: LSL primitive types (
integer,float,string,key,vector,rotation,list) - Events: All LSL event handlers (
state_entry,touch_start,timer,collision, etc.) - Built-in Functions: LSL library functions (functions starting with
ll) - Constants: Language constants (
TRUE,FALSE,PI,ZERO_VECTOR, etc.) - States: LSL state machine syntax
- Comments: Both single-line (
//) and multi-line (/* */) comments - Strings: String literals with escape sequences
- Numbers: Integer, float, and hexadecimal number formats
- Operators: All LSL operators with proper precedence
-
Copy the
lsl.tmLanguage.jsonfile to your VS Code extensions directory:- Windows:
%USERPROFILE%\.vscode\extensions\lsl-syntax\syntaxes\ - macOS:
~/.vscode/extensions/lsl-syntax/syntaxes/ - Linux:
~/.vscode/extensions/lsl-syntax/syntaxes/
- Windows:
-
Create a
package.jsonfile in the extension directory with the following content:
{
"name": "lsl-syntax",
"displayName": "LSL Syntax Highlighting",
"description": "Syntax highlighting for Linden Scripting Language (LSL)",
"version": "1.0.0",
"engines": {
"vscode": "^1.0.0"
},
"categories": ["Programming Languages"],
"contributes": {
"languages": [{
"id": "lsl",
"aliases": ["LSL", "lsl"],
"extensions": [".lsl"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "lsl",
"scopeName": "source.lsl",
"path": "./syntaxes/lsl.tmLanguage.json"
}]
}
}-
Copy
lsl.tmLanguage.jsonto your Sublime Text Packages directory:- Windows:
%APPDATA%\Sublime Text\Packages\User\ - macOS:
~/Library/Application Support/Sublime Text/Packages/User/ - Linux:
~/.config/sublime-text/Packages/User/
- Windows:
-
Restart Sublime Text and the LSL syntax will be available for
.lslfiles.
- Control Flow:
if,else,for,do,while,jump,return - State Management:
default,statedeclarations and transitions - Event Handlers: All LSL events including:
state_entry,state_exit- Touch events:
touch_start,touch,touch_end - Collision events:
collision_start,collision,collision_end - Timer and sensor events:
timer,listen,sensor,no_sensor - And many more...
- Built-in Functions: Automatic detection of LSL library functions (prefix
ll) - Data Types:
integer,float,string,key,vector,rotation,list - Constants: Mathematical constants (
PI,TWO_PI), boolean values, null keys, etc.
// Sample LSL script with syntax highlighting
default {
state_entry() {
llSay(0, "Hello, avatar!");
llSetText("I'm a scripted object!", <1,1,1>, 1.0);
llSetTimerEvent(5.0);
}
touch_start(integer total_number) {
llOwnerSay("You touched me!");
state active;
}
timer() {
llSay(0, "Timer fired!");
}
}
state active {
state_entry() {
llSay(0, "Now in active state");
}
touch_start(integer total_number) {
state default;
}
}Contributions are welcome! If you find any issues with syntax highlighting or want to add support for new LSL features:
- Fork this repository
- Make your changes to
lsl.tmLanguage.json - Test the grammar with various LSL scripts
- Submit a pull request
The grammar uses the following scope names for different syntax elements:
source.lsl- Root scopecomment.line.double-slash.lsl- Single-line commentscomment.block.lsl- Multi-line commentskeyword.control.lsl- Control flow keywordskeyword.control.state.lsl- State-related keywordsstorage.type.lsl- Data typesentity.name.function.builtin.lsl- Built-in LSL functionsentity.name.function.event.lsl- Event handlersconstant.language.lsl- Language constantsstring.quoted.double.lsl- String literalsconstant.numeric.*.lsl- Numeric literals
This project is available under the MIT License.
- LSL Portal - Official LSL documentation
- LSL Function Reference - Complete function reference
- Second Life Wiki - General Second Life scripting resources