]> O.S.I.I.S - jp/crowedit.git/commitdiff
SyntaxException CharLocation
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 27 Feb 2025 01:30:41 +0000 (02:30 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Thu, 27 Feb 2025 01:30:41 +0000 (02:30 +0100)
CrowEditBase/src/Compiler/SyntaxAnalyser.cs
CrowEditBase/src/Compiler/SyntaxException.cs

index 3ebbd771bd85813dc0e85c1868018d9af84060d4..99bfe7cca3380e7929d3c36b865181cf55f4138f 100644 (file)
@@ -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));
                }
 
 
index 6da5a1aca8a38e786dad1f306a4fcfcecc954054..bb9ff5b88b00007c75fa7e81662d810504aea388 100644 (file)
@@ -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<char> SourceText;
-               public SyntaxException(string message, Token token = default, ReadOnlyMemory<char> 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