Skip to content

Commit b987a41

Browse files
committed
TreatWarningsAsErrors
1 parent 1f90e30 commit b987a41

File tree

12 files changed

+47
-52
lines changed

12 files changed

+47
-52
lines changed

src/SimpleStateMachine.StructuralSearch/Helper/EnumHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public static bool Contains<TEnum>(Type enumType, string value, bool exception =
4040
return Enum.GetNames<TEnum>();
4141
}
4242

43-
public static IEnumerable<string?> GetNamesExcept<TEnum>(params TEnum [] excludedElements)
43+
public static IEnumerable<string> GetNamesExcept<TEnum>(params TEnum [] excludedElements)
4444
where TEnum : struct, Enum
4545
{
46-
return GetValueExcept(excludedElements).Select(x=> x.Name());
46+
return GetValueExcept(excludedElements).Select(x=> x.Name()).OfType<string>();
4747
}
4848

4949
public static IEnumerable<TEnum> GetValues<TEnum>()

src/SimpleStateMachine.StructuralSearch/Parsers/DebugParser.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Pidgin;
2+
#pragma warning disable CS9074 // The 'scoped' modifier of parameter doesn't match overridden or implemented member.
23

34
namespace SimpleStateMachine.StructuralSearch
45
{
@@ -11,9 +12,6 @@ public DebugParser(Parser<TToken, T> parser)
1112
}
1213

1314
public override bool TryParse(ref ParseState<TToken> state, ref PooledList<Expected<TToken>> expected, out T result)
14-
{
15-
var res = _parser.TryParse(ref state, ref expected, out result);
16-
return res;
17-
}
15+
=> _parser.TryParse(ref state, ref expected, out result!);
1816
}
1917
}

src/SimpleStateMachine.StructuralSearch/Parsers/EmptyStringParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Pidgin;
2+
#pragma warning disable CS9074 // The 'scoped' modifier of parameter doesn't match overridden or implemented member.
23

34
namespace SimpleStateMachine.StructuralSearch
45
{
@@ -11,8 +12,7 @@ public EmptyStringParser(bool value)
1112
_value = value;
1213
}
1314

14-
public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expected,
15-
out string result)
15+
public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expected, out string result)
1616
{
1717
result = string.Empty;
1818
return _value;

src/SimpleStateMachine.StructuralSearch/Parsers/EnumParser.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Pidgin;
44
using SimpleStateMachine.StructuralSearch.Extensions;
55
using SimpleStateMachine.StructuralSearch.Helper;
6+
#pragma warning disable CS9074 // The 'scoped' modifier of parameter doesn't match overridden or implemented member.
67

78
namespace SimpleStateMachine.StructuralSearch
89
{
@@ -18,11 +19,8 @@ public EnumParser(bool ignoreCase, params TEnum [] excluded)
1819
.Select(Parser.Try))
1920
.AsEnum<TEnum>(ignoreCase);
2021
}
21-
22-
public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expected,
23-
out TEnum result)
24-
{
25-
return _parser.TryParse(ref state, ref expected, out result);
26-
}
22+
23+
public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expected, out TEnum result)
24+
=> _parser.TryParse(ref state, ref expected, out result);
2725
}
2826
}

src/SimpleStateMachine.StructuralSearch/Parsers/ParserWithLookahead.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22
using System.Collections.Generic;
33
using Pidgin;
44

