diff --git a/dotnet/Gherkin/Ast/Background.cs b/dotnet/Gherkin/Ast/Background.cs index d481b9308c..b8ba890013 100644 --- a/dotnet/Gherkin/Ast/Background.cs +++ b/dotnet/Gherkin/Ast/Background.cs @@ -1,4 +1,4 @@ namespace Gherkin.Ast; -public class Background(Location location, string keyword, string name, string description, Step[] steps) +public class Background(Location location, string keyword, string name, string description, IEnumerable steps) : StepsContainer(location, keyword, name, description, steps); \ No newline at end of file diff --git a/dotnet/Gherkin/Ast/DataTable.cs b/dotnet/Gherkin/Ast/DataTable.cs index 3b96924169..ca2d4834ca 100644 --- a/dotnet/Gherkin/Ast/DataTable.cs +++ b/dotnet/Gherkin/Ast/DataTable.cs @@ -5,10 +5,10 @@ public class DataTable : StepArgument, IHasRows, IHasLocation public Location Location { get; private set; } public IEnumerable Rows { get; private set; } - public DataTable(TableRow[] rows) + public DataTable(List rows) { if (rows == null) throw new ArgumentNullException("rows"); - if (rows.Length == 0) throw new ArgumentException("DataTable must have at least one row", "rows"); + if (rows.Count == 0) throw new ArgumentException("DataTable must have at least one row", "rows"); Location = rows[0].Location; Rows = rows; diff --git a/dotnet/Gherkin/Ast/Examples.cs b/dotnet/Gherkin/Ast/Examples.cs index 8520886b0a..cd5f24c76b 100644 --- a/dotnet/Gherkin/Ast/Examples.cs +++ b/dotnet/Gherkin/Ast/Examples.cs @@ -1,6 +1,6 @@ namespace Gherkin.Ast; -public class Examples(Tag[] tags, Location location, string keyword, string name, string description, TableRow header, TableRow[] body) +public class Examples(IEnumerable tags, Location location, string keyword, string name, string description, TableRow header, IEnumerable body) : IHasLocation, IHasDescription, IHasRows, IHasTags { public IEnumerable Tags { get; } = tags; diff --git a/dotnet/Gherkin/Ast/Feature.cs b/dotnet/Gherkin/Ast/Feature.cs index 22676e2059..85bdfa6dc8 100644 --- a/dotnet/Gherkin/Ast/Feature.cs +++ b/dotnet/Gherkin/Ast/Feature.cs @@ -1,6 +1,6 @@ namespace Gherkin.Ast; -public class Feature(Tag[] tags, Location location, string language, string keyword, string name, string description, IHasLocation[] children) +public class Feature(IEnumerable tags, Location location, string language, string keyword, string name, string description, IEnumerable children) : IHasLocation, IHasDescription, IHasTags, IHasChildren { public IEnumerable Tags { get; } = tags; diff --git a/dotnet/Gherkin/Ast/GherkinDocument.cs b/dotnet/Gherkin/Ast/GherkinDocument.cs index 87c7e7b549..3ed039d1f2 100644 --- a/dotnet/Gherkin/Ast/GherkinDocument.cs +++ b/dotnet/Gherkin/Ast/GherkinDocument.cs @@ -1,6 +1,6 @@ namespace Gherkin.Ast; -public class GherkinDocument(Feature feature, Comment[] comments) +public class GherkinDocument(Feature feature, IEnumerable comments) { public Feature Feature { get; } = feature; public IEnumerable Comments { get; } = comments; diff --git a/dotnet/Gherkin/Ast/Rule.cs b/dotnet/Gherkin/Ast/Rule.cs index fc9905ef80..f89e4d50d9 100644 --- a/dotnet/Gherkin/Ast/Rule.cs +++ b/dotnet/Gherkin/Ast/Rule.cs @@ -1,6 +1,6 @@ namespace Gherkin.Ast; -public class Rule(Tag[] tags, Location location, string keyword, string name, string description, IHasLocation[] children) +public class Rule(IEnumerable tags, Location location, string keyword, string name, string description, IEnumerable children) : IHasLocation, IHasDescription, IHasChildren, IHasTags { public Location Location { get; } = location; diff --git a/dotnet/Gherkin/Ast/Scenario.cs b/dotnet/Gherkin/Ast/Scenario.cs index be0cfb19a7..b587101f83 100644 --- a/dotnet/Gherkin/Ast/Scenario.cs +++ b/dotnet/Gherkin/Ast/Scenario.cs @@ -1,6 +1,6 @@ namespace Gherkin.Ast; -public class Scenario(Tag[] tags, Location location, string keyword, string name, string description, Step[] steps, Examples[] examples) +public class Scenario(IEnumerable tags, Location location, string keyword, string name, string description, IEnumerable steps, IEnumerable examples) : StepsContainer(location, keyword, name, description, steps), IHasTags { public IEnumerable Tags { get; } = tags; diff --git a/dotnet/Gherkin/Ast/StepsContainer.cs b/dotnet/Gherkin/Ast/StepsContainer.cs index ec6985ddbb..e84e08bd2a 100644 --- a/dotnet/Gherkin/Ast/StepsContainer.cs +++ b/dotnet/Gherkin/Ast/StepsContainer.cs @@ -1,6 +1,6 @@ namespace Gherkin.Ast; -public abstract class StepsContainer(Location location, string keyword, string name, string description, Step[] steps) +public abstract class StepsContainer(Location location, string keyword, string name, string description, IEnumerable steps) : IHasLocation, IHasDescription, IHasSteps { public Location Location { get; } = location; diff --git a/dotnet/Gherkin/Ast/TableRow.cs b/dotnet/Gherkin/Ast/TableRow.cs index cdb7d55d94..315f0af3f9 100644 --- a/dotnet/Gherkin/Ast/TableRow.cs +++ b/dotnet/Gherkin/Ast/TableRow.cs @@ -1,6 +1,6 @@ namespace Gherkin.Ast; -public class TableRow(Location location, TableCell[] cells) : IHasLocation +public class TableRow(Location location, IEnumerable cells) : IHasLocation { public Location Location { get; } = location; public IEnumerable Cells { get; } = cells; diff --git a/dotnet/Gherkin/AstBuilder.cs b/dotnet/Gherkin/AstBuilder.cs index 12ca3927c6..f7ced49768 100644 --- a/dotnet/Gherkin/AstBuilder.cs +++ b/dotnet/Gherkin/AstBuilder.cs @@ -92,7 +92,7 @@ private object GetTransformedNode(AstNode node) var description = GetDescription(scenarioNode); var steps = GetSteps(scenarioNode); - var examples = scenarioNode.GetItems(RuleType.ExamplesDefinition).ToArray(); + List examples = [.. scenarioNode.GetItems(RuleType.ExamplesDefinition)]; return CreateScenario(tags, GetLocation(scenarioLine), scenarioLine.MatchedKeyword, scenarioLine.MatchedText, description, steps, examples, node); } case RuleType.ExamplesDefinition: @@ -102,9 +102,9 @@ private object GetTransformedNode(AstNode node) var examplesLine = examplesNode.GetToken(TokenType.ExamplesLine); var description = GetDescription(examplesNode); - var allRows = examplesNode.GetSingle(RuleType.ExamplesTable); - var header = allRows != null ? allRows.First() : null; - var rows = allRows != null ? allRows.Skip(1).ToArray() : null; + var allRows = examplesNode.GetSingle>(RuleType.ExamplesTable); + var header = allRows != null ? allRows[0] : null; + var rows = allRows != null ? allRows.Skip(1).ToList() : null; return CreateExamples(tags, GetLocation(examplesLine), examplesLine.MatchedKeyword, examplesLine.MatchedText, description, header, rows, node); } case RuleType.ExamplesTable: @@ -139,7 +139,7 @@ private object GetTransformedNode(AstNode node) if (featureLine.MatchedGherkinDialect == null) return null; var language = featureLine.MatchedGherkinDialect.Language; - return CreateFeature(tags, GetLocation(featureLine), language, featureLine.MatchedKeyword, featureLine.MatchedText, description, children.ToArray(), node); + return CreateFeature(tags, GetLocation(featureLine), language, featureLine.MatchedKeyword, featureLine.MatchedText, description, children, node); } case RuleType.Rule: { @@ -157,7 +157,7 @@ private object GetTransformedNode(AstNode node) var description = GetDescription(header); if (ruleLine.MatchedGherkinDialect == null) return null; - return CreateRule(tags, GetLocation(ruleLine), ruleLine.MatchedKeyword, ruleLine.MatchedText, description, children.ToArray(), node); + return CreateRule(tags, GetLocation(ruleLine), ruleLine.MatchedKeyword, ruleLine.MatchedText, description, children, node); } case RuleType.GherkinDocument: { @@ -178,12 +178,12 @@ protected virtual StepKeywordType GetKeywordType(Token stepLine) return stepKeywordType.Value; } - protected virtual Background CreateBackground(Location location, string keyword, string name, string description, Step[] steps, AstNode node) + protected virtual Background CreateBackground(Location location, string keyword, string name, string description, IEnumerable steps, AstNode node) { return new Background(location, keyword, name, description, steps); } - protected virtual DataTable CreateDataTable(TableRow[] rows, AstNode node) + protected virtual DataTable CreateDataTable(List rows, AstNode node) { return new DataTable(rows); } @@ -193,12 +193,12 @@ protected virtual Comment CreateComment(Location location, string text) return new Comment(location, text); } - protected virtual Examples CreateExamples(Tag[] tags, Location location, string keyword, string name, string description, TableRow header, TableRow[] body, AstNode node) + protected virtual Examples CreateExamples(IEnumerable tags, Location location, string keyword, string name, string description, TableRow header, IEnumerable body, AstNode node) { return new Examples(tags, location, keyword, name, description, header, body); } - protected virtual Scenario CreateScenario(Tag[] tags, Location location, string keyword, string name, string description, Step[] steps, Examples[] examples, AstNode node) + protected virtual Scenario CreateScenario(IEnumerable tags, Location location, string keyword, string name, string description, IEnumerable steps, IEnumerable examples, AstNode node) { return new Scenario(tags, location, keyword, name, description, steps, examples); } @@ -213,17 +213,17 @@ protected virtual Step CreateStep(Location location, string keyword, StepKeyword return new Step(location, keyword, keywordType, text, argument); } - protected virtual GherkinDocument CreateGherkinDocument(Feature feature, Comment[] gherkinDocumentComments, AstNode node) + protected virtual GherkinDocument CreateGherkinDocument(Feature feature, IEnumerable gherkinDocumentComments, AstNode node) { return new GherkinDocument(feature, gherkinDocumentComments); } - protected virtual Feature CreateFeature(Tag[] tags, Location location, string language, string keyword, string name, string description, IHasLocation[] children, AstNode node) + protected virtual Feature CreateFeature(IEnumerable tags, Location location, string language, string keyword, string name, string description, IEnumerable children, AstNode node) { return new Feature(tags, location, language, keyword, name, description, children); } - protected virtual Rule CreateRule(Tag[] tags, Location location, string keyword, string name, string description, IHasLocation[] children, AstNode node) + protected virtual Rule CreateRule(IEnumerable tags, Location location, string keyword, string name, string description, IEnumerable children, AstNode node) { return new Rule(tags, location, keyword, name, description, children); } @@ -238,7 +238,7 @@ protected Location CreateLocation(int line, int column) return new Location(line, column); } - protected virtual TableRow CreateTableRow(Location location, TableCell[] cells, AstNode node) + protected virtual TableRow CreateTableRow(Location location, IEnumerable cells, AstNode node) { return new TableRow(location, cells); } @@ -253,7 +253,7 @@ private Location GetLocation(Token token, int column = 0) return column == 0 ? token.Location : CreateLocation(token.Location.Line, column); } - private Tag[] GetTags(AstNode node) + private IEnumerable GetTags(AstNode node) { var tagsNode = node.GetSingle(RuleType.Tags); if (tagsNode == null) @@ -265,10 +265,10 @@ private Tag[] GetTags(AstNode node) foreach (var matchedItem in line.MatchedItems) tags.Add(CreateTag(GetLocation(line, matchedItem.Column), matchedItem.Text, tagsNode)); } - return tags.ToArray(); + return tags; } - private TableRow[] GetTableRows(AstNode node) + private List GetTableRows(AstNode node) { var rows = new List(); int cellCount = 0; @@ -290,7 +290,7 @@ private TableRow[] GetTableRows(AstNode node) } rows.Add(CreateTableRow(rowLocation, cells, node)); } - return rows.ToArray(); + return rows; } protected virtual void HandleAstError(string message, Location location) @@ -298,9 +298,9 @@ protected virtual void HandleAstError(string message, Location location) throw new AstBuilderException(message, location); } - private static Step[] GetSteps(AstNode scenarioDefinitionNode) + private static List GetSteps(AstNode scenarioDefinitionNode) { - return scenarioDefinitionNode.GetItems(RuleType.Step).ToArray(); + return [..scenarioDefinitionNode.GetItems(RuleType.Step)]; } private static string GetDescription(AstNode scenarioDefinitionNode) diff --git a/dotnet/Gherkin/Token.cs b/dotnet/Gherkin/Token.cs index 9aa2416e7e..71d861aa72 100644 --- a/dotnet/Gherkin/Token.cs +++ b/dotnet/Gherkin/Token.cs @@ -20,7 +20,7 @@ public Token(Location location) public TokenType MatchedType { get; set; } public string MatchedKeyword { get; set; } public string MatchedText { get; set; } - public GherkinLineSpan[] MatchedItems { get; set; } + public IEnumerable MatchedItems { get; set; } public int MatchedIndent { get; set; } public GherkinDialect MatchedGherkinDialect { get; set; } public Location Location { get; set; } diff --git a/dotnet/Gherkin/TokenMatcher.cs b/dotnet/Gherkin/TokenMatcher.cs index d6fbdb6bda..e653cf5888 100644 --- a/dotnet/Gherkin/TokenMatcher.cs +++ b/dotnet/Gherkin/TokenMatcher.cs @@ -32,7 +32,7 @@ public void Reset() currentDialect = dialectProvider.DefaultDialect; } - protected virtual void SetTokenMatched(Token token, TokenType matchedType, string text = null, string keyword = null, int? indent = null, GherkinLineSpan[] items = null) + protected virtual void SetTokenMatched(Token token, TokenType matchedType, string text = null, string keyword = null, int? indent = null, IEnumerable items = null) { token.MatchedType = matchedType; token.MatchedKeyword = keyword; @@ -113,7 +113,7 @@ public bool Match_TagLine(Token token) { if (token.Line.StartsWith(GherkinLanguageConstants.TAG_PREFIX)) { - SetTokenMatched(token, TokenType.TagLine, items: token.Line.GetTags().ToArray()); + SetTokenMatched(token, TokenType.TagLine, items: token.Line.GetTags()); return true; } return false; @@ -212,7 +212,7 @@ public bool Match_TableRow(Token token) { if (token.Line.StartsWith(GherkinLanguageConstants.TABLE_CELL_SEPARATOR)) { - SetTokenMatched(token, TokenType.TableRow, items: token.Line.GetTableCells().ToArray()); + SetTokenMatched(token, TokenType.TableRow, items: token.Line.GetTableCells()); return true; } return false;