using System.Text.RegularExpressions; namespace Convention.RScript.Matcher { 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); } } return false; } } }