Skip to content

Commit 2c67f0f

Browse files
First working prototype
Still a lot to do, but mostly cleaning up code which LSL doesn't have/need, compared to JavaScript
1 parent 02758cf commit 2c67f0f

File tree

5 files changed

+259
-58
lines changed

5 files changed

+259
-58
lines changed

Completions/Linden Scripting Language.xml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
<completion string="&lt;" />
1515
<completion string="&gt;" />
1616
</set>
17-
<?xml version="1.0" encoding="UTF-8"?>
18-
<completions>
17+
1918
<!-- "foo" -->
2019
<provider name="lsl.globals">
2120
<syntax>lsl</syntax>
@@ -736,7 +735,4 @@
736735
<completion string="well_formed_stringify" />
737736
<completion string="xor" />
738737
</set>
739-
</completions>
740-
741-
742-
</completions>
738+
</completions>

Notecard.Reader.lsl

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
// Notecard Multi-line Entries Configuration Reader v1.6 by Maddox Deluxe
2+
// Error Checking for: Key Names, values, Empty Notecard Data, Line Spaces
3+
// This script is free; you can redistribute it and/or modify it
4+
// Just read the comments on the script
5+
6+
key NotecardQueryId; // key name of the notecard
7+
key LineRequestID; // notecard line count
8+
integer LineTotal; // The number of lines in the notecard
9+
integer LineIndex; // index for data read requests
10+
11+
string Author_Name = ""; // variable for setting author name
12+
string Menu_Button_Name = ""; // variable for setting menu button name to the themes list
13+
string Back_Drop_UUID = ""; // variable for setting backdrop uuid key to the themes list
14+
string Floor_Drop_UUID = ""; // variable for setting floor drop uuid key to the themes list
15+
16+
string data; // notecard data
17+
string GetNoteName; // notecard name
18+
19+
list Themes; // our list database for testing
20+
list KeyNames; // our list database for the key names: [Author Name]. [Menu Button Name], ect..
21+
22+
integer ThemesCount; // counts how many themes they are in the notecard configuration
23+
24+
key User; // user tracker key
25+
26+
// function by Maddox Deluxe
27+
// test to dump all 3 elements in the list that goes with each other
28+
DumpListFind(list db, string name)
29+
{
30+
integer index = llListFindList(db, [name]);
31+
if (~index) {
32+
list Found = llList2List(db, index, index + 2);
33+
34+
string BN = llList2String(Found, 0);
35+
string BD = llList2String(Found, 1);
36+
string FD = llList2String(Found, 2);
37+
38+
llOwnerSay("Dump testing for list database search.\nAuthor Name: " + (string)Author_Name + "\nButton Name: " + (string)BN + "\nBackdrop Texture: " + (string)BD + "\nFloor drop Texture: " + (string)FD);
39+
40+
llOwnerSay("List Dump Found Test: " + llDumpList2String(Found, ","));
41+
42+
// llMessageLinked(LINK_SET, 0,"SET BACKDROP TEXTURE",(string)BD);
43+
if (FD != (key)"00000000-0000-0000-0000-000000000000")
44+
{
45+
// llMessageLinked(LINK_SET, 0,"SET FLOOR DROP TEXTURE",(string)FD);
46+
}
47+
48+
}
49+
}
50+
// function by Maddox Deluxe
51+
// looks for 3 elements and the search string is the first element of the set
52+
integer IsElement(list db, string search)
53+
{
54+
integer index = llListFindList(db, [search]);
55+
if (~index) {
56+
list Found = llList2List(db, index, index + 2);
57+
58+
string str = llList2String(Found, 0);
59+
if (str == search)
60+
return TRUE; // was found
61+
}
62+
return FALSE; // was not found
63+
}
64+
// function by Maddox Deluxe
65+
// checks the key names making sure they match what is setup in the notecard
66+
integer KeyNameCheck(list db, string search)
67+
{
68+
integer i;
69+
for (i = 0; i < llGetListLength(db); ++i) {
70+
string s = llList2String(db, i);
71+
if (s == search) return TRUE;
72+
}
73+
return FALSE;
74+
}
75+
76+
// Checks the uuid keys in the notecard, making sure they are real keys
77+
// 2 valid key, not NULL_KEY
78+
// 1 (TRUE): NULL_KEY
79+
// 0 (FALSE): not a key
80+
// https://wiki.secondlife.com/wiki/Category:LSL_Key
81+
integer isKey(key uuid)
82+
{
83+
if (uuid)
84+
return 2;
85+
return (uuid == NULL_KEY);
86+
}
87+
88+
// notecard initialization
89+
NoteCardInit(string GrabNoteCardName, key id) // key id could be use for dialog message or llInstantMessage
90+
{
91+
if (llGetInventoryKey(GrabNoteCardName) == NULL_KEY) // update v1.6 with notecard null key checking
92+
{
93+
llInstantMessage(id, "Notecard '" + GrabNoteCardName + "' (1) The notecard key is null, write some data in it and hit save. (2) Notecard was not found.");
94+
return;
95+
}
96+
else
97+
LineRequestID = llGetNumberOfNotecardLines(GrabNoteCardName); // total number of lines in the notecard
98+
Themes = []; // clear the themes list
99+
LineIndex = 0; // start reading from line 0
100+
ThemesCount = 0; // start adding from 0
101+
NotecardQueryId = llGetNotecardLine(GrabNoteCardName, LineIndex);
102+
KeyNames = []; // clear the keynames list
103+
// setup our key names
104+
KeyNames = ["[author name]", "[menu button name]", "[backdrop texture uuid]", "[floordrop texture uuid]"];
105+
llInstantMessage(id, "Please stand by, reading themes configuration for " + GrabNoteCardName);
106+
GetNoteName = GrabNoteCardName;
107+
}
108+
109+
ProcessThemes(string data, key id) // key id could be use for dialog message or llInstantMessage
110+
{
111+
list cmd;
112+
string cmd_grab;
113+
string value;
114+
115+
// if we are at the end of the file
116+
if (data == EOF) {
117+
llInstantMessage(id, "Done reading themes configuration for " + GetNoteName + "\n\nTotal Themes: " + (string)ThemesCount);
118+
119+
// lets use the 2nd search string for this test, the search strings are the button names in the notecard configuration
120+
string TestSearch = "Fantasy Car";
121+
if (IsElement(Themes, TestSearch) == FALSE) {
122+
llInstantMessage(id, "Themes Configuration Error. Button search string was not found.");
123+
return;
124+
}
125+
else
126+
DumpListFind(Themes, TestSearch);
127+
return;
128+
}
129+
if (data == "") {
130+
llInstantMessage(id, "Themes Configuration Format Error. (1) No DATA found. (2) Got line spaces.");
131+
llResetScript();
132+
}
133+
if (data != "") {
134+
// lets move on and read the next line
135+
NotecardQueryId = llGetNotecardLine(GetNoteName, ++LineIndex);
136+
137+
// cut off any leading blanks
138+
// ignore comment lines
139+
// if you change the comment line from // to #, make sure you change the 1 to 0
140+
if (llGetSubString(data, 0, 1) != "//" && llStringTrim(data, STRING_TRIM) != "") {
141+
cmd = llParseString2List(data, ["="], []);
142+
cmd_grab = llStringTrim(llToLower(llList2String(cmd, 0)), STRING_TRIM);
143+
value = llStringTrim(llList2String(cmd, 1), STRING_TRIM);
144+
145+
// we only need this at the start to check for key name errors :)
146+
if (KeyNameCheck(KeyNames, cmd_grab) == FALSE) {
147+
llInstantMessage(id, "Themes Configuration Format Error on line: " + (string)LineIndex + ".");
148+
llResetScript();
149+
}
150+
if (cmd_grab == "[author name]") {
151+
Author_Name = value;
152+
// error checking for Author Name
153+
if (value == "") {
154+
llInstantMessage(id, "Themes Configuration Error on line: " + (string)LineIndex + ". Author Name can not be empty.");
155+
llResetScript();
156+
}
157+
}
158+
else
159+
if (cmd_grab == "[menu button name]") {
160+
Menu_Button_Name = value;
161+
// error checking for Menu Button Name
162+
if (value == "") {
163+
llInstantMessage(id, "Themes Configuration Error on line: " + (string)LineIndex + ". Menu Button Name can not be empty.");
164+
llResetScript();
165+
}
166+
}
167+
else
168+
if (cmd_grab == "[backdrop texture uuid]") {
169+
Back_Drop_UUID = value;
170+
// error checking for BackDrop Texture UUID
171+
if (value == "" || (isKey((key)value)) == 1 || (isKey((key)value)) == 0) {
172+
llInstantMessage(id, "Themes Configuration Error on line: " + (string)LineIndex + ". (1) The Backdrop UUID Key is empty. (2) The Backdrop UUID is not a key. (3) The Backdrop UUID Key is NULL.");
173+
llResetScript();
174+
}
175+
}
176+
else
177+
if (cmd_grab == "[floordrop texture uuid]") {
178+
Floor_Drop_UUID = value;
179+
// error checking for FloorDrop Texture UUID
180+
if (value == "" || (isKey((key)value)) == 0) {
181+
llInstantMessage(id, "Themes Configuration Error on line: " + (string)LineIndex + ". (1) The Floor-drop UUID Key is empty. (2) The Floor-drop UUID is not a key.");
182+
llResetScript();
183+
}
184+
ThemesCount = ThemesCount + 1; // add +1 to our themes count
185+
Themes += [Menu_Button_Name, Back_Drop_UUID, Floor_Drop_UUID]; // add to our themes test list database
186+
}
187+
}
188+
}
189+
}
190+
default
191+
{
192+
193+
link_message(integer sender_num, integer num, string str, key id)
194+
{
195+
if (str == "SetUserKey") {
196+
// sets up the user key that click the object
197+
User = (key)id;
198+
}
199+
if (str == "LoadThemes") {
200+
// loads up our test notecard
201+
NoteCardInit((string)id, User);
202+
}
203+
}
204+
// triggered when task receives asynchronous data
205+
dataserver(key request_id, string data)
206+
{
207+
if (request_id == NotecardQueryId) {
208+
// we start processing our notecard data
209+
ProcessThemes(data, User);
210+
}
211+
}
212+
}

