2025-10-16 15:20:53 +08:00
|
|
|
|
using Convention.RScript.Parser;
|
2025-12-11 18:03:28 +08:00
|
|
|
|
using System.Collections;
|
2025-10-16 15:20:53 +08:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Convention.RScript.Runner
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ExpressionRunner : IRSentenceRunner
|
|
|
|
|
|
{
|
2025-10-17 15:46:44 +08:00
|
|
|
|
public void Compile(ExpressionParser parser, RScriptSentence sentence, RScriptContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
parser.Compile(sentence.content);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-16 15:20:53 +08:00
|
|
|
|
[return: MaybeNull]
|
|
|
|
|
|
public object Run(ExpressionParser parser, RScriptSentence sentence, RScriptContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
return parser.Evaluate(sentence.content);
|
|
|
|
|
|
}
|
2025-12-11 18:03:28 +08:00
|
|
|
|
|
|
|
|
|
|
[return: MaybeNull]
|
|
|
|
|
|
public IEnumerator RunAsync(ExpressionParser parser, RScriptSentence sentence, RScriptContext context)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = parser.Evaluate(sentence.content);
|
|
|
|
|
|
if(result is IEnumerator ir)
|
|
|
|
|
|
yield return ir;
|
|
|
|
|
|
yield return null;
|
|
|
|
|
|
}
|
2025-10-16 15:20:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|