This commit is contained in:
nub31
2025-06-01 00:40:25 +02:00
parent 795b69df1b
commit 3b06f19468
12 changed files with 192 additions and 39 deletions

View File

@@ -2,9 +2,9 @@ using System.Diagnostics.CodeAnalysis;
namespace Nub.Lang;
public readonly struct SourceSpan(SourceText content, SourceLocation start, SourceLocation end) : IEquatable<SourceSpan>
public readonly struct SourceSpan(SourceText text, SourceLocation start, SourceLocation end) : IEquatable<SourceSpan>
{
public SourceText Content { get; } = content;
public SourceText Text { get; } = text;
public SourceLocation Start { get; } = start;
public SourceLocation End { get; } = end;
@@ -21,7 +21,7 @@ public readonly struct SourceSpan(SourceText content, SourceLocation start, Sour
throw new ArgumentException("Cannot merge empty spans", nameof(spanEnumerable));
}
var files = spans.Select(s => s.Content).Distinct().ToArray();
var files = spans.Select(s => s.Text).Distinct().ToArray();
if (files.Length > 1)
{
throw new ArgumentException("Cannot merge spans from multiple files", nameof(spanEnumerable));
@@ -55,12 +55,12 @@ public readonly struct SourceSpan(SourceText content, SourceLocation start, Sour
public bool Equals(SourceSpan other)
{
return Content.Equals(other.Content) && Start.Equals(other.Start) && End.Equals(other.End);
return Text.Equals(other.Text) && Start.Equals(other.Start) && End.Equals(other.End);
}
public override int GetHashCode()
{
return HashCode.Combine(Content, Start, End);
return HashCode.Combine(Text, Start, End);
}
public static bool operator ==(SourceSpan left, SourceSpan right)
@@ -74,13 +74,14 @@ public readonly struct SourceSpan(SourceText content, SourceLocation start, Sour
}
}
public readonly struct SourceText(string text) : IEquatable<SourceText>
public readonly struct SourceText(string name, string content) : IEquatable<SourceText>
{
public string Text { get; } = text;
public string Name { get; } = name;
public string Content { get; } = content;
public bool Equals(SourceText other)
{
return Text == other.Text;
return Content == other.Content;
}
public override bool Equals([NotNullWhen(true)] object? obj)
@@ -90,7 +91,7 @@ public readonly struct SourceText(string text) : IEquatable<SourceText>
public override int GetHashCode()
{
return Text.GetHashCode();
return Content.GetHashCode();
}
public static bool operator ==(SourceText left, SourceText right)