Skip to content

Commit

Permalink
Change Object Alternates to only allow Collections
Browse files Browse the repository at this point in the history
  • Loading branch information
Struan Judd committed Dec 31, 2023
1 parent cd288ed commit caedb59
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 50 deletions.
12 changes: 6 additions & 6 deletions src/GqlPlus.Verifier/Parse/Schema/ObjectParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ public abstract class ParseObjectDefinition<F, R> : Parser<ObjectDefinition<F, R
where F : AstField<R> where R : AstReference<R>
{
private readonly Parser<F>.L _field;
private readonly Parser<ModifierAst>.LA _modifiers;
private readonly ParserArray<IParserCollections, ModifierAst>.LA _collections;
private readonly Parser<R>.L _reference;

protected ParseObjectDefinition(
Parser<F>.D field,
Parser<ModifierAst>.DA modifiers,
ParserArray<IParserCollections, ModifierAst>.DA collections,
Parser<R>.D reference)
{
_field = field;
_modifiers = modifiers;
_collections = collections;
_reference = reference;
}

Expand Down Expand Up @@ -94,9 +94,9 @@ private IResultArray<AlternateAst<R>> ParseAlternates<TContext>(TContext tokens,

AlternateAst<R> alternate = new(reference.Required());
result.Add(alternate);
var modifiers = _modifiers.Value.Parse(tokens, Label);
if (!modifiers.Optional(value => alternate.Modifiers = value)) {
return modifiers.AsPartialArray(result);
var collections = _collections.Value.Parse(tokens, Label);
if (!collections.Optional(value => alternate.Modifiers = value)) {
return collections.AsPartialArray(result);
}
}

Expand Down
28 changes: 12 additions & 16 deletions src/GqlPlus.Verifier/Parse/Schema/ParseInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

namespace GqlPlus.Verifier.Parse.Schema;

internal class ParseInput : ObjectParser<InputDeclAst, InputFieldAst, InputReferenceAst>
internal class ParseInput(
TypeName name,
Parser<TypeParameterAst>.DA param,
Parser<string>.DA aliases,
Parser<NullAst>.D option,
Parser<ObjectDefinition<InputFieldAst, InputReferenceAst>>.D definition
) : ObjectParser<InputDeclAst, InputFieldAst, InputReferenceAst>(name, param, aliases, option, definition)
{
public ParseInput(
TypeName name,
Parser<TypeParameterAst>.DA param,
Parser<string>.DA aliases,
Parser<NullAst>.D option,
Parser<ObjectDefinition<InputFieldAst, InputReferenceAst>>.D definition
) : base(name, param, aliases, option, definition) { }

protected override void ApplyDefinition(InputDeclAst result, ObjectDefinition<InputFieldAst, InputReferenceAst> value)
{
result.Extends = value.Extends;
Expand All @@ -30,13 +28,11 @@ protected override InputDeclAst MakeResult(TokenAt at, string? name, string desc
=> new(at, name!, description);
}

internal class ParseInputDefinition : ParseObjectDefinition<InputFieldAst, InputReferenceAst>
internal class ParseInputDefinition(
Parser<InputFieldAst>.D field,
ParserArray<IParserCollections, ModifierAst>.DA collections,
Parser<InputReferenceAst>.D reference
) : ParseObjectDefinition<InputFieldAst, InputReferenceAst>(field, collections, reference)
{
public ParseInputDefinition(
Parser<InputFieldAst>.D field,
Parser<ModifierAst>.DA modifiers,
Parser<InputReferenceAst>.D reference
) : base(field, modifiers, reference) { }

protected override string Label => "Input";
}
4 changes: 2 additions & 2 deletions src/GqlPlus.Verifier/Parse/Schema/ParseOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ protected override OutputDeclAst MakeResult(TokenAt at, string? name, string des

internal class ParseOutputDefinition(
Parser<OutputFieldAst>.D field,
Parser<ModifierAst>.DA modifiers,
ParserArray<IParserCollections, ModifierAst>.DA collections,
Parser<OutputReferenceAst>.D reference
) : ParseObjectDefinition<OutputFieldAst, OutputReferenceAst>(field, modifiers, reference)
) : ParseObjectDefinition<OutputFieldAst, OutputReferenceAst>(field, collections, reference)
{
protected override string Label => "Output";
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public void WithAlternateComments(string name, AlternateComment[] others)

public void WithAlternateModifiers(string name, string[] others)
=> TrueExpected(
name + "{" + others.Joined(a => $"|{a}[]?") + "}",
name + "{" + others.Joined(a => $"|{a}[][String]") + "}",
Object(name) with {
Alternates = [.. others.Select(a => Alternate(a) with { Modifiers = TestMods() })],
Alternates = [.. others.Select(a => Alternate(a) with { Modifiers = TestCollections() })],
});

public void WithAlternateModifiersBad(string name, string[] others)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
output _Schema {
: _Named
categories(_CategoryFilter): _Categories[String]
directives(_Filter): _Directives[String]
types(_TypeFilter): _Type[String]
settings(_Filter): _Setting[String]
categories(_CategoryFilter?): _Categories[String]
directives(_Filter?): _Directives[String]
types(_TypeFilter?): _Type[String]
settings(_Filter?): _Setting[String]
}

input _Filter {
names: String[]
includeReferencedTypes: Boolean = false
| "Names" String[]?
| "Names" String[]
}

input _CategoryFilter {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
output _Schema {
: _Named
categories(_CategoryFilter): _Categories[String]
directives(_Filter): _Directives[String]
types(_TypeFilter): _Type[String]
settings(_Filter): _Setting[String]
categories(_CategoryFilter?): _Categories[String]
directives(_Filter?): _Directives[String]
types(_TypeFilter?): _Type[String]
settings(_Filter?): _Setting[String]
}

input _Filter {
names: String[]
includeReferencedTypes: Boolean = false
| "Names" String[]?
| "Names" String[]
}

input _CategoryFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Success
!P
I@20/3
_CategoryFilter
?
)
:
I@38/3
I@39/3
_Categories
[String]
!OF I@9/4
Expand All @@ -24,9 +25,10 @@ Success
!P
I@20/4
_Filter
?
)
:
I@30/4
I@31/4
_Directives
[String]
!OF I@9/5
Expand All @@ -35,9 +37,10 @@ Success
!P
I@15/5
_TypeFilter
?
)
:
I@29/5
I@30/5
_Type
[String]
!OF I@9/6
Expand All @@ -46,9 +49,10 @@ Success
!P
I@18/6
_Filter
?
)
:
I@28/6
I@29/6
_Setting
[String]
}
Expand All @@ -75,7 +79,6 @@ Success
I@15/12
String
[]
?
}
{
!I I@7/15
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ Success
!P
I@20/3
_CategoryFilter
?
)
:
I@38/3
I@39/3
_Categories
[String]
!OF I@9/4
Expand All @@ -24,9 +25,10 @@ Success
!P
I@20/4
_Filter
?
)
:
I@30/4
I@31/4
_Directives
[String]
!OF I@9/5
Expand All @@ -35,9 +37,10 @@ Success
!P
I@15/5
_TypeFilter
?
)
:
I@29/5
I@30/5
_Type
[String]
!OF I@9/6
Expand All @@ -46,9 +49,10 @@ Success
!P
I@18/6
_Filter
?
)
:
I@28/6
I@29/6
_Setting
[String]
}
Expand All @@ -75,7 +79,6 @@ Success
I@15/12
String
[]
?
}
{
!I I@7/15
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[
!!! I@22/17 : Invalid Input. '_Resolution' not defined. - '_Resolution' !!!,
!!! I@16/22 : Invalid Input. '_TypeKind' not defined. - '_TypeKind' !!!,
!!! I@38/3 : Invalid Output. '_Categories' not defined. - '_Categories' !!!,
!!! I@30/4 : Invalid Output. '_Directives' not defined. - '_Directives' !!!,
!!! I@29/5 : Invalid Output. '_Type' not defined. - '_Type' !!!,
!!! I@28/6 : Invalid Output. '_Setting' not defined. - '_Setting' !!!
!!! I@39/3 : Invalid Output. '_Categories' not defined. - '_Categories' !!!,
!!! I@31/4 : Invalid Output. '_Directives' not defined. - '_Directives' !!!,
!!! I@30/5 : Invalid Output. '_Type' not defined. - '_Type' !!!,
!!! I@29/6 : Invalid Output. '_Setting' not defined. - '_Setting' !!!
]
3 changes: 3 additions & 0 deletions test/GqlPlus.Verifier.TestBase/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ public static Tokenizer Tokens(string input)

public static ModifierAst[] TestMods()
=> new[] { ModifierAst.List(AstNulls.At), ModifierAst.Optional(AstNulls.At) };

public static ModifierAst[] TestCollections()
=> new[] { ModifierAst.List(AstNulls.At), new(AstNulls.At, "String", false) };
}

0 comments on commit caedb59

Please sign in to comment.