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 #5560

Open
mingodad opened this issue May 22, 2023 · 8 comments
Open

Grammar railroad diagram #5560

mingodad opened this issue May 22, 2023 · 8 comments
Labels
type/feature req Type: feature request

Comments

@mingodad
Copy link

Using some online tools like https://www.bottlecaps.de/rr/ui and https://www.bottlecaps.de/convert/ and manually adding the tokens from the lexer we can have a nice navigable railroad diagram.

Copy and paste the EBNF shown bellow on https://www.bottlecaps.de/rr/ui on the tab Edit Grammar the click on the tab View Diagram to see/download a navigable railroad diagram.

/* converted on Mon May 22, 2023, 17:10 (UTC+02) by bison-to-w3c v0.64 which is Copyright (c) 2011-2023 by Gunther Rademacher <grd@gmx.net> */
//From: https://github.com/vesoft-inc/nebula/blob/master/src/parser/parser.yy

sentences
         ::= seq_sentences
           | ( KW_EXPLAIN | KW_PROFILE ) ( KW_FORMAT ASSIGN STRING )? ( sentence | L_BRACE seq_sentences R_BRACE ) SEMICOLON*

name_label
         ::= LABEL
           | unreserved_keyword
name_label_list
         ::= name_label ( COMMA name_label )*
legal_integer
         ::= INTEGER
unreserved_keyword
         ::= KW_SPACE
           | KW_VALUE
           | KW_VALUES
           | KW_HOST
           | KW_HOSTS
           | KW_SPACES
           | KW_USER
           | KW_USERS
           | KW_PASSWORD
           | KW_ROLE
           | KW_ROLES
           | KW_GOD
           | KW_ADMIN
           | KW_DBA
           | KW_GUEST
           | KW_GROUP
           | KW_DATA
           | KW_LEADER
           | KW_UUID
           | KW_JOB
           | KW_JOBS
           | KW_BIDIRECT
           | KW_FORCE
           | KW_PART
           | KW_PARTS
           | KW_DEFAULT
           | KW_CONFIGS
           | KW_ACCOUNT
           | KW_HDFS
           | KW_PARTITION_NUM
           | KW_REPLICA_FACTOR
           | KW_CHARSET
           | KW_COLLATE
           | KW_COLLATION
           | KW_ATOMIC_EDGE
           | KW_TTL_DURATION
           | KW_TTL_COL
           | KW_SNAPSHOT
           | KW_SNAPSHOTS
           | KW_GRAPH
           | KW_META
           | KW_STORAGE
           | KW_AGENT
           | KW_ALL
           | KW_ANY
           | KW_SINGLE
           | KW_NONE
           | KW_REDUCE
           | KW_SHORTEST
           | KW_SHORTESTPATH
           | KW_ALLSHORTESTPATHS
           | KW_NOLOOP
           | KW_CONTAINS
           | KW_STARTS
           | KW_ENDS
           | KW_VID_TYPE
           | KW_LIMIT
           | KW_SKIP
           | KW_OPTIONAL
           | KW_OFFSET
           | KW_FORMAT
           | KW_PROFILE
           | KW_BOTH
           | KW_OUT
           | KW_SUBGRAPH
           | KW_THEN
           | KW_ELSE
           | KW_END
           | KW_INTO
           | KW_NEW
           | KW_GROUPS
           | KW_ZONE
           | KW_ZONES
           | KW_LISTENER
           | KW_ELASTICSEARCH
           | KW_FULLTEXT
           | KW_STATS
           | KW_STATUS
           | KW_AUTO
           | KW_FUZZY
           | KW_PREFIX
           | KW_REGEXP
           | KW_WILDCARD
           | KW_TEXT
           | KW_SEARCH
           | KW_CLIENTS
           | KW_SIGN
           | KW_SERVICE
           | KW_TEXT_SEARCH
           | KW_RESET
           | KW_PLAN
           | KW_COMMENT
           | KW_S2_MAX_LEVEL
           | KW_S2_MAX_CELLS
           | KW_SESSION
           | KW_SESSIONS
           | KW_LOCAL
           | KW_SAMPLE
           | KW_QUERIES
           | KW_QUERY
           | KW_KILL
           | KW_TOP
           | KW_POINT
           | KW_LINESTRING
           | KW_POLYGON
           | KW_HTTP
           | KW_HTTPS
           | KW_MERGE
           | KW_DIVIDE
           | KW_RENAME
           | KW_CLEAR
expression
         ::= expression_internal
expression_internal
         ::= constant_expression
           | name_label
           | VARIABLE
           | compound_expression
           | ( MINUS | PLUS | NOT | KW_NOT | L_PAREN type_spec R_PAREN ) expression_internal
           | expression_internal ( ( STAR | DIV | MOD | PLUS | MINUS | LT | GT | LE | GE | REG | KW_IN | KW_NOT_IN | KW_CONTAINS | KW_NOT_CONTAINS | KW_STARTS_WITH | KW_NOT_STARTS_WITH | KW_ENDS_WITH | KW_NOT_ENDS_WITH | EQ | NE | KW_AND | KW_OR | KW_XOR ) expression_internal | KW_IS_NULL | KW_IS_NOT_NULL | KW_IS_EMPTY | KW_IS_NOT_EMPTY )
           | case_expression
           | predicate_expression
           | reduce_expression
           | uuid_expression
constant_expression
         ::= DOUBLE
           | STRING
           | BOOL
           | KW_NULL
           | INTEGER
compound_expression
         ::= match_path_pattern_expression
           | parenthesized_expression
           | property_expression
           | function_call_expression
           | container_expression
           | list_comprehension_expression
           | subscript_expression
           | subscript_range_expression
           | attribute_expression
parenthesized_expression
         ::= L_PAREN expression_internal R_PAREN
property_expression
         ::= input_prop_expression
           | vertex_prop_expression
           | var_prop_expression
           | edge_prop_expression
subscript_expression
         ::= ( name_label | VARIABLE | compound_expression ) L_BRACKET expression_internal R_BRACKET
subscript_range_expression
         ::= ( name_label | VARIABLE | compound_expression ) L_BRACKET ( expression_internal DOT_DOT expression_internal? | DOT_DOT expression_internal ) R_BRACKET
