Skip to main content

gql_parser/
ast.rs

1#[derive(Clone, Debug, PartialEq)]
2pub struct Program {
3    pub at_schema: Option<SchemaReference>,
4    pub definitions: Vec<BindingVariableDefinition>,
5    pub statements: Vec<Statement>,
6}
7
8#[derive(Clone, Debug, PartialEq)]
9pub enum BindingVariableDefinition {
10    Graph(GraphVariableDefinition),
11    BindingTable(BindingTableVariableDefinition),
12    Value(ValueVariableDefinition),
13}
14
15#[derive(Clone, Debug, PartialEq)]
16pub struct GraphVariableDefinition {
17    pub property_graph: bool,
18    pub name: Identifier,
19    pub typed: bool,
20    pub value_type: Option<ValueType>,
21    pub initializer: GraphExpression,
22}
23
24#[derive(Clone, Debug, PartialEq)]
25pub struct BindingTableVariableDefinition {
26    pub binding: bool,
27    pub name: Identifier,
28    pub typed: bool,
29    pub value_type: Option<ValueType>,
30    pub initializer: BindingTableExpression,
31}
32
33#[derive(Clone, Debug, PartialEq)]
34pub struct ValueVariableDefinition {
35    pub name: Identifier,
36    pub typed: bool,
37    pub value_type: Option<ValueType>,
38    pub initializer: Expr,
39}
40
41#[derive(Clone, Debug, PartialEq)]
42// Keep the public AST's owned variants stable. Boxing is a separate API change.
43#[allow(clippy::large_enum_variant)]
44pub enum Statement {
45    LinearCatalog(Vec<Statement>),
46    Query(QueryStatement),
47    Call(CallStatement),
48    Next(NextStatement),
49    Insert(InsertStatement),
50    Delete(DeleteStatement),
51    Set(SetStatement),
52    Remove(RemoveStatement),
53    CreateGraph(CreateGraphStatement),
54    DropGraph(DropGraphStatement),
55    CreateGraphType(CreateGraphTypeStatement),
56    DropGraphType(DropGraphTypeStatement),
57    CreateSchema(CreateSchemaStatement),
58    DropSchema(DropSchemaStatement),
59    SessionSet(SessionSetCommand),
60    SessionReset(SessionResetCommand),
61    SessionClose(SessionCloseCommand),
62    StartTransaction(StartTransactionStatement),
63    Commit(CommitStatement),
64    Rollback(RollbackStatement),
65}
66
67#[derive(Clone, Debug, PartialEq)]
68pub struct NextStatement {
69    pub yield_clause: Option<YieldClause>,
70    pub statement: Box<Statement>,
71}
72
73#[derive(Clone, Debug, PartialEq)]
74pub struct QueryStatement {
75    pub at_schema: Option<SchemaReference>,
76    pub use_graph: Option<GraphExpression>,
77    pub body: QueryBody,
78    pub set_operations: Vec<QuerySetOperation>,
79}
80
81#[derive(Clone, Debug, PartialEq)]
82pub struct QueryBody {
83    pub clauses: Vec<QueryClause>,
84    pub result_clause: ResultClause,
85    pub select_from: Vec<SelectGraphMatch>,
86    pub select_query: Option<SelectQuerySpecification>,
87    pub select_where: Option<Expr>,
88    pub group_by: Vec<Expr>,
89    pub empty_grouping_set: bool,
90    pub having: Option<Expr>,
91    pub order_by: Vec<OrderByItem>,
92    pub offset: Option<UnsignedIntegerSpecification>,
93    pub limit: Option<UnsignedIntegerSpecification>,
94}
95
96#[derive(Clone, Debug, PartialEq)]
97pub struct QuerySetOperation {
98    pub operator: QuerySetOperator,
99    pub quantifier: Option<SetQuantifier>,
100    pub body: QueryBody,
101}
102
103#[derive(Clone, Copy, Debug, PartialEq, Eq)]
104pub enum QuerySetOperator {
105    Union,
106    Except,
107    Intersect,
108    Otherwise,
109}
110
111#[derive(Clone, Copy, Debug, PartialEq, Eq)]
112pub enum SetQuantifier {
113    Distinct,
114    All,
115}
116
117#[derive(Clone, Debug, PartialEq)]
118pub enum QueryClause {
119    UseGraph(GraphExpression),
120    NestedQuery(Box<QueryStatement>),
121    Match(MatchClause),
122    OptionalMatchBlock(Vec<MatchClause>),
123    Filter(FilterClause),
124    Let(LetClause),
125    For(ForClause),
126    Call(CallClause),
127    Insert(InsertStatement),
128    Delete(DeleteStatement),
129    Set(SetStatement),
130    Remove(RemoveStatement),
131    OrderByPage(OrderByPageClause),
132}
133
134#[derive(Clone, Debug, PartialEq)]
135pub struct SelectGraphMatch {
136    pub graph: GraphExpression,
137    pub match_clause: MatchClause,
138}
139
140#[derive(Clone, Debug, PartialEq)]
141pub struct SelectQuerySpecification {
142    pub graph: Option<GraphExpression>,
143    pub query: Box<QueryStatement>,
144}
145
146#[derive(Clone, Debug, PartialEq)]
147pub struct MatchClause {
148    pub optional: bool,
149    pub mode: Option<MatchMode>,
150    pub patterns: Vec<PathPattern>,
151    pub keep: Option<PathPatternPrefix>,
152    pub where_clause: Option<Expr>,
153    pub yield_clause: Option<YieldClause>,
154}
155
156#[derive(Clone, Copy, Debug, PartialEq, Eq)]
157pub enum MatchMode {
158    RepeatableElements { bindings: bool },
159    DifferentEdges { bindings: bool },
160}
161
162#[derive(Clone, Debug, PartialEq)]
163pub struct FilterClause {
164    pub predicate: Expr,
165}
166
167#[derive(Clone, Debug, PartialEq)]
168pub struct LetClause {
169    pub items: Vec<LetItem>,
170}
171
172#[derive(Clone, Debug, PartialEq)]
173pub struct LetItem {
174    pub name: Identifier,
175    pub typed: bool,
176    pub value_type: Option<ValueType>,
177    pub value: Expr,
178}
179
180#[derive(Clone, Debug, PartialEq)]
181pub struct ForClause {
182    pub variable: Identifier,
183    pub source: Expr,
184    pub ordinality_or_offset: Option<ForOrdinalityOrOffset>,
185}
186
187#[derive(Clone, Debug, PartialEq)]
188pub struct ForOrdinalityOrOffset {
189    pub kind: ForOrdinalityOrOffsetKind,
190    pub variable: Identifier,
191}
192
193#[derive(Clone, Copy, Debug, PartialEq, Eq)]
194pub enum ForOrdinalityOrOffsetKind {
195    Ordinality,
196    Offset,
197}
198
199#[derive(Clone, Debug, PartialEq)]
200pub struct CallClause {
201    pub optional: bool,
202    pub call: ProcedureCall,
203    pub yield_clause: Option<YieldClause>,
204}
205
206#[derive(Clone, Debug, PartialEq)]
207pub enum ProcedureCall {
208    Named {
209        procedure: ProcedureReference,
210        args: Vec<Expr>,
211    },
212    Inline(InlineProcedureCall),
213}
214
215#[derive(Clone, Debug, PartialEq, Eq)]
216pub enum ProcedureReference {
217    Name(ProcedureName),
218    Parameter(String),
219}
220
221#[derive(Clone, Debug, PartialEq)]
222pub struct InlineProcedureCall {
223    pub variable_scope: Option<Vec<Identifier>>,
224    pub body: Box<Program>,
225}
226
227#[derive(Clone, Debug, PartialEq)]
228pub struct OrderByPageClause {
229    pub order_by: Vec<OrderByItem>,
230    pub offset: Option<UnsignedIntegerSpecification>,
231    pub limit: Option<UnsignedIntegerSpecification>,
232}
233
234#[derive(Clone, Debug, PartialEq)]
235pub struct CallStatement {
236    pub call: CallClause,
237}
238
239#[derive(Clone, Debug, PartialEq)]
240pub struct YieldClause {
241    pub items: Vec<YieldItem>,
242}
243
244#[derive(Clone, Debug, PartialEq)]
245pub enum YieldItem {
246    All,
247    Item {
248        name: Identifier,
249        alias: Option<Identifier>,
250    },
251}
252
253#[derive(Clone, Debug, PartialEq)]
254pub struct ResultClause {
255    pub kind: ResultKind,
256    pub quantifier: Option<SetQuantifier>,
257    pub distinct: bool,
258    pub items: Vec<ResultItem>,
259}
260
261#[derive(Clone, Copy, Debug, PartialEq, Eq)]
262pub enum ResultKind {
263    Return,
264    Select,
265    Finish,
266}
267
268#[derive(Clone, Debug, PartialEq)]
269pub struct ResultItem {
270    pub expr: Expr,
271    pub alias: Option<Identifier>,
272}
273
274#[derive(Clone, Debug, PartialEq)]
275pub struct OrderByItem {
276    pub expr: Expr,
277    pub direction: Option<SortDirection>,
278    pub null_ordering: Option<NullOrdering>,
279}
280
281#[derive(Clone, Copy, Debug, PartialEq, Eq)]
282pub enum SortDirection {
283    Asc,
284    Desc,
285}
286
287#[derive(Clone, Copy, Debug, PartialEq, Eq)]
288pub enum NullOrdering {
289    First,
290    Last,
291}
292
293#[derive(Clone, Debug, PartialEq)]
294pub struct InsertStatement {
295    pub patterns: Vec<PathPattern>,
296}
297
298#[derive(Clone, Debug, PartialEq)]
299pub struct DeleteStatement {
300    pub detach: bool,
301    pub items: Vec<Expr>,
302}
303
304#[derive(Clone, Debug, PartialEq)]
305pub struct SetStatement {
306    pub items: Vec<SetItem>,
307}
308
309#[derive(Clone, Debug, PartialEq)]
310// Keep the public AST's owned variants stable. Boxing is a separate API change.
311#[allow(clippy::large_enum_variant)]
312pub enum SetItem {
313    Property {
314        target: Expr,
315        value: Expr,
316    },
317    AllProperties {
318        variable: Identifier,
319        properties: MapLiteral,
320    },
321    Label {
322        variable: Identifier,
323        label: Identifier,
324    },
325}
326
327#[derive(Clone, Debug, PartialEq)]
328pub struct RemoveStatement {
329    pub items: Vec<RemoveItem>,
330}
331
332#[derive(Clone, Debug, PartialEq)]
333pub enum RemoveItem {
334    Property(Expr),
335    Label {
336        variable: Identifier,
337        label: Identifier,
338    },
339}
340
341#[derive(Clone, Debug, PartialEq)]
342pub struct SessionSetCommand {
343    pub target: SessionSetTarget,
344}
345
346#[derive(Clone, Debug, PartialEq)]
347pub enum SessionSetTarget {
348    Schema(SchemaReference),
349    Graph(GraphExpression),
350    TimeZone(Expr),
351    GraphParameter(SessionSetGraphParameter),
352    BindingTableParameter(SessionSetBindingTableParameter),
353    ValueParameter(SessionSetValueParameter),
354}
355
356#[derive(Clone, Debug, PartialEq)]
357pub struct SessionSetGraphParameter {
358    pub property_graph: bool,
359    pub if_not_exists: bool,
360    pub name: String,
361    pub typed: bool,
362    pub value_type: Option<ValueType>,
363    pub initializer: GraphExpression,
364}
365
366#[derive(Clone, Debug, PartialEq)]
367pub struct SessionSetBindingTableParameter {
368    pub binding: bool,
369    pub if_not_exists: bool,
370    pub name: String,
371    pub typed: bool,
372    pub value_type: Option<ValueType>,
373    pub initializer: BindingTableExpression,
374}
375
376#[derive(Clone, Debug, PartialEq)]
377pub struct SessionSetValueParameter {
378    pub if_not_exists: bool,
379    pub name: String,
380    pub typed: bool,
381    pub value_type: Option<ValueType>,
382    pub initializer: Expr,
383}
384
385#[derive(Clone, Debug, PartialEq, Eq)]
386pub struct SessionResetCommand {
387    pub target: SessionResetTarget,
388}
389
390#[derive(Clone, Debug, PartialEq, Eq)]
391pub enum SessionResetTarget {
392    AllCharacteristics,
393    AllParameters,
394    Schema,
395    Graph,
396    TimeZone,
397    Parameter(String),
398}
399
400#[derive(Clone, Debug, PartialEq, Eq)]
401pub struct SessionCloseCommand;
402
403#[derive(Clone, Debug, PartialEq)]
404pub struct CreateGraphStatement {
405    pub if_not_exists: bool,
406    pub or_replace: bool,
407    pub property_graph: bool,
408    pub name: GraphName,
409    pub graph_type: Option<CreateGraphType>,
410    pub source: Option<GraphExpression>,
411}
412
413#[derive(Clone, Debug, PartialEq, Eq)]
414pub struct DropGraphStatement {
415    pub if_exists: bool,
416    pub property_graph: bool,
417    pub name: GraphName,
418}
419
420#[derive(Clone, Debug, PartialEq)]
421pub struct CreateGraphTypeStatement {
422    pub if_not_exists: bool,
423    pub or_replace: bool,
424    pub property_graph: bool,
425    pub name: GraphTypeName,
426    pub source: CreateGraphTypeSource,
427}
428
429#[derive(Clone, Debug, PartialEq, Eq)]
430pub struct DropGraphTypeStatement {
431    pub if_exists: bool,
432    pub property_graph: bool,
433    pub name: GraphTypeName,
434}
435
436#[derive(Clone, Debug, PartialEq, Eq)]
437pub struct CreateSchemaStatement {
438    pub if_not_exists: bool,
439    pub name: SchemaName,
440}
441
442#[derive(Clone, Debug, PartialEq, Eq)]
443pub struct DropSchemaStatement {
444    pub if_exists: bool,
445    pub name: SchemaName,
446}
447
448#[derive(Clone, Debug, PartialEq)]
449pub enum CreateGraphType {
450    Any {
451        typed: bool,
452        property_graph: bool,
453    },
454    Like(GraphExpression),
455    Named {
456        typed: bool,
457        name: GraphTypeReference,
458    },
459    Nested {
460        typed: bool,
461        property_graph: bool,
462        body: GraphTypeBody,
463    },
464}
465
466#[derive(Clone, Debug, PartialEq)]
467pub enum CreateGraphTypeSource {
468    CopyOf(GraphTypeReference),
469    CopyOfExternal(String),
470    Like(GraphExpression),
471    Nested(GraphTypeBody),
472}
473
474#[derive(Clone, Debug, PartialEq, Eq)]
475pub struct StartTransactionStatement {
476    pub access_mode: Option<TransactionAccessMode>,
477    pub isolation_level: Option<IsolationLevel>,
478}
479
480#[derive(Clone, Copy, Debug, PartialEq, Eq)]
481pub enum TransactionAccessMode {
482    ReadOnly,
483    ReadWrite,
484}
485
486#[derive(Clone, Copy, Debug, PartialEq, Eq)]
487pub enum IsolationLevel {
488    Serializable,
489    RepeatableRead,
490    ReadCommitted,
491    ReadUncommitted,
492}
493
494#[derive(Clone, Debug, PartialEq, Eq)]
495pub struct CommitStatement;
496
497#[derive(Clone, Debug, PartialEq, Eq)]
498pub struct RollbackStatement;
499
500#[derive(Clone, Debug, PartialEq, Eq)]
501pub struct GraphName {
502    pub absolute: bool,
503    pub current_schema: bool,
504    pub home_schema: bool,
505    pub parent_levels: usize,
506    pub parts: Vec<Identifier>,
507}
508
509#[derive(Clone, Debug, PartialEq)]
510pub enum GraphExpression {
511    Variable(Box<Expr>),
512    Name(GraphName),
513    Parameter(String),
514    CurrentGraph,
515    CurrentPropertyGraph,
516    HomeGraph,
517    HomePropertyGraph,
518}
519
520#[derive(Clone, Debug, PartialEq, Eq)]
521pub struct BindingTableName {
522    pub absolute: bool,
523    pub current_schema: bool,
524    pub home_schema: bool,
525    pub parent_levels: usize,
526    pub parts: Vec<Identifier>,
527}
528
529#[derive(Clone, Debug, PartialEq)]
530pub enum BindingTableExpression {
531    NestedQuery(Box<QueryStatement>),
532    Variable(Box<Expr>),
533    Name(BindingTableName),
534    Parameter(String),
535}
536
537#[derive(Clone, Debug, PartialEq, Eq)]
538pub struct GraphTypeName {
539    pub absolute: bool,
540    pub current_schema: bool,
541    pub home_schema: bool,
542    pub parent_levels: usize,
543    pub parts: Vec<Identifier>,
544}
545
546#[derive(Clone, Debug, PartialEq, Eq)]
547pub enum GraphTypeReference {
548    Name(GraphTypeName),
549    Parameter(String),
550}
551
552#[derive(Clone, Debug, PartialEq, Eq)]
553pub struct SchemaName {
554    pub absolute: bool,
555    pub current_schema: bool,
556    pub home_schema: bool,
557    pub parent_levels: usize,
558    pub parts: Vec<Identifier>,
559}
560
561#[derive(Clone, Debug, PartialEq, Eq)]
562pub enum SchemaReference {
563    Name(SchemaName),
564    Absolute(SchemaName),
565    Root,
566    Parent { levels: usize, name: SchemaName },
567    Parameter(String),
568    CurrentSchema,
569    HomeSchema,
570}
571
572#[derive(Clone, Debug, PartialEq, Eq)]
573pub struct ProcedureName {
574    pub absolute: bool,
575    pub current_schema: bool,
576    pub home_schema: bool,
577    pub parent_levels: usize,
578    pub parts: Vec<Identifier>,
579}
580
581#[derive(Clone, Debug, PartialEq)]
582pub struct PathPattern {
583    pub variable: Option<Identifier>,
584    pub prefix: Option<PathPatternPrefix>,
585    pub parenthesized: Option<ParenthesizedPathPatternExpression>,
586    pub start: NodePattern,
587    pub chains: Vec<PathPatternChain>,
588    pub factors: Vec<PathPatternFactor>,
589    pub alternation: Option<PathPatternAlternation>,
590    pub alternatives: Vec<PathPatternTerm>,
591}
592
593#[derive(Clone, Debug, PartialEq)]
594pub struct ParenthesizedPathPatternExpression {
595    pub variable: Option<Identifier>,
596    pub prefix: Option<PathPatternPrefix>,
597    pub pattern: Box<PathPattern>,
598    pub where_clause: Option<Expr>,
599    pub quantifier: Option<PathPatternQuantifier>,
600    pub questioned: bool,
601}
602
603#[derive(Clone, Debug, PartialEq)]
604pub struct PathPatternTerm {
605    pub start: NodePattern,
606    pub chains: Vec<PathPatternChain>,
607    pub factors: Vec<PathPatternFactor>,
608}
609
610#[derive(Clone, Debug, PartialEq)]
611pub enum PathPatternFactor {
612    Node(NodePattern),
613    Relationship(RelationshipPattern),
614    Parenthesized(Box<ParenthesizedPathPatternExpression>),
615    Alternation {
616        alternation: PathPatternAlternation,
617        alternatives: Vec<Vec<PathPatternFactor>>,
618    },
619}
620
621#[derive(Clone, Copy, Debug, PartialEq, Eq)]
622pub enum PathPatternAlternation {
623    Union,
624    Multiset,
625}
626
627#[derive(Clone, Debug, PartialEq, Eq)]
628pub enum PathPatternPrefix {
629    Mode {
630        mode: PathMode,
631        path_or_paths: Option<PathOrPaths>,
632    },
633    Search(PathSearchPrefix),
634}
635
636#[derive(Clone, Copy, Debug, PartialEq, Eq)]
637pub enum PathMode {
638    Walk,
639    Trail,
640    Simple,
641    Acyclic,
642}
643
644#[derive(Clone, Copy, Debug, PartialEq, Eq)]
645pub enum PathOrPaths {
646    Path,
647    Paths,
648}
649
650#[derive(Clone, Debug, PartialEq, Eq)]
651pub enum PathSearchPrefix {
652    All {
653        mode: Option<PathMode>,
654        path_or_paths: Option<PathOrPaths>,
655    },
656    Any {
657        count: Option<UnsignedIntegerSpecification>,
658        mode: Option<PathMode>,
659        path_or_paths: Option<PathOrPaths>,
660    },
661    Shortest {
662        mode: Option<PathMode>,
663        path_or_paths: Option<PathOrPaths>,
664    },
665    AllShortest {
666        mode: Option<PathMode>,
667        path_or_paths: Option<PathOrPaths>,
668    },
669    AnyShortest {
670        mode: Option<PathMode>,
671        path_or_paths: Option<PathOrPaths>,
672    },
673    CountedShortest {
674        count: UnsignedIntegerSpecification,
675        mode: Option<PathMode>,
676        path_or_paths: Option<PathOrPaths>,
677    },
678    CountedShortestGroup {
679        count: Option<UnsignedIntegerSpecification>,
680        mode: Option<PathMode>,
681        path_or_paths: Option<PathOrPaths>,
682        groups: bool,
683    },
684}
685
686#[derive(Clone, Debug, PartialEq, Eq)]
687pub enum UnsignedIntegerSpecification {
688    Literal(u64),
689    Parameter(String),
690}
691
692#[derive(Clone, Debug, PartialEq)]
693pub struct PathPatternChain {
694    pub relationship: RelationshipPattern,
695    pub node: NodePattern,
696}
697
698#[derive(Clone, Debug, PartialEq)]
699pub struct NodePattern {
700    pub variable: Option<Identifier>,
701    pub temporary: bool,
702    pub labels: Vec<Identifier>,
703    pub label_expression: Option<LabelExpression>,
704    pub properties: Option<MapLiteral>,
705    pub where_clause: Option<Expr>,
706    pub quantifier: Option<PathPatternQuantifier>,
707}
708
709#[derive(Clone, Debug, PartialEq)]
710pub struct RelationshipPattern {
711    pub direction: Direction,
712    pub variable: Option<Identifier>,
713    pub temporary: bool,
714    pub labels: Vec<Identifier>,
715    pub label_expression: Option<LabelExpression>,
716    pub properties: Option<MapLiteral>,
717    pub where_clause: Option<Expr>,
718    pub quantifier: Option<PathPatternQuantifier>,
719}
720
721#[derive(Clone, Copy, Debug, PartialEq, Eq)]
722pub enum Direction {
723    Left,
724    Right,
725    Undirected,
726    LeftOrUndirected,
727    UndirectedOrRight,
728    LeftOrRight,
729    Any,
730}
731
732#[derive(Clone, Debug, PartialEq, Eq)]
733pub enum LabelExpression {
734    Label(Identifier),
735    Wildcard,
736    And(Box<LabelExpression>, Box<LabelExpression>),
737    Or(Box<LabelExpression>, Box<LabelExpression>),
738    Not(Box<LabelExpression>),
739    Parenthesized(Box<LabelExpression>),
740}
741
742#[derive(Clone, Debug, PartialEq, Eq)]
743pub enum PathPatternQuantifier {
744    ZeroOrMore,
745    OneOrMore,
746    Optional,
747    Fixed(u64),
748    Range { min: Option<u64>, max: Option<u64> },
749}
750
751#[derive(Clone, Debug, PartialEq, Eq)]
752pub struct GraphTypeBody {
753    pub elements: Vec<GraphTypeElement>,
754}
755
756#[derive(Clone, Debug, PartialEq, Eq)]
757pub enum GraphTypeElement {
758    Node(NodeTypeDefinition),
759    Edge(EdgeTypeDefinition),
760}
761
762#[derive(Clone, Debug, PartialEq, Eq)]
763pub struct NodeTypeDefinition {
764    pub name: Identifier,
765    pub labels: Vec<Identifier>,
766    pub properties: Vec<PropertyTypeDefinition>,
767}
768
769#[derive(Clone, Debug, PartialEq, Eq)]
770pub struct EdgeTypeDefinition {
771    pub name: Identifier,
772    pub direction: Direction,
773    pub labels: Vec<Identifier>,
774    pub source: Option<Identifier>,
775    pub destination: Option<Identifier>,
776    pub properties: Vec<PropertyTypeDefinition>,
777}
778
779#[derive(Clone, Debug, PartialEq, Eq)]
780pub struct PropertyTypeDefinition {
781    pub name: Identifier,
782    pub value_type: ValueType,
783}
784
785#[derive(Clone, Debug, PartialEq, Eq)]
786pub enum ValueType {
787    Named {
788        name: Identifier,
789        parameters: Vec<u64>,
790    },
791    CharacterString {
792        kind: CharacterStringTypeKind,
793        max_length: Option<u64>,
794    },
795    Boolean {
796        kind: BooleanTypeKind,
797    },
798    Temporal {
799        kind: TemporalTypeKind,
800    },
801    ByteString {
802        kind: ByteStringTypeKind,
803        min_length: Option<u64>,
804        max_length: Option<u64>,
805    },
806    ExactNumeric {
807        kind: ExactNumericTypeKind,
808        signed: Option<bool>,
809        precision: Option<u64>,
810        scale: Option<u64>,
811    },
812    ApproximateNumeric {
813        kind: ApproximateNumericTypeKind,
814        precision: Option<u64>,
815        scale: Option<u64>,
816    },
817    List(Box<ValueType>),
818    ListWithLength {
819        element: Box<ValueType>,
820        max_length: u64,
821    },
822    Array(Box<ValueType>),
823    ArrayWithLength {
824        element: Box<ValueType>,
825        max_length: u64,
826    },
827    Path,
828    AnyRecord,
829    Record(Vec<FieldType>),
830    AnyDynamic,
831    PropertyValue,
832    DynamicUnion(Vec<ValueType>),
833    GraphReference {
834        property_graph: bool,
835        body: Option<GraphTypeBody>,
836    },
837    NodeReference {
838        definition: Option<NodeTypeDefinition>,
839    },
840    EdgeReference {
841        definition: Option<EdgeTypeDefinition>,
842    },
843    BindingTable {
844        binding: bool,
845        fields: Vec<FieldType>,
846    },
847    NotNull(Box<ValueType>),
848}
849
850#[derive(Clone, Copy, Debug, PartialEq, Eq)]
851pub enum CharacterStringTypeKind {
852    String,
853    Varchar,
854}
855
856#[derive(Clone, Copy, Debug, PartialEq, Eq)]
857pub enum BooleanTypeKind {
858    Bool,
859    Boolean,
860}
861
862#[derive(Clone, Copy, Debug, PartialEq, Eq)]
863pub enum TemporalTypeKind {
864    ZonedDateTime,
865    LocalDateTime,
866    Date,
867    ZonedTime,
868    LocalTime,
869    Duration,
870}
871
872#[derive(Clone, Copy, Debug, PartialEq, Eq)]
873pub enum ByteStringTypeKind {
874    Bytes,
875    Binary,
876    Varbinary,
877}
878
879#[derive(Clone, Copy, Debug, PartialEq, Eq)]
880pub enum ExactNumericTypeKind {
881    Decimal,
882    Integer,
883}
884
885#[derive(Clone, Copy, Debug, PartialEq, Eq)]
886pub enum ApproximateNumericTypeKind {
887    Float,
888    Real,
889    Double,
890}
891
892#[derive(Clone, Debug, PartialEq, Eq)]
893pub struct FieldType {
894    pub name: Identifier,
895    pub value_type: ValueType,
896}
897
898#[derive(Clone, Debug, PartialEq)]
899pub enum Expr {
900    Identifier(Identifier),
901    Property {
902        base: Box<Expr>,
903        key: Identifier,
904    },
905    GraphReference {
906        property_graph: bool,
907        graph: GraphExpression,
908    },
909    BindingTableReference {
910        binding: bool,
911        table: BindingTableExpression,
912    },
913    Parameter(String),
914    Literal(Literal),
915    Unary {
916        op: UnaryOp,
917        expr: Box<Expr>,
918    },
919    Binary {
920        left: Box<Expr>,
921        op: BinaryOp,
922        right: Box<Expr>,
923    },
924    Function {
925        name: Identifier,
926        quantifier: Option<SetQuantifier>,
927        args: Vec<Expr>,
928    },
929    SubstringByLength {
930        side: SubstringSide,
931        value: Box<Expr>,
932        length: Box<Expr>,
933    },
934    Trim {
935        specification: Option<TrimSpec>,
936        trim_character: Option<Box<Expr>>,
937        value: Box<Expr>,
938    },
939    MultiTrim {
940        specification: TrimSpec,
941        value: Box<Expr>,
942        trim_characters: Option<Box<Expr>>,
943    },
944    TrimList {
945        value: Box<Expr>,
946        count: Box<Expr>,
947    },
948    Elements {
949        path: Box<Expr>,
950    },
951    StringLength {
952        unit: StringLengthUnit,
953        value: Box<Expr>,
954    },
955    Fold {
956        upper: bool,
957        value: Box<Expr>,
958    },
959    Normalize {
960        value: Box<Expr>,
961        normal_form: Option<Identifier>,
962    },
963    CurrentDate,
964    CurrentTime {
965        precision: Option<u64>,
966    },
967    CurrentTimestamp {
968        precision: Option<u64>,
969    },
970    CurrentUser,
971    DateTimeFunction {
972        function: DateTimeFunctionKind,
973        value: Option<Box<Expr>>,
974    },
975    LocalTime {
976        precision: Option<u64>,
977    },
978    LocalTimestamp {
979        precision: Option<u64>,
980    },
981    AbsoluteValue {
982        expr: Box<Expr>,
983    },
984    DurationFunction {
985        value: Box<Expr>,
986    },
987    DurationBetween {
988        left: Box<Expr>,
989        right: Box<Expr>,
990    },
991    NumericFunction {
992        function: NumericFunctionKind,
993        args: Vec<Expr>,
994    },
995    Cast {
996        expr: Box<Expr>,
997        value_type: ValueType,
998    },
999    ValueQuery {
1000        query: Box<QueryStatement>,
1001    },
1002    Let {
1003        items: Vec<LetItem>,
1004        value: Box<Expr>,
1005    },
1006    IsTyped {
1007        expr: Box<Expr>,
1008        negated: bool,
1009        value_type: ValueType,
1010    },
1011    IsNull {
1012        expr: Box<Expr>,
1013        negated: bool,
1014    },
1015    IsUnknown {
1016        expr: Box<Expr>,
1017        negated: bool,
1018    },
1019    IsTruth {
1020        expr: Box<Expr>,
1021        negated: bool,
1022        value: bool,
1023    },
1024    PropertyExists {
1025        variable: Identifier,
1026        property: Identifier,
1027    },
1028    ElementId {
1029        variable: Identifier,
1030    },
1031    Exists {
1032        patterns: Vec<PathPattern>,
1033    },
1034    ExistsQuery {
1035        query: Box<QueryStatement>,
1036    },
1037    ExistsMatch {
1038        matches: Vec<MatchClause>,
1039    },
1040    Same {
1041        variables: Vec<Identifier>,
1042    },
1043    AllDifferent {
1044        variables: Vec<Identifier>,
1045    },
1046    SourceDestination {
1047        node: Identifier,
1048        negated: bool,
1049        kind: SourceDestinationKind,
1050        edge: Identifier,
1051    },
1052    IsNormalized {
1053        expr: Box<Expr>,
1054        negated: bool,
1055        normal_form: Option<Identifier>,
1056    },
1057    IsDirected {
1058        variable: Identifier,
1059        negated: bool,
1060    },
1061    IsLabeled {
1062        variable: Identifier,
1063        negated: bool,
1064        label_expression: LabelExpression,
1065    },
1066    Case {
1067        operand: Option<Box<Expr>>,
1068        when_clauses: Vec<CaseWhenClause>,
1069        else_expr: Option<Box<Expr>>,
1070    },
1071    Coalesce(Vec<Expr>),
1072    NullIf {
1073        left: Box<Expr>,
1074        right: Box<Expr>,
1075    },
1076    List(Vec<Expr>),
1077    TypedList {
1078        type_name: ListValueTypeName,
1079        values: Vec<Expr>,
1080    },
1081    Path(Vec<Expr>),
1082    Record {
1083        explicit: bool,
1084        fields: MapLiteral,
1085    },
1086    Map(MapLiteral),
1087    Wildcard,
1088}
1089
1090#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1091pub enum TrimSpec {
1092    Leading,
1093    Trailing,
1094    Both,
1095}
1096
1097#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1098pub enum StringLengthUnit {
1099    Characters,
1100    Bytes,
1101}
1102
1103#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1104pub enum SubstringSide {
1105    Left,
1106    Right,
1107}
1108
1109#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1110pub enum NumericFunctionKind {
1111    Mod,
1112    Floor,
1113    Ceil,
1114    Sqrt,
1115    Power,
1116    Log,
1117    Log10,
1118    Ln,
1119    Exp,
1120    Sin,
1121    Cos,
1122    Tan,
1123    Cot,
1124    Sinh,
1125    Cosh,
1126    Tanh,
1127    Asin,
1128    Acos,
1129    Atan,
1130    Degrees,
1131    Radians,
1132    PathLength,
1133}
1134
1135#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1136pub enum DateTimeFunctionKind {
1137    Date,
1138    ZonedTime,
1139    ZonedDateTime,
1140    LocalTime,
1141    LocalDateTime,
1142}
1143
1144#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1145pub enum ListValueTypeName {
1146    List,
1147    Array,
1148}
1149
1150#[derive(Clone, Debug, PartialEq)]
1151pub struct CaseWhenClause {
1152    pub condition: Expr,
1153    pub additional_operands: Vec<Expr>,
1154    pub result: Expr,
1155}
1156
1157#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1158pub enum SourceDestinationKind {
1159    Source,
1160    Destination,
1161}
1162
1163#[derive(Clone, Debug, PartialEq)]
1164pub struct MapLiteral {
1165    pub entries: Vec<(Identifier, Expr)>,
1166}
1167
1168#[derive(Clone, Debug, PartialEq)]
1169pub enum Literal {
1170    Null,
1171    Boolean(bool),
1172    Unknown,
1173    Integer(i64),
1174    Decimal(f64),
1175    String(String),
1176    Bytes(Vec<u8>),
1177    Date(String),
1178    Time(String),
1179    DateTime(String),
1180    Duration(String),
1181    SqlInterval {
1182        value: String,
1183        qualifier: SqlIntervalQualifier,
1184    },
1185}
1186
1187#[derive(Clone, Debug, PartialEq, Eq)]
1188pub struct SqlIntervalQualifier {
1189    pub start: Identifier,
1190    pub start_precision: Option<u64>,
1191    pub end: Option<Identifier>,
1192    pub end_precision: Option<u64>,
1193}
1194
1195#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1196pub enum UnaryOp {
1197    Not,
1198    Pos,
1199    Neg,
1200}
1201
1202#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1203pub enum BinaryOp {
1204    Or,
1205    Xor,
1206    And,
1207    Eq,
1208    Neq,
1209    Lt,
1210    Le,
1211    Gt,
1212    Ge,
1213    Concat,
1214    Add,
1215    Sub,
1216    Mul,
1217    Div,
1218}
1219
1220#[derive(Clone, Debug, PartialEq, Eq, Hash)]
1221pub struct Identifier {
1222    pub value: String,
1223}
1224
1225impl Identifier {
1226    pub fn new(value: impl Into<String>) -> Self {
1227        Self {
1228            value: value.into(),
1229        }
1230    }
1231}