Scripts/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
nova.commands.register("gwynethllewelyn.LindenScriptingLanguage.search", (editor) => {
2+
var query = editor.getTextInRange(editor.selectedRanges[0]).trim();
3+
4+
if (query == "" || query == null) {
5+
nova.workspace.showErrorMessage("Not a valid search query.");
6+
return;
7+
}
8+
// TODO: put this inside a Nova tab instead
9+
nova.openURL("http://wiki.secondlife.com/wiki/" + encodeURIComponent(query));
10+
});
11+
12+

Syntaxes/Linden Scripting Language.xml

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,9 @@
229229

230230
<scope name="lsl.definition.property">
231231
<symbol type="property" scope="private" />
232-
<expression>(this)(\.)(\#?[a-zA-Z_\$][A-Za-zÀ-ÖØ-öø-ÿŸřŘšŠžŽ0-9_]*)\s*(\=)</expression>
233-
<capture number="1" name="lsl.keyword.self" />
232+
<expression>(\#?[a-zA-Z_\$][A-Za-zÀ-ÖØ-öø-ÿŸřŘšŠžŽ0-9_]*)\s*(\=)</expression>
233+
<capture number="1" name="lsl.identifier.property.name" />
234234
<capture number="2" name="lsl.operator" />
235-
<capture number="3" name="lsl.identifier.property.name" />
236-
<capture number="4" name="lsl.operator" />
237235
</scope>
238236

239237
<!-- !Destructuring Assignment -->
@@ -249,7 +247,7 @@
249247
</ends-with>
250248
<subscopes>
251249
<cut-off>
252-
<expression>(?=\b(?:static|async|function|class|if|else|while|for)\b)</expression>
250+
<expression>(?=\b(?:if|else|while|for)\b)</expression>
253251
</cut-off>
254252
<scope name="lsl.identifier">
255253
<symbol type="variable" scope="local" />
@@ -277,7 +275,7 @@
277275
</ends-with>
278276
<subscopes>
279277
<cut-off>
280-
<expression>(?=\b(?:static|async|function|class|if|else|while|for)\b)</expression>
278+
<expression>(?=\b(?:if|else|while|for)\b)</expression>
281279
</cut-off>
282280
<scope name="lsl.identifier">
283281
<symbol type="variable" scope="local" />
@@ -306,7 +304,7 @@
306304
</ends-with>
307305
<subscopes>
308306
<cut-off>
309-
<expression>(?=\b(?:static|async|function|class|if|else|while|for)\b)</expression>
307+
<expression>(?=\b(?:if|else|while|for)\b)</expression>
310308
</cut-off>
311309
<scope name="lsl.identifier">
312310
<symbol type="variable" scope="local" />
@@ -334,7 +332,7 @@
334332
</ends-with>
335333
<subscopes>
336334
<cut-off>
337-
<expression>(?=\b(?:static|async|function|class|if|else|while|for)\b)</expression>
335+
<expression>(?=\b(?:if|else|while|for)\b)</expression>
338336
</cut-off>
339337
<scope name="lsl.identifier">
340338
<symbol type="variable" scope="local" />
@@ -592,41 +590,6 @@
592590
<include syntax="self" collection="function-blocks" />
593591
</subscopes>
594592
</scope>
595-
596-
<scope name="lsl.method.computed">
597-
<symbol type="method">
598-
<context behavior="subtree" foldable="false" />
599-
</symbol>
600-
<starts-with>
601-
<expression>(?:(?:\b(async)(\*)?\s+)|(\*)?)(\[)</expression>
602-
<capture number="1" name="lsl.keyword.modifier" />
603-
<capture number="2" name="lsl.operator" />
604-
<capture number="3" name="lsl.operator" />
605-
<capture number="4" name="lsl.bracket" />
606-
</starts-with>
607-
<ends-with />
608-
<subscopes anchored="true">
609-
<include syntax="self" collection="comments" optional="true" repeat="true" />
610-
<scope name="lsl.method.computed.expression.name">
611-
<starts-with>
612-
<expression>(?=[^\]])</expression>
613-
</starts-with>
614-
<ends-with>
615-
<expression>(?=\])</expression>
616-
</ends-with>
617-
<subscopes anchored="true">
618-
<include syntax="self" collection="expressions" repeat="true" />
619-
</subscopes>
620-
</scope>
621-
<include syntax="self" collection="comments" optional="true" repeat="true" />
622-
<scope name="lsl.bracket">
623-
<expression>\]</expression>
624-
</scope>
625-
<include syntax="self" collection="arguments" />
626-
<include syntax="self" collection="comments" optional="true" repeat="true" />
627-
<include syntax="self" collection="function-blocks" />
628-
</subscopes>
629-
</scope>
630593
</collection>
631594

