From d95794d05c8e98877189c9c6b306110a9fc2df59 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Tue, 23 Sep 2008 13:28:17 +0000 Subject: Refactor XEngine parser as per suggestions from mikem --- .../Shared/CodeTools/CSCodeGenerator.cs | 17 +++++---- .../Shared/CodeTools/LSL2CSCodeTransformer.cs | 2 +- .../Shared/CodeTools/Tests/CSCodeGeneratorTest.cs | 28 +++++++------- .../ScriptEngine/Shared/CodeTools/lsl.lexer.cs | 27 -------------- .../ScriptEngine/Shared/CodeTools/lsl.parser.cs | 43 ++++------------------ 5 files changed, 32 insertions(+), 85 deletions(-) (limited to 'OpenSim/Region') diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs index febc5e1..5a98f4d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs @@ -726,19 +726,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools if ("LSL_Types.LSLFloat" == c.Type) { int dotIndex = c.Value.IndexOf('.') + 1; - // Skip first dot (in type name) - dotIndex = c.Value.IndexOf('.', dotIndex) + 1; if (0 < dotIndex && (dotIndex == c.Value.Length || !Char.IsDigit(c.Value[dotIndex]))) c.Value = c.Value.Insert(dotIndex, "0"); + c.Value = "new LSL_Types.LSLFloat("+c.Value+")"; + } + else if("LSL_Types.LSLInteger" == c.Type) + { + c.Value = "new LSL_Types.LSLInteger("+c.Value+")"; + } + else if("LSL_Types.LSLString" == c.Type) + { + c.Value = "new LSL_Types.LSLString(\""+c.Value+"\")"; } - // commented because the parser does it now - // need to quote strings - // if ("LSL_Types.LSLString" == c.Type) - // retstr += Generate("\""); retstr += Generate(c.Value, c); - // if ("LSL_Types.LSLString" == c.Type) - // retstr += Generate("\""); return retstr; } diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs index d472ec8..a44b545 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/LSL2CSCodeTransformer.cs @@ -153,7 +153,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools return new Constant(p, constantType, "0.0"); case "string": case "key": - return new Constant(p, constantType, "\"\""); + return new Constant(p, constantType, ""); case "list": ArgumentList al = new ArgumentList(p); return new ListConstant(p, al); diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs index fefcada..4e2766c 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Tests/CSCodeGeneratorTest.cs @@ -124,7 +124,7 @@ state another_state string expected = "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + "\n {" + - "\n LSL_Types.LSLInteger x = 0;" + + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" + "\n }\n"; CSCodeGenerator cg = new CSCodeGenerator(); @@ -148,7 +148,7 @@ state another_state string expected = "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + "\n {" + - "\n LSL_Types.LSLString y = \"\";" + + "\n LSL_Types.LSLString y = new LSL_Types.LSLString(\"\");" + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14);" + "\n y = new LSL_Types.LSLString(\"Hello\");" + "\n }\n"; @@ -235,7 +235,7 @@ state another_state string expected = "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + "\n {" + - "\n LSL_Types.LSLInteger y = 0;" + + "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" + "\n y = new LSL_Types.LSLInteger(12) - new LSL_Types.LSLInteger(3);" + "\n y = new LSL_Types.LSLInteger(12) * new LSL_Types.LSLInteger(3);" + @@ -440,7 +440,7 @@ default } "; string expected = - "\n LSL_Types.LSLString globalString = \"\";" + + "\n LSL_Types.LSLString globalString = new LSL_Types.LSLString(\"\");" + "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" + "\n LSL_Types.LSLInteger anotherGlobal = new LSL_Types.LSLInteger(20) * globalInt;" + "\n LSL_Types.LSLString onefunc()" + @@ -495,7 +495,7 @@ default } "; string expected = - "\n LSL_Types.LSLString globalString = \"\";" + + "\n LSL_Types.LSLString globalString = new LSL_Types.LSLString(\"\");" + "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" + "\n LSL_Types.LSLString onefunc(LSL_Types.LSLString addition)" + "\n {" + @@ -1251,19 +1251,19 @@ default string expected = "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + "\n {" + - "\n LSL_Types.LSLInteger i = 0;" + + "\n LSL_Types.LSLInteger i = new LSL_Types.LSLInteger(0);" + "\n LSL_Types.LSLInteger j = new LSL_Types.LSLInteger(14);" + - "\n LSL_Types.LSLFloat f = 0.0;" + + "\n LSL_Types.LSLFloat f = new LSL_Types.LSLFloat(0.0);" + "\n LSL_Types.LSLFloat g = new LSL_Types.LSLFloat(14.0);" + - "\n LSL_Types.LSLString s = \"\";" + + "\n LSL_Types.LSLString s = new LSL_Types.LSLString(\"\");" + "\n LSL_Types.LSLString t = new LSL_Types.LSLString(\"Hi there\");" + "\n LSL_Types.list l = new LSL_Types.list();" + "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3));" + - "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(0.0, 0.0, 0.0);" + + "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" + "\n LSL_Types.Vector3 w = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.5));" + - "\n LSL_Types.Quaternion r = new LSL_Types.Quaternion(0.0, 0.0, 0.0, 0.0);" + + "\n LSL_Types.Quaternion r = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" + "\n LSL_Types.Quaternion u = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.8), new LSL_Types.LSLFloat(0.7), new LSL_Types.LSLFloat(0.6), llSomeFunc());" + - "\n LSL_Types.LSLString k = \"\";" + + "\n LSL_Types.LSLString k = new LSL_Types.LSLString(\"\");" + "\n LSL_Types.LSLString n = new LSL_Types.LSLString(\"ping\");" + "\n }\n"; @@ -1292,8 +1292,8 @@ default string expected = "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" + "\n {" + - "\n LSL_Types.LSLInteger x = 0;" + - "\n LSL_Types.LSLInteger y = 0;" + + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" + + "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" + "\n x = y = new LSL_Types.LSLInteger(5);" + "\n x += y -= new LSL_Types.LSLInteger(5);" + "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x) + new LSL_Types.LSLString(\", y is: \") + (LSL_Types.LSLString) (y));" + @@ -1504,7 +1504,7 @@ default string expected = "\n public void default_event_state_entry()" + "\n {" + - "\n LSL_Types.LSLInteger x = 0;" + + "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" + "\n while (x = new LSL_Types.LSLInteger(14))" + "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" + "\n if (x = new LSL_Types.LSLInteger(24))" + diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.lexer.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.lexer.cs index 2f244a6..0f810e5 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.lexer.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.lexer.cs @@ -1,30 +1,3 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - using System;using Tools; namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { //%+STRING_CONSTANT+3 diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs index 2f9a829..bfc1afc 100644 --- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs +++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/lsl.parser.cs @@ -1,30 +1,3 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSim Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - using System;using Tools; namespace OpenSim.Region.ScriptEngine.Shared.CodeTools { //%+LSLProgramRoot+95 @@ -1304,24 +1277,24 @@ public class ReturnStatement_2 : ReturnStatement { public ReturnStatement_2(Parser yyq):base(yyq){}} public class Constant_1 : Constant { - public Constant_1(Parser yyq):base(yyq,"integer", "new LSL_Types.LSLInteger("+ + public Constant_1(Parser yyq):base(yyq,"integer", ((INTEGER_CONSTANT)(yyq.StackAt(0).m_value)) - .yytext+")"){}} + .yytext){}} public class Constant_2 : Constant { - public Constant_2(Parser yyq):base(yyq,"integer", "new LSL_Types.LSLInteger("+ + public Constant_2(Parser yyq):base(yyq,"integer", ((HEX_INTEGER_CONSTANT)(yyq.StackAt(0).m_value)) - .yytext+")"){}} + .yytext){}} public class Constant_3 : Constant { - public Constant_3(Parser yyq):base(yyq,"float", "new LSL_Types.LSLFloat("+ + public Constant_3(Parser yyq):base(yyq,"float", ((FLOAT_CONSTANT)(yyq.StackAt(0).m_value)) - .yytext+")"){}} + .yytext){}} public class Constant_4 : Constant { - public Constant_4(Parser yyq):base(yyq,"string", "new LSL_Types.LSLString(\""+ + public Constant_4(Parser yyq):base(yyq,"string", ((STRING_CONSTANT)(yyq.StackAt(0).m_value)) - .yytext+"\")"){}} + .yytext){}} public class ListConstant_1 : ListConstant { public ListConstant_1(Parser yyq):base(yyq, -- cgit v1.1