attribute_expression
         ::= ( name_label | compound_expression ) DOT name_label
case_expression
         ::= generic_case_expression
           | conditional_expression
generic_case_expression
         ::= KW_CASE case_condition ( KW_WHEN expression_internal KW_THEN expression_internal )+ case_default KW_END
conditional_expression
         ::= expression_internal QM expression_internal COLON expression_internal
case_condition
         ::= expression_internal?
case_default
         ::= ( KW_ELSE expression_internal )?
predicate_name
         ::= KW_ALL
           | KW_ANY
           | KW_SINGLE
           | KW_NONE
predicate_expression
         ::= ( predicate_name L_PAREN expression_internal KW_IN expression_internal KW_WHERE | KW_EXISTS L_PAREN ) expression_internal R_PAREN
list_comprehension_expression
         ::= L_BRACKET expression_internal KW_IN expression_internal ( KW_WHERE ( expression_internal PIPE )? | PIPE ) expression_internal R_BRACKET
reduce_expression
         ::= KW_REDUCE L_PAREN name_label ASSIGN expression_internal COMMA name_label KW_IN expression_internal PIPE expression_internal R_PAREN
input_prop_expression
         ::= INPUT_REF DOT ( name_label | STAR )
vertex_prop_expression
         ::= ( SRC_REF | DST_REF ) DOT name_label DOT name_label
var_prop_expression
         ::= VARIABLE DOT ( name_label | STAR )
edge_prop_expression
         ::= name_label DOT ( TYPE_PROP | SRC_ID_PROP | DST_ID_PROP | RANK_PROP )
function_call_expression
         ::= ( LABEL L_PAREN ( opt_argument_list | KW_DISTINCT expression_internal | STAR ) | ( KW_TIMESTAMP | KW_DATE | KW_TIME | KW_DATETIME | KW_TAGS | KW_SIGN | KW_DURATION ) L_PAREN opt_argument_list ) R_PAREN
uuid_expression
         ::= KW_UUID L_PAREN R_PAREN
match_path_pattern_expression
         ::= match_node ( match_edge match_node )+
opt_argument_list
         ::= ( ( KW_VERTEX | SRC_REF | DST_REF | KW_EDGE | expression_internal ) ( COMMA expression_internal )* )?
geo_shape_type
         ::= KW_POINT
           | KW_LINESTRING
           | KW_POLYGON
type_spec
         ::= KW_BOOL
           | KW_INT8
           | KW_INT16
           | KW_INT32
           | KW_INT64
           | KW_INT
           | KW_FLOAT
           | KW_DOUBLE
           | KW_STRING
           | KW_FIXED_STRING L_PAREN INTEGER R_PAREN
           | KW_TIMESTAMP
           | KW_DATE
           | KW_TIME
           | KW_DATETIME
           | KW_GEOGRAPHY ( L_PAREN geo_shape_type R_PAREN )?
           | KW_DURATION
container_expression
         ::= list_expression
           | set_expression
           | map_expression
list_expression
         ::= ( L_BRACKET expression_list | KW_LIST L_BRACKET opt_expression_list ) R_BRACKET
set_expression
         ::= ( L_BRACE expression_list | KW_SET L_BRACE opt_expression_list ) R_BRACE
opt_expression_list
         ::= expression_list?
expression_list
         ::= expression_internal ( COMMA expression_internal )*
map_expression
         ::= ( L_BRACE map_item_list | KW_MAP L_BRACE opt_map_item_list ) R_BRACE
opt_map_item_list
         ::= map_item_list?
map_item_list
         ::= name_label COLON expression_internal ( COMMA name_label COLON expression_internal )*
truncate_clause
         ::= ( ( KW_SAMPLE | KW_LIMIT ) expression )?
go_sentence
         ::= KW_GO step_clause from_clause over_clause where_clause yield_clause truncate_clause
step_clause
         ::= ( legal_integer ( KW_TO legal_integer )? KW_STEPS )?
from_clause
         ::= KW_FROM ( vid_list | vid_ref_expression )
vid_list ::= vid ( COMMA vid )*
vid      ::= unary_integer
           | function_call_expression
           | uuid_expression
           | STRING
           | VARIABLE
unary_integer
         ::= PLUS? legal_integer
           | MINUS INTEGER
vid_ref_expression
         ::= input_prop_expression
           | var_prop_expression
over_edge
         ::= name_label ( KW_AS name_label )?
over_edges
         ::= over_edge ( COMMA over_edge )*
over_clause
         ::= KW_OVER ( STAR | over_edges ) ( KW_REVERSELY | KW_BIDIRECT )?
where_clause
         ::= ( KW_WHERE expression )?
when_clause
         ::= ( KW_WHEN expression )?
yield_clause
         ::= ( KW_YIELD KW_DISTINCT? yield_columns )?
yield_columns
         ::= yield_column ( COMMA yield_column )*
yield_column
         ::= ( KW_VERTEX | SRC_REF | DST_REF | KW_VERTICES | KW_EDGE | KW_EDGES | KW_PATH | expression ) ( KW_AS name_label )?
group_clause
         ::= yield_columns
yield_sentence
         ::= KW_YIELD KW_DISTINCT? yield_columns where_clause
           | KW_RETURN KW_DISTINCT? yield_columns
unwind_clause
         ::= KW_UNWIND expression KW_AS name_label
unwind_sentence
         ::= KW_UNWIND expression KW_AS name_label
with_clause
         ::= KW_WITH KW_DISTINCT? match_return_items match_order_by match_skip match_limit where_clause
match_clause
         ::= KW_OPTIONAL? KW_MATCH match_path_list where_clause
reading_clause
         ::= unwind_clause
           | match_clause
reading_clauses
         ::= reading_clause+
reading_with_clause
         ::= reading_clauses? with_clause
reading_with_clauses
         ::= reading_with_clause+
match_sentence
         ::= ( reading_clauses | reading_with_clauses reading_clauses? ) match_return
match_path_pattern
         ::= ( match_path_pattern match_edge )? match_node
           | ( KW_SHORTESTPATH | KW_ALLSHORTESTPATHS ) L_PAREN match_path_pattern R_PAREN
