尝试新增命名空间的命名, 用于具有名称的块或是函数

This commit is contained in:
2025-10-15 16:50:10 +08:00
parent 4f358c9664
commit b8a87bae4c
4 changed files with 130 additions and 75 deletions

View File

@@ -1,4 +1,6 @@
namespace Convention.RScript.Matcher
using System.Text.RegularExpressions;
namespace Convention.RScript.Matcher
{
public class NamespaceMater : IRSentenceMatcher
{
@@ -14,6 +16,21 @@
sentence.mode = RScriptSentence.Mode.ExitNamespace;
return true;
}
else if (expression.StartsWith("namespace"))
{
sentence.mode = RScriptSentence.Mode.NamedSpace;
Regex regex = new(@"namespace\s*\(([a-zA-Z_][a-zA-Z0-9_]*)\)");
var match = regex.Match(expression);
if (match.Success)
{
sentence.content = match.Groups[1].Value;
return true;
}
else
{
throw new RScriptRuntimeException("Invalid namespace declaration", -1);
}
}
return false;
}
}