Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar railroad diagram #126

Open
mingodad opened this issue May 17, 2024 · 0 comments
Open

Grammar railroad diagram #126

mingodad opened this issue May 17, 2024 · 0 comments

Comments

@mingodad
Copy link

I've just added the libgraphqlparser grammar to https://mingodad.github.io/parsertl-playground/playground/ (select Graphql parser from Examples then click Parse to see a parse tree for the content in Input source) and also generated an EBNF understood by (IPV6) https://www.bottlecaps.de/rr/ui or (IPV4) https://rr.red-dove.com/ui to generate a nice navigable railroad diagram (see instructions on the EBNF shown bellow).

//
// EBNF to be viewd at
//    (IPV6) https://www.bottlecaps.de/rr/ui
//    (IPV4) https://rr.red-dove.com/ui
//
// Copy and paste this at one of the urls shown above in the 'Edit Grammar' tab
// then click the 'View Diagram' tab.
//

start::=
	  document
	//| UNRECOGNIZED_CHARACTER
	//| INVALID_CHARACTER
	//| UNTERMINATED_STRING
	//| BAD_UNICODE_ESCAPE_SEQUENCE
	//| BAD_ESCAPE_SEQUENCE

fragment_name::=
	  DIRECTIVE
	| ENUM
	| EXTEND
	| FALSE
	| FRAGMENT
	| IDENTIFIER
	| IMPLEMENTS
	| INPUT
	| INTERFACE
	| MUTATION
	| NULL
	| QUERY
	| SCALAR
	| SCHEMA
	| SUBSCRIPTION
	| TRUE
	| TYPE
	| UNION

name::=
	  fragment_name
	| ON

name_opt::=
	  /*%empty*/
	| name

document::=
	  definition_list

definition_list::=
	  definition
	| definition_list definition

definition::=
	  operation_definition
	| fragment_definition
	| schema_gate

schema_gate::=
	  schema_definition
	| scalar_type_definition
	| object_type_definition
	| interface_type_definition
	| union_type_definition
	| enum_type_definition
	| input_object_type_definition
	| type_extension_definition
	| directive_definition

operation_definition::=
	  selection_set
	| operation_type name_opt selection_set
	| operation_type name_opt variable_definitions selection_set
	| operation_type name_opt directives selection_set
	| operation_type name_opt variable_definitions directives selection_set

operation_type::=
	  QUERY
	| MUTATION
	| SUBSCRIPTION

variable_definitions::=
	  "(" variable_definition_list ")"

variable_definition_list::=
	  variable_definition
	| variable_definition_list variable_definition

variable::=
	  VARIABLE

variable_definition::=
	  variable ":" type default_value_opt

default_value_opt::=
	  /*%empty*/
	| default_value

default_value::=
	  "=" value_const

selection_set::=
	  "{" selection_list "}"

selection_set_opt::=
	  /*%empty*/
	| selection_set

selection_list::=
	  selection
	| selection_list selection

selection::=
	  field
	| fragment_spread
	| inline_fragment

field::=
	  name arguments_opt directives_opt selection_set_opt
	| name ":" name arguments_opt directives_opt selection_set_opt

arguments::=
	  "(" argument_list ")"

arguments_opt::=
	  /*%empty*/
	| arguments

argument_list::=
	  argument
	| argument_list argument

argument::=
	  name ":" value

fragment_spread::=
	  "..." fragment_name directives_opt

inline_fragment::=
	  "..." ON type_condition directives_opt selection_set
	| "..." directives_opt selection_set

fragment_definition::=
	  FRAGMENT fragment_name ON type_condition directives_opt selection_set

type_condition::=
	  type_name

value::=
	  variable
	| int_value
	| float_value
	| string_value
	| boolean_value
	| null_value
	| enum_value
	| list_value
	| object_value

int_value::=
	  INTEGER

float_value::=
	  FLOAT

string_value::=
	  STRING

value_const::=
	  int_value
	| float_value
	| string_value
	| boolean_value
	| null_value
	| enum_value
	| list_value_const
	| object_value_const