match_path
         ::= ( name_label ASSIGN )? match_path_pattern
match_path_list
         ::= match_path ( COMMA match_path )*
match_node
         ::= L_PAREN ( match_alias ( match_node_label+ | map_expression ) )? R_PAREN
           | parenthesized_expression
match_node_label
         ::= COLON name_label map_expression?
match_alias
         ::= name_label?
match_edge
         ::= MINUS_MINUS
           | MINUS_R_ARROW
           | L_ARROW_MINUS
           | L_ARROW_R_ARROW
           | ( MINUS_L_BRACKET | L_ARROW_L_BRACKET ) match_edge_prop ( R_BRACKET_MINUS | R_BRACKET_R_ARROW )
match_edge_prop
         ::= match_alias opt_match_edge_type_list match_step_range map_expression?
opt_match_edge_type_list
         ::= ( COLON name_label ( PIPE COLON? name_label )* )?
match_step_range
         ::= ( STAR ( legal_integer ( DOT_DOT legal_integer? )? | DOT_DOT legal_integer )? )?
match_return
         ::= KW_RETURN KW_DISTINCT? match_return_items match_order_by match_skip match_limit
match_return_items
         ::= STAR ( COMMA yield_columns )?
           | yield_columns
match_order_by
         ::= ( KW_ORDER KW_BY order_factors )?
match_skip
         ::= ( KW_SKIP expression )?
match_limit
         ::= ( KW_LIMIT expression )?
service_client_item
         ::= L_PAREN host_item ( COMMA ( ( KW_HTTP | KW_HTTPS ) ( COMMA STRING COMMA STRING )? | STRING COMMA STRING ) )? R_PAREN
sign_in_service_sentence
         ::= KW_SIGN KW_IN KW_TEXT KW_SERVICE service_client_item ( COMMA service_client_item? )*
sign_out_service_sentence
         ::= KW_SIGN KW_OUT KW_TEXT KW_SERVICE
base_text_search_argument
         ::= name_label DOT name_label COMMA STRING
fuzzy_text_search_argument
         ::= base_text_search_argument COMMA ( KW_AUTO | legal_integer ) COMMA ( KW_AND | KW_OR )
text_search_argument
         ::= ( base_text_search_argument | fuzzy_text_search_argument ) ( COMMA legal_integer ( COMMA legal_integer )? )?
text_search_expression
         ::= ( KW_PREFIX | KW_WILDCARD | KW_REGEXP | KW_FUZZY ) L_PAREN text_search_argument R_PAREN
lookup_where_clause
         ::= ( KW_WHERE ( text_search_expression | expression ) )?
lookup_sentence
         ::= KW_LOOKUP KW_ON name_label lookup_where_clause yield_clause
order_factor
         ::= expression ( KW_ASC | KW_DESC | KW_ASCENDING | KW_DESCENDING )?
order_factors
         ::= order_factor ( COMMA order_factor )*
order_by_sentence
         ::= KW_ORDER KW_BY order_factors
fetch_vertices_sentence
         ::= KW_FETCH KW_PROP KW_ON ( name_label_list | STAR ) ( vid_list | vid_ref_expression ) yield_clause
edge_key ::= vid R_ARROW vid ( AT rank )?
edge_keys
         ::= edge_key ( COMMA edge_key )*
edge_key_ref
         ::= input_prop_expression R_ARROW input_prop_expression ( AT ( input_prop_expression | constant_expression ) )?
           | var_prop_expression R_ARROW var_prop_expression ( AT ( var_prop_expression | constant_expression ) )?
fetch_edges_sentence
         ::= KW_FETCH KW_PROP KW_ON name_label_list ( edge_keys | edge_key_ref ) yield_clause
fetch_sentence
         ::= fetch_vertices_sentence
           | fetch_edges_sentence
find_path_sentence
         ::= KW_FIND ( KW_ALL | KW_SHORTEST | KW_NOLOOP ) KW_PATH opt_with_properties from_clause to_clause over_clause where_clause find_path_upto_clause yield_clause
opt_with_properties
         ::= ( KW_WITH KW_PROP )?
find_path_upto_clause
         ::= ( KW_UPTO legal_integer KW_STEPS )?
to_clause
         ::= KW_TO ( vid_list | vid_ref_expression )
limit_sentence
         ::= ( KW_LIMIT ( legal_integer ( COMMA | KW_OFFSET ) )? | KW_OFFSET legal_integer KW_LIMIT ) legal_integer
group_by_yield_clause
         ::= KW_YIELD KW_DISTINCT? yield_columns
group_by_sentence
         ::= KW_GROUP KW_BY group_clause group_by_yield_clause
in_bound_clause
         ::= ( KW_IN over_edges )?
out_bound_clause
         ::= ( KW_OUT over_edges )?
both_in_out_clause
         ::= ( KW_BOTH over_edges )?
get_subgraph_sentence
         ::= KW_GET KW_SUBGRAPH opt_with_properties step_clause from_clause in_bound_clause out_bound_clause both_in_out_clause where_clause yield_clause
use_sentence
         ::= KW_USE name_label
opt_if_not_exists
         ::= ( KW_IF KW_NOT KW_EXISTS )?
opt_if_exists
         ::= ( KW_IF KW_EXISTS )?
opt_create_schema_prop_list
         ::= ( create_schema_prop_item ( COMMA create_schema_prop_item )* )?
opt_ignore_existed_index
         ::= KW_IGNORE_EXISTED_INDEX?
create_schema_prop_item
         ::= KW_TTL_DURATION ASSIGN legal_integer
           | KW_TTL_COL ASSIGN STRING
           | comment_prop_assignment
create_tag_sentence
         ::= KW_CREATE KW_TAG opt_if_not_exists name_label L_PAREN ( column_spec_list COMMA? )? R_PAREN opt_create_schema_prop_list
alter_tag_sentence
         ::= KW_ALTER KW_TAG name_label ( alter_schema_opt_list alter_schema_prop_list? | alter_schema_prop_list )
alter_schema_opt_list
         ::= alter_schema_opt_item ( COMMA alter_schema_opt_item )*
