Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 34 additions & 59 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,65 +10,40 @@ trim_trailing_whitespace = true
[*.{yml,props,targets,csproj}]
indent_size = 2

[*.cs]
# IDE0079: Remove unnecessary suppression
dotnet_remove_unnecessary_suppression_exclusions = category:ReSharper

# IDE0079: Remove unnecessary suppression
# dotnet_diagnostic.IDE0079.severity = none

# CA2255: The 'ModuleInitializer' attribute should not be used in libraries
dotnet_diagnostic.CA2255.severity = none

# CS8600: Converting null literal or possible null value to non-nullable type.
dotnet_diagnostic.CS8600.severity = error

# CS8601: Possible null reference assignment.
dotnet_diagnostic.CS8601.severity = error

# CS8602: Dereference of a possibly null reference.
dotnet_diagnostic.CS8602.severity = error

# CS8603: Possible null reference return.
dotnet_diagnostic.CS8603.severity = error

# CS8604: Possible null reference argument.
dotnet_diagnostic.CS8604.severity = error

# CS8610: Nullability of reference types in type of parameter doesn't match overridden member.
dotnet_diagnostic.CS8610.severity = error

# CS8613: Nullability of reference types in return type doesn't match implicitly implemented member.
dotnet_diagnostic.CS8613.severity = error

# CS8614: Nullability of reference types in type of parameter doesn't match implicitly implemented member.
dotnet_diagnostic.CS8614.severity = error

# CS8618: Non-nullable field is uninitialized. Consider declaring as nullable.
dotnet_diagnostic.CS8618.severity = error

# CS8619: Nullability of reference types in value doesn't match target type.
dotnet_diagnostic.CS8619.severity = error

# CS8620: Argument cannot be used for parameter due to differences in the nullability of reference types.
dotnet_diagnostic.CS8620.severity = error

# CS8625: Cannot convert null literal to non-nullable reference type.
dotnet_diagnostic.CS8625.severity = error

# CS8634: The type cannot be used as type parameter in the generic type or method. Nullability of type argument doesn't match 'class' constraint.
dotnet_diagnostic.CS8634.severity = error

# CS8643: Nullability of reference types in explicit interface specifier doesn't match interface implemented by the type.
dotnet_diagnostic.CS8643.severity = error

# CS8653: A default expression introduces a null value for a type parameter.
dotnet_diagnostic.CS8653.severity = error

# CS8714: The type cannot be used as type parameter in the generic type or method. Nullability of type argument doesn't match 'notnull' constraint.
dotnet_diagnostic.CS8714.severity = error

