aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/CodeTools/YP2CSConverter.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/CodeTools/YP2CSConverter.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/YP2CSConverter.cs108
1 files changed, 108 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/YP2CSConverter.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/YP2CSConverter.cs
new file mode 100644
index 0000000..54b4861
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/YP2CSConverter.cs
@@ -0,0 +1,108 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28
29using System;
30using System.IO;
31using System.Collections.Generic;
32using System.Text;
33using System.Text.RegularExpressions;
34using OpenSim.Region.ScriptEngine.Shared.YieldProlog;
35
36namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
37{
38 public class YP2CSConverter
39 {
40 public YP2CSConverter()
41 {
42 }
43
44 public string Convert(string Script)
45 {
46 string CS_code = GenCode(Script);
47 return CS_code;
48 }
49
50 static string GenCode(string myCode)
51 {
52 Variable TermList = new Variable();
53 Variable FunctionCode = new Variable();
54
55 string CS_code = "";
56
57 int cs_pointer = myCode.IndexOf("\n//cs");
58 if (cs_pointer > 0)
59 {
60 CS_code = myCode.Substring(cs_pointer); // CS code comes after
61 myCode = myCode.Substring(0, cs_pointer);
62 }
63 myCode.Replace("//yp", "%YPCode");
64
65 StringWriter myCS_SW = new StringWriter();
66 StringReader myCode_SR = new StringReader(" yp_nop_header_nop. \n "+myCode + "\n");
67
68 YP.see(myCode_SR);
69 YP.tell(myCS_SW);
70
71 //Console.WriteLine("Mycode\n ===================================\n" + myCode+"\n");
72 foreach (bool l1 in Parser.parseInput(TermList))
73 {
74 foreach (bool l2 in YPCompiler.makeFunctionPseudoCode(TermList, FunctionCode))
75 {
76 ListPair VFC = new ListPair(FunctionCode, new Variable());
77 //Console.WriteLine("-------------------------")
78 //Console.WriteLine(FunctionCode.ToString())
79 //Console.WriteLine("-------------------------")
80 YPCompiler.convertFunctionCSharp(FunctionCode);
81 //YPCompiler.convertStringCodesCSharp(VFC);
82 }
83 }
84 YP.seen();
85 myCS_SW.Close();
86 YP.told();
87 StringBuilder bu = myCS_SW.GetStringBuilder();
88 string finalcode = "//YPEncoded\n" + bu.ToString();
89 // FIX script events (we're in the same script)
90 // 'YP.script_event(Atom.a(@"sayit"),' ==> 'sayit('
91 finalcode = Regex.Replace(finalcode,
92 @"YP.script_event\(Atom.a\(\@\""(.*?)""\)\,",
93 @"this.$1(",
94 RegexOptions.Compiled | RegexOptions.Singleline);
95 finalcode = Regex.Replace(finalcode,
96 @" static ",
97 @" ",
98 RegexOptions.Compiled | RegexOptions.Singleline);
99
100 finalcode = CS_code+"\n\r"+ finalcode;
101 finalcode = Regex.Replace(finalcode,
102 @"PrologCallback",
103 @"public IEnumerable<bool> ",
104 RegexOptions.Compiled | RegexOptions.Singleline);
105 return finalcode;
106 }
107 }
108}