alter_schema_opt_item
         ::= ( ( KW_ADD | KW_CHANGE ) L_PAREN column_spec_list | KW_DROP L_PAREN name_label ( COMMA name_label )* ) R_PAREN
alter_schema_prop_list
         ::= alter_schema_prop_item ( COMMA alter_schema_prop_item )*
alter_schema_prop_item
         ::= KW_TTL_DURATION ASSIGN legal_integer
           | KW_TTL_COL ASSIGN STRING
           | comment_prop_assignment
create_edge_sentence
         ::= KW_CREATE KW_EDGE opt_if_not_exists name_label L_PAREN ( column_spec_list COMMA? )? R_PAREN opt_create_schema_prop_list
alter_edge_sentence
         ::= KW_ALTER KW_EDGE name_label ( alter_schema_opt_list alter_schema_prop_list? | alter_schema_prop_list )
column_spec_list
         ::= column_spec ( COMMA column_spec )*
column_spec
         ::= name_label type_spec column_property*
column_property
         ::= KW_NOT? KW_NULL
           | KW_DEFAULT expression
           | comment_prop
describe_user_sentence
         ::= ( KW_DESCRIBE | KW_DESC ) KW_USER name_label
describe_tag_sentence
         ::= ( KW_DESCRIBE | KW_DESC ) KW_TAG name_label
describe_edge_sentence
         ::= ( KW_DESCRIBE | KW_DESC ) KW_EDGE name_label
drop_tag_sentence
         ::= KW_DROP KW_TAG opt_if_exists name_label
drop_edge_sentence
         ::= KW_DROP KW_EDGE opt_if_exists name_label
index_field
         ::= name_label ( L_PAREN INTEGER R_PAREN )?
opt_index_field_list
         ::= ( index_field ( COMMA index_field )* )?
create_tag_index_sentence
         ::= KW_CREATE KW_TAG KW_INDEX opt_if_not_exists name_label KW_ON name_label L_PAREN opt_index_field_list R_PAREN opt_with_index_param_list opt_comment_prop
create_edge_index_sentence
         ::= KW_CREATE KW_EDGE KW_INDEX opt_if_not_exists name_label KW_ON name_label L_PAREN opt_index_field_list R_PAREN opt_with_index_param_list opt_comment_prop
create_fulltext_index_sentence
         ::= KW_CREATE KW_FULLTEXT ( KW_TAG | KW_EDGE ) KW_INDEX name_label KW_ON name_label L_PAREN name_label R_PAREN
drop_fulltext_index_sentence
         ::= KW_DROP KW_FULLTEXT KW_INDEX name_label
comment_prop_assignment
         ::= KW_COMMENT ASSIGN STRING
comment_prop
         ::= KW_COMMENT STRING
opt_comment_prop
         ::= comment_prop?
opt_with_index_param_list
         ::= ( KW_WITH L_PAREN index_param_item ( COMMA index_param_item )* R_PAREN )?
index_param_item
         ::= ( KW_S2_MAX_LEVEL | KW_S2_MAX_CELLS ) ASSIGN legal_integer
drop_tag_index_sentence
         ::= KW_DROP KW_TAG KW_INDEX opt_if_exists name_label
drop_edge_index_sentence
         ::= KW_DROP KW_EDGE KW_INDEX opt_if_exists name_label
describe_tag_index_sentence
         ::= ( KW_DESCRIBE | KW_DESC ) KW_TAG KW_INDEX name_label
describe_edge_index_sentence
         ::= ( KW_DESCRIBE | KW_DESC ) KW_EDGE KW_INDEX name_label
rebuild_tag_index_sentence
         ::= KW_REBUILD KW_TAG KW_INDEX name_label_list?
rebuild_edge_index_sentence
         ::= KW_REBUILD KW_EDGE KW_INDEX name_label_list?
rebuild_fulltext_index_sentence
         ::= KW_REBUILD KW_FULLTEXT KW_INDEX
add_hosts_sentence
         ::= KW_ADD KW_HOSTS host_list ( KW_INTO KW_NEW? KW_ZONE name_label )?
drop_hosts_sentence
         ::= KW_DROP KW_HOSTS host_list
merge_zone_sentence
         ::= KW_MERGE KW_ZONE zone_name_list KW_INTO name_label
drop_zone_sentence
         ::= KW_DROP KW_ZONE name_label
zone_item
         ::= name_label L_PAREN host_list R_PAREN
divide_zone_sentence
         ::= KW_DIVIDE KW_ZONE name_label KW_INTO zone_item+
rename_zone_sentence
         ::= KW_RENAME KW_ZONE name_label KW_TO name_label
desc_zone_sentence
         ::= ( KW_DESCRIBE | KW_DESC ) KW_ZONE name_label
traverse_sentence
         ::= L_PAREN set_sentence R_PAREN
           | go_sentence
           | lookup_sentence
           | group_by_sentence
           | order_by_sentence
           | fetch_sentence
           | find_path_sentence
           | yield_sentence
           | get_subgraph_sentence
           | delete_vertex_sentence
           | delete_tag_sentence
           | delete_edge_sentence
           | show_queries_sentence
           | kill_query_sentence
           | describe_user_sentence
           | unwind_sentence
           | show_sentence
           | kill_session_sentence
piped_sentence
         ::= traverse_sentence ( PIPE ( traverse_sentence | limit_sentence ) )*
set_sentence
         ::= piped_sentence ( ( KW_UNION ( KW_ALL | KW_DISTINCT )? | KW_INTERSECT | KW_MINUS ) piped_sentence )*
assignment_sentence
         ::= VARIABLE ASSIGN set_sentence
insert_vertex_sentence
         ::= KW_INSERT KW_VERTEX opt_if_not_exists opt_ignore_existed_index ( vertex_tag_item ( COMMA vertex_tag_item )* )? KW_VALUES vertex_row_list
vertex_tag_item
         ::= name_label ( L_PAREN prop_list? R_PAREN )?
prop_list
         ::= name_label ( COMMA name_label? )*
vertex_row_list
         ::= vertex_row_item ( COMMA vertex_row_item )*
vertex_row_item
         ::= vid COLON L_PAREN value_list? R_PAREN
value_list
         ::= expression ( COMMA expression? )*
