您开始写一些复杂的小精灵查询时,它们不会变得相当的长。为了让它们更容易让其它人阅读,推荐把它们写成多行,缩进要按照一定的方式,这样它们看起来更有意义。笔者不打算提出一个缩进的标准,笔者相信这属于个人偏好,然而有一些事,笔者需要提一下。在小精灵控制台工作时,如果您想把查询语句拆分在多行,您需要在每一行的结尾加一个反斜杠字符或者是一个标点或一个逗号,这就可以让小精灵的解析器知道还有更多的输入。
As you begin to write more complex Gremlin queries they can get quite lengthy. In order to make
them easier for others to read it is recommended to spread them over multiple lines and indent
them in a way that makes sense. I am not going to propose an indentation standard, I believe this
should be left to personal preference however there are a few things I want to mention in passing.
When working with the Gremlin console, if you want to spread a query over multiple lines then
you will need to end each line with a backslash character or with a character such as a period or a
comma that tells the Gremlin parser that there is more to come.
下面的这个例子,我们已经在布尔运算一节见过这个查询,但是这次它排版成了我们可以直接复制粘贴到小精灵控制台的样子。
The following example shows the query we already looked at in the Boolean operations section of
this book but this time edited so that it could be copy and pasted directly into the Gremlin console.

 我们可以不使用反斜杠,如果我们把查询语句写成下面这样。每一行都有一个点号结尾,它告诉解析器下面还有步骤输入。

We can avoid the use of backslash characters if we lay the query out as follows. Each line ends with
a period which tells the parser that there are more steps coming.

 如果我们不给解析器一个或多个提示信息,还会有其它的输入,那么小精灵控制台就会试着执行每一行的内容,而不去等待下一行的信息。

If we do not give the parser one of these clues that there is more to come, the Gremlin console will
try and execute each line without waiting for the next line.
有的人发现每个步骤或者调节器处在单独的一行这样的查询更容易阅读。所以我们可以把查询写成下面这样,它仍然可以很好的工作。
Some people find it easier to read queries when each step or modulator is given its own line and
indented appropriately. So we could layout the query as shown below and it will still work just fine. 

 无论您是用反斜杠做为续行符或者前一行用一个一个点号结尾,这些都是个人的偏好。如果您想在小精灵控制台执行多行查询时,只要记得使用某一种就可以。没有具体的准则查询要写多少行或者您应当缩进多少,当您要把查询语句分布在多行时。然而无论您做什么决定,记得让您的作品更方便其它人阅读,每个步骤单独成行是更容易阅读也更容易理解的。

Whether you decide to use the backslash as a continuation character or leave the period on the
previous line is really a matter of personal preference. Just be sure to do one or the other if you
want to use multiple line queries within the Gremlin console. There is no golden rule as to how
many lines and how much indenting you should use when laying out your more complex queries.
However, whatever you decide to do, it is worth remembering that others reading your work may
find well laid out and appropriately indented steps easier to read and understand.
posted on 2022-04-21 10:17  bokeyuannicheng0000  阅读(16)  评论(0)    收藏  举报