5+
#pragma warning disable CS9074 // The 'scoped' modifier of parameter doesn't match overridden or implemented member.
6+
57
namespace SimpleStateMachine.StructuralSearch
68
{
79
public abstract class ParserWithLookahead<TToken, T> : Parser<TToken, T>
810
{
9-
protected Lazy<Parser<TToken, T>> parser;
10-
11-
public Func<IEnumerable<LookaheadResult<TToken, T>>> OnLookahead { get; set; }
11+
private Lazy<Parser<TToken, T>>? _lookaheadParser;
12+
protected Lazy<Parser<TToken, T>> LookaheadParser => _lookaheadParser ?? throw new ArgumentNullException(nameof(Lookahead));
13+
14+
public Func<IEnumerable<LookaheadResult<TToken, T>>>? OnLookahead { get; protected set; }
1215

13-
public abstract Parser<TToken, T> BuildParser(Func<Parser<TToken, T>?> next,
16+
protected abstract Parser<TToken, T> BuildParser(Func<Parser<TToken, T>?> next,
1417
Func<Parser<TToken, T>?> nextNext);
1518

1619
public void Lookahead(Func<Parser<TToken, T>?> next, Func<Parser<TToken, T>?> nextNext)
1720
{
18-
parser = new Lazy<Parser<TToken, T>>(() => BuildParser(next, nextNext));
21+
_lookaheadParser = new Lazy<Parser<TToken, T>>(() => BuildParser(next, nextNext));
1922
}
2023

21-
public override bool TryParse(ref ParseState<TToken> state, ref PooledList<Expected<TToken>> expected,
22-
out T result)
23-
{
24-
var res = parser.Value.TryParse(ref state, ref expected, out result);
25-
return res;
26-
}
24+
public override bool TryParse(ref ParseState<TToken> state, ref PooledList<Expected<TToken>> expected, out T result)
25+
=> LookaheadParser.Value.TryParse(ref state, ref expected, out result!);
2726
}
2827

2928
public class LookaheadResult<TToken, T>

src/SimpleStateMachine.StructuralSearch/Parsers/PlaceholderParser.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ namespace SimpleStateMachine.StructuralSearch
88
public class PlaceholderParser : ParserWithLookahead<char, string>, IContextDependent
99
{
1010
private readonly string _name;
11-
private IParsingContext _context;
11+
private IParsingContext? _context;
12+
private IParsingContext Context => _context ?? throw new ArgumentNullException(nameof(_context));
13+
1214
public PlaceholderParser(string name)
1315
{
1416
_name = name;
1517
}
1618

17-
public override Parser<char, string> BuildParser(Func<Parser<char, string>?> next,
19+
protected override Parser<char, string> BuildParser(Func<Parser<char, string>?> next,
1820
Func<Parser<char, string>?> nextNext)
1921
{
2022
var nextParser = next();
@@ -58,7 +60,7 @@ public override Parser<char, string> BuildParser(Func<Parser<char, string>?> nex
5860
Parser<char, string>? term = null;
5961

6062
var parenthesised = Parsers.BetweenOneOfChars(x => Parser.Char(x).AsString(),
61-
expr: Parser.Rec(() => term),
63+
expr: Parser.Rec(() => term!),
6264
Constant.AllParenthesised).JoinToString();
6365

6466
term = Parser.OneOf(parenthesised, token).Many().JoinToString();
@@ -73,24 +75,23 @@ public override Parser<char, string> BuildParser(Func<Parser<char, string>?> nex
7375
return parser;
7476
}
7577

76-
public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expected,
77-
out string result)
78+
public override bool TryParse(ref ParseState<char> state, ref PooledList<Expected<char>> expected, out string result)
7879
{
7980
bool res;
8081

8182
// No use look-ahead if placeholder is already defined
82-
if (_context.TryGetPlaceholder(_name, out var placeholder))
83+
if (Context.TryGetPlaceholder(_name, out var placeholder))
8384
{
84-
res = Parser.String(placeholder.Value).TryParse(ref state, ref expected, out result);
85+
res = Parser.String(placeholder.Value).TryParse(ref state, ref expected, out result!);
8586
}
8687
else
8788
{
88-
res = parser.Value.Match().TryParse(ref state, ref expected, out var match);
89+
res = LookaheadParser.Value.Match().TryParse(ref state, ref expected, out var match);
8990
result = match.Value;
9091
if (res)
9192
{
92-
_context.AddPlaceholder(new Placeholder(
93-
context: ref _context,
93+
Context.AddPlaceholder(new Placeholder(
94+
context: ref _context!,
9495
name: _name,
9596
match: match));
9697
}

src/SimpleStateMachine.StructuralSearch/ParsingContext.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,16 @@ public ParsingContext(IInput input)
1515
}
1616

1717
public bool TryGetPlaceholder(string name, out IPlaceholder value)
18-
{
19-
return _placeholders.TryGetValue(name, out value);
20-
}
18+
=> _placeholders.TryGetValue(name, out value!);
2119

2220
public void AddPlaceholder(IPlaceholder placeholder)
2321
{
2422
_placeholders[placeholder.Name] = placeholder;
2523
}
2624

27-
public IPlaceholder GetPlaceholder(string name)
28-
{
29-
return _placeholders[name];
30-
}
31-
25+
public IPlaceholder GetPlaceholder(string name)
26+
=> _placeholders[name];
27+
3228
public void Fill(IReadOnlyDictionary<string, IPlaceholder> placeholders)
3329
{
3430
ClearInternal();

src/SimpleStateMachine.StructuralSearch/SeriesParser.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Linq;
33
using Pidgin;
44

5+
#pragma warning disable CS9074 // The 'scoped' modifier of parameter doesn't match overridden or implemented member.
6+
57
namespace SimpleStateMachine.StructuralSearch
68
{
79
public class SeriesParser : Parser<char, IEnumerable<string>>, IContextDependent
@@ -55,7 +57,7 @@ void SkipLookedParsers(Parser<char, string> parser, ref ParseState<char> state)
5557
lookaheadParser is { OnLookahead: null })
5658
return;
5759

58-
var lookaheadResults = lookaheadParser.OnLookahead.Invoke();
60+
var lookaheadResults = lookaheadParser.OnLookahead.Invoke().ToArray();
5961

6062
foreach (var result in lookaheadResults)
6163
{

src/SimpleStateMachine.StructuralSearch/SimpleStateMachine.StructuralSearch.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFramework>net6.0</TargetFramework>
55
<LangVersion>10</LangVersion>
66
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
78
</PropertyGroup>
89

910
<ItemGroup>

src/SimpleStateMachine.StructuralSearch/StructuralSearch/FindTemplateParser.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using Pidgin;
34
using SimpleStateMachine.StructuralSearch.Extensions;
45

@@ -10,7 +11,7 @@ static FindTemplateParser()
1011
{
1112
Parenthesised = Parsers.BetweenOneOfChars(x => ParserToParser.CIChar(x)
1213
.Select(x => x.AsString()),
13-
Parser.Rec(() => Term),
14+
Parser.Rec(() => Term ?? throw new ArgumentNullException(nameof(Term))),
1415
Constant.AllParenthesised);
1516

1617
Term = Parser.OneOf(Parenthesised, Token)

0 commit comments

Comments
 (0)