Patch from Mike: errors from the LSL/C# compilers are now reported to the user in-world

0.6.0-stable
Johan Berntsson 2008-07-10 05:40:45 +00:00
parent 38da8960e9
commit d41c1f40a8
3 changed files with 33 additions and 2 deletions

View File

@ -43,7 +43,7 @@ namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL
/// <param name="script">String containing LSL source.</param>
public CSCodeGenerator(string script)
{
Parser p = new LSLSyntax();
Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
// Obviously this needs to be in a try/except block.
LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
m_astRoot = codeTransformer.Transform();

View File

@ -43,7 +43,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
/// <param name="script">String containing LSL source.</param>
public CSCodeGenerator(string script)
{
Parser p = new LSLSyntax();
Parser p = new LSLSyntax(new yyLSLSyntax(), new ErrorHandler(true));
// Obviously this needs to be in a try/except block.
LSL2CSCodeTransformer codeTransformer = new LSL2CSCodeTransformer(p.Parse(script));
m_astRoot = codeTransformer.Transform();

View File

@ -26,6 +26,7 @@
*/
using System.Collections.Generic;
using System.Text.RegularExpressions;
using NUnit.Framework;
using OpenSim.Region.ScriptEngine.Shared.CodeTools;
@ -1299,5 +1300,35 @@ default
string output = cg.Generate();
Assert.AreEqual(expected, output);
}
[Test]
[ExpectedException("Tools.CSToolsException")]
public void TestSyntaxError()
{
string input = @"default
{
state_entry()
{
integer y
}
}
";
try
{
CSCodeGenerator cg = new CSCodeGenerator(input);
string output = cg.Generate();
}
catch (Tools.CSToolsException e)
{
// The syntax error is on line 6, char 5 (expected ';', found
// '}').
Regex r = new Regex("Line ([0-9]+), char ([0-9]+)");
Match m = r.Match(e.Message);
Assert.AreEqual("6", m.Groups[1].Value);
Assert.AreEqual("5", m.Groups[2].Value);
throw;
}
}
}
}