insert_edge_sentence
         ::= KW_INSERT KW_EDGE opt_if_not_exists opt_ignore_existed_index name_label ( L_PAREN prop_list? R_PAREN )? KW_VALUES edge_row_list
edge_row_list
         ::= edge_row_item ( COMMA edge_row_item )*
edge_row_item
         ::= vid R_ARROW vid ( AT rank )? COLON L_PAREN value_list? R_PAREN
rank     ::= unary_integer
update_list
         ::= update_item ( COMMA update_item )*
update_item
         ::= name_label ( DOT name_label )? ASSIGN expression
update_vertex_sentence
         ::= ( KW_UPDATE | KW_UPSERT ) KW_VERTEX ( KW_ON name_label )? vid KW_SET update_list when_clause yield_clause
update_edge_sentence
         ::= ( KW_UPDATE | KW_UPSERT ) KW_EDGE ( vid R_ARROW vid ( AT rank )? KW_OF name_label | KW_ON name_label vid R_ARROW vid ( AT rank )? ) KW_SET update_list when_clause yield_clause
delete_vertex_sentence
         ::= KW_DELETE KW_VERTEX ( vid_list | vid_ref_expression | delete_vertex_with_edge_sentence )
delete_vertex_with_edge_sentence
         ::= ( vid_list | vid_ref_expression ) KW_WITH KW_EDGE
delete_tag_sentence
         ::= KW_DELETE KW_TAG ( name_label_list | STAR ) KW_FROM ( vid_list | vid_ref_expression )
download_sentence
         ::= KW_DOWNLOAD KW_HDFS STRING
ingest_sentence
         ::= KW_INGEST
delete_edge_sentence
         ::= KW_DELETE KW_EDGE name_label ( edge_keys | edge_key_ref )
admin_job_sentence
         ::= KW_SUBMIT KW_JOB ( KW_COMPACT | KW_FLUSH | KW_DOWNLOAD KW_HDFS STRING | KW_INGEST | KW_STATS | KW_BALANCE ( KW_LEADER | KW_DATA ( KW_REMOVE host_list )? ) )
           | KW_SHOW ( KW_JOBS | KW_JOB legal_integer )
           | KW_STOP KW_JOB legal_integer
           | KW_RECOVER KW_JOB integer_list?
show_queries_sentence
         ::= KW_SHOW KW_LOCAL? KW_QUERIES
show_sentence
         ::= KW_SHOW ( KW_HOSTS list_host_type? | KW_SPACES | KW_PARTS integer_list? | KW_PART integer_list | KW_TAGS | KW_EDGES | ( KW_TAG | KW_EDGE ) ( KW_INDEXES ( KW_BY name_label )? | KW_INDEX KW_STATUS ) | KW_USERS | ( KW_ROLES KW_IN | KW_CREATE ( KW_SPACE | ( KW_TAG | KW_EDGE ) KW_INDEX? ) ) name_label | KW_CONFIGS show_config_item | KW_SNAPSHOTS | KW_CHARSET | KW_COLLATION | KW_ZONES | KW_STATS | KW_TEXT KW_SEARCH KW_CLIENTS | KW_FULLTEXT KW_INDEXES | KW_LOCAL? KW_SESSIONS | KW_SESSION legal_integer | KW_META KW_LEADER )
list_host_type
         ::= KW_GRAPH
           | KW_META
           | KW_STORAGE KW_LISTENER?
           | KW_AGENT
config_module_enum
         ::= KW_GRAPH
           | KW_META
           | KW_STORAGE
get_config_item
         ::= ( config_module_enum COLON )? name_label
set_config_item
         ::= ( config_module_enum COLON )? name_label ASSIGN ( expression | L_BRACE update_list R_BRACE )
show_config_item
         ::= config_module_enum?
zone_name_list
         ::= name_label ( COMMA name_label )*
alter_space_sentence
         ::= KW_ALTER KW_SPACE name_label KW_ADD KW_ZONE name_label_list
create_space_sentence
         ::= KW_CREATE KW_SPACE opt_if_not_exists name_label ( ( L_PAREN space_opt_list R_PAREN )? ( KW_ON zone_name_list )? comment_prop_assignment? | KW_AS name_label )
describe_space_sentence
         ::= ( KW_DESCRIBE | KW_DESC ) KW_SPACE name_label
space_opt_list
         ::= space_opt_item ( COMMA space_opt_item? )*
space_opt_item
         ::= ( KW_PARTITION_NUM | KW_REPLICA_FACTOR ) ASSIGN legal_integer
           | ( KW_CHARSET | KW_COLLATE ) ASSIGN name_label
           | KW_VID_TYPE ASSIGN type_spec
drop_space_sentence
         ::= KW_DROP KW_SPACE opt_if_exists name_label
clear_space_sentence
         ::= KW_CLEAR KW_SPACE opt_if_exists name_label
create_user_sentence
         ::= KW_CREATE KW_USER opt_if_not_exists name_label ( KW_WITH KW_PASSWORD STRING )?
alter_user_sentence
         ::= KW_ALTER KW_USER name_label KW_WITH KW_PASSWORD STRING
drop_user_sentence
         ::= KW_DROP KW_USER opt_if_exists name_label
change_password_sentence
         ::= KW_CHANGE KW_PASSWORD name_label KW_FROM STRING KW_TO STRING
role_type_clause
         ::= KW_GOD
           | KW_ADMIN
           | KW_DBA
           | KW_USER
           | KW_GUEST
acl_item_clause
         ::= KW_ROLE? role_type_clause KW_ON name_label
grant_sentence
         ::= KW_GRANT acl_item_clause KW_TO name_label
revoke_sentence
         ::= KW_REVOKE acl_item_clause KW_FROM name_label
get_config_sentence
         ::= KW_GET KW_CONFIGS get_config_item
set_config_sentence
         ::= KW_UPDATE KW_CONFIGS set_config_item
host_list
         ::= host_item ( COMMA host_item? )*
host_item
         ::= ( IPV4 | STRING ) COLON port
port     ::= INTEGER
integer_list
         ::= legal_integer ( COMMA INTEGER? )*
