From f850030d10b7984117db9665095f53ce1828bf4f Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Sat, 11 Oct 2025 09:53:30 +0800 Subject: [PATCH] Save --- Convention/[RScript]/Matcher/BackMatcher.cs | 20 +++++++++++++++++ Convention/[RScript]/Matcher/BreakMatcher.cs | 20 +++++++++++++++++ .../Matcher/DefineVariableMatcher.cs | 20 +++++++++++++++++ Convention/[RScript]/Matcher/GotoMatcher.cs | 22 +++++++++++++++++++ Convention/[RScript]/Matcher/LabelMatcher.cs | 20 +++++++++++++++++ .../[RScript]/Matcher/NamespaceMater.cs | 20 +++++++++++++++++ 6 files changed, 122 insertions(+) create mode 100644 Convention/[RScript]/Matcher/BackMatcher.cs create mode 100644 Convention/[RScript]/Matcher/BreakMatcher.cs create mode 100644 Convention/[RScript]/Matcher/DefineVariableMatcher.cs create mode 100644 Convention/[RScript]/Matcher/GotoMatcher.cs create mode 100644 Convention/[RScript]/Matcher/LabelMatcher.cs create mode 100644 Convention/[RScript]/Matcher/NamespaceMater.cs diff --git a/Convention/[RScript]/Matcher/BackMatcher.cs b/Convention/[RScript]/Matcher/BackMatcher.cs new file mode 100644 index 0000000..ef40ec4 --- /dev/null +++ b/Convention/[RScript]/Matcher/BackMatcher.cs @@ -0,0 +1,20 @@ +using System.Text.RegularExpressions; + +namespace Convention.RScript.Matcher +{ + public class BackMatcher : IRSentenceMatcher + { + public bool Match(string expression, ref RScriptSentence sentence) + { + Regex LabelRegex = new(@"^back\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)$"); + var LabelMatch = LabelRegex.Match(expression); + if (LabelMatch.Success) + { + sentence.mode = RScriptSentence.Mode.Label; + sentence.content = LabelMatch.Groups[1].Value; + return true; + } + return false; + } + } +} diff --git a/Convention/[RScript]/Matcher/BreakMatcher.cs b/Convention/[RScript]/Matcher/BreakMatcher.cs new file mode 100644 index 0000000..3cbb9bf --- /dev/null +++ b/Convention/[RScript]/Matcher/BreakMatcher.cs @@ -0,0 +1,20 @@ +using System.Text.RegularExpressions; + +namespace Convention.RScript.Matcher +{ + public class BreakMatcher : IRSentenceMatcher + { + public bool Match(string expression, ref RScriptSentence sentence) + { + Regex LabelRegex = new(@"^break\(\s*(.+)\s*\)$"); + var LabelMatch = LabelRegex.Match(expression); + if (LabelMatch.Success) + { + sentence.mode = RScriptSentence.Mode.Label; + sentence.content = LabelMatch.Groups[1].Value; + return true; + } + return false; + } + } +} diff --git a/Convention/[RScript]/Matcher/DefineVariableMatcher.cs b/Convention/[RScript]/Matcher/DefineVariableMatcher.cs new file mode 100644 index 0000000..348e355 --- /dev/null +++ b/Convention/[RScript]/Matcher/DefineVariableMatcher.cs @@ -0,0 +1,20 @@ +using System.Text.RegularExpressions; + +namespace Convention.RScript.Matcher +{ + public class DefineVariableMatcher : IRSentenceMatcher + { + public bool Match(string expression, ref RScriptSentence sentence) + { + Regex DefineVariableRegex = new(@"^(string|int|double|float|bool|var)\s+([a-zA-Z_][a-zA-Z0-9_]*)$"); + var DefineVariableMatch = DefineVariableRegex.Match(expression); + if (DefineVariableMatch.Success) + { + sentence.mode = RScriptSentence.Mode.DefineVariable; + sentence.info = new() { DefineVariableMatch.Groups[1].Value, DefineVariableMatch.Groups[2].Value }; + return true; + } + return false; + } + } +} diff --git a/Convention/[RScript]/Matcher/GotoMatcher.cs b/Convention/[RScript]/Matcher/GotoMatcher.cs new file mode 100644 index 0000000..8e95bf7 --- /dev/null +++ b/Convention/[RScript]/Matcher/GotoMatcher.cs @@ -0,0 +1,22 @@ +using System.Text.RegularExpressions; + +namespace Convention.RScript.Matcher +{ + public class GotoMatcher : IRSentenceMatcher + { + public bool Match(string expression, ref RScriptSentence sentence) + { + + Regex GotoRegex = new(@"^goto\s*\(\s*(.+)\s*,\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)$"); + var GotoMatch = GotoRegex.Match(expression); + if (GotoMatch.Success) + { + sentence.mode = RScriptSentence.Mode.Goto; + sentence.content = GotoMatch.Groups[2].Value; + sentence.info = new() { GotoMatch.Groups[1].Value, GotoMatch.Groups[2].Value }; + return true; + } + return false; + } + } +} diff --git a/Convention/[RScript]/Matcher/LabelMatcher.cs b/Convention/[RScript]/Matcher/LabelMatcher.cs new file mode 100644 index 0000000..8216f13 --- /dev/null +++ b/Convention/[RScript]/Matcher/LabelMatcher.cs @@ -0,0 +1,20 @@ +using System.Text.RegularExpressions; + +namespace Convention.RScript.Matcher +{ + public class LabelMatcher : IRSentenceMatcher + { + public bool Match(string expression, ref RScriptSentence sentence) + { + Regex LabelRegex = new(@"^label\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)$"); + var LabelMatch = LabelRegex.Match(expression); + if (LabelMatch.Success) + { + sentence.mode = RScriptSentence.Mode.Label; + sentence.content = LabelMatch.Groups[1].Value; + return true; + } + return false; + } + } +} diff --git a/Convention/[RScript]/Matcher/NamespaceMater.cs b/Convention/[RScript]/Matcher/NamespaceMater.cs new file mode 100644 index 0000000..0059bed --- /dev/null +++ b/Convention/[RScript]/Matcher/NamespaceMater.cs @@ -0,0 +1,20 @@ +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; + } + return false; + } + } +}