From 6e13a4d1c2e9dce1c33d44ee98f75b195b617cf8 Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 3 Jul 2026 23:07:09 +0900 Subject: [PATCH] =?UTF-8?q?=E6=9B=B8=E3=81=8D=E6=8F=9B=E3=81=88=E3=81=9F?= =?UTF-8?q?=E8=A1=8C=E7=95=AA=E5=8F=B7=E3=82=92=E8=A8=98=E9=8C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scripting/Syntax/LuaRewriteContext.cs | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/LuaScript.Compat/Scripting/Syntax/LuaRewriteContext.cs b/LuaScript.Compat/Scripting/Syntax/LuaRewriteContext.cs index 97c09e3..7e7934c 100644 --- a/LuaScript.Compat/Scripting/Syntax/LuaRewriteContext.cs +++ b/LuaScript.Compat/Scripting/Syntax/LuaRewriteContext.cs @@ -7,6 +7,9 @@ namespace LuaScript.Compat.Syntax { private readonly List _input; private readonly List _output; + private List? _changedLines; + private int _line = 1; + private int _lastChangedLine; private int _temporaries; public LuaRewriteContext(List input) @@ -23,24 +26,31 @@ namespace LuaScript.Compat.Syntax public bool Changed { get; private set; } + public int[] ChangedLines => _changedLines is null ? [] : _changedLines.ToArray(); + public bool AtEnd => Index >= _input.Count; public LuaSyntaxToken Current => _input[Index]; public void Advance() => Index++; - public void Emit(LuaSyntaxToken token) => _output.Add(token); + public void Emit(LuaSyntaxToken token) + { + _output.Add(token); + if (token.Kind == LuaSyntaxTokenKind.Newline) + _line++; + } public void EmitRaw(string text) { _output.Add(new LuaSyntaxToken(LuaSyntaxTokenKind.Name, text)); - Changed = true; + MarkChanged(); } public void EmitOperator(string text) { _output.Add(new LuaSyntaxToken(LuaSyntaxTokenKind.Operator, text)); - Changed = true; + MarkChanged(); } public string NextTemporary() => "__lc" + _temporaries++; @@ -90,7 +100,16 @@ namespace LuaScript.Compat.Syntax _output.Add(new LuaSyntaxToken(LuaSyntaxTokenKind.Name, word)); if (Index < _input.Count && !_input[Index].IsTrivia) _output.Add(new LuaSyntaxToken(LuaSyntaxTokenKind.Whitespace, " ")); + MarkChanged(); + } + + private void MarkChanged() + { Changed = true; + if (_line == _lastChangedLine) + return; + (_changedLines ??= new List()).Add(_line); + _lastChangedLine = _line; } public bool TryReadTrailingLvalue(out int start, out string text)