balance_sentence
         ::= KW_BALANCE ( KW_LEADER | KW_DATA ( KW_REMOVE host_list )? )
create_snapshot_sentence
         ::= KW_CREATE KW_SNAPSHOT
drop_snapshot_sentence
         ::= KW_DROP KW_SNAPSHOT name_label
add_listener_sentence
         ::= KW_ADD KW_LISTENER KW_ELASTICSEARCH host_list
remove_listener_sentence
         ::= KW_REMOVE KW_LISTENER KW_ELASTICSEARCH
list_listener_sentence
         ::= KW_SHOW KW_LISTENER
kill_query_sentence
         ::= KW_KILL KW_QUERY L_PAREN query_unique_identifier R_PAREN
kill_session_sentence
         ::= KW_KILL ( KW_SESSIONS | KW_SESSION ) expression
query_unique_identifier_value
         ::= legal_integer
           | input_prop_expression
query_unique_identifier
         ::= ( KW_PLAN ( ASSIGN query_unique_identifier_value COMMA KW_SESSION )? | KW_SESSION ASSIGN query_unique_identifier_value COMMA KW_PLAN ) ASSIGN query_unique_identifier_value
mutate_sentence
         ::= insert_vertex_sentence
           | insert_edge_sentence
           | update_vertex_sentence
           | update_edge_sentence
           | download_sentence
           | ingest_sentence
           | admin_job_sentence
maintain_sentence
         ::= create_space_sentence
           | describe_space_sentence
           | alter_space_sentence
           | drop_space_sentence
           | clear_space_sentence
           | create_tag_sentence
           | create_edge_sentence
           | alter_tag_sentence
           | alter_edge_sentence
           | describe_tag_sentence
           | describe_edge_sentence
           | drop_tag_sentence
           | drop_edge_sentence
           | create_tag_index_sentence
           | create_edge_index_sentence
           | create_fulltext_index_sentence
           | drop_tag_index_sentence
           | drop_edge_index_sentence
           | drop_fulltext_index_sentence
           | describe_tag_index_sentence
           | describe_edge_index_sentence
           | rebuild_tag_index_sentence
           | rebuild_edge_index_sentence
           | rebuild_fulltext_index_sentence
           | add_hosts_sentence
           | drop_hosts_sentence
           | merge_zone_sentence
           | drop_zone_sentence
           | divide_zone_sentence
           | rename_zone_sentence
           | desc_zone_sentence
           | create_user_sentence
           | alter_user_sentence
           | drop_user_sentence
           | change_password_sentence
           | grant_sentence
           | revoke_sentence
           | get_config_sentence
           | set_config_sentence
           | balance_sentence
           | add_listener_sentence
           | remove_listener_sentence
           | list_listener_sentence
           | create_snapshot_sentence
           | drop_snapshot_sentence
           | sign_in_service_sentence
           | sign_out_service_sentence
sentence ::= maintain_sentence
           | use_sentence
           | set_sentence
           | assignment_sentence
           | mutate_sentence
           | match_sentence ( ( KW_UNION ( KW_ALL | KW_DISTINCT )? | KW_INTERSECT | KW_MINUS ) match_sentence )*
seq_sentences
         ::= sentence? ( SEMICOLON sentence? )*
	   
// Tokens	   

//\("[^"]+"\)\s+{ return TokenType::\([^;]+\); }
 /* Reserved keyword */
KW_GO ::= "GO"
KW_AS ::= "AS"
KW_TO ::= "TO"
KW_OR ::= "OR"
KW_AND ::= "AND"
KW_XOR ::= "XOR"
KW_USE ::= "USE"
KW_SET ::= "SET"
KW_LIST ::= "LIST"
KW_MAP ::= "MAP"
KW_FROM ::= "FROM"
KW_WHERE ::= "WHERE"
KW_MATCH ::= "MATCH"
KW_INSERT ::= "INSERT"
KW_YIELD ::= "YIELD"
KW_RETURN ::= "RETURN"
KW_DESCRIBE ::= "DESCRIBE"
KW_DESC ::= "DESC"
KW_VERTEX ::= "VERTEX"
KW_VERTICES ::= "VERTICES"
KW_EDGE ::= "EDGE"
KW_EDGES ::= "EDGES"
KW_UPDATE ::= "UPDATE"
KW_UPSERT ::= "UPSERT"
KW_WHEN ::= "WHEN"
KW_DELETE ::= "DELETE"
KW_FIND ::= "FIND"
KW_PATH ::= "PATH"
KW_LOOKUP ::= "LOOKUP"
KW_ALTER ::= "ALTER"
KW_STEPS ::= "STEPS"
KW_STEPS ::= "STEP"
KW_OVER ::= "OVER"
KW_UPTO ::= "UPTO"
KW_REVERSELY ::= "REVERSELY"
KW_INDEX ::= "INDEX"
KW_INDEXES ::= "INDEXES"
KW_REBUILD ::= "REBUILD"
KW_BOOL ::= "BOOL"
KW_INT8 ::= "INT8"
KW_INT16 ::= "INT16"
KW_INT32 ::= "INT32"
KW_INT64 ::= "INT64"
KW_INT ::= "INT"
KW_FLOAT ::= "FLOAT"
KW_DOUBLE ::= "DOUBLE"
KW_STRING ::= "STRING"
KW_FIXED_STRING ::= "FIXED_STRING"
KW_TIMESTAMP ::= "TIMESTAMP"
KW_DATE ::= "DATE"
KW_TIME ::= "TIME"
KW_DATETIME ::= "DATETIME"
KW_TAG ::= "TAG"
KW_TAGS ::= "TAGS"
KW_UNION ::= "UNION"
KW_INTERSECT ::= "INTERSECT"
KW_MINUS ::= "MINUS"
KW_NO ::= "NO"
KW_OVERWRITE ::= "OVERWRITE"
KW_SHOW ::= "SHOW"
KW_ADD ::= "ADD"
KW_CREATE ::= "CREATE"
KW_DROP ::= "DROP"
KW_REMOVE ::= "REMOVE"
KW_IF ::= "IF"
KW_NOT ::= "NOT"
KW_EXISTS ::= "EXISTS"
KW_IGNORE_EXISTED_INDEX ::= "IGNORE_EXISTED_INDEX"
KW_WITH ::= "WITH"
KW_CHANGE ::= "CHANGE"
KW_GRANT ::= "GRANT"
KW_REVOKE ::= "REVOKE"
KW_ON ::= "ON"
KW_BY ::= "BY"
KW_IN ::= "IN"
//KW_NOT_IN ::= {NOT_IN}
KW_DOWNLOAD ::= "DOWNLOAD"
KW_GET ::= "GET"
KW_OF ::= "OF"
KW_ORDER ::= "ORDER"
KW_INGEST ::= "INGEST"
KW_COMPACT ::= "COMPACT"
KW_FLUSH ::= "FLUSH"
KW_SUBMIT ::= "SUBMIT"
KW_ASC ::= "ASC"
KW_ASCENDING ::= "ASCENDING"
KW_DESCENDING ::= "DESCENDING"
KW_DISTINCT ::= "DISTINCT"
KW_FETCH ::= "FETCH"
KW_PROP ::= "PROP"
KW_BALANCE ::= "BALANCE"
KW_STOP ::= "STOP"
KW_LIMIT ::= "LIMIT"
KW_OFFSET ::= "OFFSET"
KW_IS ::= "IS"
KW_NULL ::= "NULL"
KW_RECOVER ::= "RECOVER"
KW_EXPLAIN ::= "EXPLAIN"
KW_PROFILE ::= "PROFILE"
KW_FORMAT ::= "FORMAT"
KW_CASE ::= "CASE"
KW_ACROSS ::= "ACROSS"

 /**
  * TODO(dutor) Manage the dynamic allocated objects with an object pool,
  *     so that we ease the operations such as expression rewriting, associating
  *     the original text for an unreserved keywords, etc.
  *
  */
 /* Unreserved keyword */
