解离出Runner
This commit is contained in:
28
DoRunner/ExitNamespaceRunner.cs
Normal file
28
DoRunner/ExitNamespaceRunner.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Convention.RScript.Parser;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Convention.RScript.Runner
|
||||
{
|
||||
public class ExitNamespaceRunner : IRSentenceRunner
|
||||
{
|
||||
[return: MaybeNull]
|
||||
public object Run(ExpressionParser parser, RScriptSentence sentence, RScriptContext context)
|
||||
{
|
||||
// 移除当前命名空间的变量
|
||||
foreach (var local in context.CurrentLocalSpaceVariableNames.Peek())
|
||||
{
|
||||
context.Variables.Remove(local);
|
||||
parser.context.Variables.Remove(local);
|
||||
}
|
||||
// 还原上层命名空间的变量
|
||||
foreach (var local in context.CurrentLocalSpaceVariableNames.Peek())
|
||||
{
|
||||
parser.context.Variables[local] = context.Variables[local].data;
|
||||
}
|
||||
context.CurrentLocalSpaceVariableNames.Pop();
|
||||
// 弹栈
|
||||
context.RuntimePointerStack.Pop();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user