Skip to content

Commit

Permalink
Simplified the Syntax Printer (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Mar 23, 2020
1 parent 17555f2 commit bacd442
Show file tree
Hide file tree
Showing 167 changed files with 2,579 additions and 87 deletions.
Expand Up @@ -137,7 +137,7 @@ public ValuesOfCorrectTypeVisitor(ISchema schema)
"The specified argument value " +
"does not match the argument type.\n" +
$"Argument: `{argument.Name.Value}`\n" +
$"Value: `{argument.Value}`",
$"Value: `{argument.Value.Value}`",
argument));
}
}
Expand Down
Expand Up @@ -47,7 +47,7 @@ protected override bool ParseLiteral(BooleanValueNode literal)

protected override BooleanValueNode ParseValue(bool value)
{
return value ? BooleanValueNode.TrueLiteral : BooleanValueNode.FalseLiteral;
return value ? BooleanValueNode.True : BooleanValueNode.False;
}
}
}
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -42,6 +43,10 @@ public IEnumerable<ISyntaxNode> GetNodes()
yield return Value;
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public ArgumentNode WithLocation(Location? location)
{
return new ArgumentNode(location, Name, Value);
Expand Down
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -145,23 +146,18 @@ public override int GetHashCode()
/// A <see cref="string"/> that represents the current
/// <see cref="BooleanValueNode"/>.
/// </returns>
public override string? ToString()
{
#if NETSTANDARD1_4
return Value.ToString();
#else
return Value.ToString(CultureInfo.InvariantCulture);
#endif
}
public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public BooleanValueNode WithLocation(Location? location) =>
new BooleanValueNode(location, Value);

public BooleanValueNode WithValue(bool value) =>
new BooleanValueNode(Location, value);

public static BooleanValueNode TrueLiteral { get; } = new BooleanValueNode(true);
public static BooleanValueNode True { get; } = new BooleanValueNode(true);

public static BooleanValueNode FalseLiteral { get; } = new BooleanValueNode(false);
public static BooleanValueNode False { get; } = new BooleanValueNode(false);
}
}
Expand Up @@ -9,5 +9,7 @@ public interface ISyntaxNode
Location? Location { get; }

IEnumerable<ISyntaxNode> GetNodes();

string ToString(bool indented);
}
}
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -61,6 +62,10 @@ public IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public DirectiveDefinitionNode WithLocation(Location? location)
{
return new DirectiveDefinitionNode
Expand Down
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -57,6 +58,10 @@ public IEnumerable<ISyntaxNode> GetNodes()

public IReadOnlyList<ArgumentNode> Arguments { get; }

public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public DirectiveNode WithLocation(Location? location)
{
return new DirectiveNode(location, Name, Arguments);
Expand Down
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -28,6 +29,10 @@ public DocumentNode(IReadOnlyList<IDefinitionNode> definitions)

public IEnumerable<ISyntaxNode> GetNodes() => Definitions;

public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public DocumentNode WithLocation(Location? location)
{
return new DocumentNode(location, Definitions);
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -41,6 +42,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public EnumTypeDefinitionNode WithLocation(Location? location)
{
return new EnumTypeDefinitionNode(
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -32,6 +33,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public EnumTypeExtensionNode WithLocation(Location? location)
{
return new EnumTypeExtensionNode(
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -34,6 +35,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public EnumValueDefinitionNode WithLocation(Location? location)
{
return new EnumValueDefinitionNode(
Expand Down
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -197,10 +198,9 @@ public override int GetHashCode()
/// A <see cref="string"/> that represents the current
/// <see cref="EnumValueNode"/>.
/// </returns>
public override string? ToString()
{
return Value;
}
public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public unsafe ReadOnlySpan<byte> AsSpan()
{
Expand Down
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -52,6 +53,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public FieldDefinitionNode WithLocation(Location? location)
{
return new FieldDefinitionNode(
Expand Down
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -55,6 +56,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public FieldNode WithLocation(Location? location)
{
return new FieldNode(location, Name, Alias,
Expand Down
@@ -1,6 +1,6 @@
namespace HotChocolate.Language
{
public enum FloatFormat : byte
public enum FloatFormat
{
FixedPoint = 0,
Exponential = 1
Expand Down
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -226,10 +227,9 @@ public override int GetHashCode()
/// A <see cref="string"/> that represents the current
/// <see cref="FloatValueNode"/>.
/// </returns>
public override string? ToString()
{
return Value;
}
public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public float ToSingle()
{
Expand Down
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -46,6 +47,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
yield return SelectionSet;
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public FragmentDefinitionNode WithLocation(Location? location)
{
return new FragmentDefinitionNode(
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand All @@ -25,6 +26,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public FragmentSpreadNode WithLocation(Location? location)
{
return new FragmentSpreadNode(location, Name, Directives);
Expand Down
Expand Up @@ -14,10 +14,7 @@

<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.3" />
</ItemGroup>

<ItemGroup>
<Folder Include="Visitors\" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="3.1.1" />
</ItemGroup>

</Project>
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -40,6 +41,10 @@ public IEnumerable<ISyntaxNode> GetNodes()
yield return SelectionSet;
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public InlineFragmentNode WithLocation(Location? location)
{
return new InlineFragmentNode(
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -42,6 +43,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public InputObjectTypeDefinitionNode WithLocation(Location? location)
{
return new InputObjectTypeDefinitionNode(
Expand Down
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -33,6 +34,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public InputObjectTypeExtensionNode WithLocation(Location? location)
{
return new InputObjectTypeExtensionNode(
Expand Down
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using HotChocolate.Language.Utilities;

namespace HotChocolate.Language
{
Expand Down Expand Up @@ -55,6 +56,10 @@ public override IEnumerable<ISyntaxNode> GetNodes()
}
}

public override string ToString() => SyntaxPrinter.Print(this, true);

public override string ToString(bool indented) => SyntaxPrinter.Print(this, indented);

public InputValueDefinitionNode WithLocation(Location? location)
{
return new InputValueDefinitionNode(
Expand Down

0 comments on commit bacd442

Please sign in to comment.