From: Jean-Philippe Bruyère Date: Thu, 27 Feb 2025 01:30:41 +0000 (+0100) Subject: SyntaxException CharLocation X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=0464eee536fff8170614a375958bb59ed3d1d25f;p=jp%2Fcrowedit.git SyntaxException CharLocation --- diff --git a/CrowEditBase/src/Compiler/SyntaxAnalyser.cs b/CrowEditBase/src/Compiler/SyntaxAnalyser.cs index 3ebbd77..99bfe7c 100644 --- a/CrowEditBase/src/Compiler/SyntaxAnalyser.cs +++ b/CrowEditBase/src/Compiler/SyntaxAnalyser.cs @@ -112,7 +112,8 @@ namespace CrowEditBase return !EOF; } protected void addException(string message) { - currentNode.AddException(new SyntaxException(message, curTok, source)); + CharLocation loc = lines.GetLocation(curTok.Start); + currentNode.AddException(new SyntaxException(message, loc, curTok)); } diff --git a/CrowEditBase/src/Compiler/SyntaxException.cs b/CrowEditBase/src/Compiler/SyntaxException.cs index 6da5a1a..bb9ff5b 100644 --- a/CrowEditBase/src/Compiler/SyntaxException.cs +++ b/CrowEditBase/src/Compiler/SyntaxException.cs @@ -2,18 +2,18 @@ // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; +using Crow.Text; namespace CrowEditBase { public class SyntaxException : Exception { public readonly Token Token; - public readonly ReadOnlyMemory SourceText; - public SyntaxException(string message, Token token = default, ReadOnlyMemory textBuffer = default, Exception innerException = null) + public readonly CharLocation Location; + public SyntaxException(string message, CharLocation loc, Token token = default, Exception innerException = null) : base (message, innerException) { Token = token; - SourceText = textBuffer; + Location = loc; } - public string TokenString => SourceText.Span.Slice(Token.Start,Token.Length).ToString(); - public override string ToString() => $"{Message}: {TokenString}"; + public override string ToString() => $"({Location.Line},{Location.Column}):{Message}"; } } \ No newline at end of file