# IDE0059: Unnecessary assigment of a value
dotnet_diagnostic.IDE0059.severity = none

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = none
[tests/**.cs]
# CA1707: Identifiers should not contain underscores
# Tests follow the Method_Condition_ExpectedResult naming convention.
dotnet_diagnostic.CA1707.severity = none

# CA1304, CA1305, CA1311: culture-sensitive calls
# Tests cover all StringComparison values and change the current culture on purpose.
dotnet_diagnostic.CA1304.severity = none
dotnet_diagnostic.CA1305.severity = none
dotnet_diagnostic.CA1311.severity = none

# CA1861: Avoid constant arrays as arguments
# CA1866: Use char overload
# Test inputs are built per test case; the performance of test code is irrelevant.
dotnet_diagnostic.CA1861.severity = none
dotnet_diagnostic.CA1866.severity = none

[benchmarks/**.cs]
# CA1707: Identifiers should not contain underscores
# Underscores keep the generated BenchmarkDotNet report readable.
dotnet_diagnostic.CA1707.severity = none

# CA1822: Mark members as static
# BenchmarkDotNet discovers instance methods and properties.
dotnet_diagnostic.CA1822.severity = none

# CA2201: Do not raise reserved exception types
# Benchmark setup throws Exception to abort a run on an unexpected parser result.
dotnet_diagnostic.CA2201.severity = none

# CA1806: Do not ignore method results
# Benchmarks intentionally ignore TryParse results.
dotnet_diagnostic.CA1806.severity = none
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
dotnet-version: 10.0.x

- name: Checkout
uses: actions/checkout@v4
Expand Down
14 changes: 14 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,18 @@
<PropertyGroup>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
</PropertyGroup>

<PropertyGroup>
<NoWarn>$(NoWarn);CS0649</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisLevel>latest</AnalysisLevel>
<AnalysisMode>Recommended</AnalysisMode>
<AnalysisModeStyle>Default</AnalysisModeStyle>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion benchmarks/Parsers/PidginParsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static class JsonParser
Char('r').Select (_ => '\r'),
Char('t').Select (_ => '\t'),
Char('u').Then(HexDigit.Repeat(4)
.Select(h => (char)int.Parse(new string(h.ToArray()), NumberStyles.HexNumber)))
.Select(h => (char)int.Parse(new string(h.ToArray()), NumberStyles.HexNumber, CultureInfo.InvariantCulture)))
)
)
).ManyString().Between(Quote)
Expand Down
3 changes: 2 additions & 1 deletion samples/TinyC/TinyCParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

using Ramstack.Parsing;

Expand All @@ -21,7 +22,7 @@ private static Parser<Node> CreateParser()
var number =
Set("0-9")
.OneOrMore()
.Map(Node (m) => Node.Number(int.Parse(m)))
.Map(Node (m) => Node.Number(int.Parse(m, NumberStyles.Integer, CultureInfo.InvariantCulture)))
.As("number");

var variable =
Expand Down
2 changes: 2 additions & 0 deletions src/Ramstack.Parsing/NumberKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace Ramstack.Parsing;
/// <summary>
/// Specifies the types of numeric string representations.
/// </summary>
[SuppressMessage("Naming", "CA1720:Identifier contains type name",
Justification = "The members name the numeric kinds, not the corresponding .NET types.")]
public enum NumberKind
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Ramstack.Parsing/OptionalValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ namespace Ramstack.Parsing;
/// Represents an optional value of type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The underlying type of the optional value.</typeparam>
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields",
Justification = "For performance reasons, the field is read in place, while a property getter would copy large T values on every access.")]
public readonly struct OptionalValue<T>
{
/// <summary>
Expand Down
7 changes: 5 additions & 2 deletions src/Ramstack.Parsing/Parser.Optional.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ private sealed class OptionalParser<T>(Parser<T> parser) : Parser<OptionalValue<
/// <inheritdoc />
public override bool TryParse(ref ParseContext context, out OptionalValue<T> value)
{
value = default;

if (parser.TryParse(ref context, out var result))
{
Unsafe.SkipInit(out value);

// Write directly into the caller's slot: constructing OptionalValue<T> here
// would copy T into a temporary and then into `value`.
Unsafe.AsRef(in value.Value) = result;
Unsafe.AsRef(in value.HasValue) = true;
}
else
{
value = default;
context.Advance(0);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.Parsing/PositionBookmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public readonly struct PositionBookmark
/// <summary>
/// Gets the zero-based parsing position.
/// </summary>
public readonly int Position;
public int Position { get; }

/// <summary>
/// Initializes a new instance of the <see cref="PositionBookmark"/> structure.
Expand Down
5 changes: 0 additions & 5 deletions src/Ramstack.Parsing/Ramstack.Parsing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
<Deterministic>true</Deterministic>
</PropertyGroup>

<PropertyGroup>
<NoWarn>649;1591</NoWarn>
<WarningsAsErrors>CS8600;CS8601;CS8602;CS8603;CS8604;CS8610;CS8613;CS8614;CS8618;CS8619;CS8620;CS8625;CS8643;CS8653;CS8714</WarningsAsErrors>
</PropertyGroup>

<PropertyGroup>
<RepositoryUrl>https://github.com/rameel/ramstack.parsing</RepositoryUrl>
<Authors>Rameel</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.Parsing/Utilities/CharClassExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ _ when controls.Contains(c) => "\\" + c,
else
{
sb.Append("\\u");
sb.Append(((ushort)c).ToString("x4"));
sb.Append(((ushort)c).ToString("x4", provider: null));
}
}

Expand Down
Loading