修复NamedSpaceRunner的遗漏

This commit is contained in:
2025-10-16 17:23:37 +08:00
parent 15bdb6f8db
commit 97a6e4d76b
4 changed files with 84 additions and 24 deletions

View File

@@ -95,6 +95,18 @@ namespace Convention.RScript
new BackMatcher(),
};
public Dictionary<RScriptSentence.Mode, IRSentenceRunner> SentenceRunners = new()
{
{ RScriptSentence.Mode.DefineVariable, new DefineVariableRunner() },
{ RScriptSentence.Mode.EnterNamespace, new EnterNamespaceRunner() },
{ RScriptSentence.Mode.ExitNamespace, new ExitNamespaceRunner() },
{ RScriptSentence.Mode.Goto, new GoToRunner() },
{ RScriptSentence.Mode.Breakpoint, new BreakpointRunner() },
{ RScriptSentence.Mode.Backpoint, new BackpointRunner() },
{ RScriptSentence.Mode.Expression, new ExpressionRunner() },
{ RScriptSentence.Mode.NamedSpace, new EnterNamedSpaceRunner() },
};
private RScriptSentence ParseToSentence(string expression)
{
RScriptSentence result = new()
@@ -157,28 +169,25 @@ namespace Convention.RScript
}
}
public RScriptContext(string[] expressions, RScriptImportClass import = null, RScriptVariables variables = null)
public RScriptContext(string[] expressions,
RScriptImportClass import = null,
RScriptVariables variables = null,
List<IRSentenceMatcher> matcher = null,
Dictionary<RScriptSentence.Mode, IRSentenceRunner> sentenceRunners = null)
{
this.Import = import ?? new();
this.Variables = variables ?? new();
this.Sentences = (from item in expressions select ParseToSentence(item)).ToArray();
if (matcher != null)
this.SentenceParser = matcher;
if (sentenceRunners != null)
this.SentenceRunners = sentenceRunners;
BuildUpLabelsAndNamespace();
}
public RScriptSentence CurrentSentence => Sentences[CurrentRuntimePointer];
public Dictionary<RScriptSentence.Mode, IRSentenceRunner> SentenceRunners = new()
{
{ RScriptSentence.Mode.DefineVariable, new DefineVariableRunner() },
{ RScriptSentence.Mode.EnterNamespace, new EnterNamespaceRunner() },
{ RScriptSentence.Mode.ExitNamespace, new ExitNamespaceRunner() },
{ RScriptSentence.Mode.Goto, new GoToRunner() },
{ RScriptSentence.Mode.Breakpoint, new BreakpointRunner() },
{ RScriptSentence.Mode.Backpoint, new BackpointRunner() },
{ RScriptSentence.Mode.Expression, new ExpressionRunner() },
};
internal object RunNextStep(ExpressionParser parser)
{
@@ -187,7 +196,7 @@ namespace Convention.RScript
{
return SentenceRunners.TryGetValue(sentence.mode, out var runner) ? runner.Run(parser, sentence, this) : null;
}
catch (RScriptRuntimeException)
catch (RScriptException)
{
throw;
}