diff --git a/Sources/Props/Shared.Build.props b/Sources/Props/Shared.Build.props
index 688f3f92..4a215711 100644
--- a/Sources/Props/Shared.Build.props
+++ b/Sources/Props/Shared.Build.props
@@ -4,6 +4,8 @@
latest
enable
+ true
+ $(NoWarn);NU5128
latest
diff --git a/Sources/Props/SourceGenerator.Build.props b/Sources/Props/SourceGenerator.Build.props
index 801eb272..2f266f89 100644
--- a/Sources/Props/SourceGenerator.Build.props
+++ b/Sources/Props/SourceGenerator.Build.props
@@ -1,6 +1,6 @@
-
+
netstandard2.0
diff --git a/Sources/SynKit/Libraries/C.Syntax/CToken.cs b/Sources/SynKit/Libraries/C.Syntax/CToken.cs
index 88f09b1f..765a92fa 100644
--- a/Sources/SynKit/Libraries/C.Syntax/CToken.cs
+++ b/Sources/SynKit/Libraries/C.Syntax/CToken.cs
@@ -85,7 +85,7 @@ public CToken(Text.Location range, string text, Text.Range logicalRange, string
public bool Equals(CToken? other) =>
other is not null
&& this.Range == other.Range
- && this.Location.File.Path == other.Location.File.Path
+ && this.Location.File?.Path == other.Location.File?.Path
&& this.Text == other.Text
&& this.Kind == other.Kind
&& this.LogicalRange == other.LogicalRange
diff --git a/Sources/SynKit/Libraries/Lexer/ICharStream.cs b/Sources/SynKit/Libraries/Lexer/ICharStream.cs
index ab42589a..f5f1a759 100644
--- a/Sources/SynKit/Libraries/Lexer/ICharStream.cs
+++ b/Sources/SynKit/Libraries/Lexer/ICharStream.cs
@@ -12,6 +12,9 @@ namespace Yoakke.SynKit.Lexer;
///
public interface ICharStream : IPeekableStream
{
+ ///
+ /// Gets the source file which provide content of this char stream
+ ///
public ISourceFile SourceFile { get; }
///
diff --git a/Sources/SynKit/Libraries/Lexer/Token.cs b/Sources/SynKit/Libraries/Lexer/Token.cs
index 82eb16bd..307833e2 100644
--- a/Sources/SynKit/Libraries/Lexer/Token.cs
+++ b/Sources/SynKit/Libraries/Lexer/Token.cs
@@ -20,6 +20,12 @@ public sealed record Token(Range Range, Location Location, string Text, T
///
public bool Equals(IToken? other) => this.Equals(other as Token);
+
+ ///
+ /// Indicates whether the current object is equal to another object of the same type.
+ ///
+ /// An object to compare with this object.
+ /// true if the current object is equal to the other parameter; otherwise, false.
public bool Equals(Token? other) =>
other is not null
&& this.Range == other.Range
diff --git a/Sources/SynKit/Libraries/Parser/ParseError.cs b/Sources/SynKit/Libraries/Parser/ParseError.cs
index 5dcd99e0..9c2f9e1c 100644
--- a/Sources/SynKit/Libraries/Parser/ParseError.cs
+++ b/Sources/SynKit/Libraries/Parser/ParseError.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
namespace Yoakke.SynKit.Parser;
@@ -12,7 +13,7 @@ namespace Yoakke.SynKit.Parser;
///
public class ParseError
{
- private ParseErrorElementDictionary elements;
+ private readonly ParseErrorElementDictionary elements;
///
/// The error cases in different parse contexts.
@@ -69,7 +70,7 @@ private ParseError(ParseErrorElementDictionary elements, object? got, IComparabl
// TODO: Think this through
// NOTE: Could it ever happen that first.Got and second.Got are different but neither are null?
// Would we want to unify these and move them to ParseErrorElement or something?
- // Since position is here now, Got is kind of a utility we have here, we could just aswell have a
+ // Since position is here now, Got is kind of a utility we have here, we could just as well have a
// 'reason' for each element
return new(
elements,
diff --git a/Sources/SynKit/Libraries/Parser/ParseErrorElementDictionary.cs b/Sources/SynKit/Libraries/Parser/ParseErrorElementDictionary.cs
index d98fd1ad..6acd8149 100644
--- a/Sources/SynKit/Libraries/Parser/ParseErrorElementDictionary.cs
+++ b/Sources/SynKit/Libraries/Parser/ParseErrorElementDictionary.cs
@@ -11,11 +11,11 @@ namespace Yoakke.SynKit.Parser;
internal class ParseErrorElementDictionary : IReadOnlyDictionary
{
- private string? firstKey;
- private ParseErrorElement? firstItem;
- private string? secondKey;
- private ParseErrorElement? secondItem;
- private Dictionary? elements;
+ private readonly string? firstKey;
+ private readonly ParseErrorElement? firstItem;
+ private readonly string? secondKey;
+ private readonly ParseErrorElement? secondItem;
+ private readonly Dictionary? elements;
private ParseErrorElementDictionary()
{
@@ -77,14 +77,14 @@ public bool ContainsKey(string key)
}
else
{
- return this.firstKey == key || (this.secondKey is null ? false : this.firstKey == key);
+ return this.firstKey == key || (this.secondKey is null ? false : this.secondKey == key);
}
}
public IEnumerator> GetEnumerator() =>
this.elements is null
- ? (secondKey is null)
- ? new Enumerator(this.firstKey!, this.firstItem!) : new TwoElementEnumerator(this.firstKey!, this.firstItem!, this.secondKey, this.secondItem)
+ ? (this.secondKey is null)
+ ? new Enumerator(this.firstKey!, this.firstItem!) : new TwoElementEnumerator(this.firstKey!, this.firstItem!, this.secondKey, this.secondItem!)
: this.elements.GetEnumerator();
public bool TryGetValue(string key, out ParseErrorElement value)
{
@@ -92,17 +92,17 @@ public bool TryGetValue(string key, out ParseErrorElement value)
{
if (this.firstKey == key)
{
- value = firstItem;
+ value = this.firstItem!;
return true;
}
if (this.secondKey == key)
{
- value = secondItem;
+ value = this.secondItem!;
return true;
}
- value = default;
+ value = default!;
return false;
}
@@ -165,22 +165,22 @@ public Enumerator(string key, ParseErrorElement value)
this._current = new KeyValuePair(key, value);
}
- public KeyValuePair Current
+ public readonly KeyValuePair Current
{
get
{
- if (!valid)
+ if (!this.valid)
{
throw new InvalidOperationException("The enumerator is not valid.");
}
- return _current;
+ return this._current;
}
}
- object IEnumerator.Current => this.Current;
+ readonly object IEnumerator.Current => this.Current;
- public void Dispose() {}
+ public readonly void Dispose() {}
public bool MoveNext()
{
if (!this.valid)
@@ -211,22 +211,22 @@ public TwoElementEnumerator(string firstKey, ParseErrorElement firstValue, strin
this._secondPair = new KeyValuePair(secondKey, secondValue);
}
- public KeyValuePair Current
+ public readonly KeyValuePair Current
{
get
{
- if (consumed > 2)
+ if (this.consumed > 2)
{
throw new InvalidOperationException("The enumerator is not valid.");
}
- return consumed == 1 ? _firstPair : _secondPair;
+ return this.consumed == 1 ? this._firstPair : this._secondPair;
}
}
object IEnumerator.Current => this.Current;
- public void Dispose() { }
+ public readonly void Dispose() { }
public bool MoveNext()
{
if (this.consumed >= 2)
diff --git a/Sources/SynKit/Libraries/Parser/ParseErrorExpectationSet.cs b/Sources/SynKit/Libraries/Parser/ParseErrorExpectationSet.cs
index 21ffa869..ef847192 100644
--- a/Sources/SynKit/Libraries/Parser/ParseErrorExpectationSet.cs
+++ b/Sources/SynKit/Libraries/Parser/ParseErrorExpectationSet.cs
@@ -125,12 +125,12 @@ public object Current
{
get
{
- if (!valid)
+ if (!this.valid)
{
throw new InvalidOperationException("The enumerator is not valid.");
}
- return _current ?? throw new InvalidOperationException("The enumerator is not valid.");
+ return this._current ?? throw new InvalidOperationException("The enumerator is not valid.");
}
}
diff --git a/Sources/SynKit/Libraries/Parser/ParseResult.Factory.cs b/Sources/SynKit/Libraries/Parser/ParseResult.Factory.cs
index 854e5591..c404150e 100644
--- a/Sources/SynKit/Libraries/Parser/ParseResult.Factory.cs
+++ b/Sources/SynKit/Libraries/Parser/ParseResult.Factory.cs
@@ -26,7 +26,7 @@ public static class ParseResult
///
/// The expected element.
/// The token encountered instead.
- /// The position where the error occured.
+ /// The position where the error occurred.
/// The rule context the error occurred in.
/// The created .
public static ParseError Error(object expected, object? got, IComparable position, string context) =>
diff --git a/Sources/SynKit/Libraries/Reporting/Present/TextDiagnosticsPresenter.cs b/Sources/SynKit/Libraries/Reporting/Present/TextDiagnosticsPresenter.cs
index de479c16..fec623c0 100644
--- a/Sources/SynKit/Libraries/Reporting/Present/TextDiagnosticsPresenter.cs
+++ b/Sources/SynKit/Libraries/Reporting/Present/TextDiagnosticsPresenter.cs
@@ -137,7 +137,7 @@ private void WriteSourceGroup(IEnumerable infos)
// Print the ┌─
this.buffer.ForegroundColor = this.Style.DefaultColor;
- this.buffer.Write($"{lineNumberPadding} ┌─ {sourceFile.Path}");
+ this.buffer.Write($"{lineNumberPadding} ┌─ {sourceFile?.Path ?? "(unknown)"}");
// If there is a primary info, write the line and column
if (primaryInfo != null) this.buffer.Write($":{primaryInfo.Location.Range.Start.Line + 1}:{primaryInfo.Location.Range.Start.Column + 1}");
this.buffer.WriteLine();
@@ -225,7 +225,7 @@ private void WriteSourceLine(SourceLine line)
private void WriteAnnotationLine(AnnotationLine line, string prefix)
{
var sourceFile = line.Annotations!.First().Location.File;
- var lineText = sourceFile.GetLine(line.AnnotatedLine).TrimEnd();
+ var lineText = sourceFile?.GetLine(line.AnnotatedLine).TrimEnd() ?? "(unknown)";
// Order annotations by starting position
var annotationsOrdered = line.Annotations!.OrderBy(si => si.Location.Range.Start).ToList();
@@ -316,7 +316,7 @@ private IEnumerable CollectLinePrimitives(IEnumerable si.Location.Range.Start.Line).ToList();
- var sourceFile = infos.First().Location.File;
+ var sourceFile = infos.First().Location.File!;
// Now we collect each line primitive
int? lastLineIndex = null;
diff --git a/Sources/SynKit/Tests/Parser.Tests/ParseErrorTests.cs b/Sources/SynKit/Tests/Parser.Tests/ParseErrorTests.cs
index 75993fde..dbe94cce 100644
--- a/Sources/SynKit/Tests/Parser.Tests/ParseErrorTests.cs
+++ b/Sources/SynKit/Tests/Parser.Tests/ParseErrorTests.cs
@@ -103,7 +103,7 @@ public void EnumerateTwoElements()
var secondError = new ParseError("^", null, 12, "other_expression");
var mergedError = firstError | secondError;
- var result = mergedError.Elements.ToList();
+ var result = mergedError!.Elements.ToList();
Assert.Equal("expression", result[0].Key);
Assert.Equal("expression", result[0].Value.Context);
@@ -121,7 +121,7 @@ public void EnumerateThreeElements()
var thirdError = new ParseError("^", null, 12, "third_expression");
var mergedError = firstError | secondError | thirdError;
- var result = mergedError.Elements.ToList();
+ var result = mergedError!.Elements.ToList();
Assert.Equal("expression", result[0].Key);
Assert.Equal("expression", result[0].Value.Context);