aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs76
1 files changed, 43 insertions, 33 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
index 3036ace..9f753df 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
@@ -1,29 +1,30 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4*
5 * Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15 * 15*
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26*
27*/
27 28
28using System.Collections.Generic; 29using System.Collections.Generic;
29using System.Text.RegularExpressions; 30using System.Text.RegularExpressions;
@@ -33,6 +34,8 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
33{ 34{
34 public class LSL2CSConverter 35 public class LSL2CSConverter
35 { 36 {
37
38
36 // Uses regex to convert LSL code to C# code. 39 // Uses regex to convert LSL code to C# code.
37 40
38 //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled); 41 //private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled);
@@ -173,7 +176,9 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
173 { 176 {
174 // 0 => 1: Get last 177 // 0 => 1: Get last
175 Match m = 178 Match m =
176 Regex.Match(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{", 179 //Regex.Match(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{",
180 Regex.Match(cache, @"(?![a-zA-Z_]+)\s*(state\s+)?(?<statename>[a-zA-Z_]+)[^a-zA-Z_\(\)]*{",
181
177 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 182 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
178 183
179 in_state = false; 184 in_state = false;
@@ -181,13 +186,14 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
181 { 186 {
182 // Go back to level 0, this is not a state 187 // Go back to level 0, this is not a state
183 in_state = true; 188 in_state = true;
184 current_statename = m.Groups[1].Captures[0].Value; 189 current_statename = m.Groups["statename"].Captures[0].Value;
185 //Console.WriteLine("Current statename: " + current_statename); 190 //Console.WriteLine("Current statename: " + current_statename);
186 cache = 191 cache =
192 //@"(?<s1>(?![a-zA-Z_]+)\s*)" + @"([a-zA-Z_]+)(?<s2>[^a-zA-Z_\(\)]*){",
187 Regex.Replace(cache, 193 Regex.Replace(cache,
188 @"(?<s1>(?![a-zA-Z_]+)\s*)" + @"([a-zA-Z_]+)(?<s2>[^a-zA-Z_\(\)]*){", 194 @"(?<s1>(?![a-zA-Z_]+)\s*)" + @"(state\s+)?([a-zA-Z_]+)(?<s2>[^a-zA-Z_\(\)]*){",
189 "${s1}${s2}", 195 "${s1}${s2}",
190 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 196 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
191 } 197 }
192 ret += cache; 198 ret += cache;
193 cache = String.Empty; 199 cache = String.Empty;
@@ -208,7 +214,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
208 Regex.Replace(cache, 214 Regex.Replace(cache,
209 @"^(\s*)((?!(if|switch|for|while)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", 215 @"^(\s*)((?!(if|switch|for|while)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)",
210 @"$1public " + current_statename + "_event_$2", 216 @"$1public " + current_statename + "_event_$2",
211 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 217 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
212 } 218 }
213 219
214 ret += cache; 220 ret += cache;
@@ -254,10 +260,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
254 260
255 // Replace <x,y,z> and <x,y,z,r> 261 // Replace <x,y,z> and <x,y,z,r>
256 Script = 262 Script =
257 Regex.Replace(Script, @"<([^,>;]*,[^,>;\)]*,[^,>;\)]*,[^,>;\)]*)>", @"new LSL_Types.Quaternion($1)", 263 Regex.Replace(Script, @"<([^,>;]*,[^,>;]*,[^,>;]*,[^,>;]*)>", @"new LSL_Types.Quaternion($1)",
258 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 264 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
259 Script = 265 Script =
260 Regex.Replace(Script, @"<([^,>;]*,[^,>;\)]*,[^,>;\)]*)>", @"new LSL_Types.Vector3($1)", 266 Regex.Replace(Script, @"<([^,>;)]*,[^,>;]*,[^,>;]*)>", @"new LSL_Types.Vector3($1)",
261 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 267 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
262 268
263 // Replace List []'s 269 // Replace List []'s
@@ -274,6 +280,10 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
274 Regex.Replace(Script, @"\((float|int)\)\s*([a-zA-Z0-9_.]+(\s*\([^\)]*\))?)", @"$1.Parse($2)", 280 Regex.Replace(Script, @"\((float|int)\)\s*([a-zA-Z0-9_.]+(\s*\([^\)]*\))?)", @"$1.Parse($2)",
275 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 281 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
276 282
283 // Replace "state STATENAME" with "state("statename")"
284 Script =
285 Regex.Replace(Script, @"(state)\s+([^;\n\r]+)(;[\r\n\s])", "$1(\"$2\")$3",
286 RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline | RegexOptions.IgnoreCase);
277 287
278 // REPLACE BACK QUOTES 288 // REPLACE BACK QUOTES
279 foreach (string key in quotes.Keys) 289 foreach (string key in quotes.Keys)
@@ -305,4 +315,4 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
305 return Return; 315 return Return;
306 } 316 }
307 } 317 }
308} 318} \ No newline at end of file