boolean_value::=
	  TRUE
	| FALSE

null_value::=
	  NULL

enum_value::=
	  DIRECTIVE
	| ENUM
	| EXTEND
	| FRAGMENT
	| IDENTIFIER
	| IMPLEMENTS
	| INPUT
	| INTERFACE
	| MUTATION
	| ON
	| QUERY
	| SCALAR
	| SCHEMA
	| SUBSCRIPTION
	| TYPE
	| UNION

list_value::=
	  "[" "]"
	| "[" value_list "]"

value_list::=
	  value
	| value_list value

list_value_const::=
	  "[" "]"
	| "[" value_const_list "]"

value_const_list::=
	  value_const
	| value_const_list value_const

object_value::=
	  "{" "}"
	| "{" object_field_list "}"

object_field_list::=
	  object_field
	| object_field_list object_field

object_field::=
	  name ":" value

object_value_const::=
	  "{" "}"
	| "{" object_field_const_list "}"

object_field_const_list::=
	  object_field_const
	| object_field_const_list object_field_const

object_field_const::=
	  name ":" value_const

directives::=
	  directive_list

directives_opt::=
	  /*%empty*/
	| directives

directive_list::=
	  directive
	| directive_list directive

directive::=
	  "@" name arguments_opt

type::=
	  type_name
	| list_type
	| non_null_type

type_name::=
	  name

list_type::=
	  "[" type "]"

non_null_type::=
	  type_name "!"
	| list_type "!"

schema_definition::=
	  SCHEMA directives_opt "{" operation_type_definition_list "}"

operation_type_definition_list::=
	  operation_type_definition
	| operation_type_definition_list operation_type_definition

operation_type_definition::=
	  operation_type ":" type_name

scalar_type_definition::=
	  SCALAR name directives_opt

object_type_definition::=
	  TYPE name implements_interfaces_opt directives_opt "{" field_definition_list "}"

implements_interfaces_opt::=
	  /*%empty*/
	| IMPLEMENTS type_name_list

type_name_list::=
	  type_name
	| type_name_list type_name

field_definition::=
	  name arguments_definition_opt ":" type directives_opt

field_definition_list::=
	  field_definition
	| field_definition_list field_definition

arguments_definition_opt::=
	  /*%empty*/
	| arguments_definition

arguments_definition::=
	  "(" input_value_definition_list ")"

input_value_definition_list::=
	  input_value_definition
	| input_value_definition_list input_value_definition

input_value_definition::=
	  name ":" type default_value_opt directives_opt

interface_type_definition::=
	  INTERFACE name directives_opt "{" field_definition_list "}"

union_type_definition::=
	  UNION name directives_opt "=" union_members

union_members::=
	  type_name
	| union_members "|" type_name

enum_type_definition::=
	  ENUM name directives_opt "{" enum_value_definition_list "}"

enum_value_definition::=
	  name directives_opt

enum_value_definition_list::=
	  enum_value_definition
	| enum_value_definition_list enum_value_definition

input_object_type_definition::=
	  INPUT name directives_opt "{" input_value_definition_list "}"

type_extension_definition::=
	  EXTEND object_type_definition

directive_definition::=
	  DIRECTIVE "@" name arguments_definition_opt ON directive_locations

directive_locations::=
	  name
	| directive_locations "|" name

//Tokens

DIRECTIVE ::= "directive"
ENUM ::= "enum"
EXTEND ::= "extend"
FALSE ::= "false"
FRAGMENT ::= "fragment"
IMPLEMENTS ::= "implements"
INPUT ::= "input"
INTERFACE ::= "interface"
MUTATION ::= "mutation"
NULL ::= "null"
ON ::= "on"
QUERY ::= "query"
SCALAR ::= "scalar"
SCHEMA ::= "schema"
SUBSCRIPTION ::= "subscription"
TRUE ::= "true"
TYPE ::= "type"
UNION ::= "union"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant