aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs76
1 files changed, 22 insertions, 54 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
index f058566..d9042b5 100644
--- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
+++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSL/LSL2CSConverter.cs
@@ -18,11 +18,12 @@ namespace LSL2CS.Converter
18 DataTypes.Add("float", "float"); 18 DataTypes.Add("float", "float");
19 DataTypes.Add("string", "string"); 19 DataTypes.Add("string", "string");
20 DataTypes.Add("key", "string"); 20 DataTypes.Add("key", "string");
21 DataTypes.Add("vector", "vector"); 21 DataTypes.Add("vector", "Axiom.Math.Vector3");
22 DataTypes.Add("rotation", "rotation"); 22 DataTypes.Add("rotation", "Axiom.Math.Quaternion");
23 DataTypes.Add("list", "list"); 23 DataTypes.Add("list", "list");
24 DataTypes.Add("null", "null"); 24 DataTypes.Add("null", "null");
25 } 25 }
26
26 27
27 28
28 29
@@ -34,37 +35,14 @@ namespace LSL2CS.Converter
34 // Prepare script for processing 35 // Prepare script for processing
35 // 36 //
36 37
37 // Here we will remove those linebreaks that are allowed in so many languages. 38 // Clean up linebreaks
38 // One hard-ass regex should do the job.
39
40 // Then we will add some linebreaks.
41 Script = Regex.Replace(Script, @"\r\n", "\n"); 39 Script = Regex.Replace(Script, @"\r\n", "\n");
42 Script = Regex.Replace(Script, @"\n", "\r\n"); 40 Script = Regex.Replace(Script, @"\n", "\r\n");
43 //Script = Regex.Replace(Script, @"\n\s*{", @"{");
44 //Script = Regex.Replace(Script, @"[\r\n]", @"");
45
46 // Then we remove unwanted linebreaks
47
48
49 ////
50 //// Split up script to process line by line
51 ////
52 //int count = 0;
53 //string line;
54 //Regex r = new Regex("\r?\n", RegexOptions.Multiline | RegexOptions.Compiled);
55 //string[] lines = r.Split(Script);
56
57 //for (int i = 0; i < lines.Length; i++)
58 //{
59 // // Remove space in front and back
60 // line = lines[i].Trim();
61 // count++;
62 // Return += count + ". " + translate(line) + "\r\n";
63 //}
64 41
65 42
66 // QUOTE REPLACEMENT 43 // QUOTE REPLACEMENT
67 //char[] SA = Script.ToCharArray(); 44 // temporarily replace quotes so we can work our magic on the script without
45 // always considering if we are inside our outside ""'s
68 string _Script = ""; 46 string _Script = "";
69 string C; 47 string C;
70 bool in_quote = false; 48 bool in_quote = false;
@@ -129,8 +107,10 @@ namespace LSL2CS.Converter
129 107
130 108
131 109
132 110 //
133 // PROCESS STATES 111 // PROCESS STATES
112 // Remove state definitions and add state names to start of each event within state
113 //
134 int ilevel = 0; 114 int ilevel = 0;
135 int lastlevel = 0; 115 int lastlevel = 0;
136 string ret = ""; 116 string ret = "";
@@ -190,13 +170,6 @@ namespace LSL2CS.Converter
190 current_statename = ""; 170 current_statename = "";
191 } 171 }
192 172
193 // if we moved from level 0 to level 1 don't add last word + {
194 // if we moved from level 1 to level 0 don't add last }
195 // if level > 0 cache all data so we can run regex on it when going to level 0
196
197
198
199
200 break; 173 break;
201 } 174 }
202 lastlevel = ilevel; 175 lastlevel = ilevel;
@@ -209,17 +182,23 @@ namespace LSL2CS.Converter
209 182
210 183
211 184
212 // Replace CAST - (integer) with (int) 185 foreach (string key in DataTypes.Keys)
213 Script = Regex.Replace(Script, @"\(integer\)", @"(int)", RegexOptions.Compiled | RegexOptions.Multiline); 186 {
214 // Replace return types and function variables - integer a() and f(integer a, integer a) 187 string val;
215 Script = Regex.Replace(Script, @"(^|;|}|[\(,])(\s*int)eger(\s*)", @"$1$2$3", RegexOptions.Compiled | RegexOptions.Multiline); 188 DataTypes.TryGetValue(key, out val);
189
190 // Replace CAST - (integer) with (int)
191 Script = Regex.Replace(Script, @"\(" + key + @"\)", @"(" + val + ")", RegexOptions.Compiled | RegexOptions.Multiline);
192 // Replace return types and function variables - integer a() and f(integer a, integer a)
193 Script = Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)", @"$1$2" + val + "$3", RegexOptions.Compiled | RegexOptions.Multiline);
194 }
216 195
217 // Add "void" in front of functions that needs it 196 // Add "void" in front of functions that needs it
218 Script = Regex.Replace(Script, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 197 Script = Regex.Replace(Script, @"^(\s*)((?!if|switch|for)[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
219 198
220 // Replace <x,y,z> and <x,y,z,r> 199 // Replace <x,y,z> and <x,y,z,r>
221 Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"Rotation.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 200 Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new Axiom.Math.Quaternion($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
222 Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"Vector.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 201 Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"new Axiom.Math.Vector3($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
223 202
224 // Replace List []'s 203 // Replace List []'s
225 Script = Regex.Replace(Script, @"\[([^\]]*)\]", @"List.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline); 204 Script = Regex.Replace(Script, @"\[([^\]]*)\]", @"List.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
@@ -239,6 +218,7 @@ namespace LSL2CS.Converter
239 } 218 }
240 219
241 220
221 // Add namespace, class name and inheritance
242 Return = "namespace SecondLife {" + Environment.NewLine; 222 Return = "namespace SecondLife {" + Environment.NewLine;
243 Return += "public class Script : LSL_BaseClass {" + Environment.NewLine; 223 Return += "public class Script : LSL_BaseClass {" + Environment.NewLine;
244 Return += Script; 224 Return += Script;
@@ -246,18 +226,6 @@ namespace LSL2CS.Converter
246 226
247 return Return; 227 return Return;
248 } 228 }
249 //private string GetWord(char[] SA, int p)
250 //{
251 // string ret = "";
252 // for (int i = p; p < SA.Length; i++)
253 // {
254 // if (!rnw.IsMatch(SA[i].ToString()))
255 // break;
256 // ret += SA[i];
257 // }
258 // return ret;
259 //}
260
261 229
262 230
263 } 231 }