KW_HOST ::= "HOST"
KW_HOSTS ::= "HOSTS"
KW_SPACE ::= "SPACE"
KW_SPACES ::= "SPACES"
KW_VALUE ::= "VALUE"
KW_VALUES ::= "VALUES"
KW_USER ::= "USER"
KW_USERS ::= "USERS"
KW_PASSWORD ::= "PASSWORD"
KW_ROLE ::= "ROLE"
KW_ROLES ::= "ROLES"
KW_GOD ::= "GOD"
KW_ADMIN ::= "ADMIN"
KW_DBA ::= "DBA"
KW_GUEST ::= "GUEST"
KW_GROUP ::= "GROUP"
KW_PARTITION_NUM ::= "PARTITION_NUM"
KW_REPLICA_FACTOR ::= "REPLICA_FACTOR"
KW_VID_TYPE ::= "VID_TYPE"
KW_CHARSET ::= "CHARSET"
KW_COLLATE ::= "COLLATE"
KW_COLLATION ::= "COLLATION"
KW_ATOMIC_EDGE ::= "ATOMIC_EDGE"
KW_ALL ::= "ALL"
KW_ANY ::= "ANY"
KW_SINGLE ::= "SINGLE"
KW_NONE ::= "NONE"
KW_REDUCE ::= "REDUCE"
KW_LEADER ::= "LEADER"
KW_UUID ::= "UUID"
KW_DATA ::= "DATA"
KW_SNAPSHOT ::= "SNAPSHOT"
KW_SNAPSHOTS ::= "SNAPSHOTS"
KW_ACCOUNT ::= "ACCOUNT"
KW_JOBS ::= "JOBS"
KW_JOB ::= "JOB"
KW_BIDIRECT ::= "BIDIRECT"
KW_STATS ::= "STATS"
KW_STATUS ::= "STATUS"
KW_FORCE ::= "FORCE"
KW_PART ::= "PART"
KW_PARTS ::= "PARTS"
KW_DEFAULT ::= "DEFAULT"
KW_HDFS ::= "HDFS"
KW_CONFIGS ::= "CONFIGS"
KW_TTL_DURATION ::= "TTL_DURATION"
KW_TTL_COL ::= "TTL_COL"
KW_GRAPH ::= "GRAPH"
KW_META ::= "META"
KW_AGENT ::= "AGENT"
KW_STORAGE ::= "STORAGE"
KW_SHORTEST ::= "SHORTEST"
KW_NOLOOP ::= "NOLOOP"
KW_SHORTESTPATH ::= "SHORTESTPATH"
KW_ALLSHORTESTPATHS ::= "AllSHORTESTPATHS"
KW_OUT ::= "OUT"
KW_BOTH ::= "BOTH"
KW_SUBGRAPH ::= "SUBGRAPH"
KW_CONTAINS ::= "CONTAINS"
//{NOT_CONTAINS}              { return TokenType::KW_NOT_CONTAINS; }
KW_STARTS ::= "STARTS"
//{STARTS_WITH}               { return TokenType::KW_STARTS_WITH;}
//{NOT_STARTS_WITH}           { return TokenType::KW_NOT_STARTS_WITH;}
KW_ENDS ::= "ENDS"
//{ENDS_WITH}                 { return TokenType::KW_ENDS_WITH;}
//{NOT_ENDS_WITH}             { return TokenType::KW_NOT_ENDS_WITH;}
//{IS_NULL}                   { return TokenType::KW_IS_NULL;}
//{IS_NOT_NULL}               { return TokenType::KW_IS_NOT_NULL;}
//{IS_EMPTY}                  { return TokenType::KW_IS_EMPTY;}
//{IS_NOT_EMPTY}              { return TokenType::KW_IS_NOT_EMPTY;}
KW_UNWIND ::= "UNWIND" 
KW_SKIP ::= "SKIP"
KW_OPTIONAL ::= "OPTIONAL"
KW_THEN ::= "THEN"
KW_ELSE ::= "ELSE"
KW_END ::= "END"
KW_GROUPS ::= "GROUPS"
KW_ZONE ::= "ZONE"
KW_ZONES ::= "ZONES"
KW_INTO ::= "INTO"
KW_NEW ::= "NEW"
KW_LISTENER ::= "LISTENER"
KW_ELASTICSEARCH ::= "ELASTICSEARCH"
KW_HTTP ::= "HTTP"
KW_HTTPS ::= "HTTPS"
KW_FULLTEXT ::= "FULLTEXT"
KW_AUTO ::= "AUTO"
KW_FUZZY ::= "FUZZY"
KW_PREFIX ::= "PREFIX"
KW_REGEXP ::= "REGEXP"
KW_WILDCARD ::= "WILDCARD"
KW_TEXT ::= "TEXT"
KW_SEARCH ::= "SEARCH"
KW_CLIENTS ::= "CLIENTS"
KW_SIGN ::= "SIGN"
KW_SERVICE ::= "SERVICE"
KW_TEXT_SEARCH ::= "TEXT_SEARCH"
KW_RESET ::= "RESET"
KW_PLAN ::= "PLAN"
KW_COMMENT ::= "COMMENT"
KW_S2_MAX_LEVEL ::= "S2_MAX_LEVEL"
KW_S2_MAX_CELLS ::= "S2_MAX_CELLS"
KW_LOCAL ::= "LOCAL"
KW_SESSIONS ::= "SESSIONS"
KW_SESSION ::= "SESSION"
KW_SAMPLE ::= "SAMPLE"
KW_QUERIES ::= "QUERIES"
KW_QUERY ::= "QUERY"
KW_KILL ::= "KILL"
KW_TOP ::= "TOP"
KW_GEOGRAPHY ::= "GEOGRAPHY"
KW_POINT ::= "POINT"
KW_LINESTRING ::= "LINESTRING"
KW_POLYGON ::= "POLYGON"
KW_DURATION ::= "DURATION"
KW_MERGE ::= "MERGE"
KW_RENAME ::= "RENAME"
KW_DIVIDE ::= "DIVIDE"
KW_CLEAR ::= "CLEAR"

