mirror of
https://github.com/biomejs/biome.git
synced 2025-12-23 08:21:13 +00:00
578 lines
15 KiB
Text
578 lines
15 KiB
Text
// GraphQL Un-Grammar.
|
|
//
|
|
// This grammar specifies the structure of Rust's concrete syntax tree.
|
|
// It does not specify parsing rules (ambiguities, precedence, etc are out of scope).
|
|
// Tokens are processed -- contextual keywords are recognised, compound operators glued.
|
|
//
|
|
// Legend:
|
|
//
|
|
// // -- comment
|
|
// Name = -- non-terminal definition
|
|
// 'ident' -- token (terminal)
|
|
// A B -- sequence
|
|
// A | B -- alternation
|
|
// A* -- zero or more repetition
|
|
// (A (',' A)* ','?) -- repetition of node A separated by ',' and allowing a trailing comma
|
|
// (A (',' A)*) -- repetition of node A separated by ',' without a trailing comma
|
|
// A? -- zero or one repetition
|
|
// (A) -- same as A
|
|
// label:A -- suggested name for field of AST node
|
|
|
|
// NOTES
|
|
//
|
|
// - SyntaxNode, SyntaxToken and SyntaxElement will be stripped from the codegen
|
|
// - Bogus nodes are special nodes used to keep track of broken code; they are
|
|
// not part of the grammar but they will appear inside the green tree
|
|
//
|
|
|
|
|
|
///////////////
|
|
// BOGUS NODES
|
|
///////////////
|
|
// SyntaxElement is a generic data structure that is meant to track nodes and tokens
|
|
// in cases where we care about both types
|
|
//
|
|
// As Bogus* node will need to yield both tokens and nodes without discrimination,
|
|
// and their children will need to yield nodes and tokens as well.
|
|
// For this reason, SyntaxElement = SyntaxElement
|
|
SyntaxElement = SyntaxElement
|
|
|
|
GraphqlBogus = SyntaxElement*
|
|
GraphqlBogusDefinition = SyntaxElement*
|
|
GraphqlBogusSelection = SyntaxElement*
|
|
GraphqlBogusValue = SyntaxElement*
|
|
GraphqlBogusType = SyntaxElement*
|
|
|
|
GraphqlLiteralName = value: 'ident'
|
|
GraphqlNameBinding = value: 'ident'
|
|
GraphqlNameReference = value: 'ident'
|
|
|
|
GraphqlRoot =
|
|
bom: 'UNICODE_BOM'?
|
|
definitions: GraphqlDefinitionList
|
|
eof: 'EOF'
|
|
|
|
GraphqlDefinitionList = AnyGraphqlDefinition*
|
|
|
|
AnyGraphqlDefinition =
|
|
GraphqlOperationDefinition
|
|
| GraphqlSelectionSet
|
|
| GraphqlFragmentDefinition
|
|
| GraphqlDirectiveDefinition
|
|
| GraphqlSchemaDefinition
|
|
| GraphqlSchemaExtension
|
|
| AnyGraphqlTypeDefinition
|
|
| AnyGraphqlTypeExtension
|
|
| GraphqlBogusDefinition
|
|
|
|
AnyGraphqlTypeDefinition =
|
|
GraphqlScalarTypeDefinition
|
|
| GraphqlObjectTypeDefinition
|
|
| GraphqlInterfaceTypeDefinition
|
|
| GraphqlUnionTypeDefinition
|
|
| GraphqlEnumTypeDefinition
|
|
| GraphqlInputObjectTypeDefinition
|
|
|
|
AnyGraphqlTypeExtension =
|
|
GraphqlScalarTypeExtension
|
|
| GraphqlObjectTypeExtension
|
|
| GraphqlInterfaceTypeExtension
|
|
| GraphqlUnionTypeExtension
|
|
| GraphqlEnumTypeExtension
|
|
| GraphqlInputObjectTypeExtension
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Language.Operations.Query-shorthand
|
|
AnyGraphqlOperationDefinition = GraphqlOperationDefinition | GraphqlSelectionSet
|
|
|
|
// query/mutation/subscription operation
|
|
// https://spec.graphql.org/October2021/#sec-Language.Operations
|
|
GraphqlOperationDefinition =
|
|
type: GraphqlOperationType
|
|
name: GraphqlNameBinding?
|
|
variables: GraphqlVariableDefinitions?
|
|
directives: GraphqlDirectiveList
|
|
selection_set: GraphqlSelectionSet
|
|
|
|
// https://spec.graphql.org/October2021/#OperationType
|
|
GraphqlOperationType =
|
|
value_token: ('query' | 'mutation' | 'subscription')
|
|
|
|
// describe query selections
|
|
// https://spec.graphql.org/October2021/#sec-Selection-Sets
|
|
GraphqlSelectionSet =
|
|
'{'
|
|
selections: GraphqlSelectionList
|
|
'}'
|
|
|
|
GraphqlSelectionList = AnyGraphqlSelection*
|
|
|
|
// https://spec.graphql.org/October2021/#Selection
|
|
AnyGraphqlSelection =
|
|
GraphqlField
|
|
| GraphqlFragmentSpread
|
|
| GraphqlInlineFragment
|
|
| GraphqlBogusSelection
|
|
|
|
// { a: b(c: d) @ef {...} }
|
|
// ^^^^^^^^^^^^^^^^^^^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Language.Fields
|
|
GraphqlField =
|
|
alias: GraphqlAlias?
|
|
name: GraphqlLiteralName
|
|
arguments: GraphqlArguments?
|
|
directives: GraphqlDirectiveList
|
|
selection_set: GraphqlSelectionSet?
|
|
|
|
// { a: b }
|
|
// ^^^
|
|
// https://spec.graphql.org/October2021/#Alias
|
|
GraphqlAlias =
|
|
value: GraphqlLiteralName
|
|
':'
|
|
|
|
// { b(c: d) }
|
|
// ^^^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Language.Fields
|
|
GraphqlArguments =
|
|
'('
|
|
arguments: GraphqlArgumentList
|
|
')'
|
|
|
|
GraphqlArgumentList = GraphqlArgument*
|
|
|
|
// { b(c: d) }
|
|
// ^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Language.Arguments
|
|
GraphqlArgument =
|
|
name: GraphqlLiteralName
|
|
':'
|
|
value: AnyGraphqlValue
|
|
|
|
// { ...a }
|
|
// ^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Language.Fragments
|
|
GraphqlFragmentSpread =
|
|
'...'
|
|
name: GraphqlNameReference
|
|
directives: GraphqlDirectiveList
|
|
|
|
// { ... on A { b } }
|
|
// ^^^^^^^^^^^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Inline-Fragments
|
|
GraphqlInlineFragment =
|
|
'...'
|
|
type_condition: GraphqlTypeCondition?
|
|
directives: GraphqlDirectiveList
|
|
selection_set: GraphqlSelectionSet
|
|
|
|
// fragment a on A { b }
|
|
// https://spec.graphql.org/October2021/#sec-Language.Fragments
|
|
GraphqlFragmentDefinition =
|
|
'fragment'
|
|
name: GraphqlNameBinding
|
|
type_condition: GraphqlTypeCondition
|
|
directives: GraphqlDirectiveList
|
|
selection_set: GraphqlSelectionSet
|
|
|
|
GraphqlTypeCondition =
|
|
'on'
|
|
type: GraphqlNameReference
|
|
|
|
AnyGraphqlValue =
|
|
GraphqlVariableReference
|
|
| GraphqlStringValue
|
|
| GraphqlFloatValue
|
|
| GraphqlIntValue
|
|
| GraphqlBooleanValue
|
|
| GraphqlNullValue
|
|
| GraphqlEnumValue
|
|
| GraphqlListValue
|
|
| GraphqlObjectValue
|
|
| GraphqlBogusValue
|
|
|
|
// https://spec.graphql.org/October2021/#sec-String-Value
|
|
GraphqlStringValue = 'graphql_string_literal'
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Float-Value
|
|
GraphqlFloatValue = 'graphql_float_literal'
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Int-Value
|
|
GraphqlIntValue = 'graphql_int_literal'
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Boolean-Value
|
|
GraphqlBooleanValue = value_token: ('true' | 'false')
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Null-Value
|
|
GraphqlNullValue = 'null'
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Enum-Value
|
|
GraphqlEnumValue = value: GraphqlLiteralName
|
|
|
|
// https://spec.graphql.org/October2021/#sec-List-Value
|
|
GraphqlListValue =
|
|
'['
|
|
elements: GraphqlListValueElementList
|
|
']'
|
|
|
|
GraphqlListValueElementList = AnyGraphqlValue*
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Input-Object-Values
|
|
GraphqlObjectValue =
|
|
'{'
|
|
members: GraphqlObjectValueMemberList
|
|
'}'
|
|
|
|
GraphqlObjectValueMemberList = GraphqlObjectField*
|
|
|
|
// https://spec.graphql.org/October2021/#ObjectField
|
|
GraphqlObjectField =
|
|
name: GraphqlLiteralName
|
|
':'
|
|
value: AnyGraphqlValue
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Language.Variables
|
|
GraphqlVariableDefinitions =
|
|
'('
|
|
elements: GraphqlVariableDefinitionList
|
|
')'
|
|
|
|
GraphqlVariableDefinitionList = GraphqlVariableDefinition*
|
|
|
|
// $episode: Episode = JEDI
|
|
// https://spec.graphql.org/October2021/#VariableDefinition
|
|
GraphqlVariableDefinition =
|
|
variable: GraphqlVariableBinding
|
|
':'
|
|
type: AnyGraphqlType
|
|
default: GraphqlDefaultValue?
|
|
directives: GraphqlDirectiveList
|
|
|
|
// https://spec.graphql.org/October2021/#Variable
|
|
GraphqlVariableBinding =
|
|
'$'
|
|
name: GraphqlLiteralName
|
|
|
|
// https://spec.graphql.org/October2021/#Variable
|
|
GraphqlVariableReference =
|
|
'$'
|
|
name: GraphqlLiteralName
|
|
|
|
// https://spec.graphql.org/October2021/#DefaultValue
|
|
GraphqlDefaultValue =
|
|
'='
|
|
value: AnyGraphqlValue
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Language.Variables
|
|
AnyGraphqlType =
|
|
AnyGraphqlPrimitiveType
|
|
| GraphqlNonNullType
|
|
| GraphqlBogusType
|
|
|
|
AnyGraphqlPrimitiveType = GraphqlNameReference | GraphqlListType
|
|
|
|
// nullable, [String]
|
|
// https://spec.graphql.org/October2021/#ListType
|
|
GraphqlListType =
|
|
'['
|
|
element: AnyGraphqlType
|
|
']'
|
|
|
|
// String!
|
|
// https://spec.graphql.org/October2021/#NonNullType
|
|
GraphqlNonNullType =
|
|
base: AnyGraphqlPrimitiveType
|
|
'!'
|
|
|
|
// @a(b: c) @d(e: f)
|
|
// This is often used as optional in the spec, represented by an empty list
|
|
// https://spec.graphql.org/October2021/#sec-Language.Directives
|
|
GraphqlDirectiveList =
|
|
GraphqlDirective*
|
|
|
|
// @a(b: c)
|
|
// https://spec.graphql.org/October2021/#Directive
|
|
GraphqlDirective =
|
|
'@'
|
|
name: GraphqlNameReference
|
|
arguments: GraphqlArguments?
|
|
|
|
// "abc" schema {query: Query}
|
|
// https://spec.graphql.org/October2021/#sec-Schema
|
|
GraphqlSchemaDefinition =
|
|
description: GraphqlDescription?
|
|
'schema'
|
|
directives: GraphqlDirectiveList
|
|
root_operation_types: GraphqlRootOperationTypes
|
|
|
|
// schema {query: Query}
|
|
// ^^^^^^^^^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Root-Operation-Types
|
|
GraphqlRootOperationTypeDefinitionList = GraphqlRootOperationTypeDefinition*
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Schema-Extension
|
|
// extend schema @x {mutation: Mutation}
|
|
GraphqlSchemaExtension =
|
|
'extend'
|
|
'schema'
|
|
directives: GraphqlDirectiveList
|
|
root_operation_types: GraphqlRootOperationTypes?
|
|
|
|
GraphqlRootOperationTypes =
|
|
'{'
|
|
root_operation_type: GraphqlRootOperationTypeDefinitionList
|
|
'}'
|
|
|
|
// schema {query: Query}
|
|
// ^^^^^^^^^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Root-Operation-Types
|
|
GraphqlRootOperationTypeDefinition =
|
|
operation_type: GraphqlOperationType
|
|
':'
|
|
named_type: GraphqlNameReference
|
|
|
|
// "abc" schema {query: Query}
|
|
// ^^^^^
|
|
GraphqlDescription =
|
|
GraphqlStringValue
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Scalars
|
|
GraphqlScalarTypeDefinition =
|
|
description: GraphqlDescription?
|
|
'scalar'
|
|
name: GraphqlNameBinding
|
|
directives: GraphqlDirectiveList
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Scalar-Extensions
|
|
GraphqlScalarTypeExtension =
|
|
'extend'
|
|
'scalar'
|
|
name: GraphqlNameReference
|
|
directives: GraphqlDirectiveList
|
|
|
|
// type A implements B {c: d}
|
|
// https://spec.graphql.org/October2021/#sec-Objects
|
|
GraphqlObjectTypeDefinition =
|
|
description: GraphqlDescription?
|
|
'type'
|
|
name: GraphqlNameBinding
|
|
implements: GraphqlImplementsInterfaces?
|
|
directives: GraphqlDirectiveList
|
|
fields: GraphqlFieldsDefinition?
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Object-Extensions
|
|
// extend type C implements A @i {e: f}
|
|
GraphqlObjectTypeExtension =
|
|
'extend'
|
|
'type'
|
|
name: GraphqlNameReference
|
|
implements: GraphqlImplementsInterfaces?
|
|
directives: GraphqlDirectiveList
|
|
fields: GraphqlFieldsDefinition?
|
|
|
|
// extend type C implements
|
|
// & A
|
|
// & B
|
|
// https://spec.graphql.org/October2021/#ImplementsInterfaces
|
|
GraphqlImplementsInterfaces =
|
|
'implements'
|
|
'&'?
|
|
interfaces: GraphqlImplementsInterfaceList
|
|
|
|
// A & B & C
|
|
GraphqlImplementsInterfaceList = (GraphqlNameReference ('&' GraphqlNameReference)*)
|
|
|
|
// type A implements B {c: d}
|
|
// ^^^^^^
|
|
GraphqlFieldsDefinition =
|
|
'{'
|
|
fields: GraphqlFieldDefinitionList
|
|
'}'
|
|
|
|
GraphqlFieldDefinitionList = GraphqlFieldDefinition*
|
|
|
|
// "xyz" a(x: y): A @d
|
|
// https://spec.graphql.org/October2021/#FieldDefinition
|
|
GraphqlFieldDefinition =
|
|
description: GraphqlDescription?
|
|
name: GraphqlLiteralName
|
|
arguments: GraphqlArgumentsDefinition?
|
|
':'
|
|
type: AnyGraphqlType
|
|
directives: GraphqlDirectiveList
|
|
|
|
// "xyz" a(x: y): A @d
|
|
// ^^^^^^
|
|
// https://spec.graphql.org/October2021/#sec-Field-Arguments
|
|
GraphqlArgumentsDefinition =
|
|
'('
|
|
arguments: GraphqlArgumentDefinitionList
|
|
')'
|
|
|
|
GraphqlArgumentDefinitionList = GraphqlInputValueDefinition*
|
|
|
|
// ("xyz" x: y = yyy @d)
|
|
// https://spec.graphql.org/October2021/#InputValueDefinition
|
|
GraphqlInputValueDefinition =
|
|
description: GraphqlDescription?
|
|
name: GraphqlLiteralName
|
|
':'
|
|
type: AnyGraphqlType
|
|
default: GraphqlDefaultValue?
|
|
directives: GraphqlDirectiveList
|
|
|
|
// "xyz" interface A implements B @d {x: y}
|
|
// https://spec.graphql.org/October2021/#sec-Interfaces
|
|
GraphqlInterfaceTypeDefinition =
|
|
description: GraphqlDescription?
|
|
'interface'
|
|
name: GraphqlNameBinding
|
|
implements: GraphqlImplementsInterfaces?
|
|
directives: GraphqlDirectiveList
|
|
fields: GraphqlFieldsDefinition?
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Interface-Extensions
|
|
// extend interface A implements B @i {e: f}
|
|
GraphqlInterfaceTypeExtension =
|
|
'extend'
|
|
'interface'
|
|
name: GraphqlNameReference
|
|
implements: GraphqlImplementsInterfaces?
|
|
directives: GraphqlDirectiveList
|
|
fields: GraphqlFieldsDefinition?
|
|
|
|
// union A =
|
|
// | B
|
|
// | C
|
|
// https://spec.graphql.org/October2021/#sec-Unions
|
|
GraphqlUnionTypeDefinition =
|
|
description: GraphqlDescription?
|
|
'union'
|
|
name: GraphqlNameBinding
|
|
directives: GraphqlDirectiveList
|
|
union_members: GraphqlUnionMemberTypes?
|
|
|
|
// https://spec.graphql.org/October2021/#UnionMemberTypes
|
|
GraphqlUnionMemberTypes =
|
|
'='
|
|
'|'?
|
|
members: GraphqlUnionMemberTypeList
|
|
|
|
// A | B | C
|
|
GraphqlUnionMemberTypeList = (GraphqlNameReference ('|' GraphqlNameReference)*)
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Union-Extensions
|
|
// extend union A @d
|
|
GraphqlUnionTypeExtension =
|
|
'extend'
|
|
'union'
|
|
name: GraphqlNameReference
|
|
directives: GraphqlDirectiveList
|
|
union_members: GraphqlUnionMemberTypes?
|
|
|
|
// "xyz" enum A @d {
|
|
// B
|
|
// C
|
|
// }
|
|
// https://spec.graphql.org/October2021/#sec-Enums
|
|
GraphqlEnumTypeDefinition =
|
|
description: GraphqlDescription?
|
|
'enum'
|
|
name: GraphqlNameBinding
|
|
directives: GraphqlDirectiveList
|
|
enum_values: GraphqlEnumValuesDefinition?
|
|
|
|
// { A }
|
|
// https://spec.graphql.org/October2021/#EnumValuesDefinition
|
|
GraphqlEnumValuesDefinition =
|
|
'{'
|
|
values: GraphqlEnumValueList
|
|
'}'
|
|
|
|
GraphqlEnumValueList = GraphqlEnumValueDefinition*
|
|
|
|
// enum A {
|
|
// "xyz" B @d
|
|
// }
|
|
// https://spec.graphql.org/October2021/#EnumValueDefinition
|
|
GraphqlEnumValueDefinition =
|
|
description: GraphqlDescription?
|
|
value: GraphqlLiteralName
|
|
directives: GraphqlDirectiveList
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Enum-Extensions
|
|
// extend enum A @d { Y }
|
|
GraphqlEnumTypeExtension =
|
|
'extend'
|
|
'enum'
|
|
name: GraphqlNameReference
|
|
directives: GraphqlDirectiveList
|
|
enum_values: GraphqlEnumValuesDefinition?
|
|
|
|
// "xyz" input A @d { x: y }
|
|
// https://spec.graphql.org/October2021/#sec-Input-Object
|
|
GraphqlInputObjectTypeDefinition =
|
|
description: GraphqlDescription?
|
|
'input'
|
|
name: GraphqlNameBinding
|
|
directives: GraphqlDirectiveList
|
|
input_fields: GraphqlInputFieldsDefinition?
|
|
|
|
// https://spec.graphql.org/October2021/#InputFieldsDefinition
|
|
GraphqlInputFieldsDefinition =
|
|
'{'
|
|
fields: GraphqlInputFieldList
|
|
'}'
|
|
|
|
GraphqlInputFieldList = GraphqlInputValueDefinition*
|
|
|
|
// https://spec.graphql.org/October2021/#sec-Input-Object-Extensions
|
|
// extend input A @d { x: y }
|
|
GraphqlInputObjectTypeExtension =
|
|
'extend'
|
|
'input'
|
|
name: GraphqlNameReference
|
|
directives: GraphqlDirectiveList
|
|
input_fields: GraphqlInputFieldsDefinition?
|
|
|
|
// directive @a(b: c) repeatable on
|
|
// | QUERY
|
|
// | MUTATION
|
|
// https://spec.graphql.org/October2021/#sec-Type-System.Directives
|
|
GraphqlDirectiveDefinition =
|
|
description: GraphqlDescription?
|
|
'directive'
|
|
'@'
|
|
name: GraphqlNameBinding
|
|
arguments: GraphqlArgumentsDefinition?
|
|
'repeatable'?
|
|
'on'
|
|
'|'?
|
|
locations: GraphqlDirectiveLocationList
|
|
|
|
// https://spec.graphql.org/October2021/#DirectiveLocations
|
|
GraphqlDirectiveLocationList =
|
|
(GraphqlDirectiveLocation ('|' GraphqlDirectiveLocation)*)
|
|
|
|
// https://spec.graphql.org/October2021/#DirectiveLocation
|
|
GraphqlDirectiveLocation =
|
|
value_token: (
|
|
'QUERY'
|
|
| 'MUTATION'
|
|
| 'SUBSCRIPTION'
|
|
| 'FIELD'
|
|
| 'FRAGMENT_DEFINITION'
|
|
| 'FRAGMENT_SPREAD'
|
|
| 'INLINE_FRAGMENT'
|
|
| 'VARIABLE_DEFINITION'
|
|
| 'SCHEMA'
|
|
| 'SCALAR'
|
|
| 'OBJECT'
|
|
| 'FIELD_DEFINITION'
|
|
| 'ARGUMENT_DEFINITION'
|
|
| 'INTERFACE'
|
|
| 'UNION'
|
|
| 'ENUM'
|
|
| 'ENUM_VALUE'
|
|
| 'INPUT_OBJECT'
|
|
| 'INPUT_FIELD_DEFINITION'
|
|
)
|