Skip to content

Commit cd3483b

Browse files
committed
Refactor the grammar to disambiguate errors
1 parent b36604d commit cd3483b

File tree

2 files changed

+630
-197
lines changed

2 files changed

+630
-197
lines changed

GraphQLTree.cpp

Lines changed: 54 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -574,120 +574,63 @@ struct ast_control
574574
}
575575
};
576576

577-
template <> const std::string ast_control<bof>::error_message = "Expected beginning of file";
578-
template <> const std::string ast_control<opt<utf8::bom>>::error_message = "Expected optional UTF8 byte-order-mark";
579-
template <> const std::string ast_control<star<ignored>>::error_message = "Expected optional ignored characters";
580-
template <> const std::string ast_control<plus<ignored>>::error_message = "Expected ignored characters";
581-
template <> const std::string ast_control<until<ascii::eolf>>::error_message = "Expected Comment";
582-
template <> const std::string ast_control<eof>::error_message = "Expected end of file";
583-
template <> const std::string ast_control<list<definition, plus<ignored>>>::error_message = "Expected list of Definitions";
584-
template <> const std::string ast_control<selection_set>::error_message = "Expected SelectionSet";
585-
template <> const std::string ast_control<fragment_name>::error_message = "Expected FragmentName";
586-
template <> const std::string ast_control<type_condition>::error_message = "Expected TypeCondition";
587-
template <> const std::string ast_control<opt<seq<star<ignored>, directives>>>::error_message = "Expected optional Directives";
588-
template <> const std::string ast_control<one<'{'>>::error_message = "Expected {";
589-
template <> const std::string ast_control<list<root_operation_definition, plus<ignored>>>::error_message = "Expected RootOperationTypeDefinition";
590577
template <> const std::string ast_control<one<'}'>>::error_message = "Expected }";
591-
template <> const std::string ast_control<one<'@'>>::error_message = "Expected @";
592-
template <> const std::string ast_control<directive_name>::error_message = "Expected Directive Name";
593-
template <> const std::string ast_control<arguments_definition>::error_message = "Expected ArgumentsDefinition";
594-
template <> const std::string ast_control<on_keyword>::error_message = "Expected \"on\" keyword";
595-
template <> const std::string ast_control<directive_locations>::error_message = "Expected DirectiveLocations";
596-
template <> const std::string ast_control<schema_extension>::error_message = "Expected SchemaExtension";
597-
template <> const std::string ast_control<
598-
seq<opt<seq<plus<ignored>, operation_name>>, opt<seq<star<ignored>, variable_definitions>>, opt<seq<star<ignored>, directives>>, star<ignored>, selection_set>>::error_message = "Expected OperationDefinition";
599-
template <> const std::string ast_control<list<selection, plus<ignored>>>::error_message = "Expected Selections";
600-
template <> const std::string ast_control<scalar_name>::error_message = "Expected ScalarType Name";
601-
template <> const std::string ast_control<object_name>::error_message = "Expected ObjectType Name";
602-
template <> const std::string ast_control<
603-
sor<seq<opt<seq<plus<ignored>, implements_interfaces>>, opt<seq<star<ignored>, directives>>, seq<star<ignored>, fields_definition>>
604-
, seq<opt<seq<plus<ignored>, implements_interfaces>>, seq<star<ignored>, directives>>
605-
, opt<seq<plus<ignored>, implements_interfaces>>>>::error_message = "Expected ObjectTypeDefinition";
606-
template <> const std::string ast_control<interface_name>::error_message = "Expected InterfaceType Name";
607-
template <> const std::string ast_control<
608-
sor<seq<opt<seq<star<ignored>, directives>>, seq<star<ignored>, fields_definition>>
609-
, opt<seq<star<ignored>, directives>>>>::error_message = "Expected InterfaceTypeDefinition";
610-
template <> const std::string ast_control<
611-
sor<seq<opt<directives>, one<'{'>, star<ignored>, list<operation_type_definition, plus<ignored>>, star<ignored>, one<'}'>>
612-
, directives>>::error_message = "Expected SchemaExtension";
613-
template <> const std::string ast_control<union_name>::error_message = "Expected UnionType Name";
614-
template <> const std::string ast_control<
615-
sor<seq<opt<seq<star<ignored>, directives>>, seq<star<ignored>, union_member_types>>
616-
, opt<seq<star<ignored>, directives>>>>::error_message = "Expected UnionTypeDefinition";
617-
template <> const std::string ast_control<enum_name>::error_message = "Expected EnumType Name";
618-
template <> const std::string ast_control<
619-
sor<seq<opt<seq<star<ignored>, directives>>, seq<star<ignored>, enum_values_definition>>
620-
, opt<seq<star<ignored>, directives>>>>::error_message = "Expected EnumTypeDefinition";
621-
template <> const std::string ast_control<
622-
sor<seq<opt<seq<star<ignored>, directives>>, seq<star<ignored>, input_fields_definition>>
623-
, opt<seq<star<ignored>, directives>>>>::error_message = "Expected InputObjectTypeDefinition";
624-
template <> const std::string ast_control<directives>::error_message = "Expected list of Directives";
625-
template <> const std::string ast_control<
626-
sor<seq<opt<seq<plus<ignored>, implements_interfaces>>, opt<seq<star<ignored>, directives>>, star<ignored>, fields_definition>
627-
, seq<opt<seq<plus<ignored>, implements_interfaces>>, star<ignored>, directives>
628-
, seq<plus<ignored>, implements_interfaces>>>::error_message = "Expected ObjectTypeExtension";
629-
template <> const std::string ast_control<
630-
sor<seq<opt<seq<directives, star<ignored>>>, fields_definition>
631-
, directives>>::error_message = "Expected InterfaceTypeExtension";
632-
template <> const std::string ast_control<
633-
sor<seq<opt<seq<directives, star<ignored>>>, union_member_types>
634-
, directives>>::error_message = "Expected UnionTypeExtension";
635-
template <> const std::string ast_control<
636-
sor<seq<opt<seq<directives, star<ignored>>>, enum_values_definition>
637-
, directives>>::error_message = "Expected EnumTypeExtension";
638-
template <> const std::string ast_control<
639-
sor<seq<opt<seq<directives, star<ignored>>>, input_fields_definition>
640-
, directives>>::error_message = "Expected InputObjectTypeExtension";
641-
template <> const std::string ast_control<name>::error_message = "Expected Name";
642-
template <> const std::string ast_control<named_type>::error_message = "Expected NamedType";
643-
template <> const std::string ast_control<list<input_field_definition, plus<ignored>>>::error_message = "Expected InputValueDefinitions";
578+
template <> const std::string ast_control<one<']'>>::error_message = "Expected ]";
644579
template <> const std::string ast_control<one<')'>>::error_message = "Expected )";
645-
template <> const std::string ast_control<one<':'>>::error_message = "Expected :";
646-
template <> const std::string ast_control<
647-
sor<executable_directive_location
648-
, type_system_directive_location>>::error_message = "Expected DirectiveLocation";
649-
template <> const std::string ast_control<opt<seq<star<ignored>, arguments>>>::error_message = "Expected optional Arguments";
650-
template <> const std::string ast_control<block_quote_token>::error_message = "Expected \"\"\"";
651580
template <> const std::string ast_control<quote_token>::error_message = "Expected \"";
652-
template <> const std::string ast_control<
653-
sor<seq<opt<seq<star<ignored>, arguments>>, opt<seq<star<ignored>, directives>>, seq<star<ignored>, selection_set>>
654-
, seq<opt<seq<star<ignored>, arguments>>, seq<star<ignored>, directives>>
655-
, opt<seq<star<ignored>, arguments>>>>::error_message = "Expected Field";
656-
template <> const std::string ast_control<type_name>::error_message = "Expected Type";
657-
template <> const std::string ast_control<
658-
sor<seq<opt<seq<star<ignored>, default_value>>, seq<star<ignored>, directives>>
659-
, opt<seq<star<ignored>, default_value>>>>::error_message = "Expected InputValueDefinition";
660-
template <> const std::string ast_control<list<field_definition, plus<ignored>>>::error_message = "Expected FieldsDefinitions";
661-
template <> const std::string ast_control<opt<seq<star<ignored>, one<'&'>>>>::error_message = "Expected optional '&'";
662-
template <> const std::string ast_control<list<interface_type, seq<star<ignored>, one<'&'>, star<ignored>>>>::error_message = "Expected ImplementsInterfaces";
663-
template <> const std::string ast_control<opt<seq<star<ignored>, one<'|'>>>>::error_message = "Expected optional '|'";
664-
template <> const std::string ast_control<list<union_type, seq<star<ignored>, one<'|'>, star<ignored>>>>::error_message = "Expected UnionMemberTypes";
665-
template <> const std::string ast_control<list<enum_value_definition, plus<ignored>>>::error_message = "Expected EnumValuesDefinition";
666-
template <> const std::string ast_control<star<sor<block_escape_sequence, block_quote_character>>>::error_message = "Expected optional BlockStringCharacters";
667-
template <> const std::string ast_control<star<sor<string_escape_sequence, string_quote_character>>>::error_message = "Expected optional StringCharacters";
668-
template <> const std::string ast_control<sor<nonnull_type, list_type, named_type>>::error_message = "Expected Type";
669-
template <> const std::string ast_control<opt<seq<star<ignored>, default_value>>>::error_message = "Expected optional DefaultValue";
670-
template <> const std::string ast_control<list<variable, plus<ignored>>>::error_message = "Expected VariableDefinitions";
671-
template <> const std::string ast_control<opt<seq<star<ignored>, arguments_definition>>>::error_message = "Expected optional ArgumentsDefinition";
672-
template <> const std::string ast_control<list<argument, plus<ignored>>>::error_message = "Expected Arguments";
673-
template <> const std::string ast_control<one<']'>>::error_message = "Expected ]";
674-
template <> const std::string ast_control<sor<escaped_unicode, escaped_char>>::error_message = "Expected EscapeSequence";
675-
template <> const std::string ast_control<input_value>::error_message = "Expected Value";
676-
template <> const std::string ast_control<
677-
sor<list_value
678-
, object_value
679-
, variable_value
680-
, integer_value
681-
, float_value
682-
, string_value
683-
, bool_value
684-
, null_keyword
685-
, enum_value>>::error_message = "Expected Value";
686-
template <> const std::string ast_control<rep<4, xdigit>>::error_message = "Expected EscapedUnicode";
687-
template <> const std::string ast_control<opt<list<list_entry, plus<ignored>>>>::error_message = "Expected optional ListValues";
688-
template <> const std::string ast_control<opt<list<object_field, plus<ignored>>>>::error_message = "Expected optional ObjectValues";
689-
template <> const std::string ast_control<plus<digit>>::error_message = "Expected Digits";
690-
template <> const std::string ast_control<opt<sign>>::error_message = "Expected optional Sign";
581+
template <> const std::string ast_control<block_quote_token>::error_message = "Expected \"\"\"";
582+
583+
template <> const std::string ast_control<variable_name_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Variable";
584+
template <> const std::string ast_control<escaped_unicode_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#EscapedUnicode";
585+
template <> const std::string ast_control<string_escape_sequence_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#EscapedCharacter";
586+
template <> const std::string ast_control<string_quote_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#StringCharacter";
587+
template <> const std::string ast_control<block_quote_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#BlockStringCharacter";
588+
template <> const std::string ast_control<fractional_part_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#FractionalPart";
589+
template <> const std::string ast_control<exponent_part_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ExponentPart";
590+
template <> const std::string ast_control<argument_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Argument";
591+
template <> const std::string ast_control<arguments_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Arguments";
592+
template <> const std::string ast_control<list_value_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ListValue";
593+
template <> const std::string ast_control<object_field_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ObjectField";
594+
template <> const std::string ast_control<object_value_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ObjectValue";
595+
template <> const std::string ast_control<input_value_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Value";
596+
template <> const std::string ast_control<default_value_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#DefaultValue";
597+
template <> const std::string ast_control<list_type_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ListType";
598+
template <> const std::string ast_control<type_name_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Type";
599+
template <> const std::string ast_control<variable_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#VariableDefinition";
600+
template <> const std::string ast_control<variable_definitions_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#VariableDefinitions";
601+
template <> const std::string ast_control<directive_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Directive";
602+
template <> const std::string ast_control<field_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Field";
603+
template <> const std::string ast_control<type_condition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#TypeCondition";
604+
template <> const std::string ast_control<fragement_spread_or_inline_fragment_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#FragmentSpread or https://facebook.github.io/graphql/June2018/#InlineFragment";
605+
template <> const std::string ast_control<selection_set_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#SelectionSet";
606+
template <> const std::string ast_control<operation_definition_operation_type_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#OperationDefinition";
607+
template <> const std::string ast_control<fragment_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#FragmentDefinition";
608+
template <> const std::string ast_control<root_operation_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#RootOperationTypeDefinition";
609+
template <> const std::string ast_control<schema_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#SchemaDefinition";
610+
template <> const std::string ast_control<scalar_type_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ScalarTypeDefinition";
611+
template <> const std::string ast_control<arguments_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ArgumentsDefinition";
612+
template <> const std::string ast_control<field_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#FieldDefinition";
613+
template <> const std::string ast_control<fields_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#FieldsDefinition";
614+
template <> const std::string ast_control<implements_interfaces_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ImplementsInterfaces";
615+
template <> const std::string ast_control<object_type_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ObjectTypeDefinition";
616+
template <> const std::string ast_control<interface_type_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#InterfaceTypeDefinition";
617+
template <> const std::string ast_control<union_member_types_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#UnionMemberTypes";
618+
template <> const std::string ast_control<union_type_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#UnionTypeDefinition";
619+
template <> const std::string ast_control<enum_value_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#EnumValueDefinition";
620+
template <> const std::string ast_control<enum_values_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#EnumValuesDefinition";
621+
template <> const std::string ast_control<enum_type_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#EnumTypeDefinition";
622+
template <> const std::string ast_control<input_field_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#InputValueDefinition";
623+
template <> const std::string ast_control<input_fields_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#InputFieldsDefinition";
624+
template <> const std::string ast_control<input_object_type_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#InputObjectTypeDefinition";
625+
template <> const std::string ast_control<directive_definition_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#DirectiveDefinition";
626+
template <> const std::string ast_control<schema_extension_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#SchemaExtension";
627+
template <> const std::string ast_control<scalar_type_extension_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ScalarTypeExtension";
628+
template <> const std::string ast_control<object_type_extension_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#ObjectTypeExtension";
629+
template <> const std::string ast_control<interface_type_extension_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#InterfaceTypeExtension";
630+
template <> const std::string ast_control<union_type_extension_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#UnionTypeExtension";
631+
template <> const std::string ast_control<enum_type_extension_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#EnumTypeExtension";
632+
template <> const std::string ast_control<input_object_type_extension_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#InputObjectTypeExtension";
633+
template <> const std::string ast_control<document_content>::error_message = "Expected https://facebook.github.io/graphql/June2018/#Document";
691634

692635
std::unique_ptr<ast<std::string>> parseString(std::string&& input)
693636
{

0 commit comments

Comments
 (0)