-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
parser.yy
4085 lines (3800 loc) · 128 KB
/
parser.yy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Bison options
%language "C++"
%skeleton "lalr1.cc"
%no-lines
%locations
%define api.namespace { nebula }
%define api.parser.class { GraphParser }
// Parameters of scanner and parser
%lex-param { nebula::GraphScanner& scanner }
%parse-param { nebula::GraphScanner& scanner }
%parse-param { std::string &errmsg }
%parse-param { nebula::Sentence** sentences }
%parse-param { nebula::graph::QueryContext* qctx }
%code requires {
#include <iostream>
#include <sstream>
#include <string>
#include <cstddef>
#include "parser/ExplainSentence.h"
#include "parser/SequentialSentences.h"
#include "interface/gen-cpp2/meta_types.h"
#include "common/expression/AttributeExpression.h"
#include "common/expression/LabelAttributeExpression.h"
#include "common/expression/VariableExpression.h"
#include "common/expression/CaseExpression.h"
#include "common/expression/TextSearchExpression.h"
#include "common/expression/PredicateExpression.h"
#include "common/expression/ListComprehensionExpression.h"
#include "common/expression/AggregateExpression.h"
#include "common/function/FunctionManager.h"
#include "common/expression/ReduceExpression.h"
#include "graph/util/ParserUtil.h"
#include "graph/util/ExpressionUtils.h"
#include "graph/context/QueryContext.h"
#include "graph/util/SchemaUtil.h"
namespace nebula {
class GraphScanner;
}
static constexpr size_t MAX_ABS_INTEGER = 9223372036854775808ULL;
static constexpr size_t kCommentLengthLimit = 256;
using namespace nebula;
}
%code {
#include "GraphScanner.h"
static int yylex(nebula::GraphParser::semantic_type* yylval,
nebula::GraphParser::location_type *yylloc,
nebula::GraphScanner& scanner);
void ifOutOfRange(const int64_t input,
const nebula::GraphParser::location_type& loc);
}
// Define types of semantic values
%union {
bool boolval;
int64_t intval;
double doubleval;
std::string *strval;
nebula::meta::cpp2::GeoShape geo_shape;
nebula::meta::cpp2::ColumnTypeDef *type;
nebula::Expression *expr;
nebula::Sentence *sentence;
nebula::Sentence *sentences;
nebula::SequentialSentences *seq_sentences;
nebula::ExplainSentence *explain_sentence;
nebula::ColumnProperty *col_property;
nebula::ColumnProperties *col_properties;
nebula::ColumnSpecification *colspec;
nebula::ColumnSpecificationList *colspeclist;
nebula::ColumnNameList *column_name_list;
nebula::StepClause *step_clause;
nebula::StepClause *find_path_upto_clause;
nebula::FromClause *from_clause;
nebula::ToClause *to_clause;
nebula::VertexIDList *vid_list;
nebula::NameLabelList *name_label_list;
nebula::OverEdge *over_edge;
nebula::OverEdges *over_edges;
nebula::OverClause *over_clause;
nebula::WhereClause *where_clause;
nebula::WhereClause *lookup_where_clause;
nebula::WhenClause *when_clause;
nebula::YieldClause *yield_clause;
nebula::YieldClause *group_by_yield_clause;
nebula::YieldColumns *yield_columns;
nebula::YieldColumn *yield_column;
nebula::TruncateClause *truncate_clause;
nebula::VertexTagList *vertex_tag_list;
nebula::VertexTagItem *vertex_tag_item;
nebula::PropertyList *prop_list;
nebula::ValueList *value_list;
nebula::VertexRowList *vertex_row_list;
nebula::VertexRowItem *vertex_row_item;
nebula::EdgeRowList *edge_row_list;
nebula::EdgeRowItem *edge_row_item;
nebula::UpdateList *update_list;
nebula::UpdateItem *update_item;
nebula::ArgumentList *argument_list;
nebula::SpaceOptList *space_opt_list;
nebula::SpaceOptItem *space_opt_item;
nebula::AlterSchemaOptList *alter_schema_opt_list;
nebula::AlterSchemaOptItem *alter_schema_opt_item;
nebula::RoleTypeClause *role_type_clause;
nebula::AclItemClause *acl_item_clause;
nebula::SchemaPropList *create_schema_prop_list;
nebula::SchemaPropItem *create_schema_prop_item;
nebula::SchemaPropList *alter_schema_prop_list;
nebula::SchemaPropItem *alter_schema_prop_item;
nebula::IndexParamList *index_param_list;
nebula::IndexParamItem *index_param_item;
nebula::OrderFactor *order_factor;
nebula::OrderFactors *order_factors;
nebula::meta::cpp2::ConfigModule config_module;
nebula::meta::cpp2::ListHostType list_host_type;
nebula::ConfigRowItem *config_row_item;
nebula::EdgeKey *edge_key;
nebula::EdgeKeys *edge_keys;
nebula::EdgeKeyRef *edge_key_ref;
nebula::GroupClause *group_clause;
nebula::HostList *host_list;
nebula::HostAddr *host_item;
nebula::ZoneNameList *zone_name_list;
nebula::ZoneItem *zone_item;
nebula::ZoneItemList *zone_item_list;
std::vector<int32_t> *integer_list;
nebula::InBoundClause *in_bound_clause;
nebula::OutBoundClause *out_bound_clause;
nebula::BothInOutClause *both_in_out_clause;
ExpressionList *expression_list;
MapItemList *map_item_list;
MatchPath *match_path;
MatchPathList *match_path_list;
MatchNode *match_node;
MatchNodeLabel *match_node_label;
MatchNodeLabelList *match_node_label_list;
MatchEdge *match_edge;
MatchEdgeProp *match_edge_prop;
MatchEdgeTypeList *match_edge_type_list;
MatchReturnItems *match_return_items;
MatchReturn *match_return;
ReadingClause *reading_clause;
MatchClauseList *match_clause_list;
MatchStepRange *match_step_range;
nebula::meta::cpp2::IndexFieldDef *index_field;
nebula::IndexFieldList *index_field_list;
CaseList *case_list;
nebula::TextSearchArgument *text_search_argument;
nebula::TextSearchArgument *base_text_search_argument;
nebula::TextSearchArgument *fuzzy_text_search_argument;
nebula::meta::cpp2::ServiceClient *service_client_item;
nebula::ServiceClientList *service_client_list;
nebula::QueryUniqueIdentifier *query_unique_identifier;
}
/* destructors */
%destructor {} <sentences>
// Expression related memory will be managed by object pool
%destructor {} <expr> <argument_list> <case_list> <expression_list> <map_item_list>
%destructor {} <text_search_argument> <base_text_search_argument> <fuzzy_text_search_argument>
%destructor {} <boolval> <intval> <doubleval> <type> <config_module> <integer_list> <list_host_type> <geo_shape>
%destructor { delete $$; } <*>
/* keywords */
%token KW_BOOL KW_INT8 KW_INT16 KW_INT32 KW_INT64 KW_INT KW_FLOAT KW_DOUBLE
%token KW_STRING KW_FIXED_STRING KW_TIMESTAMP KW_DATE KW_TIME KW_DATETIME KW_DURATION
%token KW_GO KW_AS KW_TO KW_USE KW_SET KW_FROM KW_WHERE KW_ALTER
%token KW_MATCH KW_INSERT KW_VALUE KW_VALUES KW_YIELD KW_RETURN KW_CREATE KW_VERTEX KW_VERTICES KW_IGNORE_EXISTED_INDEX
%token KW_EDGE KW_EDGES KW_STEPS KW_OVER KW_UPTO KW_REVERSELY KW_SPACE KW_DELETE KW_FIND
%token KW_TAG KW_TAGS KW_UNION KW_INTERSECT KW_MINUS
%token KW_NO KW_OVERWRITE KW_IN KW_DESCRIBE KW_DESC KW_SHOW KW_HOST KW_HOSTS KW_PART KW_PARTS KW_ADD
%token KW_PARTITION_NUM KW_REPLICA_FACTOR KW_CHARSET KW_COLLATE KW_COLLATION KW_VID_TYPE
%token KW_ATOMIC_EDGE
%token KW_COMMENT KW_S2_MAX_LEVEL KW_S2_MAX_CELLS
%token KW_DROP KW_CLEAR KW_REMOVE KW_SPACES KW_INGEST KW_INDEX KW_INDEXES
%token KW_IF KW_NOT KW_EXISTS KW_WITH
%token KW_BY KW_DOWNLOAD KW_HDFS KW_UUID KW_CONFIGS KW_FORCE
%token KW_GET KW_DECLARE KW_GRAPH KW_META KW_STORAGE KW_AGENT
%token KW_TTL KW_TTL_DURATION KW_TTL_COL KW_DATA KW_STOP
%token KW_FETCH KW_PROP KW_UPDATE KW_UPSERT KW_WHEN
%token KW_ORDER KW_ASC KW_LIMIT KW_SAMPLE KW_OFFSET KW_ASCENDING KW_DESCENDING
%token KW_DISTINCT KW_ALL KW_OF
%token KW_BALANCE KW_LEADER KW_RESET KW_PLAN
%token KW_SHORTEST KW_PATH KW_NOLOOP KW_SHORTESTPATH KW_ALLSHORTESTPATHS
%token KW_IS KW_NULL KW_DEFAULT
%token KW_SNAPSHOT KW_SNAPSHOTS KW_LOOKUP
%token KW_JOBS KW_JOB KW_RECOVER KW_FLUSH KW_COMPACT KW_REBUILD KW_SUBMIT KW_STATS KW_STATUS
%token KW_BIDIRECT
%token KW_USER KW_USERS KW_ACCOUNT
%token KW_PASSWORD KW_CHANGE KW_ROLE KW_ROLES
%token KW_GOD KW_ADMIN KW_DBA KW_GUEST KW_GRANT KW_REVOKE KW_ON
%token KW_OUT KW_BOTH KW_SUBGRAPH KW_ACROSS
%token KW_EXPLAIN KW_PROFILE KW_FORMAT
%token KW_CONTAINS
%token KW_STARTS KW_ENDS
%token KW_UNWIND KW_SKIP KW_OPTIONAL
%token KW_CASE KW_THEN KW_ELSE KW_END
%token KW_GROUP KW_ZONE KW_GROUPS KW_ZONES KW_INTO KW_NEW
%token KW_LISTENER KW_ELASTICSEARCH KW_FULLTEXT KW_HTTPS KW_HTTP
%token KW_AUTO KW_FUZZY KW_PREFIX KW_REGEXP KW_WILDCARD
%token KW_TEXT KW_SEARCH KW_CLIENTS KW_SIGN KW_SERVICE KW_TEXT_SEARCH
%token KW_ANY KW_SINGLE KW_NONE
%token KW_REDUCE
%token KW_LOCAL
%token KW_SESSIONS KW_SESSION
%token KW_KILL KW_QUERY KW_QUERIES KW_TOP
%token KW_GEOGRAPHY KW_POINT KW_LINESTRING KW_POLYGON
%token KW_LIST KW_MAP
%token KW_MERGE KW_DIVIDE KW_RENAME
/* symbols */
%token L_PAREN R_PAREN L_BRACKET R_BRACKET L_BRACE R_BRACE COMMA
MINUS_L_BRACKET R_BRACKET_MINUS L_ARROW_L_BRACKET R_BRACKET_R_ARROW PIPE
MINUS_MINUS MINUS_R_ARROW L_ARROW_MINUS L_ARROW_R_ARROW ASSIGN DOT DOT_DOT
COLON QM SEMICOLON L_ARROW R_ARROW AT ID_PROP TYPE_PROP
SRC_ID_PROP DST_ID_PROP RANK_PROP INPUT_REF DST_REF SRC_REF
/* token type specification */
%token <boolval> BOOL
%token <intval> INTEGER
%token <doubleval> DOUBLE
%token <strval> STRING VARIABLE LABEL IPV4
%type <strval> name_label unreserved_keyword predicate_name
%type <expr> expression expression_internal
%type <expr> property_expression
%type <expr> vertex_prop_expression
%type <expr> edge_prop_expression
%type <expr> input_prop_expression
%type <expr> var_prop_expression
%type <expr> generic_case_expression
%type <expr> conditional_expression
%type <expr> vid_ref_expression
%type <expr> vid
%type <expr> function_call_expression
%type <expr> uuid_expression
%type <expr> list_expression
%type <expr> set_expression
%type <expr> map_expression
%type <expr> container_expression
%type <expr> subscript_expression
%type <expr> subscript_range_expression
%type <expr> attribute_expression
%type <expr> case_expression
%type <expr> predicate_expression
%type <expr> list_comprehension_expression
%type <expr> reduce_expression
%type <expr> compound_expression
%type <expr> text_search_expression
%type <expr> constant_expression
%type <expr> query_unique_identifier_value
%type <expr> match_path_pattern_expression
%type <expr> parenthesized_expression
%type <argument_list> argument_list opt_argument_list
%type <geo_shape> geo_shape_type
%type <type> type_spec
%type <step_clause> step_clause
%type <from_clause> from_clause
%type <vid_list> vid_list
%type <over_edge> over_edge
%type <over_edges> over_edges
%type <over_clause> over_clause
%type <where_clause> where_clause
%type <lookup_where_clause> lookup_where_clause
%type <when_clause> when_clause
%type <truncate_clause> truncate_clause
%type <yield_clause> yield_clause group_by_yield_clause
%type <yield_columns> yield_columns
%type <yield_column> yield_column
%type <vertex_tag_list> vertex_tag_list
%type <vertex_tag_item> vertex_tag_item
%type <prop_list> prop_list
%type <value_list> value_list
%type <vertex_row_list> vertex_row_list
%type <vertex_row_item> vertex_row_item
%type <edge_row_list> edge_row_list
%type <edge_row_item> edge_row_item
%type <update_list> update_list
%type <update_item> update_item
%type <space_opt_list> space_opt_list
%type <space_opt_item> space_opt_item
%type <alter_schema_opt_list> alter_schema_opt_list
%type <alter_schema_opt_item> alter_schema_opt_item
%type <create_schema_prop_list> create_schema_prop_list opt_create_schema_prop_list
%type <create_schema_prop_item> create_schema_prop_item
%type <alter_schema_prop_list> alter_schema_prop_list
%type <alter_schema_prop_item> alter_schema_prop_item
%type <index_param_list> opt_with_index_param_list index_param_list
%type <index_param_item> index_param_item
%type <order_factor> order_factor
%type <order_factors> order_factors
%type <config_module> config_module_enum
%type <list_host_type> list_host_type
%type <config_row_item> show_config_item get_config_item set_config_item
%type <edge_key> edge_key
%type <edge_keys> edge_keys
%type <edge_key_ref> edge_key_ref
%type <to_clause> to_clause
%type <find_path_upto_clause> find_path_upto_clause
%type <group_clause> group_clause
%type <host_list> host_list
%type <host_item> host_item
%type <zone_item> zone_item
%type <zone_item_list> zone_item_list
%type <integer_list> integer_list
%type <in_bound_clause> in_bound_clause
%type <out_bound_clause> out_bound_clause
%type <both_in_out_clause> both_in_out_clause
%type <expression_list> expression_list opt_expression_list
%type <map_item_list> map_item_list opt_map_item_list
%type <case_list> when_then_list
%type <expr> case_condition
%type <expr> case_default
%type <match_path> match_path_pattern match_relationships_pattern
%type <match_path> match_path
%type <match_path_list> match_path_list
%type <match_node> match_node
%type <match_node_label> match_node_label
%type <match_node_label_list> match_node_label_list
%type <match_edge> match_edge
%type <match_edge_prop> match_edge_prop
%type <match_return_items> match_return_items
%type <match_return> match_return
%type <expr> match_skip
%type <expr> match_limit
%type <strval> match_alias
%type <match_edge_type_list> match_edge_type_list
%type <match_edge_type_list> opt_match_edge_type_list
%type <reading_clause> unwind_clause with_clause match_clause reading_clause
%type <match_clause_list> reading_clauses reading_with_clause reading_with_clauses
%type <match_step_range> match_step_range
%type <order_factors> match_order_by
%type <text_search_argument> text_search_argument
%type <base_text_search_argument> base_text_search_argument
%type <fuzzy_text_search_argument> fuzzy_text_search_argument
%type <service_client_item> service_client_item
%type <service_client_list> service_client_list
%type <intval> legal_integer unary_integer rank port
%type <strval> comment_prop_assignment comment_prop opt_comment_prop
%type <col_property> column_property
%type <col_properties> column_properties
%type <colspec> column_spec
%type <colspeclist> column_spec_list
%type <column_name_list> column_name_list
%type <zone_name_list> zone_name_list
%type <role_type_clause> role_type_clause
%type <acl_item_clause> acl_item_clause
%type <name_label_list> name_label_list
%type <index_field> index_field
%type <index_field_list> index_field_list opt_index_field_list
%type <query_unique_identifier> query_unique_identifier
%type <sentence> maintain_sentence
%type <sentence> create_space_sentence describe_space_sentence drop_space_sentence clear_space_sentence alter_space_sentence
%type <sentence> create_tag_sentence create_edge_sentence
%type <sentence> alter_tag_sentence alter_edge_sentence
%type <sentence> drop_tag_sentence drop_edge_sentence
%type <sentence> describe_tag_sentence describe_edge_sentence
%type <sentence> create_tag_index_sentence create_edge_index_sentence create_fulltext_index_sentence
%type <sentence> drop_tag_index_sentence drop_edge_index_sentence drop_fulltext_index_sentence
%type <sentence> describe_tag_index_sentence describe_edge_index_sentence
%type <sentence> rebuild_tag_index_sentence rebuild_edge_index_sentence rebuild_fulltext_index_sentence
%type <sentence> add_hosts_sentence drop_hosts_sentence
%type <sentence> drop_zone_sentence desc_zone_sentence
%type <sentence> merge_zone_sentence divide_zone_sentence rename_zone_sentence
%type <sentence> create_snapshot_sentence drop_snapshot_sentence
%type <sentence> add_listener_sentence remove_listener_sentence list_listener_sentence
%type <sentence> admin_job_sentence
%type <sentence> create_user_sentence alter_user_sentence drop_user_sentence change_password_sentence describe_user_sentence
%type <sentence> show_queries_sentence kill_query_sentence kill_session_sentence
%type <sentence> show_sentence
%type <sentence> mutate_sentence
%type <sentence> insert_vertex_sentence insert_edge_sentence
%type <sentence> delete_vertex_sentence delete_edge_sentence delete_tag_sentence delete_vertex_with_edge_sentence
%type <sentence> update_vertex_sentence update_edge_sentence
%type <sentence> download_sentence ingest_sentence
%type <sentence> traverse_sentence unwind_sentence
%type <sentence> go_sentence match_sentence lookup_sentence find_path_sentence get_subgraph_sentence
%type <sentence> group_by_sentence order_by_sentence limit_sentence
%type <sentence> fetch_sentence fetch_vertices_sentence fetch_edges_sentence
%type <sentence> set_sentence piped_sentence assignment_sentence match_sentences
%type <sentence> yield_sentence use_sentence
%type <sentence> grant_sentence revoke_sentence
%type <sentence> set_config_sentence get_config_sentence balance_sentence
%type <sentence> sentence
%type <seq_sentences> seq_sentences
%type <explain_sentence> explain_sentence
%type <sentences> sentences
%type <sentence> sign_in_service_sentence sign_out_service_sentence
%type <boolval> opt_if_not_exists
%type <boolval> opt_if_exists
%type <boolval> opt_with_properties
%type <boolval> opt_ignore_existed_index
// Define precedence and associativity of tokens.
// Associativity:
// The associativity of an operator op determines how repeated uses of the operator nest:
// whether ‘x op y op z’ is parsed by grouping x with y first or by grouping y with z first.
// %left specifies left-associativity (grouping x with y first) and %right specifies right-associativity (grouping y with z first).
// %nonassoc specifies no associativity, which means that ‘x op y op z’ is considered a syntax error.
//
// Precedence:
// The precedence of an operator determines how it nests with other operators.
// All the tokens declared in a single precedence declaration have equal precedence and nest together according to their associativity.
// When two tokens declared in different precedence declarations associate, the one declared later has the higher precedence and is grouped first.
%left QM COLON
%left KW_OR KW_XOR
%left KW_AND
%right KW_NOT
%left EQ NE LT LE GT GE REG KW_IN KW_NOT_IN KW_CONTAINS KW_NOT_CONTAINS KW_STARTS_WITH KW_ENDS_WITH KW_NOT_STARTS_WITH KW_NOT_ENDS_WITH KW_IS_NULL KW_IS_NOT_NULL KW_IS_EMPTY KW_IS_NOT_EMPTY
%nonassoc DUMMY_LOWER_THAN_MINUS
%left PLUS MINUS
%left STAR DIV MOD
%right NOT
%nonassoc DUMMY_LOWER_THAN_L_BRACE
%nonassoc L_BRACE KW_MAP
%nonassoc UNARY_PLUS
%nonassoc UNARY_MINUS
%nonassoc CASTING
%start sentences
%%
name_label
: LABEL { $$ = $1; }
| unreserved_keyword { $$ = $1; }
;
name_label_list
: name_label {
$$ = new NameLabelList();
$$->add($1);
}
| name_label_list COMMA name_label {
$1->add($3);
$$ = $1;
}
;
legal_integer
: INTEGER {
ifOutOfRange($1, @1);
$$ = $1;
}
;
/**
* TODO(dutor) Tweak the scanner to keep the original text along the unreserved keywords
*/
unreserved_keyword
: KW_SPACE { $$ = new std::string("space"); }
| KW_VALUE { $$ = new std::string("value"); }
| KW_VALUES { $$ = new std::string("values"); }
| KW_HOST { $$ = new std::string("host"); }
| KW_HOSTS { $$ = new std::string("hosts"); }
| KW_SPACES { $$ = new std::string("spaces"); }
| KW_USER { $$ = new std::string("user"); }
| KW_USERS { $$ = new std::string("users"); }
| KW_PASSWORD { $$ = new std::string("password"); }
| KW_ROLE { $$ = new std::string("role"); }
| KW_ROLES { $$ = new std::string("roles"); }
| KW_GOD { $$ = new std::string("god"); }
| KW_ADMIN { $$ = new std::string("admin"); }
| KW_DBA { $$ = new std::string("dba"); }
| KW_GUEST { $$ = new std::string("guest"); }
| KW_GROUP { $$ = new std::string("group"); }
| KW_DATA { $$ = new std::string("data"); }
| KW_LEADER { $$ = new std::string("leader"); }
| KW_UUID { $$ = new std::string("uuid"); }
| KW_JOB { $$ = new std::string("job"); }
| KW_JOBS { $$ = new std::string("jobs"); }
| KW_BIDIRECT { $$ = new std::string("bidirect"); }
| KW_FORCE { $$ = new std::string("force"); }
| KW_PART { $$ = new std::string("part"); }
| KW_PARTS { $$ = new std::string("parts"); }
| KW_DEFAULT { $$ = new std::string("default"); }
| KW_CONFIGS { $$ = new std::string("configs"); }
| KW_ACCOUNT { $$ = new std::string("account"); }
| KW_HDFS { $$ = new std::string("hdfs"); }
| KW_PARTITION_NUM { $$ = new std::string("partition_num"); }
| KW_REPLICA_FACTOR { $$ = new std::string("replica_factor"); }
| KW_CHARSET { $$ = new std::string("charset"); }
| KW_COLLATE { $$ = new std::string("collate"); }
| KW_COLLATION { $$ = new std::string("collation"); }
| KW_ATOMIC_EDGE { $$ = new std::string("atomic_edge"); }
| KW_TTL_DURATION { $$ = new std::string("ttl_duration"); }
| KW_TTL_COL { $$ = new std::string("ttl_col"); }
| KW_SNAPSHOT { $$ = new std::string("snapshot"); }
| KW_SNAPSHOTS { $$ = new std::string("snapshots"); }
| KW_GRAPH { $$ = new std::string("graph"); }
| KW_META { $$ = new std::string("meta"); }
| KW_STORAGE { $$ = new std::string("storage"); }
| KW_AGENT { $$ = new std::string("agent"); }
| KW_ALL { $$ = new std::string("all"); }
| KW_ANY { $$ = new std::string("any"); }
| KW_SINGLE { $$ = new std::string("single"); }
| KW_NONE { $$ = new std::string("none"); }
| KW_REDUCE { $$ = new std::string("reduce"); }
| KW_SHORTEST { $$ = new std::string("shortest"); }
| KW_SHORTESTPATH { $$ = new std::string("shortestpath"); }
| KW_ALLSHORTESTPATHS { $$ = new std::string("allshortestpaths"); }
| KW_NOLOOP { $$ = new std::string("noloop"); }
| KW_CONTAINS { $$ = new std::string("contains"); }
| KW_STARTS { $$ = new std::string("starts"); }
| KW_ENDS { $$ = new std::string("ends"); }
| KW_VID_TYPE { $$ = new std::string("vid_type"); }
| KW_LIMIT { $$ = new std::string("limit"); }
| KW_SKIP { $$ = new std::string("skip"); }
| KW_OPTIONAL { $$ = new std::string("optional"); }
| KW_OFFSET { $$ = new std::string("offset"); }
| KW_FORMAT { $$ = new std::string("format"); }
| KW_PROFILE { $$ = new std::string("profile"); }
| KW_BOTH { $$ = new std::string("both"); }
| KW_OUT { $$ = new std::string("out"); }
| KW_SUBGRAPH { $$ = new std::string("subgraph"); }
| KW_THEN { $$ = new std::string("then"); }
| KW_ELSE { $$ = new std::string("else"); }
| KW_END { $$ = new std::string("end"); }
| KW_INTO { $$ = new std::string("into"); }
| KW_NEW { $$ = new std::string("new"); }
| KW_GROUPS { $$ = new std::string("groups"); }
| KW_ZONE { $$ = new std::string("zone"); }
| KW_ZONES { $$ = new std::string("zones"); }
| KW_LISTENER { $$ = new std::string("listener"); }
| KW_ELASTICSEARCH { $$ = new std::string("elasticsearch"); }
| KW_FULLTEXT { $$ = new std::string("fulltext"); }
| KW_STATS { $$ = new std::string("stats"); }
| KW_STATUS { $$ = new std::string("status"); }
| KW_AUTO { $$ = new std::string("auto"); }
| KW_FUZZY { $$ = new std::string("fuzzy"); }
| KW_PREFIX { $$ = new std::string("prefix"); }
| KW_REGEXP { $$ = new std::string("regexp"); }
| KW_WILDCARD { $$ = new std::string("wildcard"); }
| KW_TEXT { $$ = new std::string("text"); }
| KW_SEARCH { $$ = new std::string("search"); }
| KW_CLIENTS { $$ = new std::string("clients"); }
| KW_SIGN { $$ = new std::string("sign"); }
| KW_SERVICE { $$ = new std::string("service"); }
| KW_TEXT_SEARCH { $$ = new std::string("text_search"); }
| KW_RESET { $$ = new std::string("reset"); }
| KW_PLAN { $$ = new std::string("plan"); }
| KW_COMMENT { $$ = new std::string("comment"); }
| KW_S2_MAX_LEVEL { $$ = new std::string("s2_max_level"); }
| KW_S2_MAX_CELLS { $$ = new std::string("s2_max_cells"); }
| KW_SESSION { $$ = new std::string("session"); }
| KW_SESSIONS { $$ = new std::string("sessions"); }
| KW_LOCAL { $$ = new std::string("local"); }
| KW_SAMPLE { $$ = new std::string("sample"); }
| KW_QUERIES { $$ = new std::string("queries"); }
| KW_QUERY { $$ = new std::string("query"); }
| KW_KILL { $$ = new std::string("kill"); }
| KW_TOP { $$ = new std::string("top"); }
| KW_POINT { $$ = new std::string("point"); }
| KW_LINESTRING { $$ = new std::string("linestring"); }
| KW_POLYGON { $$ = new std::string("polygon"); }
| KW_HTTP { $$ = new std::string("http"); }
| KW_HTTPS { $$ = new std::string("https"); }
| KW_MERGE { $$ = new std::string("merge"); }
| KW_DIVIDE { $$ = new std::string("divide"); }
| KW_RENAME { $$ = new std::string("rename"); }
| KW_CLEAR { $$ = new std::string("clear"); }
;
expression
: expression_internal {
if(!graph::ExpressionUtils::checkExprDepth($1)){
// delete $1;
std::ostringstream errStr;
errStr << "The above expression's depth exceeds the maximum depth:" << FLAGS_max_expression_depth;
throw nebula::GraphParser::syntax_error(@1, errStr.str());
}
$$ = $1;
}
;
expression_internal
: constant_expression {
$$ = $1;
}
| name_label {
$$ = LabelExpression::make(qctx->objPool(), *$1);
delete $1;
}
| VARIABLE {
$$ = VariableExpression::make(qctx->objPool(), *$1);
delete $1;
}
| compound_expression {
$$ = $1;
}
| MINUS {
scanner.setUnaryMinus(true);
} expression_internal %prec UNARY_MINUS {
if (scanner.isIntMin()) {
$$ = $3;
scanner.setIsIntMin(false);
} else {
$$ = UnaryExpression::makeNegate(qctx->objPool(), $3);
}
scanner.setUnaryMinus(false);
}
| PLUS expression_internal %prec UNARY_PLUS {
$$ = UnaryExpression::makePlus(qctx->objPool(), $2);
}
| NOT expression_internal {
$$ = UnaryExpression::makeNot(qctx->objPool(), $2);
}
| KW_NOT expression_internal {
$$ = UnaryExpression::makeNot(qctx->objPool(), $2);
}
| L_PAREN type_spec R_PAREN expression_internal %prec CASTING {
$$ = TypeCastingExpression::make(qctx->objPool(), graph::SchemaUtil::propTypeToValueType($2->type), $4);
delete $2;
}
| expression_internal STAR expression_internal {
$$ = ArithmeticExpression::makeMultiply(qctx->objPool(), $1, $3);
}
| expression_internal DIV expression_internal {
$$ = ArithmeticExpression::makeDivision(qctx->objPool(), $1, $3);
}
| expression_internal MOD expression_internal {
$$ = ArithmeticExpression::makeMod(qctx->objPool(), $1, $3);
}
| expression_internal PLUS expression_internal {
$$ = ArithmeticExpression::makeAdd(qctx->objPool(), $1, $3);
}
| expression_internal MINUS expression_internal {
$$ = ArithmeticExpression::makeMinus(qctx->objPool(), $1, $3);
}
| expression_internal LT expression_internal {
$$ = RelationalExpression::makeLT(qctx->objPool(), $1, $3);
}
| expression_internal GT expression_internal {
$$ = RelationalExpression::makeGT(qctx->objPool(), $1, $3);
}
| expression_internal LE expression_internal {
$$ = RelationalExpression::makeLE(qctx->objPool(), $1, $3);
}
| expression_internal GE expression_internal {
$$ = RelationalExpression::makeGE(qctx->objPool(), $1, $3);
}
| expression_internal REG expression_internal {
$$ = RelationalExpression::makeREG(qctx->objPool(), $1, $3);
}
| expression_internal KW_IN expression_internal {
$$ = RelationalExpression::makeIn(qctx->objPool(), $1, $3);
}
| expression_internal KW_NOT_IN expression_internal {
$$ = RelationalExpression::makeNotIn(qctx->objPool(), $1, $3);
}
| expression_internal KW_CONTAINS expression_internal {
$$ = RelationalExpression::makeContains(qctx->objPool(), $1, $3);
}
| expression_internal KW_NOT_CONTAINS expression_internal {
$$ = RelationalExpression::makeNotContains(qctx->objPool(), $1, $3);
}
| expression_internal KW_STARTS_WITH expression_internal {
$$ = RelationalExpression::makeStartsWith(qctx->objPool(), $1, $3);
}
| expression_internal KW_NOT_STARTS_WITH expression_internal {
$$ = RelationalExpression::makeNotStartsWith(qctx->objPool(), $1, $3);
}
| expression_internal KW_ENDS_WITH expression_internal {
$$ = RelationalExpression::makeEndsWith(qctx->objPool(), $1, $3);
}
| expression_internal KW_NOT_ENDS_WITH expression_internal {
$$ = RelationalExpression::makeNotEndsWith(qctx->objPool(), $1, $3);
}
| expression_internal KW_IS_NULL {
$$ = UnaryExpression::makeIsNull(qctx->objPool(), $1);
}
| expression_internal KW_IS_NOT_NULL {
$$ = UnaryExpression::makeIsNotNull(qctx->objPool(), $1);
}
| expression_internal KW_IS_EMPTY {
$$ = UnaryExpression::makeIsEmpty(qctx->objPool(), $1);
}
| expression_internal KW_IS_NOT_EMPTY {
$$ = UnaryExpression::makeIsNotEmpty(qctx->objPool(), $1);
}
| expression_internal EQ expression_internal {
$$ = RelationalExpression::makeEQ(qctx->objPool(), $1, $3);
}
| expression_internal NE expression_internal {
$$ = RelationalExpression::makeNE(qctx->objPool(), $1, $3);
}
| expression_internal KW_AND expression_internal {
$$ = LogicalExpression::makeAnd(qctx->objPool(), $1, $3);
}
| expression_internal KW_OR expression_internal {
$$ = LogicalExpression::makeOr(qctx->objPool(), $1, $3);
}
| expression_internal KW_XOR expression_internal {
$$ = LogicalExpression::makeXor(qctx->objPool(), $1, $3);
}
| case_expression {
$$ = $1;
}
| predicate_expression {
$$ = $1;
}
| reduce_expression {
$$ = $1;
}
| uuid_expression {
$$ = $1;
}
;
constant_expression
: DOUBLE {
$$ = ConstantExpression::make(qctx->objPool(), $1);
}
| STRING {
$$ = ConstantExpression::make(qctx->objPool(), *$1);
delete $1;
}
| BOOL {
$$ = ConstantExpression::make(qctx->objPool(), $1);
}
| KW_NULL {
$$ = ConstantExpression::make(qctx->objPool(), NullType::__NULL__);
}
| INTEGER {
$$ = ConstantExpression::make(qctx->objPool(), $1);
}
;
compound_expression
: match_path_pattern_expression {
$$ = $1;
}
| parenthesized_expression {
$$ = $1;
}
| property_expression {
$$ = $1;
}
| function_call_expression {
$$ = $1;
}
| container_expression {
$$ = $1;
}
| list_comprehension_expression {
$$ = $1;
}
| subscript_expression {
$$ = $1;
}
| subscript_range_expression {
$$ = $1;
}
| attribute_expression {
$$ = $1;
}
;
parenthesized_expression
: L_PAREN expression_internal R_PAREN {
$$ = $2;
}
;
property_expression
: input_prop_expression {
$$ = $1;
}
| vertex_prop_expression {
$$ = $1;
}
| var_prop_expression {
$$ = $1;
}
| edge_prop_expression {
$$ = $1;
}
;
subscript_expression
: name_label L_BRACKET expression_internal R_BRACKET {
$$ = SubscriptExpression::make(qctx->objPool(), LabelExpression::make(qctx->objPool(), *$1), $3);
delete $1;
}
| VARIABLE L_BRACKET expression_internal R_BRACKET {
$$ = SubscriptExpression::make(qctx->objPool(), VariableExpression::make(qctx->objPool(), *$1), $3);
delete $1;
}
| compound_expression L_BRACKET expression_internal R_BRACKET {
$$ = SubscriptExpression::make(qctx->objPool(), $1, $3);
}
;
subscript_range_expression
: name_label L_BRACKET expression_internal DOT_DOT expression_internal R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), LabelExpression::make(qctx->objPool(), *$1), $3, $5);
delete($1);
}
| name_label L_BRACKET DOT_DOT expression_internal R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), LabelExpression::make(qctx->objPool(), *$1), nullptr, $4);
delete($1);
}
| name_label L_BRACKET expression_internal DOT_DOT R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), LabelExpression::make(qctx->objPool(), *$1), $3, nullptr);
delete($1);
}
| VARIABLE L_BRACKET expression_internal DOT_DOT expression_internal R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), VariableExpression::make(qctx->objPool(), *$1), $3, $5);
delete($1);
}
| VARIABLE L_BRACKET DOT_DOT expression_internal R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), VariableExpression::make(qctx->objPool(), *$1), nullptr, $4);
delete($1);
}
| VARIABLE L_BRACKET expression_internal DOT_DOT R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), VariableExpression::make(qctx->objPool(), *$1), $3, nullptr);
delete($1);
}
| compound_expression L_BRACKET expression_internal DOT_DOT expression_internal R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), $1, $3, $5);
}
| compound_expression L_BRACKET DOT_DOT expression_internal R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), $1, nullptr, $4);
}
| compound_expression L_BRACKET expression_internal DOT_DOT R_BRACKET {
$$ = SubscriptRangeExpression::make(qctx->objPool(), $1, $3, nullptr);
}
;
attribute_expression
: name_label DOT name_label {
$$ = LabelAttributeExpression::make(qctx->objPool(), LabelExpression::make(qctx->objPool(), *$1),
ConstantExpression::make(qctx->objPool(), *$3));
delete $1;
delete $3;
}
| compound_expression DOT name_label {
$$ = AttributeExpression::make(qctx->objPool(), $1, ConstantExpression::make(qctx->objPool(), *$3));
delete $3;
}
;
case_expression
: generic_case_expression {
$$ = $1;
}
| conditional_expression {
$$ = $1;
}
;
generic_case_expression
: KW_CASE case_condition when_then_list case_default KW_END {
auto expr = CaseExpression::make(qctx->objPool(), $3);
expr->setCondition($2);
expr->setDefault($4);
$$ = expr;
}
;
conditional_expression
: expression_internal QM expression_internal COLON expression_internal {
auto cases = CaseList::make(qctx->objPool());
cases->add($1, $3);
auto expr = CaseExpression::make(qctx->objPool(), cases, false);
expr->setDefault($5);
$$ = expr;
}
;
case_condition
: %empty {
$$ = nullptr;
}
| expression_internal {
$$ = $1;
}
;
case_default
: %empty {
$$ = nullptr;
}
| KW_ELSE expression_internal {
$$ = $2;
}
;
when_then_list
: KW_WHEN expression_internal KW_THEN expression_internal {
$$ = CaseList::make(qctx->objPool());
$$->add($2, $4);
}
| when_then_list KW_WHEN expression_internal KW_THEN expression_internal {
$1->add($3, $5);
$$ = $1;
}
;
predicate_name
: KW_ALL { $$ = new std::string("all"); }
| KW_ANY { $$ = new std::string("any"); }
| KW_SINGLE { $$ = new std::string("single"); }
| KW_NONE { $$ = new std::string("none"); }
;
predicate_expression
: predicate_name L_PAREN expression_internal KW_IN expression_internal KW_WHERE expression_internal R_PAREN {
if ($3->kind() != Expression::Kind::kLabel) {
delete $1;
throw nebula::GraphParser::syntax_error(@3, "The loop variable must be a label in predicate functions");
}
std::string innerVar = static_cast<const LabelExpression *>($3)->name();
auto *expr = PredicateExpression::make(qctx->objPool(), *$1, innerVar, $5, $7); // TODO(jie) Use std::unique_ptr<std::string>
nebula::graph::ParserUtil::rewritePred(qctx, expr, innerVar);
$$ = expr;
delete $1;
}
| KW_EXISTS L_PAREN expression_internal R_PAREN {
if ($3->kind() != Expression::Kind::kLabelAttribute && $3->kind() != Expression::Kind::kAttribute &&
$3->kind() != Expression::Kind::kSubscript) {
throw nebula::GraphParser::syntax_error(@3, "The exists only accept LabelAttribute, Attribute and Subscript");
}
$$ = PredicateExpression::make(qctx->objPool(), "exists", "", $3, nullptr);
}
;
list_comprehension_expression
: L_BRACKET expression_internal KW_IN expression_internal KW_WHERE expression_internal R_BRACKET {
if ($2->kind() != Expression::Kind::kLabel) {
throw nebula::GraphParser::syntax_error(@2, "The loop variable must be a label in list comprehension");
}
auto &innerVar = static_cast<const LabelExpression *>($2)->name();
auto *expr = ListComprehensionExpression::make(qctx->objPool(), innerVar, $4, $6, nullptr);
nebula::graph::ParserUtil::rewriteLC(qctx, expr, innerVar);
$$ = expr;
}
| L_BRACKET expression_internal KW_IN expression_internal PIPE expression_internal R_BRACKET {
if ($2->kind() != Expression::Kind::kLabel) {
throw nebula::GraphParser::syntax_error(@2, "The loop variable must be a label in list comprehension");
}
auto &innerVar = static_cast<const LabelExpression *>($2)->name();
auto *expr = ListComprehensionExpression::make(qctx->objPool(), innerVar, $4, nullptr, $6);
nebula::graph::ParserUtil::rewriteLC(qctx, expr, innerVar);
$$ = expr;
}
| L_BRACKET expression_internal KW_IN expression_internal KW_WHERE expression_internal PIPE expression_internal R_BRACKET {
if ($2->kind() != Expression::Kind::kLabel) {
throw nebula::GraphParser::syntax_error(@2, "The loop variable must be a label in list comprehension");
}
auto &innerVar = static_cast<const LabelExpression *>($2)->name();
auto *expr = ListComprehensionExpression::make(qctx->objPool(), innerVar, $4, $6, $8);
nebula::graph::ParserUtil::rewriteLC(qctx, expr, innerVar);
$$ = expr;
}
;
reduce_expression
: KW_REDUCE L_PAREN name_label ASSIGN expression_internal COMMA name_label KW_IN expression_internal PIPE expression_internal R_PAREN {
auto *expr = ReduceExpression::make(qctx->objPool(), *$3, $5, *$7, $9, $11);
nebula::graph::ParserUtil::rewriteReduce(qctx, expr, *$3, *$7);
$$ = expr;
delete $3;
delete $7;
}
;
input_prop_expression
: INPUT_REF DOT name_label {
$$ = InputPropertyExpression::make(qctx->objPool(), *$3);
delete $3;
}
| INPUT_REF DOT STAR {
$$ = InputPropertyExpression::make(qctx->objPool(), "*");
}
;
vertex_prop_expression
: SRC_REF DOT name_label DOT name_label {
$$ = SourcePropertyExpression::make(qctx->objPool(), *$3, *$5);
delete $3;