Files
RScript/Matcher/NamespaceMater.cs

38 lines
1.2 KiB
C#
Raw Normal View History

using System.Text.RegularExpressions;
namespace Convention.RScript.Matcher
2025-10-13 19:39:36 +08:00
{
public class NamespaceMater : IRSentenceMatcher
{
public bool Match(string expression, ref RScriptSentence sentence)
{
if (expression == "{")
{
sentence.mode = RScriptSentence.Mode.EnterNamespace;
return true;
}
else if (expression == "}")
{
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);
}
}
2025-10-13 19:39:36 +08:00
return false;
}
}
}