Skip to content

Commit

Permalink
Fixed parser issues (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Aug 30, 2018
1 parent b10d938 commit 69ec923
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,18 @@
},
{
"Kind": "ObjectTypeDefinition",
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "Foo"
},
"Description": {
"Kind": "StringValue",
"Location": null,
"Value": "This is a description\nof the `Foo` type.",
"Block": true
},
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "Foo"
},
"Directives": [],
"Interfaces": [
{
Expand Down Expand Up @@ -441,13 +441,13 @@
},
{
"Kind": "ObjectTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "AnnotatedObject"
},
"Description": null,
"Directives": [
{
"Kind": "Directive",
Expand Down Expand Up @@ -552,13 +552,13 @@
},
{
"Kind": "ObjectTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "UndefinedType"
},
"Description": null,
"Directives": [],
"Interfaces": [],
"Fields": []
Expand Down Expand Up @@ -648,13 +648,13 @@
},
{
"Kind": "InterfaceTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "Bar"
},
"Description": null,
"Directives": [],
"Fields": [
{
Expand Down Expand Up @@ -730,13 +730,13 @@
},
{
"Kind": "InterfaceTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "AnnotatedInterface"
},
"Description": null,
"Directives": [
{
"Kind": "Directive",
Expand Down Expand Up @@ -819,13 +819,13 @@
},
{
"Kind": "InterfaceTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "UndefinedInterface"
},
"Description": null,
"Directives": [],
"Fields": []
},
Expand Down Expand Up @@ -912,13 +912,13 @@
},
{
"Kind": "UnionTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "Feed"
},
"Description": null,
"Directives": [],
"Types": [
{
Expand Down Expand Up @@ -952,13 +952,13 @@
},
{
"Kind": "UnionTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "AnnotatedUnion"
},
"Description": null,
"Directives": [
{
"Kind": "Directive",
Expand Down Expand Up @@ -994,13 +994,13 @@
},
{
"Kind": "UnionTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "AnnotatedUnionTwo"
},
"Description": null,
"Directives": [
{
"Kind": "Directive",
Expand Down Expand Up @@ -1036,13 +1036,13 @@
},
{
"Kind": "UnionTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "UndefinedUnion"
},
"Description": null,
"Directives": [],
"Types": []
},
Expand Down Expand Up @@ -1100,24 +1100,24 @@
},
{
"Kind": "ScalarTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "CustomScalar"
},
"Description": null,
"Directives": []
},
{
"Kind": "ScalarTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "AnnotatedScalar"
},
"Description": null,
"Directives": [
{
"Kind": "Directive",
Expand Down Expand Up @@ -1154,13 +1154,13 @@
},
{
"Kind": "EnumTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "Site"
},
"Description": null,
"Directives": [],
"Values": [
{
Expand Down Expand Up @@ -1189,13 +1189,13 @@
},
{
"Kind": "EnumTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "AnnotatedEnum"
},
"Description": null,
"Directives": [
{
"Kind": "Directive",
Expand Down Expand Up @@ -1246,13 +1246,13 @@
},
{
"Kind": "EnumTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "UndefinedEnum"
},
"Description": null,
"Directives": [],
"Values": []
},
Expand Down Expand Up @@ -1303,13 +1303,13 @@
},
{
"Kind": "InputObjectTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "InputType"
},
"Description": null,
"Directives": [],
"Fields": [
{
Expand Down Expand Up @@ -1366,13 +1366,13 @@
},
{
"Kind": "InputObjectTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "AnnotatedInput"
},
"Description": null,
"Directives": [
{
"Kind": "Directive",
Expand Down Expand Up @@ -1422,13 +1422,13 @@
},
{
"Kind": "InputObjectTypeDefinition",
"Description": null,
"Location": null,
"Name": {
"Kind": "Name",
"Location": null,
"Value": "UndefinedInput"
},
"Description": null,
"Directives": [],
"Fields": []
},
Expand Down Expand Up @@ -1668,7 +1668,7 @@
"Arguments": []
}
],
"OperationTypes": null
"OperationTypes": []
},
{
"Kind": "SchemaExtension",
Expand Down
26 changes: 16 additions & 10 deletions src/Language/Parser/Parser.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,10 @@ private SchemaExtensionNode ParseSchemaExtension(ParserContext context)
List<DirectiveNode> directives =
ParseDirectives(context, true);

List<OperationTypeDefinitionNode> operationTypeDefinitions = null;
if (context.Current.IsLeftBrace())
{
operationTypeDefinitions =
ParseMany(context,
TokenKind.LeftBrace,
ParseOperationTypeDefinition,
TokenKind.RightBrace);
}
List<OperationTypeDefinitionNode> operationTypeDefinitions =
ParseOperationTypeDefinitions(context);

if (directives.Count == 0 && operationTypeDefinitions?.Count == 0)
if (directives.Count == 0 && operationTypeDefinitions.Count == 0)
{
throw context.Unexpected(start);
}
Expand All @@ -75,6 +68,19 @@ private SchemaExtensionNode ParseSchemaExtension(ParserContext context)
);
}

private List<OperationTypeDefinitionNode> ParseOperationTypeDefinitions(
ParserContext context)
{
if (context.Current.IsLeftBrace())
{
return ParseMany(context,
TokenKind.LeftBrace,
ParseOperationTypeDefinition,
TokenKind.RightBrace);
}
return new List<OperationTypeDefinitionNode>();
}

private ScalarTypeExtensionNode ParseScalarTypeExtension(
ParserContext context)
{
Expand Down

0 comments on commit 69ec923

Please sign in to comment.