-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDebugExecutor.cs
More file actions
82 lines (76 loc) · 1.88 KB
/
Copy pathDebugExecutor.cs
File metadata and controls
82 lines (76 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.IO;
namespace AlbLib.Scripting
{
/// <summary>
/// Dummy implementation of <see cref="ScriptExecutionMachine"/> which writes parsed functions to an output.
/// </summary>
[Serializable]
public class DebugExecutor : ScriptExecutionMachine
{
/// <summary>
/// Output where to write debug information.
/// </summary>
public TextWriter Output{get;set;}
/// <summary>
/// Occurs when a comment is found.
/// </summary>
/// <param name="comment">
/// Found comment.
/// </param>
public override void OnComment(string comment)
{
Output.WriteLine("//"+comment);
}
/// <summary>
/// Occurs when a function is called.
/// </summary>
/// <param name="function">
/// Found function name.
/// </param>
/// <param name="args">
/// Found function arguments.
/// </param>
public override void OnFunction(string function, int[] args)
{
Output.WriteLine("{0}({1})", function, String.Join(", ", args));
}
/// <summary>
/// Initializes new instance using <see cref="Console.Out"/> as an output.
/// </summary>
public DebugExecutor() : this(Console.Out)
{}
/// <summary>
/// Initializes new instance using <paramref name="output"/> as an output.
/// </summary>
/// <param name="output">
/// Output where debug information will be written.
/// </param>
public DebugExecutor(TextWriter output)
{
Output = output;
}
/// <summary>
/// Executes a script.
/// </summary>
/// <param name="script">
/// Script text.
/// </param>
/// <returns>
/// True on success.
/// </returns>
/// <exception cref="ScriptExecutionException">
/// When any exception raises in script execution.
/// </exception>
public override bool Execute(string script)
{
ScriptExecutionException exception;
if(!Execute(script, out exception))
{
throw exception;
}else{
return true;
}
}
}
}