-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssql.html
242 lines (231 loc) · 13.8 KB
/
ssql.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" type="text/css" href="./professional.css">
<title>SsQL</title>
</head>
<body>
<nav id="top">
<span><a href="./standard.html">Standard</a></span>
<span><a href="./notation.html">notation</a></span>
<span>|</span>
<span><a href="./professional.html">Professional</a></span>
<span>SsQL</span>
</nav>
<article>
<h1>Siteswap Query Language</h1>
<p>By using the Siteswap Query Language (SsQL), you can specify the search method and the display method of results in detail. The complete syntax is:</p>
<pre>
FROM "pattern"
LET variable-definition
WHERE acquisition-condition
SELECT display-items
ORDER BY sort-condition
LIMIT number
</pre>
<p>However, you can omit everything except the FROM clause. Specify the clauses that are not omitted in this order. The LET clause can be specified multiple times.</p>
<p>In the FROM clause, describe the search <a href="./notation.html">pattern</a> with double quotation marks. If you want to use double quotation marks in your pattern, you must escape them with \.</p>
<p>Only the maximum number can be specified in the LIMIT clause. The time limit can not be specified, so if you want to stop the search halfway, press the stop button. If you omit the LIMIT clause, the search continues indefinitely.</p>
<section>
<h2>Acquisition condition</h2>
<p>Specify the acquisition condition by combining variables, properties, methods, and operators in the WHERE clause. For example:</p>
<pre>
WHERE $0.balls == 3
</pre>
<p>If the condition is satisfied, the string is acquired, and if not, it is not acquired. If you omit the WHERE clause, you get all the generated strings.</p>
<p>Variables include auto-defined variables and user-defined variables. Auto-defined variables are specified by $ + numbers such as $0, $1, $2, .... User-defined variables will be described later. $0 represents the entire string, and $1, $2, etc. represent the first group, second group, and so on. You can write $ instead of $0 as an abbreviation. If the pattern specified in the FROM clause is (5+)([13]), the string are assigned to the variable as follows.</p>
<table class="border">
<tr><th> </th><th>$0</th><th>$1</th><th>$2</th></tr>
<tr><td>1st</td><td>51</td><td>5</td><td>1</td></tr>
<tr><td>2nd</td><td>53</td><td>5</td><td>3</td></tr>
<tr><td>3rd</td><td>551</td><td>55</td><td>1</td></tr>
<tr><td>4th</td><td>553</td><td>55</td><td>3</td></tr>
<tr><td>5th</td><td>5551</td><td>555</td><td>1</td></tr>
<tr><td>:</td><td>:</td><td>:</td><td>:</td></tr>
</table>
<p>Properties are specified after variable and dot.</p>
<table class="border">
<tr><th>property</th><th>explanation</th><th>example</th></tr>
<tr><td>pattern</td><td>the string itself</td><td>315315</td></tr>
<tr><td>length</td><td>string length</td><td>6</td></tr>
<tr><td>sum</td><td>sum of heights</td><td>18</td></tr>
<tr><td>reverse</td><td>reverse order</td><td>513513</td></tr>
<tr><td>min</td><td>minimum pattern</td><td>153153</td></tr>
<tr><td>max</td><td>maximum pattern</td><td>531531</td></tr>
<tr><td>omission</td><td>abbreviation</td><td>315</td></tr>
<tr><td>standard</td><td>standard form</td><td>531</td></tr>
<tr><td>jugglable</td><td>whether jugglable</td><td>1</td></tr>
<tr><td>valid</td><td>whether valid siteswap</td><td>1</td></tr>
<tr><td>balls</td><td>number of balls</td><td>3</td></tr>
<tr><td>period</td><td>siteswap period</td><td>3</td></tr>
<tr><td>state</td><td>siteswap state</td><td>19</td></tr>
<tr><td>int10</td><td>base 10 value</td><td>315315</td></tr>
<tr><td>int36</td><td>base 36 value</td><td>183315353</td></tr>
</table>
<p>The value of "jugglable" is 1 if it is jugglable and 0 otherwise. "valid" is similar. "balls" and "state" will be -1 if the pattern is not jugglable. "period" will be -1 if the pattern is not a siteswap, even if it is jugglable. "int10" is a numerical value from the beginning to the position where it can be regarded as a decimal integer. "int36" is similar. Property can be omitted. If omitted, it is assumed that "pattern" is specified.</p>
<p>Methods are specified in the same way as properties, but with parentheses followed by arguments, such as $0.at(1). In the example in the following table, methods are applied to string "12345".</p>
<table class="border">
<tr><th>method</th><th>explanation</th><th>n = 1</th><th>n = -2</th></tr>
<tr><td>at(n)</td><td>character at that index</td><td>2</td><td>4</td></tr>
<tr><td>rotate(n)</td><td>rotation for n characters</td><td>23451</td><td>45123</td></tr>
<tr><td>skip(n)</td><td>skip n characters</td><td>2345</td><td>123</td></tr>
<tr><td>take(n)</td><td>take n characters</td><td>1</td><td>45</td></tr>
</table>
<p>All of these methods count from the left if you specify 0 or a positive number as an argument, and from the right if you specify a negative number. The leftmost position is 0 and the rightmost position is -1.</p>
<p>Some methods are iterative methods that take a lambda expression as an argument.</p>
<table class="border">
<tr><th>iterator</th><th>explanation</th></tr>
<tr><td>every(lambda)</td><td>whether it holds for all indexes</td></tr>
<tr><td>some(lambda)</td><td>whether it holds for any one index</td></tr>
</table>
<p>Lambda expressions are specified in the following format:</p>
<pre>
index => condition
</pre>
<p>or</p>
<pre>
index, whole => condition
</pre>
<p>Here, both the index variable and the variable that represents the whole are user-defined variables. User-defined variables can be specified as $ + strings, such as $index, $x1, $_, and can be used in acquisition conditions. The following is a concrete example of the former format.</p>
<pre>
$0.every($index => $0.at($index) == 1)
</pre>
<p>If the length of $0 is n, 0 to n-1 are assigned to $index in order, and the right side of => is iterated. On the right side, it is determined whether the characters from the 0th digit to the n-1th digit are 1, so throughout this example, it is determined whether all the digits of $0 are 1.</p>
<pre>
$0.take(2).some($index, $whole => $whole.at($index) == 1)
</pre>
<p>This is a concrete example of the latter form, which determines if there is a 1 in the first two digits of $0. It is the same as writing $0.take(2) instead of $whole, but more concise.</p>
<p>The following is a list of operators by priority.</p>
<table class="border">
<tr><th>priority</th><th>operator</th><th>meaning</th></tr>
<tr><td>1</td><td>.</td><td>string on the right is a property or a method</td></tr>
<tr><td rowspan="3">2</td><td>*</td><td>multiplication</td></tr>
<tr><td>/</td><td>quotient of integer division</td></tr>
<tr><td>%</td><td>remainder of integer division</td></tr>
<tr><td rowspan="3">3</td><td>+</td><td>addition</td></tr>
<tr><td>-</td><td>subtraction</td></tr>
<tr><td>&</td><td>concatenation of strings</td></tr>
<tr><td rowspan="9">4</td><td>==</td><td>left and right values are equal</td></tr>
<tr><td>!=</td><td rowspan="2">left and right values are different</td></tr>
<tr><td><></td></tr>
<tr><td><</td><td>left value is less than right value</td></tr>
<tr><td><=</td><td>left value is less than or equal to right value</td></tr>
<tr><td>></td><td>left value is more than right value</td></tr>
<tr><td>>=</td><td>left value is more than or equal to right value</td></tr>
<tr><td>IN(...)</td><td>left value is contained in ...</td></tr>
<tr><td>NOT IN(...)</td><td>left value is not contained in ...</td></tr>
<tr><td>5</td><td>NOT</td><td>right condition is false</td></tr>
<tr><td>6</td><td>AND</td><td>both left and right conditions are true</td></tr>
<tr><td>7</td><td>OR</td><td>either left or right condition is true</td></tr>
</table>
<p>If operators with the same priority are listed, they are evaluated from the left. When you want to change the priority, enclose the part in parentheses, such as 2*(3+4).</p>
<p>Only decimal integers are treated as numbers. When performing numerical calculation on a string, it is assumed that the "int10" property is implicitly specified. The result of the comparison operation is 1 for true and 0 for false. In the operation of NOT, AND and OR, only the number 0, the string "0", and the empty string represent false, and true otherwise.</p>
<p>The IN operator is used as follows:</p>
<pre>
$0.standard IN("71", "62", "53")
</pre>
<p>In this case, it will be true (or 1) if the standard form of the variable $0 is 71, 62, or 53.</p>
</section>
<section>
<h2>Display items</h2>
<p>Specify display items such as variables and constants separated by white space in the SELECT clause. For example:</p>
<pre>
SELECT $0 "(" $0.balls ")"
</pre>
<p>White spaces are not included in the displayed string, so specify the spaces in double quotation marks if necessary. The string enclosed in double quotation marks is output as is. If you omit the SELECT clause, you get the entire generated string (assuming $0.pattern was specified).</p>
<p>You can also use operators. For example:</p>
<pre>
SELECT $0.int10 "+1=" $0.int10 + 1
</pre>
<p>genarates 3+1=4 etc.</p>
<p>To suppress the output of the same string, specify DISTINCT after SELECT. If you want to generate only unique strings, describe as follows.</p>
<pre>
SELECT DISTINCT $0
</pre>
<p>DISTINCT is similar to the WHERE clause in that it limits the number of strings displayed, but WHERE covers the conditions that the generated string satisfies, whereas DISTINCT only covers whether the entire string processed by SELECT already exists.</p>
</section>
<section>
<h2>Sort condition</h2>
<p>Specify sorting conditions separated by commas in the ORDER BY clause.</p>
<pre>
ORDER BY $0.period DESC, $0
</pre>
<p>If you specify DESC after the condition, the order will be descending. If you specify ASC or nothing, the order will be ascending. The above example means "descending by siteswap period, then ascending by string itself". If the strings generated are 3, 441, 531, then the longer siteswap periods 441 and 531 come first and the shorter period 3 comes later. In 441 and 531, 441 is smaller as a string, so it comes earlier, and finally 441 531 3 is output.</p>
<p>If you omit the ORDER BY clause, they are displayed in the order they were generated.</p>
</section>
<section>
<h2>Variable definition</h2>
<p>The LET clause defines a variable that can be used throughout the statement.</p>
<pre>
LET $const = "123"
</pre>
<p>The left side of equal is the variable name, and the right side is the definition. Like user-defined variables that appear in lambda expressions, variable names are specified with the $ + string. The first character of the variable name can be an alphabet or an underscore, and numbers can be used in addition to that after the second character. Case is ignored and $name and $Name and $NAME are treated as the same name. You can not define multiple variables with the same name.</p>
<p>Any number of LET clauses can be written for one SsQL statement. You can use variables as well as constants in definitions.</p>
<pre>
LET $var1 = $1
LET $var2 = $var1 + 3
LET $var3 = $0.at($index)
</pre>
<p>Using an undefined variable will result in an error, but the order of definition does not matter, so there is no problem if you use $var3 as follows.</p>
<pre>
WHERE $0.every($index => $var3 < 3)
</pre>
</section>
<section>
<h2>Comments and other</h2>
<p>You can also write a comment in SsQL.</p>
<pre>
-- 1 line comment
/* Multi-
line
comment */
</pre>
<p>Line comments are from -- to the end of the line, block comments are from /* to */. Only one line comment can be specified per line, and it can not span multiple lines. On the other hand, a block comment can be written over multiple lines, or multiple block comments can be written in the middle of a line. However, you can not nest comments.</p>
<p>You can write SsQL in free format. That is spaces, line breaks, and comments between keywords are ignored.</p>
<p>Uppercase letters are converted to lowercase. The message when there is an error is also displayed as a string converted to lowercase letters.</p>
</section>
<section>
<h2>Language specifications</h2>
<p>For reference, I describe the specifications of the accepted SsQL in <a href="../haba/notation.html">HABA format</a>.</p>
<pre>
Query ::= From Let* Where? Select? Order? Limit? ;
From ::= 'FROM' String ;
String ::= """(\\""|[^""])*""" ;
Let ::= 'LET' User '=' Term ;
Where ::= 'WHERE' Condition ;
Condition ::= Part ('OR' Part)* ;
Part ::= Unit ('AND' Unit)* ;
Unit ::= 'NOT'? Expression ;
Expression ::= Term (Compare Term | Clause)? ;
Term ::= Factor (('+' | '-' | '&') Factor)* ;
Factor ::= Value (('*' | '/' | '%') Value)* ;
Value ::= Element ('.' (Property | Method | Iterator))* ;
Element ::= Auto | User | Literal | '(' Condition ')' ;
Auto ::= "\$[0-9]*" ;
User ::= "\$[a-z_][a-z_0-9]*" ;
Literal ::= String | Integer ;
Integer ::= "[0-9]+" ;
Property ::= 'pattern' | 'length' | 'sum' | 'reverse' | 'min' | 'max' | 'omission' | 'standard' | 'jugglable' | 'valid' | 'balls' | 'period' | 'state' | 'int10' | 'int36' ;
Method ::= ('at' | 'rotate' | 'skip' | 'take') '(' Parameter ')' ;
Parameter ::= Term | '-' Value ;
Iterator ::= ('every' | 'some') '(' Lambda ')' ;
Lambda ::= User (',' User)? '=>' Condition ;
Compare ::= '==' | '!=' | '<>' | '<' | '<=' | '>' | '>=' ;
Clause ::= 'NOT'? 'IN' '(' List ')' ;
List ::= Literal (',' Literal)* ;
Select ::= 'SELECT' 'DISTINCT'? View ;
View ::= Term+ ;
Order ::= 'ORDER' 'BY' Multiple ;
Multiple ::= Single (',' Single)* ;
Single ::= Value ('ASC' | 'DESC')? ;
Limit ::= 'LIMIT' Term ;
Space ::= "\s+" ;
Line ::= "--[^\n]*(\n|$)" ;
Block ::= "/\*((?!\*/)[\s\S])*\*/" ;
</pre>
</section>
</article>
</body>
</html>