632595
<!-- !Properties -->
@@ -644,7 +607,7 @@
644607
</ends-with>
645608
<subscopes>
646609
<cut-off>
647-
<expression>(?=\b(?:static|async|function|class|if|else|while|for)\b)</expression>
610+
<expression>(?=\b(?:if|else|while|for)\b)</expression>
648611
</cut-off>
649612
<include syntax="self" collection="comments" />
650613
<include syntax="self" collection="keywords" />
@@ -669,7 +632,7 @@
669632
</ends-with>
670633
<subscopes>
671634
<cut-off>
672-
<expression>(?=\b(?:static|async|function|class|if|else|while|for)\b)</expression>
635+
<expression>(?=\b(?:if|else|while|for)\b)</expression>
673636
</cut-off>
674637
<include syntax="self" collection="comments" />
675638
<include syntax="self" collection="keywords" />
@@ -904,8 +867,6 @@
904867
<string>return</string>
905868
</strings>
906869
</scope>
907-
<scope name="lsl.keyword.self">
908-
</scope>
909870
</collection>
910871

911872
<!-- !Expressions -->
@@ -1707,8 +1668,8 @@
17071668
</scope>
17081669
<!-- All past, present and future Linden Lab LSL functions start with ll..() -->
17091670
<scope name="lsl.identifier.core.function.unknown">
1710-
<strings prefix="(?&lt;!\.)ll" suffix="(?=\()">
1711-
</strings>
1671+
<expression>"(?&lt;!\.)ll([a-zA-Z_]+[a-zA-Z0-9_]*)(?=\()"</expression>
1672+
<capture number="1" name="lsl.identifier.function.name" />
17121673
</scope>
17131674
<scope name="lsl.identifier.ossl.function.avatar">
17141675
<strings prefix="(?&lt;!\.)" suffix="(?=\()">
@@ -2022,6 +1983,7 @@
20221983
<string>string</string>
20231984
<string>vector</string>
20241985
</strings>
1986+
</scope>
20251987
<scope name="lsl.identifier.function">
20261988
<expression>(?&lt;!\.)((?:\b[a-zA-Z_]|\$)[A-Za-zÀ-ÖØ-öø-ÿŸřŘšŠžŽ0-9_]*)(?=\()</expression>
20271989
</scope>

0 commit comments

Comments
 (0)