diff --git a/.cursor/rules/core.mdc b/.cursor/rules/core.mdc index 13d66fd..e337eb0 100644 --- a/.cursor/rules/core.mdc +++ b/.cursor/rules/core.mdc @@ -1,7 +1,5 @@ --- -description: -globs: -alwaysApply: true +alwaysApply: false --- ## RIPER-5 + O1 思维 + 代理执行协议 diff --git a/Convention/[RScript]/Matcher/BackMatcher.cs b/Convention/[RScript]/Matcher/BackMatcher.cs index ef40ec4..95e5793 100644 --- a/Convention/[RScript]/Matcher/BackMatcher.cs +++ b/Convention/[RScript]/Matcher/BackMatcher.cs @@ -6,11 +6,11 @@ namespace Convention.RScript.Matcher { public bool Match(string expression, ref RScriptSentence sentence) { - Regex LabelRegex = new(@"^back\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)$"); + Regex LabelRegex = new(@"back\s*\(\s*(.+)\s*\)"); var LabelMatch = LabelRegex.Match(expression); if (LabelMatch.Success) { - sentence.mode = RScriptSentence.Mode.Label; + sentence.mode = RScriptSentence.Mode.Backpoint; sentence.content = LabelMatch.Groups[1].Value; return true; } diff --git a/Convention/[RScript]/Matcher/BreakMatcher.cs b/Convention/[RScript]/Matcher/BreakMatcher.cs index 3cbb9bf..7549d24 100644 --- a/Convention/[RScript]/Matcher/BreakMatcher.cs +++ b/Convention/[RScript]/Matcher/BreakMatcher.cs @@ -6,11 +6,11 @@ namespace Convention.RScript.Matcher { public bool Match(string expression, ref RScriptSentence sentence) { - Regex LabelRegex = new(@"^break\(\s*(.+)\s*\)$"); + Regex LabelRegex = new(@"break\s*\(\s*(.+)\s*\)"); var LabelMatch = LabelRegex.Match(expression); if (LabelMatch.Success) { - sentence.mode = RScriptSentence.Mode.Label; + sentence.mode = RScriptSentence.Mode.Breakpoint; sentence.content = LabelMatch.Groups[1].Value; return true; } diff --git a/Convention/[RScript]/Matcher/DefineVariableMatcher.cs b/Convention/[RScript]/Matcher/DefineVariableMatcher.cs index 348e355..f3d9018 100644 --- a/Convention/[RScript]/Matcher/DefineVariableMatcher.cs +++ b/Convention/[RScript]/Matcher/DefineVariableMatcher.cs @@ -6,7 +6,7 @@ namespace Convention.RScript.Matcher { 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_]*)$"); + 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) { diff --git a/Convention/[RScript]/Matcher/GotoMatcher.cs b/Convention/[RScript]/Matcher/GotoMatcher.cs index 8e95bf7..93e2ffe 100644 --- a/Convention/[RScript]/Matcher/GotoMatcher.cs +++ b/Convention/[RScript]/Matcher/GotoMatcher.cs @@ -7,7 +7,7 @@ namespace Convention.RScript.Matcher public bool Match(string expression, ref RScriptSentence sentence) { - Regex GotoRegex = new(@"^goto\s*\(\s*(.+)\s*,\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)$"); + Regex GotoRegex = new(@"goto\s*\(\s*(.+)\s*,\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)"); var GotoMatch = GotoRegex.Match(expression); if (GotoMatch.Success) { diff --git a/Convention/[RScript]/Matcher/LabelMatcher.cs b/Convention/[RScript]/Matcher/LabelMatcher.cs index 8216f13..2b7d622 100644 --- a/Convention/[RScript]/Matcher/LabelMatcher.cs +++ b/Convention/[RScript]/Matcher/LabelMatcher.cs @@ -6,7 +6,7 @@ namespace Convention.RScript.Matcher { public bool Match(string expression, ref RScriptSentence sentence) { - Regex LabelRegex = new(@"^label\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)$"); + Regex LabelRegex = new(@"label\s*\(\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\)"); var LabelMatch = LabelRegex.Match(expression); if (LabelMatch.Success) { diff --git a/Convention/[RScript]/RScriptContext.cs b/Convention/[RScript]/RScriptContext.cs index bdfee9f..f122ffa 100644 --- a/Convention/[RScript]/RScriptContext.cs +++ b/Convention/[RScript]/RScriptContext.cs @@ -200,7 +200,7 @@ namespace Convention.RScript private void DoExitNamespace(ExpressionParser parser) { - // 移除在本命名空间中定义的变量 + // 移除当前命名空间的变量 foreach (var local in CurrentLocalSpaceVariableNames.Peek()) { Variables.Remove(local); @@ -216,6 +216,29 @@ namespace Convention.RScript RuntimePointerStack.Pop(); } + private void DoJumpRuntimePointer(ExpressionParser parser, int target) + { + bool isForwardMove = target > CurrentRuntimePointer; + int step = isForwardMove ? 1 : -1; + for (; CurrentRuntimePointer != target; CurrentRuntimePointer += step) + { + if (CurrentSentence.mode == RScriptSentence.Mode.ExitNamespace) + { + if (isForwardMove) + DoExitNamespace(parser); + else + DoEnterNamespace(parser); + } + else if (CurrentSentence.mode == RScriptSentence.Mode.EnterNamespace) + { + if (isForwardMove) + DoEnterNamespace(parser); + else + DoExitNamespace(parser); + } + } + } + private void DoGoto(ExpressionParser parser, RScriptSentence sentence) { // 检查并跳转到指定标签 @@ -224,7 +247,7 @@ namespace Convention.RScript if (Labels.TryGetValue(sentence.content, out var labelPointer)) { GotoPointerStack.Push(CurrentRuntimePointer); - CurrentRuntimePointer = labelPointer; + DoJumpRuntimePointer(parser, labelPointer); } else { @@ -256,7 +279,7 @@ namespace Convention.RScript private void DoBackpoint(ExpressionParser parser, RScriptSentence sentence) { - // 检查并跳转到上次跳转的位置的后一个位置 + // 检查并跳转到上次跳转的位置 if (parser.Evaluate(sentence.content)) { if (GotoPointerStack.Count == 0) @@ -265,7 +288,7 @@ namespace Convention.RScript } else { - CurrentRuntimePointer = GotoPointerStack.Pop() + 1; + DoJumpRuntimePointer(parser, GotoPointerStack.Pop()); } } } diff --git a/[Test]/Program.cs b/[Test]/Program.cs index 458687b..cb66667 100644 --- a/[Test]/Program.cs +++ b/[Test]/Program.cs @@ -14,8 +14,8 @@ public class Program var result = engine.Run(@" double i; i = 2.0; +label(test); { - label(test); goto(true,func1); goto(100>i,test); } @@ -24,11 +24,11 @@ result = i; goto(true,end); +label(func1); { - label(func1); i = Pow(i,2.0); - back(true); } +back(true); label(end); ", import);