Source: https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/syntax-conventions/ Documentation version: v5.3.2 # Syntax notation The syntax notation used in the documentation is an [Extended Backus–Naur Form (EBNF)](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form), which defines the syntax of the GQL language with a set of production rules. Each production rule is specified by a sequence of lexical elements, each of which may be a terminal symbol or a non-terminal symbol. - Terminal symbols are the basic elements of the language and cannot be changed by the production rules. - Non-terminal symbols are those that can be replaced by groups of terminal symbols after applying the production rules recursively to them. ## Terminal symbols Terminal symbols are written within single quotes ('). They are meant to be used as they are. Keywords and literal symbols are the two types of terminal symbols used in the syntax. ### Keywords Keywords are written in all uppercase letters. Example: ```` for_statement ::= 'FOR' identifier 'IN' list_value_expression ```` In the preceding example, `FOR` and `IN` are keywords. For more information, see [Keywords and identifiers](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/keywords-identifiers/). ### Literal symbols The following are the literal symbols used in the syntax: | Literal symbol | Description | `,` | A comma is used to separate elements. | `.` | A period is used to reference a property of a node or an edge, or a field of a record. For more information, see [Property value expression](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/expressions/property/). | `=` | An equal sign is used to assign a value to a variable. | `( )` | Parentheses are used to enclose arguments of a [function](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/#functions), to enclose the parameters for a [procedure](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/procedures/create/), to [group](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/dql/clauses/group-by/) a result set, or to specify a node type. | `[ ]` | Square brackets are used to declare a [list value](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/data-types/list-type/) or specify an edge type. | `:` | A colon is used to separate the name and value of a property or specify the labels for a node type or edge type. For more information, see [Patterns](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/patterns/). | `{ }` | Curly brackets are used to indicate a [subquery](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/expressions/subquery/), to specify the number of [repetitive edge patterns](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/dql/match/#graph_pattern_quantifier), or to enclose a set of [properties](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/expressions/property/). | `*` | An asterisk sign may be used as follows: It can be used to indicate the subtraction of two numbers. For more information, see [operators](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/operators/). It can be used as a wildcard in the following cases: In the [MATCH](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/dql/match/#graph_pattern_quantifier) statement, it indicates zero or more occurrences of an edge pattern. In the [RETURN](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/dql/return/) statement, it returns all results. In the [count](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/functions/aggregate/#count) function, it counts all rows including nulls and duplicates. | `/` | A slash is used to indicate the division of two numbers. For more information, see [operators](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/operators/). | `%` | A percent sign matches any sequence of characters, including no characters in the [like](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/functions/string/#like) function, and is used to specify temporal value formats in [temporal types](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/data-types/temporal-type/#temporal_value_formats). | `&` | An ampersand is used to separate multiple labels for a node type or edge type. | `@` | An at sign is used to specify a node type or edge type. | `\` | A backslash is used to escape special characters in a string, or to indicate that the statement will continue on the next line. | `" "` | Double quotes are used to enclose a [reserved keyword](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/keywords-identifiers/) or a string. | `' '` | Single quotes are used to enclose a string. | ```` | Backticks are used to enclose a [reserved keyword](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/keywords-identifiers/). | `!` | An exclamation mark is used to indicate the negation of a condition, or indicate the exclusion of a label in a [label expression](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/expressions/label/). | `+` | A plus sign is used to indicate the addition of two numbers. For more information, see [operators](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/operators/). | `<=` | A less than or equal to sign is used to compare two values. For more information, see [operators](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/operators/). | `>=` | A greater than or equal to sign is used to compare two values. For more information, see [operators](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/operators/). | `<>` | Angle brackets are used to indicate that the values on either side of the brackets are not equal. For more information, see [operators](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/operators/). | `-[]->` | This symbol is used to indicate an edge pointing right. Example: `(v1)-[e]->(v2)` | `<-[]-` | This symbol is used to indicate an edge pointing left, for example, `(v1)<-[e]-(v2)`. | `~[]~` | This symbol is used to indicate an undirected edge, for example, `(v1)~[e]~(v2)`. | `~[]~>` | This symbol is used to indicate an undirected edge or an edge pointing right, for example, `(v1)~[e]~>(v2)`. | `<~[]~` | This symbol is used to indicate an undirected edge or an edge pointing left, for example, `(v1)<~[e]~(v2)`. | `<-[]->` | This symbol is used to indicate an edge pointing either left or right, for example, `(v1)<-[e]->(v2)`. | `-[]-` | This symbol is used to indicate an edge with any direction, for example, `(v1)-[e]-(v2)`. | `->` | This symbol is used to indicate an edge pointing right, for example, `(v1)->(v2)`, or indicate that each element in a list is transformed to a new element by using a [lambda value expression](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/expressions/lambda/). | `<-` | This symbol is used to indicate an edge pointing left, for example, `(v1)<-(v2)`. | `~` | This symbol is used to indicate an undirected edge, for example, `(v1)~(v2)`. | `~>` | This symbol is used to indicate an undirected edge or an edge pointing right, for example, `(v1)~>(v2)`. | `<~` | This symbol is used to indicate an undirected edge or an edge pointing left, for example, `(v1)<~(v2)`. | `<->` | This symbol is used to indicate an edge pointing in either direction, for example, `(v1)<->(v2)`. | `-` | This symbol is used to indicate an edge with any direction, for example, `(v1)-(v2)`, or indicate the subtraction of two numbers. For more information, see [operators](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/operators/). ## Non-terminal symbols Non-terminal symbols are the elements composed of terminal symbols and other non-terminal symbols, such as operators, parameters, and syntax fragments. Non-terminal symbols are not written within single quotes ('). ### Operators Operators define how to compose non-terminal symbols from terminal symbols. The following operators are used in the syntax: | Operation | Operator | Description | definition | `::=` | A double colon followed by an equal sign is used to separate the element defined by the rule from its definition. The element being defined appears to the left of the operator and the formula that defines the element appears to the right of the operator. | option | `?` | A question mark is used to indicate that the element to which it applies is optional. | choice | `|` | A vertical bar is used to separate two elements that are alternatives. | repetition | `*` | An asterisk is used to indicate that the element to which it applies may appear any number of times. | repetition | `+` | A plus sign is used to indicate that the element to which it applies may appear one or more times. | grouping | `()` | Parentheses are used to group elements. The elements within one group are treated as a single element. | terminal string | `''` | Single quotes are used to enclose terminal symbols. ### Parameters Parameters are specified in snake-case notation. For each parameter, you must specify a value when you write the statement. For more information about the parameters, see the Parameters section of the corresponding topic. Example: ```` for_statement ::= 'FOR' identifier 'IN' list_value_expression ```` In the preceding example, `identifier` and `list_value_expression` represent parameters that you must specify when you write the FOR statement. ### Syntax fragments Syntax fragments are non-terminal symbols that serve to break up syntax that is too long, too complex, or too repetitious. Each syntax fragment is expanded as a separate syntax section and recursively referenced in the main syntax section. Fragment names are also specified in snake-case notation. Example: ```` match_statement ::= ( 'OPTIONAL' )? 'MATCH' graph_pattern graph_pattern_yield_clause? graph_pattern ::= path_pattern ( ',' path_pattern )* ( 'WHERE' search_condition )? ... ```` In the preceding example, `graph_pattern`, `graph_pattern_yield_clause`, `path_pattern`, and `search_condition` are all syntax fragments.