BOOL ::= "TRUE" | "FALSE"

DOT ::= "."
DOT_DOT ::= ".."
COMMA ::= ","
COLON ::= ":"
SEMICOLON ::= ";"
AT ::= "@"
QM ::= "?"

PLUS ::= "+"
MINUS ::= "-"
STAR ::= "*"
DIV ::= "/"
MOD ::= "%"
NOT ::= "!"

LT ::= "<"
LE ::= "<="
GT ::= ">"
GE ::= ">="
EQ ::= "=="
NE ::= "!="
NE ::= "<>"
REG ::= "=~"

PIPE ::= "|"

ASSIGN ::= "="

L_PAREN ::= "("
R_PAREN ::= ")"
L_BRACKET ::= "["
R_BRACKET ::= "]"
L_BRACE ::= "{"
R_BRACE ::= "}"

L_ARROW ::= "<-"
R_ARROW ::= "->"

MINUS_L_BRACKET ::= "-["
R_BRACKET_MINUS ::= "]-"
L_ARROW_L_BRACKET ::= "<-["
R_BRACKET_R_ARROW ::= "]->"
MINUS_MINUS ::= "--"
MINUS_R_ARROW ::= "-->"
L_ARROW_MINUS ::= "<--"
L_ARROW_R_ARROW ::= "<-->"

ID_PROP ::= "_id"
TYPE_PROP ::= "_type"
SRC_ID_PROP ::= "_src"
DST_ID_PROP ::= "_dst"
RANK_PROP ::= "_rank"
DST_REF ::= "$$"
SRC_REF ::= "$^"
INPUT_REF ::= "$-"
@mingodad mingodad added the type/feature req Type: feature request label May 22, 2023
@wey-gu
Copy link
Contributor

wey-gu commented May 23, 2023

Dear @mingodad

This is mind-blowing to me, thanks!!!

Screenshot 2023-05-23 at 10 54 49
Screenshot 2023-05-23 at 10 54 05
Screenshot 2023-05-23 at 10 53 52

Could we convert the .yy file to the parsable format in a program way? What is the expected change/proposal to better help leverage the diagram?

@mingodad
Copy link
Author

mingodad commented May 23, 2023

Hello @wey-gu for a better view probably reorder the rules from top-down to bottom-up (for presentation only) , I just moved manually the start rule to the top to make easy start navigating the grammar:

sentences
         ::= seq_sentences
           | ( KW_EXPLAIN | KW_PROFILE ) ( KW_FORMAT ASSIGN STRING )? ( sentence | L_BRACE seq_sentences R_BRACE ) SEMICOLON*

There is this download https://www.bottlecaps.de/rr/download/rr-2.0-java11.zip to convert the EBNF to railroad diagram offline.

I also added the ability to dump the EBNF from the .yy grammar extending bison here https://github.com/mingodad/lalr-parser-test , but the tokens from the .ll lexer are extracted manually with the help of search and replace with regular expressions on an editor.

Probably because the grammar and lexer doesn't change too frequently and when they change usually it's small changes then probably update/enhance manually the EBNF can be an option.

@wey-gu
Copy link
Contributor

wey-gu commented May 29, 2023

Got it, make sense, it won't change that often, even not that software-defined, would work and benefit a lot! Thanks!

@whitewum we could leverage what @mingodad helped provide to add a railroad diagram to our documentation per clause chapters.

ref: https://www.cockroachlabs.com/docs/stable/select-clause.html

@wey-gu
Copy link
Contributor

wey-gu commented May 29, 2023

BTW @mingodad the ebnf above was generated by:

right?
Thanks!

@mingodad
Copy link
Author

I've just added parser.yy to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible online editor/tester (select Nebula parser from Examples then click Parse to see a parser tree for the content in Input source editor).

I hope it can help debug/develop/test/document this project grammar !

Any feedback is welcome !

@wey-gu
Copy link
Contributor

wey-gu commented Sep 29, 2023

Amazing work @mingodad !!
🤯

@yixinglu @dutor @xtcyclist @czpmango @HarrisChu

@wey-gu
Copy link
Contributor

wey-gu commented Nov 21, 2023

ping @ChrisChen2023 , we could leverage this in docs to auto-gen railroad diagrams :)

@mingodad
Copy link
Author

Yes there is an option to generate it in "Generate" select "EBNF grammar and copy to clipboard" then click "Parse", the token are not included by default (some manual copy/paste/search/replace) needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature req Type: feature request
Projects
None yet
Development

No branches or pull requests

2 participants