| 1 |
--- |
| 2 |
layout: base |
| 3 |
title: Specification |
| 4 |
--- |
| 5 |
|
| 6 |
<style> |
| 7 |
/* Non-terminals */ |
| 8 |
i { |
| 9 |
font-family: Arial, sans-serif; |
| 10 |
font-style: italic; |
| 11 |
color: #008 |
| 12 |
} |
| 13 |
|
| 14 |
/* Value sets */ |
| 15 |
em { |
| 16 |
font-family: Arial, sans-serif; |
| 17 |
font-style: italic; |
| 18 |
color: #800 |
| 19 |
} |
| 20 |
|
| 21 |
code { |
| 22 |
font-family: Courier New, monospace; |
| 23 |
background-color: #efefef; |
| 24 |
font-size: 15px; |
| 25 |
} |
| 26 |
|
| 27 |
div.desugar-rule { |
| 28 |
font-size:75%; |
| 29 |
} |
| 30 |
|
| 31 |
div.desugar-rule-group { |
| 32 |
padding: 3px 0; |
| 33 |
} |
| 34 |
|
| 35 |
div.sequent-rule { |
| 36 |
margin:10px; |
| 37 |
float:left; |
| 38 |
font-size:75%; |
| 39 |
} |
| 40 |
|
| 41 |
div.rules { |
| 42 |
overflow: auto; |
| 43 |
width:100% |
| 44 |
} |
| 45 |
</style> |
| 46 |
|
| 47 |
<div style="display:none"> |
| 48 |
\[ |
| 49 |
\newcommand{\assert}[1]{\texttt{assert }#1} |
| 50 |
\newcommand{\array}[1]{[ #1 ]} |
| 51 |
\newcommand{\assign}[2]{ #1\texttt{ = }#2} |
| 52 |
\newcommand{\binary}[3]{ #1\texttt{ }#2\texttt{ }#3} |
| 53 |
\newcommand{\error}[1]{\texttt{error }#1} |
| 54 |
\newcommand{\false}{\texttt{false}} |
| 55 |
\newcommand{\function}[2]{\texttt{function}\texttt{(} #1\texttt{)}{\ #2}} |
| 56 |
\newcommand{\if}[3]{\texttt{if }#1\texttt{ then }#2\texttt{ else }#3} |
| 57 |
\newcommand{\ifnoelse}[2]{\texttt{if }#1\texttt{ then }#2} |
| 58 |
\newcommand{\import}[1]{\texttt{import }#1} |
| 59 |
\newcommand{\importstr}[1]{\texttt{importstr }#1} |
| 60 |
\newcommand{\importbin}[1]{\texttt{importbin }#1} |
| 61 |
\newcommand{\index}[2]{#1\texttt{[}#2\texttt{]}} |
| 62 |
\newcommand{\local}[2]{\texttt{local }#1\texttt{ ; }#2} |
| 63 |
\newcommand{\null}{\texttt{null}} |
| 64 |
\newcommand{\object}[1]{\{ #1 \}} |
| 65 |
\newcommand{\objlocal}[1]{\texttt{local }#1} |
| 66 |
\newcommand{\ocomp}[4]{\object{[#1]:#2\texttt{ for }#3\texttt{ in }#4}} |
| 67 |
\newcommand{\self}{\texttt{self}} |
| 68 |
\newcommand{\super}{\texttt{super}} |
| 69 |
\newcommand{\true}{\texttt{true}} |
| 70 |
\newcommand{\unary}[2]{\texttt{ }#1\texttt{ }#2} |
| 71 |
|
| 72 |
\newcommand{\rule}[3]{\frac{#2}{#3}\textrm{(#1)}} |
| 73 |
\] |
| 74 |
</div> |
| 75 |
|
| 76 |
<div class="hgroup"> |
| 77 |
<div class="hgroup-inline"> |
| 78 |
<div class="panel"> |
| 79 |
<h1 id="specification">Jsonnet Specification</h1> |
| 80 |
</div> |
| 81 |
<div style="clear: both"></div> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
|
| 85 |
<div class="hgroup"> |
| 86 |
<div class="hgroup-inline"> |
| 87 |
<div class="panel"> |
| 88 |
<p> |
| 89 |
This page is the authority on what Jsonnet programs should do. It defines Jsonnet lexing |
| 90 |
and syntax. It describes which programs should be rejected statically (i.e. before |
| 91 |
execution). Finally, it specifies the manner in which the program is executed, i.e. the |
| 92 |
JSON that is output, or the runtime error if there is one. |
| 93 |
</p> |
| 94 |
<p> |
| 95 |
The specification is intended to be terse, precise, and illuminate all the subtleties and |
| 96 |
edge cases in order to allow fully-compatible language reimplementations and tools. The |
| 97 |
specification employs some standard theoretical computer science techniques, namely <a |
| 98 |
href="https://en.wikipedia.org/wiki/Type_system">type systems</a> and <a |
| 99 |
href="https://en.wikipedia.org/wiki/Operational_semantics">big step operational |
| 100 |
semantics</a>. If you just want to write Jsonnet code (not build a Jsonnet interpreter or |
| 101 |
tool), you don't need to read this. You should read the <a |
| 102 |
href="/learning/tutorial.html">tutorial</a> and <a href="/ref/language.html">reference</a> . |
| 103 |
</p> |
| 104 |
</div> |
| 105 |
<div style="clear: both"></div> |
| 106 |
</div> |
| 107 |
</div> |
| 108 |
|
| 109 |
|
| 110 |
<div class="hgroup"> |
| 111 |
<div class="hgroup-inline"> |
| 112 |
<div class="panel"> |
| 113 |
<h2 id="lexing">Lexing</h2> |
| 114 |
</div> |
| 115 |
<div style="clear: both"></div> |
| 116 |
</div> |
| 117 |
</div> |
| 118 |
|
| 119 |
<div class="hgroup"> |
| 120 |
<div class="hgroup-inline"> |
| 121 |
<div class="panel"> |
| 122 |
<p> |
| 123 |
A Jsonnet program is UTF-8 encoded text. The file is a sequence of tokens, separated by |
| 124 |
optional whitespace and comments. Whitespace consists of space, tab, newline and carriage |
| 125 |
return. Tokens are lexed greedily. Comments are either single line comments, beginning |
| 126 |
with a <code>#</code> or a <code>//</code>, or block comments beginning with <code>/*</code> |
| 127 |
and terminating at the first <code>*/</code> encountered within the comment. |
| 128 |
</p> |
| 129 |
<ul> |
| 130 |
<li> |
| 131 |
<p> |
| 132 |
<i>id</i>: Matched by <tt>[_a-zA-Z][_a-zA-Z0-9]*</tt>. |
| 133 |
</p> |
| 134 |
<p> |
| 135 |
Some identifiers are reserved as keywords, thus are not in the set <i>id</i>: |
| 136 |
<code>assert</code> <code>else</code> <code>error</code> <code>false</code> |
| 137 |
<code>for</code> <code>function</code> <code>if</code> <code>import</code> |
| 138 |
<code>importstr</code> <code>importbin</code> <code>in</code> <code>local</code> <code>null</code> |
| 139 |
<code>tailstrict</code> <code>then</code> <code>self</code> <code>super</code> |
| 140 |
<code>true</code>. |
| 141 |
</p> |
| 142 |
</li> |
| 143 |
<li> |
| 144 |
<p> |
| 145 |
<i>number</i>: As defined by <a href="https://json.org/">JSON</a>, with two exceptions: |
| 146 |
<ul> |
| 147 |
<li> |
| 148 |
Numeric literals may be rendered with underscores (<code>_</code>) between any two adjacent 0-9 digits |
| 149 |
to improve readability. The underscores are discarded by the lexer. |
| 150 |
<br /> |
| 151 |
Examples: <code>1_000_000</code>, <code>0.000_001</code>, <code>6.022_140_76e23</code> |
| 152 |
</li> |
| 153 |
<li> |
| 154 |
Negative numbers are lexed as the <code>-</code> unary operator applied to a positive number to |
| 155 |
simplify parsing. |
| 156 |
</li> |
| 157 |
</ul> |
| 158 |
</p> |
| 159 |
</li> |
| 160 |
<li> |
| 161 |
<p> |
| 162 |
<i>string</i>: Which can have five quoting forms: |
| 163 |
</p> |
| 164 |
<ul> |
| 165 |
<li> |
| 166 |
Double-quoted, beginning with <code>"</code> and ending with the first subsequent |
| 167 |
non-quoted <code>"</code> |
| 168 |
</li> |
| 169 |
<li> |
| 170 |
Single-quoted, beginning with <code>'</code> and ending with the first subsequent |
| 171 |
non-quoted <code>'</code> |
| 172 |
</li> |
| 173 |
<li> |
| 174 |
Double-quoted verbatim, beginning with <code>@"</code> and ending with the first |
| 175 |
subsequent non-quoted <code>"</code> |
| 176 |
</li> |
| 177 |
<li> |
| 178 |
Single-quoted verbatim, beginning with <code>@'</code> and ending with the first |
| 179 |
subsequent non-quoted <code>'</code> |
| 180 |
</li> |
| 181 |
<li> |
| 182 |
Text block, beginning with <code>|||</code> followed by an optional |
| 183 |
<code>-</code>, then optional whitespace and a new-line. The next non-empty |
| 184 |
line must be prefixed with some non-zero length whitespace <i>W</i>. The |
| 185 |
block ends at the first subsequent line that is non-empty and does not begin |
| 186 |
with <i>W</i>, and it is an error if this line does not contain some |
| 187 |
optional whitespace followed by <code>|||</code>. The content of the string |
| 188 |
is the concatenation of all the lines between the two <code>|||</code>, |
| 189 |
which either begin with <i>W</i> (in which case that prefix is stripped) or |
| 190 |
they are empty lines (in which case they remain as empty lines). The line |
| 191 |
ending style in the file is preserved in the string. If the beginning |
| 192 |
<code>|||</code> was followed by <code>-</code> then the final new-line is |
| 193 |
stripped from the resulting string. This form cannot be used in |
| 194 |
<code>import</code> statements. |
| 195 |
</li> |
| 196 |
</ul> |
| 197 |
<p> |
| 198 |
Double- and single-quoted strings are allowed to span multiple lines, in which case |
| 199 |
whatever dos/unix end-of-line character your editor inserts will be put in the string. |
| 200 |
They both understand the following escape characters: <code>"'\/bfnrt</code> which have |
| 201 |
their standard meanings, as well as <code>\uXXXX</code> for hexadecimal unicode escapes. |
| 202 |
</p> |
| 203 |
<p> |
| 204 |
Verbatim strings eschew all of the normal string escaping, including hexadecimal unicode |
| 205 |
escapes. Every character in a verbatim string is processed literally, with the |
| 206 |
exception of doubled end-quotes. Within a verbatim single-quoted string, |
| 207 |
<code>''</code> is processed as <code>'</code>, and a verbatim double-quoted string, |
| 208 |
<code>""</code> is processed as <code>"</code>. |
| 209 |
</p> |
| 210 |
<p> |
| 211 |
In the rest of this specification, the string is assumed to be canonicalized into a |
| 212 |
sequence of unicode codepoints with no record of the original quoting form as well and |
| 213 |
any escape characters removed. |
| 214 |
</p> |
| 215 |
</li> |
| 216 |
<li> |
| 217 |
<p> |
| 218 |
<i>symbol</i>: The following single-character symbols: |
| 219 |
</p> |
| 220 |
<p><code>{}[],.();</code></p> |
| 221 |
</li> |
| 222 |
<li> |
| 223 |
<p> |
| 224 |
<i>operator</i>: A sequence of at least one of the following single-character symbols: |
| 225 |
<code>!$:~+-&|^=<>*/%</code>. |
| 226 |
</p> |
| 227 |
<p> |
| 228 |
Additionally it is subject to the following rules, which may cause the lexing to terminate with a shorter |
| 229 |
token: |
| 230 |
</p> |
| 231 |
<ul> |
| 232 |
<li> |
| 233 |
The sequence <code>//</code> is not allowed in an operator. |
| 234 |
</li> |
| 235 |
<li> |
| 236 |
The sequence <code>/*</code> is not allowed in an operator. |
| 237 |
</li> |
| 238 |
<li> |
| 239 |
The sequence <code>|||</code> is not allowed in an operator. |
| 240 |
</li> |
| 241 |
<li> |
| 242 |
If the sequence has more than one character, it is not allowed to end in any of |
| 243 |
<code>+</code>, <code>-</code>, <code>~</code>, <code>!</code>, <code>$</code>. |
| 244 |
</li> |
| 245 |
</ul> |
| 246 |
</li> |
| 247 |
</ul> |
| 248 |
</div> |
| 249 |
<div style="clear: both"></div> |
| 250 |
</div> |
| 251 |
</div> |
| 252 |
|
| 253 |
|
| 254 |
<div class="hgroup"> |
| 255 |
<div class="hgroup-inline"> |
| 256 |
<div class="panel"> |
| 257 |
<h2 id="abstract_syntax">Abstract Syntax</h2> |
| 258 |
</div> |
| 259 |
<div style="clear: both"></div> |
| 260 |
</div> |
| 261 |
</div> |
| 262 |
|
| 263 |
<div class="hgroup"> |
| 264 |
<div class="hgroup-inline"> |
| 265 |
<div class="panel"> |
| 266 |
<p> |
| 267 |
The notation used here is as follows: { } denotes zero or more repetitions of a sequence of |
| 268 |
tokens, and [ ] represents an optional sequence of tokens. This is not to be confused with |
| 269 |
<code>{ }</code> and <code>[ ]</code> which represent tokens in Jsonnet itself. |
| 270 |
</p> |
| 271 |
|
| 272 |
<p> |
| 273 |
Note that although the lexer will generate tokens for a wide range of operators, only a |
| 274 |
finite set are currently parseable, the rest being reserved for possible future use. |
| 275 |
</p> |
| 276 |
</div> |
| 277 |
<div style="clear: both"></div> |
| 278 |
</div> |
| 279 |
</div> |
| 280 |
|
| 281 |
<div class="inverse hgroup"> |
| 282 |
<div class="hgroup-inline"> |
| 283 |
<div class="panel wide"> |
| 284 |
<table> |
| 285 |
<tr> |
| 286 |
<td><i>expr ∈ Expr</i></td> |
| 287 |
<td>::=</td> |
| 288 |
<td> |
| 289 |
<code>null</code> | |
| 290 |
<code>true</code> | |
| 291 |
<code>false</code> | |
| 292 |
<code>self</code> | |
| 293 |
<code>$</code> | |
| 294 |
<i>string</i> | |
| 295 |
<i>number</i> |
| 296 |
</td> |
| 297 |
</tr> |
| 298 |
|
| 299 |
<!-- object --> |
| 300 |
<tr> |
| 301 |
<td></td> |
| 302 |
<td> | </td> |
| 303 |
<td> |
| 304 |
<code>{</code> |
| 305 |
<i>objinside</i> |
| 306 |
<code>}</code> |
| 307 |
</td> |
| 308 |
</tr> |
| 309 |
|
| 310 |
<!-- array --> |
| 311 |
<tr> |
| 312 |
<td></td> |
| 313 |
<td>|</td> |
| 314 |
<td> |
| 315 |
<code>[</code> |
| 316 |
[ <i>expr</i> { <code>,</code> <i>expr</i> } [ <code>,</code> ] ] |
| 317 |
<code>]</code> |
| 318 |
</td> |
| 319 |
</tr> |
| 320 |
|
| 321 |
<!-- array comprehension --> |
| 322 |
<tr> |
| 323 |
<td></td> |
| 324 |
<td> | </td> |
| 325 |
<td> |
| 326 |
<code>[</code> |
| 327 |
<i>expr</i> |
| 328 |
[ <code>,</code> ] |
| 329 |
<i>forspec</i> <i>compspec</i> |
| 330 |
<code>]</code> |
| 331 |
</td> |
| 332 |
</tr> |
| 333 |
|
| 334 |
<!-- object index (id) --> |
| 335 |
<tr> |
| 336 |
<td></td> |
| 337 |
<td> | </td> |
| 338 |
<td> |
| 339 |
<i>expr</i> |
| 340 |
<code>.</code> |
| 341 |
<i>id</i> |
| 342 |
</td> |
| 343 |
</tr> |
| 344 |
|
| 345 |
<!-- object index (general) --> |
| 346 |
<tr> |
| 347 |
<td></td> |
| 348 |
<td> | </td> |
| 349 |
<td> |
| 350 |
<i>expr</i> |
| 351 |
<code>[</code> |
| 352 |
[ <i>expr</i> ] |
| 353 |
[ <code>:</code> [ <i> expr</i> ] |
| 354 |
[ <code>:</code> [ <i>expr</i> ] ] ] |
| 355 |
<code>]</code> |
| 356 |
</td> |
| 357 |
</tr> |
| 358 |
|
| 359 |
<!-- super index (id) --> |
| 360 |
<tr> |
| 361 |
<td></td> |
| 362 |
<td> | </td> |
| 363 |
<td> |
| 364 |
<code>super</code> |
| 365 |
<code>.</code> |
| 366 |
<i>id</i> |
| 367 |
</td> |
| 368 |
</tr> |
| 369 |
|
| 370 |
<!-- super index (general) --> |
| 371 |
<tr> |
| 372 |
<td></td> |
| 373 |
<td> | </td> |
| 374 |
<td> |
| 375 |
<code>super</code> |
| 376 |
<code>[</code> |
| 377 |
<i>expr</i> |
| 378 |
<code>]</code> |
| 379 |
</td> |
| 380 |
</tr> |
| 381 |
|
| 382 |
<!-- apply --> |
| 383 |
<tr> |
| 384 |
<td></td> |
| 385 |
<td> | </td> |
| 386 |
<td> |
| 387 |
<i>expr</i> |
| 388 |
<code>(</code> |
| 389 |
[ <i>args</i> ] |
| 390 |
<code>)</code> |
| 391 |
</td> |
| 392 |
</tr> |
| 393 |
|
| 394 |
<!-- var --> |
| 395 |
<tr> |
| 396 |
<td></td> |
| 397 |
<td> | </td> |
| 398 |
<td> |
| 399 |
<i>id</i> |
| 400 |
</td> |
| 401 |
</tr> |
| 402 |
|
| 403 |
<!-- local expression --> |
| 404 |
<tr> |
| 405 |
<td></td> |
| 406 |
<td> | </td> |
| 407 |
<td> |
| 408 |
<code>local</code> |
| 409 |
<i>bind</i> |
| 410 |
{ |
| 411 |
<code>,</code> |
| 412 |
<i>bind</i> |
| 413 |
} |
| 414 |
<code>;</code> |
| 415 |
<i>expr</i> |
| 416 |
</td> |
| 417 |
</tr> |
| 418 |
|
| 419 |
<!-- conditional --> |
| 420 |
<tr> |
| 421 |
<td></td> |
| 422 |
<td> | </td> |
| 423 |
<td> |
| 424 |
<code>if</code> |
| 425 |
<i>expr</i> |
| 426 |
<code>then</code> |
| 427 |
<i>expr</i> |
| 428 |
[ <code>else</code> |
| 429 |
<i>expr</i> ] |
| 430 |
</td> |
| 431 |
</tr> |
| 432 |
|
| 433 |
<!-- binary --> |
| 434 |
<tr> |
| 435 |
<td></td> |
| 436 |
<td> | </td> |
| 437 |
<td> |
| 438 |
<i>expr</i> |
| 439 |
<i>binaryop</i> |
| 440 |
<i>expr</i> |
| 441 |
</td> |
| 442 |
</tr> |
| 443 |
|
| 444 |
<!-- unary --> |
| 445 |
<tr> |
| 446 |
<td></td> |
| 447 |
<td> | </td> |
| 448 |
<td> |
| 449 |
<i>unaryop</i> |
| 450 |
<i>expr</i> |
| 451 |
</td> |
| 452 |
</tr> |
| 453 |
|
| 454 |
<!-- object apply --> |
| 455 |
<tr> |
| 456 |
<td></td> |
| 457 |
<td> | </td> |
| 458 |
<td> |
| 459 |
<i>expr</i> |
| 460 |
<code>{</code> |
| 461 |
<i>objinside</i> |
| 462 |
<code>}</code> |
| 463 |
</td> |
| 464 |
</tr> |
| 465 |
|
| 466 |
<!-- function --> |
| 467 |
<tr> |
| 468 |
<td></td> |
| 469 |
<td> | </td> |
| 470 |
<td> |
| 471 |
<code>function</code> |
| 472 |
<code>(</code> |
| 473 |
[ <i>params</i> ] |
| 474 |
<code>)</code> |
| 475 |
<i>expr</i> |
| 476 |
</td> |
| 477 |
</tr> |
| 478 |
|
| 479 |
<!-- assert --> |
| 480 |
<tr> |
| 481 |
<td></td> |
| 482 |
<td> | </td> |
| 483 |
<td> |
| 484 |
<i>assert</i> |
| 485 |
<code>;</code> |
| 486 |
<i>expr</i> |
| 487 |
</td> |
| 488 |
</tr> |
| 489 |
|
| 490 |
<!-- import --> |
| 491 |
<tr> |
| 492 |
<td></td> |
| 493 |
<td> | </td> |
| 494 |
<td> |
| 495 |
<code>import</code> |
| 496 |
<i>string</i> |
| 497 |
</td> |
| 498 |
</tr> |
| 499 |
|
| 500 |
<!-- importstr --> |
| 501 |
<tr> |
| 502 |
<td></td> |
| 503 |
<td> | </td> |
| 504 |
<td> |
| 505 |
<code>importstr</code> |
| 506 |
<i>string</i> |
| 507 |
</td> |
| 508 |
</tr> |
| 509 |
|
| 510 |
<!-- importbin --> |
| 511 |
<tr> |
| 512 |
<td></td> |
| 513 |
<td> | </td> |
| 514 |
<td> |
| 515 |
<code>importbin</code> |
| 516 |
<i>string</i> |
| 517 |
</td> |
| 518 |
</tr> |
| 519 |
|
| 520 |
<!-- error --> |
| 521 |
<tr> |
| 522 |
<td></td> |
| 523 |
<td> | </td> |
| 524 |
<td> |
| 525 |
<code>error</code> |
| 526 |
<i>expr</i> |
| 527 |
</td> |
| 528 |
</tr> |
| 529 |
|
| 530 |
<!-- super in e --> |
| 531 |
<tr> |
| 532 |
<td></td> |
| 533 |
<td> | </td> |
| 534 |
<td> |
| 535 |
<i>expr</i> <code>in</code> <code>super</code> |
| 536 |
</td> |
| 537 |
</tr> |
| 538 |
</table> |
| 539 |
|
| 540 |
|
| 541 |
<p></p> |
| 542 |
|
| 543 |
<!-- AUX STUFF --> |
| 544 |
|
| 545 |
<table> |
| 546 |
<tr> |
| 547 |
<td><i>objinside</i></td> |
| 548 |
<td>::=</td> |
| 549 |
<td> |
| 550 |
<!-- object --> |
| 551 |
{ <i>member</i> <code>,</code> } [ <i>member</i> ] |
| 552 |
</td> |
| 553 |
</tr> |
| 554 |
|
| 555 |
<!-- object comprehension --> |
| 556 |
<tr> |
| 557 |
<td></td> |
| 558 |
<td> | </td> |
| 559 |
<td> |
| 560 |
{ <i>objlocal</i> <code>,</code> } |
| 561 |
<code>[</code> |
| 562 |
<i>expr</i> |
| 563 |
<code>]</code> |
| 564 |
<code>:</code> |
| 565 |
<i>expr</i> |
| 566 |
[ { <code>,</code> <i>objlocal</i> } ] [ <code>,</code> ] |
| 567 |
<i>forspec</i> <i>compspec</i> |
| 568 |
</td> |
| 569 |
</tr> |
| 570 |
|
| 571 |
<!-- member --> |
| 572 |
<tr> |
| 573 |
<td><i>member</i></td> |
| 574 |
<td>::=</td> |
| 575 |
<td> |
| 576 |
<i>objlocal</i> | <i>assert</i> | <i>field</i> |
| 577 |
</td> |
| 578 |
</tr> |
| 579 |
|
| 580 |
<!-- field --> |
| 581 |
<tr> |
| 582 |
<td><i>field ∈ Field</i></td> |
| 583 |
<td>::=</td> |
| 584 |
<td> |
| 585 |
<i>fieldname</i> |
| 586 |
[ <code>+</code> ] <i>h</i> |
| 587 |
<i>expr</i> |
| 588 |
</td> |
| 589 |
</tr> |
| 590 |
|
| 591 |
<!-- method --> |
| 592 |
<tr> |
| 593 |
<td></td> |
| 594 |
<td> | </td> |
| 595 |
<td> |
| 596 |
<i>fieldname</i> |
| 597 |
<code>(</code> |
| 598 |
[ <i>params</i> ] |
| 599 |
<code>)</code> |
| 600 |
<i>h</i> |
| 601 |
<i>expr</i> |
| 602 |
</td> |
| 603 |
</tr> |
| 604 |
|
| 605 |
<!-- colons --> |
| 606 |
<tr> |
| 607 |
<td><i>h ∈ Hidden</i></td> |
| 608 |
<td>::=</td> |
| 609 |
<td> |
| 610 |
<code>:</code> | <code>::</code> | <code>:::</code> |
| 611 |
</td> |
| 612 |
</tr> |
| 613 |
|
| 614 |
<!-- obj local --> |
| 615 |
<tr> |
| 616 |
<td><i>objlocal</i></td> |
| 617 |
<td>::=</td> |
| 618 |
<td> |
| 619 |
<code>local</code> <i>bind</i> |
| 620 |
</td> |
| 621 |
</tr> |
| 622 |
|
| 623 |
<!-- compspec (object comps) --> |
| 624 |
<tr> |
| 625 |
<td><i>compspec ∈ CompSpec</i></td> |
| 626 |
<td>::=</td> |
| 627 |
<td> |
| 628 |
{ <i>forspec</i> | <i>ifspec</i> } |
| 629 |
</td> |
| 630 |
</tr> |
| 631 |
|
| 632 |
<!-- for spec (object comps) --> |
| 633 |
<tr> |
| 634 |
<td><i>forspec</i></td> |
| 635 |
<td>::=</td> |
| 636 |
<td> |
| 637 |
<code>for</code> |
| 638 |
<i>id</i> |
| 639 |
<code>in</code> |
| 640 |
<i>expr</i> |
| 641 |
</td> |
| 642 |
</tr> |
| 643 |
|
| 644 |
<!-- if spec (object comps) --> |
| 645 |
<tr> |
| 646 |
<td><i>ifspec</i></td> |
| 647 |
<td>::=</td> |
| 648 |
<td> |
| 649 |
<code>if</code> |
| 650 |
<i>expr</i> |
| 651 |
</td> |
| 652 |
</tr> |
| 653 |
|
| 654 |
<!-- fieldname --> |
| 655 |
<tr> |
| 656 |
<td><i>fieldname</i></td> |
| 657 |
<td>::=</td> |
| 658 |
<td> |
| 659 |
<i>id</i> | |
| 660 |
<i>string</i> | |
| 661 |
<code>[</code> |
| 662 |
<i>expr</i> |
| 663 |
<code>]</code> |
| 664 |
</td> |
| 665 |
</tr> |
| 666 |
</table> |
| 667 |
|
| 668 |
<p></p> |
| 669 |
|
| 670 |
<!-- obj assert --> |
| 671 |
<table> |
| 672 |
<tr> |
| 673 |
<td><i>assert</i></td> |
| 674 |
<td>::=</td> |
| 675 |
<td> |
| 676 |
<code>assert</code> <i>expr</i> [ <code>:</code> <i>expr</i> ] |
| 677 |
</td> |
| 678 |
</tr> |
| 679 |
</table> |
| 680 |
|
| 681 |
<!-- bind --> |
| 682 |
<table> |
| 683 |
<tr> |
| 684 |
<td><i>bind ∈ Bind</i></td> |
| 685 |
<td>::=</td> |
| 686 |
<td> |
| 687 |
<i>id</i> |
| 688 |
<code>=</code> |
| 689 |
<i>expr</i> |
| 690 |
</td> |
| 691 |
</tr> |
| 692 |
<tr> |
| 693 |
<td></td> |
| 694 |
<td> | </td> |
| 695 |
<td> |
| 696 |
<i>id</i> |
| 697 |
<code>(</code> |
| 698 |
[ <i>params</i> ] |
| 699 |
<code>)</code> |
| 700 |
<code>=</code> |
| 701 |
<i>expr</i> |
| 702 |
</td> |
| 703 |
</tr> |
| 704 |
</table> |
| 705 |
|
| 706 |
<p></p> |
| 707 |
|
| 708 |
<!-- args --> |
| 709 |
<table> |
| 710 |
<tr> |
| 711 |
<td><i>args</i></td> |
| 712 |
<td>::=</td> |
| 713 |
<td> |
| 714 |
<i>expr</i> { <code>,</code> <i>expr</i> } { <code>,</code> <i>id</i> <code>=</code> |
| 715 |
<i>expr</i> } [ <code>,</code> ] |
| 716 |
</td> |
| 717 |
</tr> |
| 718 |
|
| 719 |
<tr> |
| 720 |
<td></td> |
| 721 |
<td>|</td> |
| 722 |
<td> |
| 723 |
<i>id</i> <code>=</code> <i>expr</i> { <code>,</code> <i>id</i> <code>=</code> |
| 724 |
<i>expr</i> } [ <code>,</code> ] |
| 725 |
</td> |
| 726 |
</tr> |
| 727 |
</table> |
| 728 |
|
| 729 |
<p></p> |
| 730 |
|
| 731 |
<!-- params --> |
| 732 |
<table> |
| 733 |
<tr> |
| 734 |
<td><i>params</i></td> |
| 735 |
<td>::=</td> |
| 736 |
<td> |
| 737 |
<i>param</i> { <code>,</code> <i>param</i> } [ <code>,</code> ] |
| 738 |
</td> |
| 739 |
</tr> |
| 740 |
</table> |
| 741 |
|
| 742 |
|
| 743 |
<!-- param --> |
| 744 |
<table> |
| 745 |
<tr> |
| 746 |
<td><i>param</i></td> |
| 747 |
<td>::=</td> |
| 748 |
<td> |
| 749 |
<i>id</i> [ <code>=</code> <i>expr</i> ] |
| 750 |
</td> |
| 751 |
</tr> |
| 752 |
</table> |
| 753 |
|
| 754 |
|
| 755 |
<p></p> |
| 756 |
|
| 757 |
<!-- binaryop --> |
| 758 |
<table> |
| 759 |
<tr> |
| 760 |
<td><i>binaryop</i></td> |
| 761 |
<td>::=</td> |
| 762 |
<td> |
| 763 |
<code>*</code> | |
| 764 |
<code>/</code> | |
| 765 |
<code>%</code> | |
| 766 |
<code>+</code> | |
| 767 |
<code>-</code> | |
| 768 |
<code><<</code> | |
| 769 |
<code>>></code> | |
| 770 |
<code><</code> | |
| 771 |
<code><=</code> | |
| 772 |
<code>></code> | |
| 773 |
<code>>=</code> | |
| 774 |
<code>==</code> | |
| 775 |
<code>!=</code> | |
| 776 |
<code>in</code> | |
| 777 |
<code>&</code> | |
| 778 |
<code>^</code> | |
| 779 |
<code>|</code> | |
| 780 |
<code>&&</code> | |
| 781 |
<code>||</code> |
| 782 |
</td> |
| 783 |
</tr> |
| 784 |
|
| 785 |
<!-- unaryop --> |
| 786 |
<tr> |
| 787 |
<td><i>unaryop</i></td> |
| 788 |
<td>::=</td> |
| 789 |
<td> <code>-</code> | <code>+</code> | <code>!</code> | <code>~</code> </td> |
| 790 |
</tr> |
| 791 |
</table> |
| 792 |
|
| 793 |
</div> |
| 794 |
<div style="clear: both"></div> |
| 795 |
</div> |
| 796 |
</div> |
| 797 |
|
| 798 |
|
| 799 |
<div class="hgroup"> |
| 800 |
<div class="hgroup-inline"> |
| 801 |
<div class="panel"> |
| 802 |
<h2 id="associativity_precedence">Associativity and Operator Precedence</h2> |
| 803 |
</div> |
| 804 |
<div style="clear: both"></div> |
| 805 |
</div> |
| 806 |
</div> |
| 807 |
|
| 808 |
<div class="hgroup"> |
| 809 |
<div class="hgroup-inline"> |
| 810 |
<div class="panel"> |
| 811 |
<p> |
| 812 |
The abstract syntax by itself cannot unambiguously parse a sequence of tokens. Ambiguities |
| 813 |
are resolved according to the following rules, which can also be overridden by adding |
| 814 |
parenthesis symbols <code>()</code>. |
| 815 |
</p> |
| 816 |
|
| 817 |
<p> |
| 818 |
Everything is left associative. In the case of <code>assert</code>, <code>error</code>, |
| 819 |
<code>function</code>, <code>if</code>, <code>import</code>, <code>importstr</code>, <code>importbin</code>, and |
| 820 |
<code>local</code>, ambiguity is resolved by consuming as many tokens as possible on the |
| 821 |
right hand side. For example the parentheses are redundant in <code>local x = 1; (x + |
| 822 |
x)</code>. All remaining ambiguities are resolved according to the following decreasing |
| 823 |
order of precedence: |
| 824 |
</p> |
| 825 |
|
| 826 |
<ol> |
| 827 |
<li><code>e(...)</code> <code>e[...]</code> <code>e.f</code> <code>e {...}</code> |
| 828 |
(application, indexing, and implicit object composition)</li> |
| 829 |
<li><code>+</code> <code>-</code> <code>!</code> <code>~</code> |
| 830 |
(the unary operators)</li> |
| 831 |
<li><code>*</code> <code>/</code> <code>%</code> |
| 832 |
(these, and the remainder below, are binary operators)</li> |
| 833 |
<li><code>+</code> <code>-</code></li> |
| 834 |
<li><code><<</code> <code>>></code></li> |
| 835 |
<li> |
| 836 |
<code><</code> <code>></code> <code><=</code> <code>>=</code> <code>in</code> |
| 837 |
</li> |
| 838 |
<li><code>==</code> <code>!=</code></li> |
| 839 |
<li><code>&</code></li> |
| 840 |
<li><code>^</code></li> |
| 841 |
<li><code>|</code></li> |
| 842 |
<li><code>&&</code></li> |
| 843 |
<li><code>||</code></li> |
| 844 |
</ol> |
| 845 |
</div> |
| 846 |
<div style="clear: both"></div> |
| 847 |
</div> |
| 848 |
</div> |
| 849 |
|
| 850 |
|
| 851 |
<div class="hgroup"> |
| 852 |
<div class="hgroup-inline"> |
| 853 |
<div class="panel"> |
| 854 |
<h2 id="core">Core Language Subset</h2> |
| 855 |
</div> |
| 856 |
<div style="clear: both"></div> |
| 857 |
</div> |
| 858 |
</div> |
| 859 |
|
| 860 |
<div class="hgroup"> |
| 861 |
<div class="hgroup-inline"> |
| 862 |
<div class="panel"> |
| 863 |
<p> |
| 864 |
To make the specification of Jsonnet as simple as possible, many of the language features |
| 865 |
are represented as syntax sugar. Below is defined the core syntax and the desugaring |
| 866 |
function from the abstract syntax to the core syntax. Both the static checking rules and |
| 867 |
the operational semantics are defined at the level of the core language, so it is possible |
| 868 |
to desugar immediately after parsing. |
| 869 |
</p> |
| 870 |
</div> |
| 871 |
<div style="clear: both"></div> |
| 872 |
</div> |
| 873 |
</div> |
| 874 |
|
| 875 |
|
| 876 |
<div class="hgroup"> |
| 877 |
<div class="hgroup-inline"> |
| 878 |
<div class="panel"> |
| 879 |
<h3 id="core_syntax">Core Syntax</h3> |
| 880 |
</div> |
| 881 |
<div style="clear: both"></div> |
| 882 |
</div> |
| 883 |
</div> |
| 884 |
|
| 885 |
<div class="hgroup"> |
| 886 |
<div class="hgroup-inline"> |
| 887 |
<div class="panel"> |
| 888 |
<p> |
| 889 |
The core language has the following simplifications: |
| 890 |
</p> |
| 891 |
<ul> |
| 892 |
<li> |
| 893 |
The set of identifiers now includes <code>$</code>, which is no-longer a special keyword. |
| 894 |
</li> |
| 895 |
<li> |
| 896 |
The following binary operators are removed: <code>!=</code> <code>==</code> <code>%</code> |
| 897 |
<code>in</code> |
| 898 |
</li> |
| 899 |
<li>Array slices <code>[::]</code> are removed.</li> |
| 900 |
<li> |
| 901 |
Array and object comprehensions are replaced with a simple object comprehension construct. |
| 902 |
</li> |
| 903 |
<li>Expression-level asserts are removed.</li> |
| 904 |
<li>Object-level level assert messages are removed.</li> |
| 905 |
<li> |
| 906 |
Object-level level assert values are ignored, but their evaluation may still raise an |
| 907 |
error. |
| 908 |
</li> |
| 909 |
<li>Object methods and local functions are removed.</li> |
| 910 |
<li>Object-level locals are removed.</li> |
| 911 |
<li>Object field name definitions can only be expressions.</li> |
| 912 |
<li>The <code>+:</code>, <code>+::</code>, and <code>+:::</code> sugars are removed.</li> |
| 913 |
<li>Field lookup is only possible through <code>e[e]</code>.</li> |
| 914 |
<li>All conditionals must have an else branch.</li> |
| 915 |
<li>The keyword <code>super</code> can exist on its own.</li> |
| 916 |
</ul> |
| 917 |
<p> |
| 918 |
Commas are no-longer part of this abstract syntax but we may still write them in our |
| 919 |
notation to make the presentation more clear. |
| 920 |
</p> |
| 921 |
<p> |
| 922 |
Also removed in the core language are <code>import</code>, <code>importstr</code>, and <code>importbin</code>. The |
| 923 |
semantics of these constructs is that they are replaced with either the contents of the |
| 924 |
file, or an error construct if importing failed (e.g. due to I/O errors). In the first |
| 925 |
case, the file is parsed, desugared, and subject to static checking before it can be |
| 926 |
substituted. In the case of <code>importstr</code>, the file is substituted in the form of a string, so it |
| 927 |
merely needs to contain valid UTF-8. For <code>importbin</code>, the file is substituted as an array of integer numbers between 0 and 255 inclusive. |
| 928 |
</p> |
| 929 |
<p> |
| 930 |
A given Jsonnet file can be recursively imported via <code>import</code>. Thus, the |
| 931 |
implementation loads files lazily (i.e. during execution) as opposed to via static |
| 932 |
desugaring. The imported Jsonnet file is parsed and statically checked in isolation. |
| 933 |
Therefore, the behavior of the import is not affected by the environment into which it is |
| 934 |
imported. The files are cached by filename, so that even if the file changes on disk during |
| 935 |
Jsonnet execution, referential transparency is maintained. |
| 936 |
</p> |
| 937 |
<table> |
| 938 |
<tr> |
| 939 |
<td><i>e ∈ Core</i></td> |
| 940 |
<td>::=</td> |
| 941 |
<td> |
| 942 |
<code>null</code> | |
| 943 |
<code>true</code> | |
| 944 |
<code>false</code> | |
| 945 |
<code>self</code> | |
| 946 |
<code>super</code> | |
| 947 |
<i>string</i> | |
| 948 |
<i>number</i> |
| 949 |
</td> |
| 950 |
</tr> |
| 951 |
|
| 952 |
<!-- core objects --> |
| 953 |
<tr> |
| 954 |
<td></td> |
| 955 |
<td> | </td> |
| 956 |
<td> |
| 957 |
<code>{</code> |
| 958 |
{ |
| 959 |
<code>assert</code> <i>e</i> |
| 960 |
} |
| 961 |
{ |
| 962 |
<code>[</code> <i>e</i> <code>]</code> <i>h</i> <i>e</i> |
| 963 |
} |
| 964 |
<code>}</code> |
| 965 |
</td> |
| 966 |
</tr> |
| 967 |
|
| 968 |
<!-- core object comprehension --> |
| 969 |
<tr> |
| 970 |
<td></td> |
| 971 |
<td> | </td> |
| 972 |
<td> |
| 973 |
<code>{</code> |
| 974 |
<code>[</code> <i>e</i> <code>]</code> <code>:</code> <i>e</i> |
| 975 |
<code>for</code> <i>id</i> <code>in</code> <i>e</i> |
| 976 |
<code>}</code> |
| 977 |
</td> |
| 978 |
</tr> |
| 979 |
|
| 980 |
<!-- core array --> |
| 981 |
<tr> |
| 982 |
<td></td> |
| 983 |
<td> | </td> |
| 984 |
<td> |
| 985 |
<code>[</code> |
| 986 |
{ <i>e</i> } |
| 987 |
<code>]</code> |
| 988 |
</td> |
| 989 |
</tr> |
| 990 |
|
| 991 |
<!-- core index --> |
| 992 |
<tr> |
| 993 |
<td></td> |
| 994 |
<td> | </td> |
| 995 |
<td> |
| 996 |
<i>e</i> |
| 997 |
<code>[</code> |
| 998 |
<i>e</i> |
| 999 |
<code>]</code> |
| 1000 |
</td> |
| 1001 |
</tr> |
| 1002 |
|
| 1003 |
<!-- core apply --> |
| 1004 |
<tr> |
| 1005 |
<td></td> |
| 1006 |
<td> | </td> |
| 1007 |
<td> |
| 1008 |
<i>e</i> |
| 1009 |
<code>(</code> |
| 1010 |
{ <i>e</i> } |
| 1011 |
{ <i>id</i> <code>=</code> <i>e</i> } |
| 1012 |
<code>)</code> |
| 1013 |
</td> |
| 1014 |
</tr> |
| 1015 |
|
| 1016 |
<!-- core var --> |
| 1017 |
<tr> |
| 1018 |
<td></td> |
| 1019 |
<td> | </td> |
| 1020 |
<td> |
| 1021 |
<i>id</i> |
| 1022 |
</td> |
| 1023 |
</tr> |
| 1024 |
|
| 1025 |
<!-- core local --> |
| 1026 |
<tr> |
| 1027 |
<td></td> |
| 1028 |
<td> | </td> |
| 1029 |
<td> |
| 1030 |
<code>local</code> |
| 1031 |
<i>id</i> <code>=</code> <i>e</i> |
| 1032 |
{ |
| 1033 |
<i>id</i> <code>=</code> <i>e</i> |
| 1034 |
} |
| 1035 |
<code>;</code> |
| 1036 |
<i>e</i> |
| 1037 |
</td> |
| 1038 |
</tr> |
| 1039 |
|
| 1040 |
<!-- core conditional --> |
| 1041 |
<tr> |
| 1042 |
<td></td> |
| 1043 |
<td> | </td> |
| 1044 |
<td> |
| 1045 |
<code>if</code> |
| 1046 |
<i>e</i> |
| 1047 |
<code>then</code> |
| 1048 |
<i>e</i> |
| 1049 |
<code>else</code> |
| 1050 |
<i>e</i> |
| 1051 |
</td> |
| 1052 |
</tr> |
| 1053 |
|
| 1054 |
<!-- core unary op --> |
| 1055 |
<tr> |
| 1056 |
<td></td> |
| 1057 |
<td> | </td> |
| 1058 |
<td> |
| 1059 |
<i>e</i> |
| 1060 |
<i>binaryop</i> |
| 1061 |
<i>e</i> |
| 1062 |
</td> |
| 1063 |
</tr> |
| 1064 |
|
| 1065 |
<!-- core binary op --> |
| 1066 |
<tr> |
| 1067 |
<td></td> |
| 1068 |
<td> | </td> |
| 1069 |
<td> |
| 1070 |
<i>unaryop</i> |
| 1071 |
<i>e</i> |
| 1072 |
</td> |
| 1073 |
</tr> |
| 1074 |
|
| 1075 |
<!-- core closure --> |
| 1076 |
<tr> |
| 1077 |
<td></td> |
| 1078 |
<td> | </td> |
| 1079 |
<td> |
| 1080 |
<code>function</code> |
| 1081 |
<code>(</code> |
| 1082 |
{ <i>id</i> <code>=</code> <i>e</i> } |
| 1083 |
<code>)</code> |
| 1084 |
<i>e</i> |
| 1085 |
</td> |
| 1086 |
</tr> |
| 1087 |
|
| 1088 |
<!-- core error --> |
| 1089 |
<tr> |
| 1090 |
<td></td> |
| 1091 |
<td> | </td> |
| 1092 |
<td> |
| 1093 |
<code>error</code> |
| 1094 |
<i>e</i> |
| 1095 |
</td> |
| 1096 |
</tr> |
| 1097 |
</table> |
| 1098 |
</div> |
| 1099 |
<div style="clear: both"></div> |
| 1100 |
</div> |
| 1101 |
</div> |
| 1102 |
|
| 1103 |
|
| 1104 |
<div class="hgroup"> |
| 1105 |
<div class="hgroup-inline"> |
| 1106 |
<div class="panel"> |
| 1107 |
<h3 id="desugaring">Desugaring</h3> |
| 1108 |
</div> |
| 1109 |
<div style="clear: both"></div> |
| 1110 |
</div> |
| 1111 |
</div> |
| 1112 |
|
| 1113 |
<div class="hgroup"> |
| 1114 |
<div class="hgroup-inline"> |
| 1115 |
<div class="panel"> |
| 1116 |
<p> |
| 1117 |
Desugaring removes constructs that are not in the core language by replacing them with |
| 1118 |
constructs that are. It is defined via the following functions, which proceed by |
| 1119 |
syntax-directed recursion. If a function is not defined on a construct then it simply |
| 1120 |
recurses into the sub-expressions of that construct. Note that we import the standard |
| 1121 |
library at the top of every file, and some of the desugarings call functions defined in the |
| 1122 |
standard library. Their behavior is specified by implementation. However not all standard |
| 1123 |
library functions are written in Jsonnet. The ones that are built into the interpreter |
| 1124 |
(e.g. reflection) will be given special operational semantics rules with the rest of the |
| 1125 |
core language constructs. |
| 1126 |
</p> |
| 1127 |
</div> |
| 1128 |
<div style="clear: both"></div> |
| 1129 |
</div> |
| 1130 |
</div> |
| 1131 |
|
| 1132 |
<div class="inverse hgroup"> |
| 1133 |
<div class="hgroup-inline"> |
| 1134 |
<div class="panel wide"> |
| 1135 |
<div class="desugar-rule-group"> |
| 1136 |
<p> |
| 1137 |
<i>desugar</i>: Expr → Core. This desugars a Jsonnet file. Let \(e_{std}\) be the parsed |
| 1138 |
content of <a href="https://github.com/google/jsonnet/blob/master/stdlib/std.jsonnet"> |
| 1139 |
<tt>std.jsonnet</tt></a>. |
| 1140 |
</p> |
| 1141 |
<div class="desugar-rule"> |
| 1142 |
\[ |
| 1143 |
desugar(e) = desugar_{expr}(\local{\texttt{\$std} = e_{std}}{\local{\texttt{std} = \texttt{\$std}}{e}}, false) |
| 1144 |
\] |
| 1145 |
</div> |
| 1146 |
</div> |
| 1147 |
<div class="desugar-rule-group"> |
| 1148 |
<p> |
| 1149 |
<i>desugar<sub>expr</sub></i>: (Expr × Boolean) → Core: This desugars an expression. The |
| 1150 |
second parameter of the function tracks whether we are within an object. |
| 1151 |
</p> |
| 1152 |
<div class="desugar-rule"> |
| 1153 |
\[ |
| 1154 |
desugar_{expr}(\{ |
| 1155 |
\objlocal{bind_1} \ldots \objlocal{bind_n}, |
| 1156 |
assert_1 \ldots assert_m, field_1 \ldots field_p |
| 1157 |
\}, b) = \\ |
| 1158 |
\hspace{10mm} |
| 1159 |
\textrm{let }binds = \left\{\begin{array}{ll} |
| 1160 |
bind_1 \ldots bind_n & \textrm{if }b \\ |
| 1161 |
bind_1 \ldots bind_n, \objlocal{$ = \self} & \textrm{otherwise} \\ |
| 1162 |
\end{array}\right. \\ |
| 1163 |
\hspace{10mm} |
| 1164 |
\textrm{let } obj = \{ \\ |
| 1165 |
\hspace{20mm} desugar_{assert}(assert_1, binds) |
| 1166 |
\ldots desugar_{assert}(assert_m, binds), \\ |
| 1167 |
\hspace{20mm} desugar_{field}(field_1, binds) |
| 1168 |
\ldots desugar_{field}(field_p, binds, b) \\ |
| 1169 |
\hspace{10mm} \} \\ |
| 1170 |
\hspace{10mm} \textrm{in } \left\{\begin{array}{ll} |
| 1171 |
\local{\texttt{\$outerself} = \self, \texttt{\$outersuper} = \super} {obj} |
| 1172 |
& \textrm{if }b \\ |
| 1173 |
obj & \textrm{otherwise} \\ |
| 1174 |
\end{array}\right. \\ |
| 1175 |
\] |
| 1176 |
</div> |
| 1177 |
<div class="desugar-rule"> |
| 1178 |
\[ |
| 1179 |
desugar_{expr}(\object{ |
| 1180 |
\objlocal{bind_1} \ldots \objlocal{bind_m}, |
| 1181 |
[e_f] : e_{body}, |
| 1182 |
\objlocal{bind_m+1} \ldots \objlocal{bind_n} |
| 1183 |
forspec\ compspec |
| 1184 |
}, b) = \\ |
| 1185 |
|
| 1186 |
\hspace{10mm} \textrm{Let } arr \textrm{ fresh and } x_1 \ldots x_n |
| 1187 |
\textrm{ be the sequence of variables defined in }forspec\ compspec \\ |
| 1188 |
|
| 1189 |
\hspace{10mm} \object{ \\ |
| 1190 |
\hspace{20mm} [desugar_{expr}(\local{x_1=arr[0] \ldots x_n=arr[n-1]}{e_f}, b)]: \\ |
| 1191 |
\hspace{30mm} desugar_{expr}( |
| 1192 |
\local{x_1=arr[0] \ldots x_n=arr[n-1]}{ |
| 1193 |
\local{bind_1 \ldots bind_n}{e_{body}} |
| 1194 |
}, true) \\ |
| 1195 |
\hspace{20mm} \textrm{ for } arr \textrm{ in } |
| 1196 |
desugar_{expr}([ [x_1 \ldots x_n] forspec\ compspec, b): \\ |
| 1197 |
\hspace{10mm}} |
| 1198 |
\] |
| 1199 |
</div> |
| 1200 |
<div class="desugar-rule"> |
| 1201 |
\[ |
| 1202 |
desugar_{expr}([e\ forspec\ compspec], b) = desugar_{arrcomp}(e, forspec\ compspec, b) |
| 1203 |
\] |
| 1204 |
</div> |
| 1205 |
<div class="desugar-rule"> |
| 1206 |
\[ |
| 1207 |
desugar_{expr}(\local {bind_1 \ldots bind_n} e, b) = |
| 1208 |
\local {desugar_{bind}(bind_1, b) \ldots |
| 1209 |
desugar_{bind}(bind_n, b)} {desugar_{expr}(e, b)} |
| 1210 |
\] |
| 1211 |
</div> |
| 1212 |
<div class="desugar-rule"> |
| 1213 |
\[ |
| 1214 |
desugar_{expr}(e \{ objinside \}, b) = desugar_{expr}(e + \{ objinside \}, b) |
| 1215 |
\] |
| 1216 |
</div> |
| 1217 |
<div class="desugar-rule"> |
| 1218 |
\[ |
| 1219 |
desugar_{expr}(\function{p_1 \ldots p_n}e, b) = \function{desugar_{param}(p_1, b)\ldots desugar_{param}(p_n, b)} desugar_{expr}(e, b) |
| 1220 |
\] |
| 1221 |
</div> |
| 1222 |
<div class="desugar-rule"> |
| 1223 |
\[ |
| 1224 |
desugar_{expr}(\assert e ; e', b) = |
| 1225 |
desugar_{expr}(\assert e : \texttt{"Assertion failed"} ; e', b) |
| 1226 |
\] |
| 1227 |
</div> |
| 1228 |
<div class="desugar-rule"> |
| 1229 |
\[ |
| 1230 |
desugar_{expr}(\assert e : e' ; e'', b) = desugar_{expr}(\if {e} {e''} {\error{e'}}, b) |
| 1231 |
\] |
| 1232 |
</div> |
| 1233 |
|
| 1234 |
<!-- 1 slice default --> |
| 1235 |
|
| 1236 |
<div class="desugar-rule"> |
| 1237 |
\[ |
| 1238 |
desugar_{expr}(e[e':e'':], b) = desugar_{expr}(e[e':e'':\null], b) |
| 1239 |
\] |
| 1240 |
</div> |
| 1241 |
|
| 1242 |
<div class="desugar-rule"> |
| 1243 |
\[ |
| 1244 |
desugar_{expr}(e[e':e''], b) = desugar_{expr}(e[e':e'':\null], b) |
| 1245 |
\] |
| 1246 |
</div> |
| 1247 |
|
| 1248 |
<div class="desugar-rule"> |
| 1249 |
\[ |
| 1250 |
desugar_{expr}(e[e'::e'''], b) = desugar_{expr}(e[e':\null:e'''], b) |
| 1251 |
\] |
| 1252 |
</div> |
| 1253 |
|
| 1254 |
<div class="desugar-rule"> |
| 1255 |
\[ |
| 1256 |
desugar_{expr}(e[:e'':e'''], b) = desugar_{expr}(e[\null:e'':e'''], b) |
| 1257 |
\] |
| 1258 |
</div> |
| 1259 |
|
| 1260 |
<!-- 2 slice defaults --> |
| 1261 |
|
| 1262 |
<div class="desugar-rule"> |
| 1263 |
\[ |
| 1264 |
desugar_{expr}(e[e':], b) = desugar_{expr}(e[e':\null:\null], b) |
| 1265 |
\] |
| 1266 |
</div> |
| 1267 |
|
| 1268 |
<div class="desugar-rule"> |
| 1269 |
\[ |
| 1270 |
desugar_{expr}(e[:e'':], b) = desugar_{expr}(e[\null:e'':\null], b) |
| 1271 |
\] |
| 1272 |
</div> |
| 1273 |
|
| 1274 |
<div class="desugar-rule"> |
| 1275 |
\[ |
| 1276 |
desugar_{expr}(e[:e''], b) = desugar_{expr}(e[\null:e'':\null], b) |
| 1277 |
\] |
| 1278 |
</div> |
| 1279 |
|
| 1280 |
<div class="desugar-rule"> |
| 1281 |
\[ |
| 1282 |
desugar_{expr}(e[::e'''], b) = desugar_{expr}(e[\null:\null:e'''], b) |
| 1283 |
\] |
| 1284 |
</div> |
| 1285 |
|
| 1286 |
<!-- 3 slice defaults --> |
| 1287 |
|
| 1288 |
<div class="desugar-rule"> |
| 1289 |
\[ |
| 1290 |
desugar_{expr}(e[::], b) = desugar_{expr}(e[\null:\null:\null], b) |
| 1291 |
\] |
| 1292 |
</div> |
| 1293 |
|
| 1294 |
<div class="desugar-rule"> |
| 1295 |
\[ |
| 1296 |
desugar_{expr}(e[:], b) = desugar_{expr}(e[\null:\null:\null], b) |
| 1297 |
\] |
| 1298 |
</div> |
| 1299 |
|
| 1300 |
<!-- slice --> |
| 1301 |
|
| 1302 |
<div class="desugar-rule"> |
| 1303 |
\[ |
| 1304 |
desugar_{expr}(e[e':e'':e'''], b) = |
| 1305 |
desugar_{expr}(\texttt{\$std.slice}(e, e', e'', e'''), b) |
| 1306 |
\] |
| 1307 |
</div> |
| 1308 |
|
| 1309 |
<div class="desugar-rule"> |
| 1310 |
\[ |
| 1311 |
desugar_{expr}(\ifnoelse e e'), b) = |
| 1312 |
\if {desugar_{expr}(e, b)} {desugar_{expr}(e', b)} {\null} |
| 1313 |
\] |
| 1314 |
</div> |
| 1315 |
|
| 1316 |
<div class="desugar-rule"> |
| 1317 |
\[ |
| 1318 |
desugar_{expr}(e.id, b) = desugar_{expr}(e, b)[\texttt{"}id\texttt{"}] |
| 1319 |
\] |
| 1320 |
</div> |
| 1321 |
|
| 1322 |
<div class="desugar-rule"> |
| 1323 |
\[ |
| 1324 |
desugar_{expr}(\super.id, b) = \super[\texttt{"}id\texttt{"}] |
| 1325 |
\] |
| 1326 |
</div> |
| 1327 |
|
| 1328 |
<div class="desugar-rule"> |
| 1329 |
\[ |
| 1330 |
desugar_{expr}(e \mathop{\textrm{!=}} e', b) = desugar_{expr}(!(e \mathop{==} e'), b) |
| 1331 |
\] |
| 1332 |
</div> |
| 1333 |
|
| 1334 |
<div class="desugar-rule"> |
| 1335 |
\[ |
| 1336 |
desugar_{expr}(e \mathop{==} e', b) = desugar_{expr}(\texttt{\$std.equals}(e, e'), b) |
| 1337 |
\] |
| 1338 |
</div> |
| 1339 |
|
| 1340 |
<div class="desugar-rule"> |
| 1341 |
\[ |
| 1342 |
desugar_{expr}(e \mathop{\%} e', b) = desugar_{expr}(\texttt{\$std.mod}(e, e'), b) |
| 1343 |
\] |
| 1344 |
</div> |
| 1345 |
|
| 1346 |
<div class="desugar-rule"> |
| 1347 |
\[ |
| 1348 |
desugar_{expr}(e \mathop{\texttt{in}} e', b) = |
| 1349 |
desugar_{expr}(\texttt{\$std.objectHasEx}(e', e, \texttt{true}), b) |
| 1350 |
\] |
| 1351 |
</div> |
| 1352 |
|
| 1353 |
<div class="desugar-rule"> |
| 1354 |
\[ |
| 1355 |
desugar_{expr}(e \mathop{\texttt{in}} \texttt{super}, b) = |
| 1356 |
desugar_{expr}(\texttt{\$std.objectHasEx}(\texttt{super}, e, \texttt{true}), b) |
| 1357 |
\] |
| 1358 |
</div> |
| 1359 |
</div> |
| 1360 |
<div class="desugar-rule-group"> |
| 1361 |
<p> |
| 1362 |
<i>desugar<sub>assert</sub></i>: (Field × [Bind]) → Field. This desugars object |
| 1363 |
assertions. |
| 1364 |
</p> |
| 1365 |
<div class="desugar-rule"> |
| 1366 |
\[ |
| 1367 |
desugar_{assert}(\assert e, binds) = |
| 1368 |
desugar_{assert}(\assert e : \texttt{"Assertion failed"}, binds) |
| 1369 |
\] |
| 1370 |
</div> |
| 1371 |
<div class="desugar-rule"> |
| 1372 |
\[ |
| 1373 |
desugar_{assert}(\assert e : e', binds) = |
| 1374 |
\assert{desugar_{expr}(\local{binds}{\if{e}{\null}{\error{e'}}}, \true)} |
| 1375 |
\] |
| 1376 |
</div> |
| 1377 |
</div> |
| 1378 |
<div class="desugar-rule-group"> |
| 1379 |
<p> |
| 1380 |
<i>desugar<sub>field</sub></i>: (Field × [Bind] × Boolean) → Field. This desugars object fields. |
| 1381 |
Recall that <i>h</i> ranges over <code>:</code>, <code>::</code>, <code>:::</code>. The |
| 1382 |
boolean records whether the object containing this field is itself in another object. The |
| 1383 |
notation <i>string(id)</i> means converting the identifier token to a string literal. |
| 1384 |
</p> |
| 1385 |
<div class="desugar-rule"> |
| 1386 |
\[ |
| 1387 |
desugar_{field}(id \mathrel{h} e, binds, b) = |
| 1388 |
desugar_{field}([string(id)] \mathrel{h} e), binds, b) |
| 1389 |
\] |
| 1390 |
</div> |
| 1391 |
<div class="desugar-rule"> |
| 1392 |
\[ |
| 1393 |
desugar_{field}(id \mathrel{+h} e, binds, b) = |
| 1394 |
desugar_{field}([string(id)] \mathrel{+h} e), binds, b) |
| 1395 |
\] |
| 1396 |
</div> |
| 1397 |
<div class="desugar-rule"> |
| 1398 |
\[ |
| 1399 |
desugar_{field}(id(params) \mathrel{h} e, binds, b) = |
| 1400 |
desugar_{field}([string(id)](params) \mathrel{h} e), binds, b) |
| 1401 |
\] |
| 1402 |
</div> |
| 1403 |
<div class="desugar-rule"> |
| 1404 |
\[ |
| 1405 |
desugar_{field}(string \mathrel{h} e, binds, b) = |
| 1406 |
desugar_{field}([string] \mathrel{h} e), binds, b) |
| 1407 |
\] |
| 1408 |
</div> |
| 1409 |
<div class="desugar-rule"> |
| 1410 |
\[ |
| 1411 |
desugar_{field}(string \mathrel{+h} e, binds, b) = |
| 1412 |
desugar_{field}([string] \mathrel{+h} e), binds, b) |
| 1413 |
\] |
| 1414 |
</div> |
| 1415 |
<div class="desugar-rule"> |
| 1416 |
\[ |
| 1417 |
desugar_{field}(string(params) \mathrel{h} e, binds, b) = |
| 1418 |
desugar_{field}([string](params) \mathrel{h} e), binds, b) |
| 1419 |
\] |
| 1420 |
</div> |
| 1421 |
<div class="desugar-rule"> |
| 1422 |
\[ |
| 1423 |
desugar_{field}([e] \mathrel{h} e', binds, b) = |
| 1424 |
[desugar_{expr}(e, b)] \mathrel{h} desugar_{expr}(\local{binds}{e}, \true) |
| 1425 |
\] |
| 1426 |
</div> |
| 1427 |
<div class="desugar-rule"> |
| 1428 |
\[ |
| 1429 |
desugar_{field}([e] \mathrel{+h} e', binds, b) = \\ |
| 1430 |
\hspace{10mm} |
| 1431 |
\textrm{let } e'' = e[\texttt{\$outerself} / \self, \texttt{\$outersuper} / \super] \\ |
| 1432 |
\hspace{10mm} |
| 1433 |
\textrm{let } e''' = \if{e''\mathrel{\texttt{in}} \super}{\super[e''] + {e'}}{e'} \\ |
| 1434 |
\hspace{10mm} |
| 1435 |
\textrm{in } desugar_{field}([e] \mathrel{h} e''', binds, b) |
| 1436 |
\] |
| 1437 |
</div> |
| 1438 |
<div class="desugar-rule"> |
| 1439 |
\[ |
| 1440 |
desugar_{field}([e](params) \mathrel{h} e', binds, b) = |
| 1441 |
desugar_{field}([e] \mathrel{h} \function{params}{e'}, binds, b) |
| 1442 |
\] |
| 1443 |
</div> |
| 1444 |
</div> |
| 1445 |
<div class="desugar-rule-group"> |
| 1446 |
<p> |
| 1447 |
<i>desugar<sub>bind</sub></i>: (Bind × Boolean) → Field. This desugars local bindings. |
| 1448 |
</p> |
| 1449 |
<div class="desugar-rule"> |
| 1450 |
\[ |
| 1451 |
desugar_{bind}(id \texttt{=} e, b) = |
| 1452 |
id \texttt{=} desugar_{expr}(e, b) |
| 1453 |
\] |
| 1454 |
</div> |
| 1455 |
<div class="desugar-rule"> |
| 1456 |
\[ |
| 1457 |
desugar_{bind}(id(params) \texttt{=} e, b) = |
| 1458 |
id \texttt{=} desugar_{expr}(\function{params}e, b) |
| 1459 |
\] |
| 1460 |
</div> |
| 1461 |
</div> |
| 1462 |
<div class="desugar-rule-group"> |
| 1463 |
<p> |
| 1464 |
<i>desugar<sub>param</sub></i>: (Param × Boolean) → Param. This desugars function parameters. |
| 1465 |
</p> |
| 1466 |
<div class="desugar-rule"> |
| 1467 |
\[ |
| 1468 |
desugar_{param}(id, b) = |
| 1469 |
id \texttt{=} \error{\texttt{"Parameter not bound"}} |
| 1470 |
\] |
| 1471 |
</div> |
| 1472 |
<div class="desugar-rule"> |
| 1473 |
\[ |
| 1474 |
desugar_{param}(id \texttt{=} e, b) = |
| 1475 |
id \texttt{=} desugar_{expr}(e, b) |
| 1476 |
\] |
| 1477 |
</div> |
| 1478 |
</div> |
| 1479 |
<div class="desugar-rule-group"> |
| 1480 |
<p> |
| 1481 |
<i>desugar<sub>arrcomp</sub></i>: (Expr × CompSpec × Boolean) → Field. This desugars |
| 1482 |
array comprehensions. |
| 1483 |
</p> |
| 1484 |
<div class="desugar-rule"> |
| 1485 |
\[ |
| 1486 |
desugar_{arrcomp}(e, \textrm{if }e'\ compspec, b) = |
| 1487 |
desugar_{expr}(\if{e'}{desugar_{arrcomp}(e, compspec, b)}{[\ ]}, b) |
| 1488 |
\] |
| 1489 |
</div> |
| 1490 |
<div class="desugar-rule"> |
| 1491 |
\[ |
| 1492 |
desugar_{arrcomp}(e, \textrm{if }e', b) = |
| 1493 |
desugar_{expr}(\if{e'}{[e]}{[\ ]}, b) |
| 1494 |
\] |
| 1495 |
</div> |
| 1496 |
<div class="desugar-rule"> |
| 1497 |
\[ |
| 1498 |
desugar_{arrcomp}(e, \textrm{for }x\textrm{ in }e'\ compspec, b) = \\ |
| 1499 |
\hspace{10mm}\textrm{Let }arr, i\textrm{ fresh} \\ |
| 1500 |
\hspace{10mm}desugar_{expr}( |
| 1501 |
\local{arr = e'}{ |
| 1502 |
\texttt{\$std.join}(\\\hspace{20mm}[\ ], \texttt{\$std.makeArray}( |
| 1503 |
\texttt{\$std.length}(arr), |
| 1504 |
\function{i}{\local{x = arr[i]}{desugar_{arrcomp}(e, compspec, b)}} |
| 1505 |
)) |
| 1506 |
}, |
| 1507 |
b |
| 1508 |
) |
| 1509 |
\] |
| 1510 |
</div> |
| 1511 |
<div class="desugar-rule"> |
| 1512 |
\[ |
| 1513 |
desugar_{arrcomp}(e, \textrm{for }x\textrm{ in }e', b) = \\ |
| 1514 |
\hspace{10mm}\textrm{Let }arr, i\textrm{ fresh} \\ |
| 1515 |
\hspace{10mm}desugar_{expr}( |
| 1516 |
\local{arr = e'}{ |
| 1517 |
\texttt{\$std.join}(\\\hspace{20mm}[\ ], \texttt{\$std.makeArray}( |
| 1518 |
\texttt{\$std.length}(arr), |
| 1519 |
\function{i}{\local{x = arr[i]}{[e]}} |
| 1520 |
)) |
| 1521 |
}, |
| 1522 |
b |
| 1523 |
) |
| 1524 |
\] |
| 1525 |
</div> |
| 1526 |
</div> |
| 1527 |
</div> |
| 1528 |
<div style="clear: both"></div> |
| 1529 |
</div> |
| 1530 |
</div> |
| 1531 |
|
| 1532 |
|
| 1533 |
<div class="hgroup"> |
| 1534 |
<div class="hgroup-inline"> |
| 1535 |
<div class="panel"> |
| 1536 |
<h3 id="static_checking">Static Checking</h3> |
| 1537 |
</div> |
| 1538 |
<div style="clear: both"></div> |
| 1539 |
</div> |
| 1540 |
</div> |
| 1541 |
|
| 1542 |
<div class="hgroup"> |
| 1543 |
<div class="hgroup-inline"> |
| 1544 |
<div class="panel"> |
| 1545 |
<p> |
| 1546 |
After the Jsonnet program is parsed and desugared, a syntax-directed algorithm is employed |
| 1547 |
to reject programs that contain certain classes of errors. This is presented like a static |
| 1548 |
type system, except that there are no static types. Programs are only rejected if they use |
| 1549 |
undefined variables, or if <code>self</code>, <code>super</code> or <code>$</code> are used |
| 1550 |
outside the bounds of an object. In the core language, <code>$</code> has been desugared to |
| 1551 |
a variable, so its checking is implicit in the checking of bound variables. |
| 1552 |
</p> |
| 1553 |
<p> |
| 1554 |
The static checking is described below as a judgement \(Γ ⊢ e\), where \(Γ\) is the set of |
| 1555 |
variables in scope of \(e\). The set \(Γ\) initially contains only <code>std</code>, the |
| 1556 |
implicit standard library. In the case of imported files, each jsonnet file is checked |
| 1557 |
independently of the other files. |
| 1558 |
</p> |
| 1559 |
</div> |
| 1560 |
<div style="clear: both"></div> |
| 1561 |
</div> |
| 1562 |
</div> |
| 1563 |
|
| 1564 |
|
| 1565 |
<div class="inverse hgroup"> |
| 1566 |
<div class="hgroup-inline"> |
| 1567 |
<div class="panel wide"> |
| 1568 |
<div class="rules"> |
| 1569 |
<div class="sequent-rule"> |
| 1570 |
\[ |
| 1571 |
\rule{chk-lit} { |
| 1572 |
} { |
| 1573 |
\_ ⊢ \null, \true, \false, string, number |
| 1574 |
} |
| 1575 |
\] |
| 1576 |
</div> |
| 1577 |
<div class="sequent-rule"> |
| 1578 |
\[ |
| 1579 |
\rule{chk-self} { |
| 1580 |
\self ∈ Γ |
| 1581 |
} { |
| 1582 |
Γ ⊢ \self |
| 1583 |
} |
| 1584 |
\] |
| 1585 |
</div> |
| 1586 |
<div class="sequent-rule"> |
| 1587 |
\[ |
| 1588 |
\rule{chk-super} { |
| 1589 |
\super ∈ Γ |
| 1590 |
} { |
| 1591 |
Γ ⊢ \super |
| 1592 |
} |
| 1593 |
\] |
| 1594 |
</div> |
| 1595 |
<div class="sequent-rule"> |
| 1596 |
\[ |
| 1597 |
\rule{chk-object} { |
| 1598 |
Γ ⊢ e_1 \ldots e_m |
| 1599 |
\\ |
| 1600 |
Γ ∪ \{\self,\super\} ⊢ e'_1 \ldots e'_n |
| 1601 |
\\ |
| 1602 |
∀ i,j: e_i ∈ string ∧ e_j = e_i ⇒ i = j |
| 1603 |
} { |
| 1604 |
Γ ⊢ \object{[e_1] h_1 e'_1 \ldots [e_m] h_m e'_m, |
| 1605 |
\assert e'_{m+1} \ldots \assert e'_n} |
| 1606 |
} |
| 1607 |
\] |
| 1608 |
</div> |
| 1609 |
<div class="sequent-rule"> |
| 1610 |
\[ |
| 1611 |
\rule{chk-object-comp} { |
| 1612 |
Γ ∪ \{x\} ⊢ e_1 |
| 1613 |
\\ |
| 1614 |
Γ ∪ \{x,\self,\super\} ⊢ e_2 |
| 1615 |
\\ |
| 1616 |
Γ ⊢ e_3 |
| 1617 |
} { |
| 1618 |
Γ ⊢ \ocomp{e_1}{e_2}{x}{e_3} |
| 1619 |
} |
| 1620 |
\] |
| 1621 |
</div> |
| 1622 |
<div class="sequent-rule"> |
| 1623 |
\[ |
| 1624 |
\rule{chk-array} { |
| 1625 |
Γ ⊢ e_1 \ldots e_n |
| 1626 |
} { |
| 1627 |
Γ ⊢ \array{e_1 \ldots e_n} |
| 1628 |
} |
| 1629 |
\] |
| 1630 |
</div> |
| 1631 |
<div class="sequent-rule"> |
| 1632 |
\[ |
| 1633 |
\rule{chk-array-index} { |
| 1634 |
Γ ⊢ e |
| 1635 |
\\ |
| 1636 |
Γ ⊢ e' |
| 1637 |
} { |
| 1638 |
Γ ⊢ e[e'] |
| 1639 |
} |
| 1640 |
\] |
| 1641 |
</div> |
| 1642 |
<div class="sequent-rule"> |
| 1643 |
\[ |
| 1644 |
\rule{chk-apply} { |
| 1645 |
Γ ⊢ e |
| 1646 |
\\ |
| 1647 |
∀ i∈\{1\ldots n\}: Γ ⊢ e_i |
| 1648 |
\\ |
| 1649 |
∀ i,j∈\{1\ldots n\}: x_i = x_j ⇒ i = j |
| 1650 |
} { |
| 1651 |
Γ ⊢ e(x_1 = e_1 \ldots x_n = e_n) |
| 1652 |
} |
| 1653 |
\] |
| 1654 |
</div> |
| 1655 |
<div class="sequent-rule"> |
| 1656 |
\[ |
| 1657 |
\rule{chk-var} { |
| 1658 |
x ∈ Γ |
| 1659 |
} { |
| 1660 |
Γ ⊢ x |
| 1661 |
} |
| 1662 |
\] |
| 1663 |
</div> |
| 1664 |
<div class="sequent-rule"> |
| 1665 |
\[ |
| 1666 |
\rule{chk-local} { |
| 1667 |
Γ ∪ \{x_1 \ldots x_n\} ⊢ e_1 \ldots e_n, e |
| 1668 |
\\ |
| 1669 |
∀ i,j: x_i = x_j ⇒ i = j |
| 1670 |
} { |
| 1671 |
Γ ⊢ \local{\assign{x_1}{e_1} \ldots \assign{x_n}{e_n}}e |
| 1672 |
} |
| 1673 |
\] |
| 1674 |
</div> |
| 1675 |
<div class="sequent-rule"> |
| 1676 |
\[ |
| 1677 |
\rule{chk-if} { |
| 1678 |
Γ ⊢ e_1, e_2, e_3 |
| 1679 |
} { |
| 1680 |
Γ ⊢ \if{e_1}{e_2}{e_3} |
| 1681 |
} |
| 1682 |
\] |
| 1683 |
</div> |
| 1684 |
<div class="sequent-rule"> |
| 1685 |
\[ |
| 1686 |
\rule{chk-binary} { |
| 1687 |
Γ ⊢ e_L, e_R |
| 1688 |
} { |
| 1689 |
Γ ⊢ \binary{e_L}{sym}{e_R} |
| 1690 |
} |
| 1691 |
\] |
| 1692 |
</div> |
| 1693 |
<div class="sequent-rule"> |
| 1694 |
\[ |
| 1695 |
\rule{chk-unary} { |
| 1696 |
Γ ⊢ e |
| 1697 |
} { |
| 1698 |
Γ ⊢ \unary{sym}{e} |
| 1699 |
} |
| 1700 |
\] |
| 1701 |
</div> |
| 1702 |
<div class="sequent-rule"> |
| 1703 |
\[ |
| 1704 |
\rule{chk-function} { |
| 1705 |
∀ i ∈ \{m+1 \ldots n\}: Γ ∪ \{x_1 \ldots x_n\} ⊢ e_i |
| 1706 |
\\ |
| 1707 |
Γ ∪ \{x_1 \ldots x_n\} ⊢ e' |
| 1708 |
\\ |
| 1709 |
∀ i,j: x_i = x_j ⇒ i = j |
| 1710 |
} { |
| 1711 |
Γ ⊢ \function{x_1\ldots x_m, x_{m+1}=e_{m+1}\ldots x_n=e_n}{e'} |
| 1712 |
} |
| 1713 |
\] |
| 1714 |
</div> |
| 1715 |
<div class="sequent-rule"> |
| 1716 |
\[ |
| 1717 |
\rule{chk-import} { |
| 1718 |
} { |
| 1719 |
Γ ⊢ \import{s} |
| 1720 |
} |
| 1721 |
\] |
| 1722 |
</div> |
| 1723 |
<div class="sequent-rule"> |
| 1724 |
\[ |
| 1725 |
\rule{chk-importstr} { |
| 1726 |
} { |
| 1727 |
Γ ⊢ \importstr{s} |
| 1728 |
} |
| 1729 |
\] |
| 1730 |
</div> |
| 1731 |
<div class="sequent-rule"> |
| 1732 |
\[ |
| 1733 |
\rule{chk-importbin} { |
| 1734 |
} { |
| 1735 |
Γ ⊢ \importbin{s} |
| 1736 |
} |
| 1737 |
\] |
| 1738 |
</div> |
| 1739 |
<div class="sequent-rule"> |
| 1740 |
\[ |
| 1741 |
\rule{chk-error} { |
| 1742 |
Γ ⊢ e |
| 1743 |
} { |
| 1744 |
Γ ⊢ \error{e} |
| 1745 |
} |
| 1746 |
\] |
| 1747 |
</div> |
| 1748 |
</div> |
| 1749 |
</div> |
| 1750 |
<div style="clear: both"></div> |
| 1751 |
</div> |
| 1752 |
</div> |
| 1753 |
|
| 1754 |
|
| 1755 |
<div class="hgroup"> |
| 1756 |
<div class="hgroup-inline"> |
| 1757 |
<div class="panel"> |
| 1758 |
<h3 id="semantics">Operational Semantics</h3> |
| 1759 |
</div> |
| 1760 |
<div style="clear: both"></div> |
| 1761 |
</div> |
| 1762 |
</div> |
| 1763 |
|
| 1764 |
<div class="hgroup"> |
| 1765 |
<div class="hgroup-inline"> |
| 1766 |
<div class="panel"> |
| 1767 |
<p> |
| 1768 |
We present two sets of operational semantics rules. The first defines the judgement \(e ↓ |
| 1769 |
v\) which represents the execution of Jsonnet expressions into Jsonnet values. The other |
| 1770 |
defines the judgement \(v ⇓ j\) which represents <dfn>manifestation</dfn>, the process by |
| 1771 |
which Jsonnet values are converted into JSON values. |
| 1772 |
</p> |
| 1773 |
|
| 1774 |
<p> |
| 1775 |
We model both explicit runtime errors (raised by the error construct) and implicit runtime |
| 1776 |
errors (e.g. array bounds errors) as stuck execution. Errors can occur both in the \(e ↓ |
| 1777 |
v\) judgement and in the \(v ⇓ j\) judgement (because it is defined in terms of \(e ↓ v\)). |
| 1778 |
</p> |
| 1779 |
</div> |
| 1780 |
<div style="clear: both"></div> |
| 1781 |
</div> |
| 1782 |
</div> |
| 1783 |
|
| 1784 |
<div class="hgroup"> |
| 1785 |
<div class="hgroup-inline"> |
| 1786 |
<div class="panel"> |
| 1787 |
<h4 id="jsonnet_values">Jsonnet Values</h4> |
| 1788 |
</div> |
| 1789 |
<div style="clear: both"></div> |
| 1790 |
</div> |
| 1791 |
</div> |
| 1792 |
|
| 1793 |
<div class="hgroup"> |
| 1794 |
<div class="hgroup-inline"> |
| 1795 |
<div class="panel"> |
| 1796 |
<p> |
| 1797 |
When executed, Jsonnet expressions yield Jsonnet values. These need to be manifested, an |
| 1798 |
additional step, to get JSON values. The differences between Jsonnet values and JSON values |
| 1799 |
are: 1) Jsonnet values contain functions (which are not representable in JSON). 2) Due to |
| 1800 |
the lazy semantics, both object fields and array elements have yet to be executed to yield |
| 1801 |
values. 3) Object assertions still need to be checked. |
| 1802 |
</p> |
| 1803 |
<p> |
| 1804 |
Execution of a statically-checked expression will never yield an object with duplicate field |
| 1805 |
names. By abuse of notation, we consider two objects to be equivalent even if their fields |
| 1806 |
and assertions are re-ordered. However this is not true of array elements or function |
| 1807 |
parameters. |
| 1808 |
</p> |
| 1809 |
</div> |
| 1810 |
<div style="clear: both"></div> |
| 1811 |
</div> |
| 1812 |
</div> |
| 1813 |
|
| 1814 |
<div class="inverse hgroup"> |
| 1815 |
<div class="hgroup-inline"> |
| 1816 |
<div class="panel wide"> |
| 1817 |
<table> |
| 1818 |
<tr> |
| 1819 |
<td><em>v</em></td> |
| 1820 |
<td>∈</td> |
| 1821 |
<td><em>Value</em></td> |
| 1822 |
<td>=</td> |
| 1823 |
<td> |
| 1824 |
<em>Primitive</em> ∪ |
| 1825 |
<em>Object</em> ∪ |
| 1826 |
<em>Function</em> ∪ |
| 1827 |
<em>Array</em> |
| 1828 |
</td> |
| 1829 |
</tr> |
| 1830 |
<tr> |
| 1831 |
<td></td> |
| 1832 |
<td></td> |
| 1833 |
<td><em>Primitive</em></td> |
| 1834 |
<td>::=</td> |
| 1835 |
<td> |
| 1836 |
<code>null</code> | <code>true</code> | <code>false</code> | <i>string</i> |
| 1837 |
| <i>double</i> |
| 1838 |
</td> |
| 1839 |
</tr> |
| 1840 |
<tr> |
| 1841 |
<td><em>o</em></td> |
| 1842 |
<td>∈</td> |
| 1843 |
<td><em>Object</em></td> |
| 1844 |
<td>::=</td> |
| 1845 |
<td> |
| 1846 |
<code>{</code> |
| 1847 |
{ <code>assert</code> <i>e</i> } { <i>string</i> <i>h</i> <i>e</i> } |
| 1848 |
<code>}</code> |
| 1849 |
</td> |
| 1850 |
</tr> |
| 1851 |
<tr> |
| 1852 |
<td></td> |
| 1853 |
<td></td> |
| 1854 |
<td><em>Function</em></td> |
| 1855 |
<td>::=</td> |
| 1856 |
<td> |
| 1857 |
<code>function (</code> { <i>id</i>=<i>e</i> } <code>)</code> <i>e</i> |
| 1858 |
</td> |
| 1859 |
</tr> |
| 1860 |
<tr> |
| 1861 |
<td><em>a</em></td> |
| 1862 |
<td>∈</td> |
| 1863 |
<td><em>Array</em></td> |
| 1864 |
<td>::=</td> |
| 1865 |
<td> |
| 1866 |
<code>[</code> { <i>e</i> } <code>]</code> |
| 1867 |
</td> |
| 1868 |
</tr> |
| 1869 |
</table> |
| 1870 |
</div> |
| 1871 |
<div style="clear: both"></div> |
| 1872 |
</div> |
| 1873 |
</div> |
| 1874 |
|
| 1875 |
<div class="hgroup"> |
| 1876 |
<div class="hgroup-inline"> |
| 1877 |
<div class="panel"> |
| 1878 |
<h4 id="hidden_inheritance">Hidden status inheritance</h4> |
| 1879 |
</div> |
| 1880 |
<div style="clear: both"></div> |
| 1881 |
</div> |
| 1882 |
</div> |
| 1883 |
|
| 1884 |
<div class="hgroup"> |
| 1885 |
<div class="hgroup-inline"> |
| 1886 |
<div class="panel"> |
| 1887 |
<p> |
| 1888 |
The hidden status of fields is preserved over inheritance if the right hand side uses the |
| 1889 |
<code>:</code> form. This is codified with the following function: |
| 1890 |
</p> |
| 1891 |
<div class="rules"> |
| 1892 |
<div class="sequent-rule"> |
| 1893 |
\[ |
| 1894 |
h_L + h_R = \left\{\begin{array}{ll} |
| 1895 |
h_L & \textrm{if }h_R = \texttt{:} \\ |
| 1896 |
h_R & \textrm{otherwise} \\ |
| 1897 |
\end{array}\right. |
| 1898 |
\] |
| 1899 |
</div> |
| 1900 |
</div> |
| 1901 |
</div> |
| 1902 |
<div style="clear: both"></div> |
| 1903 |
</div> |
| 1904 |
</div> |
| 1905 |
|
| 1906 |
<div class="hgroup"> |
| 1907 |
<div class="hgroup-inline"> |
| 1908 |
<div class="panel"> |
| 1909 |
<h4 id="substitution">Capture-Avoiding Substitution</h4> |
| 1910 |
</div> |
| 1911 |
<div style="clear: both"></div> |
| 1912 |
</div> |
| 1913 |
</div> |
| 1914 |
|
| 1915 |
<div class="hgroup"> |
| 1916 |
<div class="hgroup-inline"> |
| 1917 |
<div class="panel"> |
| 1918 |
<p> |
| 1919 |
The rules for capture-avoiding variable substitution [<i>e</i>/<i>id</i>] are an |
| 1920 |
extension of those in the <a href="https://en.wikipedia.org/wiki/Lambda_calculus">lambda |
| 1921 |
calculus</a>. |
| 1922 |
</p> |
| 1923 |
</div> |
| 1924 |
<div style="clear: both"></div> |
| 1925 |
</div> |
| 1926 |
</div> |
| 1927 |
|
| 1928 |
<div class="inverse hgroup"> |
| 1929 |
<div class="hgroup-inline"> |
| 1930 |
<div class="panel wide"> |
| 1931 |
<p>Let y ≠ x.</p> |
| 1932 |
<table> |
| 1933 |
<tr> |
| 1934 |
<td> |
| 1935 |
<code>self</code>[<i>e</i>/<i>x</i>] = <code>self</code> |
| 1936 |
</td> |
| 1937 |
</tr> |
| 1938 |
<tr> |
| 1939 |
<td> |
| 1940 |
<code>super</code>[<i>e</i>/<i>x</i>] = <code>super</code> |
| 1941 |
</td> |
| 1942 |
</tr> |
| 1943 |
<tr> |
| 1944 |
<td> |
| 1945 |
<i>x</i>[<i>e</i>/<i>x</i>] = <i>e</i> |
| 1946 |
</td> |
| 1947 |
</tr> |
| 1948 |
<tr> |
| 1949 |
<td> |
| 1950 |
<i>y</i>[<i>e</i>/<i>x</i>] = <i>y</i> |
| 1951 |
</td> |
| 1952 |
</tr> |
| 1953 |
<tr> |
| 1954 |
<td colspan=2> |
| 1955 |
<code>{</code> |
| 1956 |
... |
| 1957 |
<code>assert</code> <i>e'</i> |
| 1958 |
... |
| 1959 |
<code>[</code><i>e''</i><code>]</code> <i>h</i> <i>e'''</i> |
| 1960 |
... |
| 1961 |
<code>}</code>[<i>e</i>/<i>x</i>] = |
| 1962 |
<code>{</code> |
| 1963 |
... |
| 1964 |
<code>assert</code> <i>e'</i>[<i>e</i>/<i>x</i>] |
| 1965 |
... |
| 1966 |
<code>[</code><i>e'</i>[<i>e</i>/<i>x</i>]<code>]</code> <i>h</i> |
| 1967 |
<i>e''</i>[<i>e</i>/<i>x</i>] |
| 1968 |
... |
| 1969 |
<code>}</code> |
| 1970 |
</td> |
| 1971 |
</tr> |
| 1972 |
<tr> |
| 1973 |
<td> |
| 1974 |
<code>{</code> |
| 1975 |
<code>[</code><i>e'</i><code>]</code><code>:</code> <i>e''</i> |
| 1976 |
<code>for</code> <i>x</i> <code>in</code> <i>e'''</i> |
| 1977 |
<code>}</code>[<i>e</i>/<i>x</i>] = |
| 1978 |
<code>{</code> |
| 1979 |
<code>[</code><i>e'</i><code>]</code><code>:</code> <i>e''</i> |
| 1980 |
<code>for</code> <i>x</i> <code>in</code> <i>e'''</i>[<i>e</i>/<i>x</i>] |
| 1981 |
<code>}</code> |
| 1982 |
</td> |
| 1983 |
</tr> |
| 1984 |
<tr> |
| 1985 |
<td> |
| 1986 |
<code>{</code> |
| 1987 |
<code>[</code><i>e'</i><code>]</code><code>:</code> <i>e''</i> |
| 1988 |
<code>for</code> <i>y</i> <code>in</code> <i>e'''</i> |
| 1989 |
<code>}</code>[<i>e</i>/<i>x</i>] = |
| 1990 |
<code>{</code> |
| 1991 |
<code>[</code><i>e'</i>[<i>e</i>/<i>x</i>]<code>]:</code> |
| 1992 |
<i>e''</i>[<i>e</i>/<i>x</i>] |
| 1993 |
<code>for</code> <i>y</i> <code>in</code> <i>e'''</i> [<i>e</i>/<i>x</i>] |
| 1994 |
<code>}</code> |
| 1995 |
</td> |
| 1996 |
</tr> |
| 1997 |
<tr> |
| 1998 |
<td> |
| 1999 |
(<code>local</code> ... <i>y</i><code>=</code><i>e'</i> ... <code>;</code> <i>e''</i>) |
| 2000 |
[<i>e</i>/<i>x</i>] = |
| 2001 |
<code>local</code> ... <i>y</i><code>=</code><i>e'</i> ... <code>;</code> <i>e''</i> |
| 2002 |
</td> |
| 2003 |
<td>(If any variable matches.)</td> |
| 2004 |
</tr> |
| 2005 |
<tr> |
| 2006 |
<td> |
| 2007 |
(<code>local</code> ... <i>y</i><code>=</code><i>e'</i> ... <code>;</code> <i>e''</i>) |
| 2008 |
[<i>e</i>/<i>x</i>] = |
| 2009 |
<code>local</code> ... <i>y</i><code>=</code><i>e'</i>[<i>e</i>/<i>x</i>] ... |
| 2010 |
<code>;</code><i>e''</i>[<i>e</i>/<i>x</i>] |
| 2011 |
</td> |
| 2012 |
<td>(If no variable matches.)</td> |
| 2013 |
</tr> |
| 2014 |
<tr> |
| 2015 |
<td> |
| 2016 |
(<code>function</code> <code>(</code> |
| 2017 |
... <i>y</i>=<i>e'</i> ... |
| 2018 |
<code>)</code> <i>e''</i>)[<i>e</i>/<i>x</i>] = |
| 2019 |
<code>function</code> <code>(</code> |
| 2020 |
... <i>y</i>=<i>e'</i> ... |
| 2021 |
<code>)</code><i>e''</i> |
| 2022 |
</td> |
| 2023 |
<td>(If any param matches.)</td> |
| 2024 |
</tr> |
| 2025 |
<tr> |
| 2026 |
<td> |
| 2027 |
(<code>function</code> <code>(</code> |
| 2028 |
... <i>y</i>=<i>e'</i> ... |
| 2029 |
<code>)</code> <i>e''</i>)[<i>e</i>/<i>x</i>] = |
| 2030 |
<code>function</code> <code>(</code> |
| 2031 |
... <i>y</i>=<i>e'</i>[<i>e</i>/<i>x</i>] ... |
| 2032 |
<code>)</code> <i>e''</i>[<i>e</i>/<i>x</i>] |
| 2033 |
</td> |
| 2034 |
<td>(If no param matches.)</td> |
| 2035 |
</tr> |
| 2036 |
<tr> |
| 2037 |
<td> |
| 2038 |
Otherwise, <i>e'</i> [<i>e</i>/<i>x</i>] proceeds via syntax-directed recursion into |
| 2039 |
subterms of <i>e'</i>. |
| 2040 |
</td> |
| 2041 |
</tr> |
| 2042 |
</table> |
| 2043 |
</div> |
| 2044 |
<div style="clear: both"></div> |
| 2045 |
</div> |
| 2046 |
</div> |
| 2047 |
|
| 2048 |
<div class="hgroup"> |
| 2049 |
<div class="hgroup-inline"> |
| 2050 |
<div class="panel"> |
| 2051 |
<p> |
| 2052 |
The rules for keyword substitution ⟦<i>e</i>/<i>kw</i>⟧ for <i>kw</i> ∈ { <code>self</code>, |
| 2053 |
<code>super</code> } avoid substituting keywords that are captured by nested objects: |
| 2054 |
</p> |
| 2055 |
</div> |
| 2056 |
<div style="clear: both"></div> |
| 2057 |
</div> |
| 2058 |
</div> |
| 2059 |
|
| 2060 |
<div class="inverse hgroup"> |
| 2061 |
<div class="hgroup-inline"> |
| 2062 |
<div class="panel wide"> |
| 2063 |
<table> |
| 2064 |
<tr> |
| 2065 |
<td> |
| 2066 |
<code>self</code> |
| 2067 |
⟦<i>e</i>/<code>self</code>⟧ = <i>e</i> |
| 2068 |
</td> |
| 2069 |
</tr> |
| 2070 |
<tr> |
| 2071 |
<td> |
| 2072 |
<code>super</code> |
| 2073 |
⟦<i>e</i>/<code>super</code>⟧ = <i>e</i> |
| 2074 |
</td> |
| 2075 |
</tr> |
| 2076 |
<tr> |
| 2077 |
<td> |
| 2078 |
<code>self</code> |
| 2079 |
⟦<i>e</i>/<code>super</code>⟧ = <code>self</code> |
| 2080 |
</td> |
| 2081 |
</tr> |
| 2082 |
<tr> |
| 2083 |
<td> |
| 2084 |
<code>super</code> |
| 2085 |
⟦<i>e</i>/<code>self</code>⟧ = <code>super</code> |
| 2086 |
</td> |
| 2087 |
</tr> |
| 2088 |
<tr> |
| 2089 |
<td> |
| 2090 |
<code>{</code> |
| 2091 |
... |
| 2092 |
<code>assert</code> <i>e'</i> |
| 2093 |
... |
| 2094 |
<code>[</code><i>e''</i><code>]</code><i>h</i> <i>e'''</i> |
| 2095 |
... |
| 2096 |
<code>}</code> |
| 2097 |
⟦<i>e</i>/<i>kw</i>⟧ = |
| 2098 |
<code>{</code> |
| 2099 |
... |
| 2100 |
<code>assert</code> <i>e'</i> |
| 2101 |
... |
| 2102 |
<code>[</code><i>e''</i>⟦<i>e</i>/<i>kw</i>⟧<code>]</code><i>h</i> <i>e'''</i> |
| 2103 |
... |
| 2104 |
<code>}</code> |
| 2105 |
</td> |
| 2106 |
</tr> |
| 2107 |
<tr> |
| 2108 |
<td> |
| 2109 |
<code>{</code> |
| 2110 |
<code>[</code><i>e'</i><code>]</code><code>:</code> <i>e''</i> |
| 2111 |
<code>for</code> <i>x</i> <code>in</code> <i>e'''</i> |
| 2112 |
<code>}</code>⟦<i>e</i>/<i>kw</i>⟧ = |
| 2113 |
<code>{</code> |
| 2114 |
<code>[</code><i>e'</i>⟦<i>e'</i>/<i>kw</i>⟧<code>]</code><code>:</code> <i>e''</i> |
| 2115 |
<code>for</code> <i>x</i> <code>in</code> <i>e'''</i>⟦<i>e</i>/<i>kw</i>⟧ |
| 2116 |
<code>}</code> |
| 2117 |
</td> |
| 2118 |
</tr> |
| 2119 |
<tr> |
| 2120 |
<td> |
| 2121 |
Otherwise, <i>e'</i>⟦<i>e'</i>/<i>kw</i>⟧ proceeds via syntax-directed recursion into |
| 2122 |
the subterms of <i>e'</i>. |
| 2123 |
</td> |
| 2124 |
</tr> |
| 2125 |
</table> |
| 2126 |
</div> |
| 2127 |
<div style="clear: both"></div> |
| 2128 |
</div> |
| 2129 |
</div> |
| 2130 |
|
| 2131 |
|
| 2132 |
<div class="hgroup"> |
| 2133 |
<div class="hgroup-inline"> |
| 2134 |
<div class="panel"> |
| 2135 |
<h4 id="execution">Execution</h4> |
| 2136 |
</div> |
| 2137 |
<div style="clear: both"></div> |
| 2138 |
</div> |
| 2139 |
</div> |
| 2140 |
|
| 2141 |
<div class="hgroup"> |
| 2142 |
<div class="hgroup-inline"> |
| 2143 |
<div class="panel"> |
| 2144 |
<p> |
| 2145 |
The following big step operational semantics rules define the execution of Jsonnet programs, |
| 2146 |
i.e. the reduction of a Jsonnet program <i>e</i> into its Jsonnet value <em>v</em> via the |
| 2147 |
judgement \(e ↓ v\). |
| 2148 |
</p> |
| 2149 |
<div style="clear: both"></div> |
| 2150 |
</div> |
| 2151 |
</div> |
| 2152 |
|
| 2153 |
|
| 2154 |
<div class="inverse hgroup"> |
| 2155 |
<div class="hgroup-inline"> |
| 2156 |
<div class="panel wide"> |
| 2157 |
<p> |
| 2158 |
Let <em>f</em> range over strings, as used in object field names. |
| 2159 |
</p> |
| 2160 |
<div class="rules"> |
| 2161 |
|
| 2162 |
<div class="sequent-rule"> |
| 2163 |
\[ |
| 2164 |
\rule{value} { |
| 2165 |
v ∈ \{\null, \true, \false\} ∪ String ∪ Number ∪ Function ∪ Array |
| 2166 |
} { |
| 2167 |
v ↓ v |
| 2168 |
} |
| 2169 |
\] |
| 2170 |
</div> |
| 2171 |
|
| 2172 |
<div class="sequent-rule"> |
| 2173 |
\[ |
| 2174 |
\rule{object} { |
| 2175 |
∀i∈\{1\ldots p\}: e_i ↓ f_i |
| 2176 |
\\ |
| 2177 |
∀i∈\{p+1 \ldots n\}: e_i ↓ \null |
| 2178 |
\\ |
| 2179 |
∀i,j∈\{1\ldots p\}: f_i = f_j ⇒ i = j |
| 2180 |
\\ |
| 2181 |
o = \object{ |
| 2182 |
\assert{e_1} \ldots \assert{e_m}, f_1\mathop{h_1}e''_1 \ldots f_p\mathop{h_p}e''_p |
| 2183 |
} |
| 2184 |
} { |
| 2185 |
\object{\assert{e_1} \ldots \assert{e_m}, |
| 2186 |
[e'_1]\mathop{h_1}e''_1 \ldots [e'_n]\mathop{h_n}e''_n } ↓ o |
| 2187 |
} |
| 2188 |
\] |
| 2189 |
</div> |
| 2190 |
|
| 2191 |
<div class="sequent-rule"> |
| 2192 |
\[ |
| 2193 |
\rule{object-comp} { |
| 2194 |
e_{arr} ↓ [ e_1 \ldots e_n ] |
| 2195 |
\\ |
| 2196 |
∀i∈\{1 \ldots n\}: e_{field}[e_i/x] ↓ f_i |
| 2197 |
\\ |
| 2198 |
∀i,j∈\{1\ldots n\}: f_i = f_j ≠ \null ⇒ i = j |
| 2199 |
\\ |
| 2200 |
\{ (f'_1, e'_1) \ldots (f'_m, e'_m) \} = |
| 2201 |
\{ (f_i, e_{body}[e_i/x]) \ | \ i ∈\{1\ldots n\} ∧ f_i ≠ \null \} |
| 2202 |
\\ |
| 2203 |
o = \object{f'_1: e'_1 \ldots f'_m: e'_m} |
| 2204 |
} { |
| 2205 |
\ocomp{e_{field}}{e_{body}}{x}{e_{arr}} ↓ o |
| 2206 |
} |
| 2207 |
\] |
| 2208 |
</div> |
| 2209 |
|
| 2210 |
<div class="sequent-rule"> |
| 2211 |
\[ |
| 2212 |
\rule{array-index} { |
| 2213 |
e ↓ \array{e_0 \ldots e_n} |
| 2214 |
\\ |
| 2215 |
e' ↓ i ∈ \{ 0 \ldots n \} |
| 2216 |
\\ |
| 2217 |
e_i ↓ v |
| 2218 |
} { |
| 2219 |
\index{e}{e'} ↓ v |
| 2220 |
} |
| 2221 |
\] |
| 2222 |
</div> |
| 2223 |
|
| 2224 |
<div class="sequent-rule"> |
| 2225 |
\[ |
| 2226 |
\rule{object-index} { |
| 2227 |
e ↓ o = \object{\assert{e'''_1} \ldots \assert{e'''_m}, f_1 h_1 e''_1 \ldots f_n h_n e''_n} |
| 2228 |
\\ |
| 2229 |
∀j ∈ \{1 \ldots m \}: e'''_j⟦ o / \self, \{\} / \super ⟧↓\_ |
| 2230 |
\\ |
| 2231 |
e' ↓ f_i |
| 2232 |
\\ |
| 2233 |
e''_i ⟦ o / \self, \{\} / \super ⟧ ↓ v |
| 2234 |
} { |
| 2235 |
\index{e}{e'} ↓ v |
| 2236 |
} |
| 2237 |
\] |
| 2238 |
</div> |
| 2239 |
|
| 2240 |
<div class="sequent-rule"> |
| 2241 |
\[ |
| 2242 |
\rule{apply} { |
| 2243 |
e_0 ↓ \function{y_1=e'_1 \ldots y_p=e'_p}{e_b} |
| 2244 |
\\ |
| 2245 |
∀i∈\{m+1 \ldots n\}: x_i ∈ \{y_1 \ldots y_p\} |
| 2246 |
\\ |
| 2247 |
∀i∈\{1 \ldots p\}: e''_i = \left\{\begin{array}{ll} |
| 2248 |
e_i & \textrm{if } i ≤ m \\ |
| 2249 |
e_j & \textrm{if } y_i=x_j \textrm{ for some } j \\ |
| 2250 |
e'_i & \textrm{otherwise}\\ |
| 2251 |
\end{array}\right. |
| 2252 |
\\ |
| 2253 |
(\local{y_1=e''_1 \ldots y_p=e''_p}{e_b}) ↓ v |
| 2254 |
} { |
| 2255 |
e_0(e_1 \ldots e_m, x_{m+1}=e_{m+1} \ldots x_n = e_n) ↓ v |
| 2256 |
} |
| 2257 |
\] |
| 2258 |
</div> |
| 2259 |
|
| 2260 |
<div class="sequent-rule"> |
| 2261 |
\[ |
| 2262 |
\rule{local} { |
| 2263 |
e ↓ v |
| 2264 |
} { |
| 2265 |
\local{\_}e ↓ v |
| 2266 |
} |
| 2267 |
\] |
| 2268 |
</div> |
| 2269 |
|
| 2270 |
<div class="sequent-rule"> |
| 2271 |
\[ |
| 2272 |
\rule{local-var} { |
| 2273 |
binds = \assign{x_1}{e_1} \ldots \assign{x_n}{e_n} |
| 2274 |
\\ |
| 2275 |
\local{binds}{e[\local{binds}{e_1} / x_1 \ldots \local{binds}{e_n} / x_n ]} ↓ v |
| 2276 |
} { |
| 2277 |
\local{binds}e ↓ v |
| 2278 |
} |
| 2279 |
\] |
| 2280 |
</div> |
| 2281 |
|
| 2282 |
<div class="sequent-rule"> |
| 2283 |
\[ |
| 2284 |
\rule{if-true} { |
| 2285 |
e_1 ↓ \true \hspace{15pt} e_2 ↓ v |
| 2286 |
} { |
| 2287 |
\if{e_1}{e_2}{e_3} ↓ v |
| 2288 |
} |
| 2289 |
\] |
| 2290 |
</div> |
| 2291 |
|
| 2292 |
<div class="sequent-rule"> |
| 2293 |
\[ |
| 2294 |
\rule{if-false} { |
| 2295 |
e_1 ↓ \false \hspace{15pt} e_3 ↓ v |
| 2296 |
} { |
| 2297 |
\if{e_1}{e_2}{e_3} ↓ v |
| 2298 |
} |
| 2299 |
\] |
| 2300 |
</div> |
| 2301 |
|
| 2302 |
<div class="sequent-rule"> |
| 2303 |
\[ |
| 2304 |
\rule{object-inherit} { |
| 2305 |
e^L ↓ \object{ |
| 2306 |
\assert e''^L_1 \ldots \assert e''^L_n,\ |
| 2307 |
f_1 h^L_1 e^L_1 \ldots f_m h^L_m e^L_m,\ |
| 2308 |
f'^L_1 h'^L_1 e'^L_1 \ldots f'^L_p h'^L_p e'^L_p |
| 2309 |
} |
| 2310 |
\\ |
| 2311 |
e^R ↓ \object{ |
| 2312 |
\assert e''^R_1 \ldots \assert e''^R_q,\ |
| 2313 |
f_1 h^R_1 e^R_1 \ldots f_m h^R_m e^R_m,\ |
| 2314 |
f'^R_1 h'^R_1 e'^R_1 \ldots f'^R_r h'^R_r e'^R_r |
| 2315 |
} |
| 2316 |
\\ |
| 2317 |
\{ f'^L_1 \ldots f'^L_p \} ∩ \{ f'^R_1 \ldots f'^R_r \} = ∅ |
| 2318 |
\\ |
| 2319 |
x, y \textrm{ fresh} \hspace{15pt} \textrm{let } S = λe . e⟦x/\self, y/\super⟧ |
| 2320 |
\\ |
| 2321 |
e_s = \super + \object{ |
| 2322 |
\assert S(e''^L_1) \ldots \assert S(e''^L_n),\\ |
| 2323 |
\hspace{20mm} |
| 2324 |
f_1 h^L_1 S(e^L_1) \ldots f_m h^L_m S(e^L_m),\ |
| 2325 |
f'^L_1 h'^L_1 S(e'^L_1) \ldots f'^L_p h'^L_p S(e'^L_p) |
| 2326 |
} |
| 2327 |
\\ |
| 2328 |
∀i∈\{1 \ldots m\}: h'''_i = h^L_i + h^R_i ∧ |
| 2329 |
e'''_i = (\local{x = \self, y = \super}{e^R_i ⟦e_s / \super⟧}) |
| 2330 |
\\ |
| 2331 |
o = \{ \\ |
| 2332 |
\hspace{5mm} \assert e''^L_1 \ldots \assert e''^L_n, \ |
| 2333 |
\assert e''^R_1 \ldots \assert e''^R_q, \\ |
| 2334 |
\hspace{5mm} f'^L_1 h'^L_1 e'^L_1 \ldots f'^L_p h'^L_p e'^L_p, \ |
| 2335 |
f'^R_1 h'^R_1 e'^R_1 \ldots f'^R_r h'^R_r e'^R_r, \ |
| 2336 |
f_1 h'''_1 e'''_m \ldots f_m h'''_m e'''_m \\ |
| 2337 |
\} |
| 2338 |
} { |
| 2339 |
e^L \texttt{ + } e^R ↓ o |
| 2340 |
} |
| 2341 |
\] |
| 2342 |
</div> |
| 2343 |
|
| 2344 |
<div class="sequent-rule"> |
| 2345 |
\[ |
| 2346 |
\rule{array-concat} { |
| 2347 |
e ↓ \array{e_0 \ldots e_m} |
| 2348 |
\\ |
| 2349 |
e' ↓ \array{e_{m+1} \ldots e_n} |
| 2350 |
} { |
| 2351 |
e + e' ↓ \array{e_1 \ldots e_n} |
| 2352 |
} |
| 2353 |
\] |
| 2354 |
</div> |
| 2355 |
|
| 2356 |
<div class="sequent-rule"> |
| 2357 |
\[ |
| 2358 |
\rule{string-concat} { |
| 2359 |
e_L ↓ v_L \hspace{15pt} e_R ↓ v_R |
| 2360 |
\\ |
| 2361 |
v_L ∈ String \vee v_R ∈ String |
| 2362 |
} { |
| 2363 |
e_L \texttt{ + } e_R ↓ stringconcat(tostring(v_L), tostring(v_R)) |
| 2364 |
} |
| 2365 |
\] |
| 2366 |
</div> |
| 2367 |
|
| 2368 |
<!-- TODO(sbarzowski) Consider explicitly introducing std.cmp (three way comparison) --> |
| 2369 |
<div class="sequent-rule"> |
| 2370 |
\[ |
| 2371 |
\rule{less-than-true} { |
| 2372 |
\texttt{std.cmp}(e_L, e_R) ↓ -1 |
| 2373 |
} { |
| 2374 |
e_L < e_R ↓ \texttt{true} |
| 2375 |
} |
| 2376 |
\] |
| 2377 |
</div> |
| 2378 |
|
| 2379 |
<div class="sequent-rule"> |
| 2380 |
\[ |
| 2381 |
\rule{less-than-false} { |
| 2382 |
\texttt{std.cmp}(e_L, e_R) ↓ r |
| 2383 |
\\ |
| 2384 |
r ∈ \{0, 1\} |
| 2385 |
} { |
| 2386 |
e_L < e_R ↓ \texttt{false} |
| 2387 |
} |
| 2388 |
\] |
| 2389 |
</div> |
| 2390 |
|
| 2391 |
<div class="sequent-rule"> |
| 2392 |
\[ |
| 2393 |
\rule{greater-than-true} { |
| 2394 |
\texttt{std.cmp}(e_L, e_R) ↓ 1 |
| 2395 |
} { |
| 2396 |
e_L < e_R ↓ \texttt{true} |
| 2397 |
} |
| 2398 |
\] |
| 2399 |
</div> |
| 2400 |
|
| 2401 |
<div class="sequent-rule"> |
| 2402 |
\[ |
| 2403 |
\rule{greater-than-false} { |
| 2404 |
\texttt{std.cmp}(e_L, e_R) ↓ r |
| 2405 |
\\ |
| 2406 |
r ∈ \{-1, 0\} |
| 2407 |
} { |
| 2408 |
e_L < e_R ↓ \texttt{false} |
| 2409 |
} |
| 2410 |
\] |
| 2411 |
</div> |
| 2412 |
|
| 2413 |
<div class="sequent-rule"> |
| 2414 |
\[ |
| 2415 |
\rule{less-or-equal-true} { |
| 2416 |
\texttt{std.cmp}(e_L, e_R) ↓ r |
| 2417 |
\\ |
| 2418 |
r ∈ \{-1, 0\} |
| 2419 |
} { |
| 2420 |
e_L <= e_R ↓ \texttt{true} |
| 2421 |
} |
| 2422 |
\] |
| 2423 |
</div> |
| 2424 |
|
| 2425 |
<div class="sequent-rule"> |
| 2426 |
\[ |
| 2427 |
\rule{less-or-equal-false} { |
| 2428 |
\texttt{std.cmp}(e_L, e_R) ↓ 1 |
| 2429 |
} { |
| 2430 |
e_L <= e_R ↓ \texttt{false} |
| 2431 |
} |
| 2432 |
\] |
| 2433 |
</div> |
| 2434 |
|
| 2435 |
<div class="sequent-rule"> |
| 2436 |
\[ |
| 2437 |
\rule{greater-or-equal-true} { |
| 2438 |
\texttt{std.cmp}(e_L, e_R) ↓ r |
| 2439 |
\\ |
| 2440 |
r ∈ \{0, 1\} |
| 2441 |
} { |
| 2442 |
e_L >= e_R ↓ \texttt{true} |
| 2443 |
} |
| 2444 |
\] |
| 2445 |
</div> |
| 2446 |
|
| 2447 |
<div class="sequent-rule"> |
| 2448 |
\[ |
| 2449 |
\rule{greater-or-equal-false} { |
| 2450 |
\texttt{std.cmp}(e_L, e_R) ↓ -1 |
| 2451 |
} { |
| 2452 |
e_L >= e_R ↓ \texttt{false} |
| 2453 |
} |
| 2454 |
\] |
| 2455 |
</div> |
| 2456 |
|
| 2457 |
<div class="sequent-rule"> |
| 2458 |
\[ |
| 2459 |
\rule{cmp-array-left-empty} { |
| 2460 |
e_L ↓ \array{} \hspace{15pt} e_R ↓ \array{a_0 \ldots a_{n - 1}} |
| 2461 |
\\ |
| 2462 |
n > 0 |
| 2463 |
} { |
| 2464 |
\texttt{std.cmp}(e_L, e_R) ↓ -1 |
| 2465 |
} |
| 2466 |
\] |
| 2467 |
</div> |
| 2468 |
|
| 2469 |
<div class="sequent-rule"> |
| 2470 |
\[ |
| 2471 |
\rule{cmp-array-right-empty} { |
| 2472 |
e_L ↓ \array{a_0 \ldots a_{n - 1}} \hspace{15pt} e_R ↓ \array{} |
| 2473 |
\\ |
| 2474 |
n > 0 |
| 2475 |
} { |
| 2476 |
\texttt{std.cmp}(e_L, e_R) ↓ 1 |
| 2477 |
} |
| 2478 |
\] |
| 2479 |
</div> |
| 2480 |
|
| 2481 |
<div class="sequent-rule"> |
| 2482 |
\[ |
| 2483 |
\rule{cmp-array-both-empty} { |
| 2484 |
e_L ↓ \array{} \hspace{15pt} e_R ↓ \array{} |
| 2485 |
} { |
| 2486 |
\texttt{std.cmp}(e_L, e_R) ↓ 0 |
| 2487 |
} |
| 2488 |
\] |
| 2489 |
</div> |
| 2490 |
|
| 2491 |
<div class="sequent-rule"> |
| 2492 |
\[ |
| 2493 |
\rule{cmp-array-first-different} { |
| 2494 |
e_L ↓ \array{a_0 \ldots a_{n - 1}} \hspace{15pt} e_R ↓ \array{b_0 \ldots b_{m - 1}} |
| 2495 |
\\ |
| 2496 |
n > 0 \hspace{15pt} m > 0 |
| 2497 |
\\ |
| 2498 |
\texttt{std.cmp}(a_0, b_0) ↓ r |
| 2499 |
\\ |
| 2500 |
r ≠ 0 |
| 2501 |
} { |
| 2502 |
\texttt{std.cmp}(e_L, e_R) ↓ r |
| 2503 |
} |
| 2504 |
\] |
| 2505 |
</div> |
| 2506 |
|
| 2507 |
<div class="sequent-rule"> |
| 2508 |
\[ |
| 2509 |
\rule{cmp-array-first-equal} { |
| 2510 |
e_L ↓ \array{a_0 \ldots a_{n - 1}} \hspace{15pt} e_R ↓ \array{b_0 \ldots b_{m - 1}} |
| 2511 |
\\ |
| 2512 |
n > 0 \hspace{15pt} m > 0 |
| 2513 |
\\ |
| 2514 |
\texttt{std.cmp}(a_0, b_0) ↓ 0 |
| 2515 |
\\ |
| 2516 |
\texttt{std.cmp}(\array{a_1 \ldots a_{n - 1}}, \array{b_1 \ldots b_{m - 1}}) ↓ r' |
| 2517 |
} { |
| 2518 |
\texttt{std.cmp}(e_L, e_R) ↓ r' |
| 2519 |
} |
| 2520 |
\] |
| 2521 |
</div> |
| 2522 |
|
| 2523 |
<div class="sequent-rule"> |
| 2524 |
\[ |
| 2525 |
\rule{cmp-string} { |
| 2526 |
e_L ↓ v_L \hspace{15pt} e_R ↓ v_R |
| 2527 |
\\ |
| 2528 |
v_L ∈ String |
| 2529 |
\\ |
| 2530 |
v_R ∈ String |
| 2531 |
} { |
| 2532 |
\texttt{std.cmp}(e_L, e_R) ↓ stringcmp(v_L, v_R) |
| 2533 |
} |
| 2534 |
\] |
| 2535 |
</div> |
| 2536 |
|
| 2537 |
<div class="sequent-rule"> |
| 2538 |
\[ |
| 2539 |
\rule{cmp-number} { |
| 2540 |
e_L ↓ v_L \hspace{15pt} e_R ↓ v_R |
| 2541 |
\\ |
| 2542 |
v_L ∈ Number |
| 2543 |
\\ |
| 2544 |
v_R ∈ Number |
| 2545 |
} { |
| 2546 |
\texttt{std.cmp}(e_L, e_R) ↓ numbercmp(v_L, v_R) |
| 2547 |
} |
| 2548 |
\] |
| 2549 |
</div> |
| 2550 |
|
| 2551 |
<div class="sequent-rule"> |
| 2552 |
\[ |
| 2553 |
\rule{boolean-and-shortcut} { |
| 2554 |
e_L ↓ \false |
| 2555 |
} { |
| 2556 |
e_L \texttt{ && } e_R ↓ \false |
| 2557 |
} |
| 2558 |
\] |
| 2559 |
</div> |
| 2560 |
|
| 2561 |
<div class="sequent-rule"> |
| 2562 |
\[ |
| 2563 |
\rule{boolean-and-longcut} { |
| 2564 |
e_L ↓ \true |
| 2565 |
\\ |
| 2566 |
e_R ↓ b |
| 2567 |
} { |
| 2568 |
e_L \texttt{ && } e_R ↓ b |
| 2569 |
} |
| 2570 |
\] |
| 2571 |
</div> |
| 2572 |
|
| 2573 |
<div class="sequent-rule"> |
| 2574 |
\[ |
| 2575 |
\rule{boolean-or-shortcut} { |
| 2576 |
e_L ↓ \true |
| 2577 |
} { |
| 2578 |
e_L \texttt{ || } e_R ↓ \true |
| 2579 |
} |
| 2580 |
\] |
| 2581 |
</div> |
| 2582 |
|
| 2583 |
<div class="sequent-rule"> |
| 2584 |
\[ |
| 2585 |
\rule{boolean-or-longcut} { |
| 2586 |
e_L ↓ \false |
| 2587 |
\\ |
| 2588 |
e_R ↓ b |
| 2589 |
} { |
| 2590 |
e_L \texttt{ || } e_R ↓ b |
| 2591 |
} |
| 2592 |
\] |
| 2593 |
</div> |
| 2594 |
|
| 2595 |
<div class="sequent-rule"> |
| 2596 |
\[ |
| 2597 |
\rule{not-true} { |
| 2598 |
e ↓ \true |
| 2599 |
} { |
| 2600 |
\texttt{!} e ↓ \false |
| 2601 |
} |
| 2602 |
\] |
| 2603 |
</div> |
| 2604 |
|
| 2605 |
<div class="sequent-rule"> |
| 2606 |
\[ |
| 2607 |
\rule{not-false} { |
| 2608 |
e ↓ \false |
| 2609 |
} { |
| 2610 |
\texttt{!} e ↓ \true |
| 2611 |
} |
| 2612 |
\] |
| 2613 |
</div> |
| 2614 |
|
| 2615 |
<div class="sequent-rule"> |
| 2616 |
\[ |
| 2617 |
\rule{primitiveEquals} { |
| 2618 |
e ↓ v |
| 2619 |
\\ |
| 2620 |
e' ↓ v' |
| 2621 |
\\ |
| 2622 |
b = (v ∈ String ∨ v ∈ Boolean ∨ v ∈ Number ∨ v = \null) ∧ v = v' |
| 2623 |
} { |
| 2624 |
\texttt{std.primitiveEquals}(e, e') ↓ b |
| 2625 |
} |
| 2626 |
\] |
| 2627 |
</div> |
| 2628 |
|
| 2629 |
<div class="sequent-rule"> |
| 2630 |
\[ |
| 2631 |
\rule{length-array} { |
| 2632 |
e ↓ \array{e_0 \ldots e_{n - 1}} |
| 2633 |
} { |
| 2634 |
\texttt{std.length}(e) ↓ n |
| 2635 |
} |
| 2636 |
\] |
| 2637 |
</div> |
| 2638 |
|
| 2639 |
<div class="sequent-rule"> |
| 2640 |
\[ |
| 2641 |
\rule{length-object} { |
| 2642 |
\texttt{std.length}(\texttt{std.objectFieldsEx}(e, false) ↓ n |
| 2643 |
} { |
| 2644 |
\texttt{std.length}(e) ↓ n |
| 2645 |
} |
| 2646 |
\] |
| 2647 |
</div> |
| 2648 |
|
| 2649 |
<div class="sequent-rule"> |
| 2650 |
\[ |
| 2651 |
\rule{length-string} { |
| 2652 |
e ↓ v ∈ String |
| 2653 |
} { |
| 2654 |
\texttt{std.length}(e) ↓ strlen(v) |
| 2655 |
} |
| 2656 |
\] |
| 2657 |
</div> |
| 2658 |
|
| 2659 |
<div class="sequent-rule"> |
| 2660 |
\[ |
| 2661 |
\rule{makeArray} { |
| 2662 |
e ↓ n |
| 2663 |
\\ |
| 2664 |
e' ↓ f ∈ Function |
| 2665 |
} { |
| 2666 |
\texttt{std.makeArray}(e, e') ↓ \array{f(0) \ldots f(n - 1)} |
| 2667 |
} |
| 2668 |
\] |
| 2669 |
</div> |
| 2670 |
|
| 2671 |
<div class="sequent-rule"> |
| 2672 |
\[ |
| 2673 |
\rule{filter} { |
| 2674 |
e ↓ f ∈ Function |
| 2675 |
\\ |
| 2676 |
e' ↓ \array{e_0 \ldots e_{n - 1}} |
| 2677 |
\\ |
| 2678 |
j_1 \ldots j_m = \{ i \ |\ f(e_i) ↓ \true \} |
| 2679 |
} { |
| 2680 |
\texttt{std.filter}(e, e') ↓ \array{e_{j_1} \ldots e_{j_m}} |
| 2681 |
} |
| 2682 |
\] |
| 2683 |
</div> |
| 2684 |
|
| 2685 |
<div class="sequent-rule"> |
| 2686 |
\[ |
| 2687 |
\rule{type-null} { |
| 2688 |
e ↓ \texttt{null} |
| 2689 |
} { |
| 2690 |
\texttt{std.type}(e) ↓ \texttt{"null"} |
| 2691 |
} |
| 2692 |
\] |
| 2693 |
</div> |
| 2694 |
|
| 2695 |
<div class="sequent-rule"> |
| 2696 |
\[ |
| 2697 |
\rule{type-boolean} { |
| 2698 |
e ↓ v ∈ Boolean |
| 2699 |
} { |
| 2700 |
\texttt{std.type}(e) ↓ \texttt{"boolean"} |
| 2701 |
} |
| 2702 |
\] |
| 2703 |
</div> |
| 2704 |
|
| 2705 |
<div class="sequent-rule"> |
| 2706 |
\[ |
| 2707 |
\rule{type-number} { |
| 2708 |
e ↓ v ∈ Number |
| 2709 |
} { |
| 2710 |
\texttt{std.type}(e) ↓ \texttt{"number"} |
| 2711 |
} |
| 2712 |
\] |
| 2713 |
</div> |
| 2714 |
|
| 2715 |
<div class="sequent-rule"> |
| 2716 |
\[ |
| 2717 |
\rule{type-string} { |
| 2718 |
e ↓ v ∈ String |
| 2719 |
} { |
| 2720 |
\texttt{std.type}(e) ↓ \texttt{"string"} |
| 2721 |
} |
| 2722 |
\] |
| 2723 |
</div> |
| 2724 |
|
| 2725 |
<div class="sequent-rule"> |
| 2726 |
\[ |
| 2727 |
\rule{type-object} { |
| 2728 |
e ↓ v ∈ Object |
| 2729 |
} { |
| 2730 |
\texttt{std.type}(e) ↓ \texttt{"object"} |
| 2731 |
} |
| 2732 |
\] |
| 2733 |
</div> |
| 2734 |
|
| 2735 |
<div class="sequent-rule"> |
| 2736 |
\[ |
| 2737 |
\rule{type-function} { |
| 2738 |
e ↓ v ∈ Function |
| 2739 |
} { |
| 2740 |
\texttt{std.type}(e) ↓ \texttt{"function"} |
| 2741 |
} |
| 2742 |
\] |
| 2743 |
</div> |
| 2744 |
|
| 2745 |
<div class="sequent-rule"> |
| 2746 |
\[ |
| 2747 |
\rule{type-array} { |
| 2748 |
e ↓ v ∈ Array |
| 2749 |
} { |
| 2750 |
\texttt{std.type}(e) ↓ \texttt{"array"} |
| 2751 |
} |
| 2752 |
\] |
| 2753 |
</div> |
| 2754 |
|
| 2755 |
<div class="sequent-rule"> |
| 2756 |
\[ |
| 2757 |
\rule{object-has-ex} { |
| 2758 |
e' ↓ f |
| 2759 |
\\ |
| 2760 |
e'' ↓ b' |
| 2761 |
\\ |
| 2762 |
e ↓ \object{\assert{e'_1} \ldots \assert{e'_m}, f_1 h_1 e_1 \ldots f_n h_n e_n } |
| 2763 |
\\ |
| 2764 |
b = ∃i: f = f_i ∧ (h_i \mathop{≠} :: \mathop{∨} b') |
| 2765 |
} { |
| 2766 |
\texttt{std.objectHasEx}(e, e', e'') ↓ b |
| 2767 |
} |
| 2768 |
\] |
| 2769 |
</div> |
| 2770 |
|
| 2771 |
<div class="sequent-rule"> |
| 2772 |
\[ |
| 2773 |
\rule{object-fields-ex} { |
| 2774 |
e' ↓ b' |
| 2775 |
\\ |
| 2776 |
e ↓ \object{\assert{e'_1} \ldots \assert{e'_m}, f_1 h_1 e_1 \ldots f_n h_n e_n } |
| 2777 |
\\ |
| 2778 |
\{ f'_1 \ldots f'_p \} = \{ f\ |\ ∃i: f = f_i ∧ (h_i \mathop{≠} :: \mathop{∨} b') \} |
| 2779 |
\\ |
| 2780 |
∀i,j∈\{1 \ldots p\}: i≤j ⇒ f'_i≤f'_j |
| 2781 |
} { |
| 2782 |
\texttt{std.objectFieldsEx}(e, e') ↓ \array{f'_1 \ldots f'_p} |
| 2783 |
} |
| 2784 |
\] |
| 2785 |
</div> |
| 2786 |
|
| 2787 |
</div> |
| 2788 |
</div> |
| 2789 |
<div style="clear: both"></div> |
| 2790 |
</div> |
| 2791 |
</div> |
| 2792 |
|
| 2793 |
<div class="hgroup"> |
| 2794 |
<div class="hgroup-inline"> |
| 2795 |
<div class="panel"> |
| 2796 |
<p> |
| 2797 |
String concatenation will implicitly convert one of the values to a string if necessary. |
| 2798 |
This is similar to Java. The referred function \(tostring\) returns its argument unchanged |
| 2799 |
if it is a string. Otherwise it will manifest its argument as a JSON value \(j\) and |
| 2800 |
unparse it as a single line of text. The referred function \(strlen\) returns the number of |
| 2801 |
unicode characters in the string. |
| 2802 |
</p> |
| 2803 |
<p> |
| 2804 |
The numeric semantics are as follows: |
| 2805 |
</p> |
| 2806 |
<ul> |
| 2807 |
<li> |
| 2808 |
<b>Arithmetic:</b> Binary <code>*</code>, <code>/</code>, <code>+</code>, <code>-</code>, |
| 2809 |
<code><</code>, <code><=</code>, <code>></code>, <code>>=</code>, and unary |
| 2810 |
<code>+</code> and <code>-</code> operate on numbers and have IEEE double precision |
| 2811 |
floating point semantics, except that the special states NaN, Infinity raise errors. Note |
| 2812 |
that <code>+</code> is also overloaded on objects, arrays, and when either argument is a |
| 2813 |
string. Also, <code><</code>, <code><=</code>, <code>></code>, <code>>=</code> |
| 2814 |
are overloaded on strings and on arrays. In both cases the comparison is performed |
| 2815 |
lexicographically (in case of strings, by unicode codepoint). |
| 2816 |
</li> |
| 2817 |
<li> |
| 2818 |
<b>Bitwise:</b> Operators |
| 2819 |
<code><<</code>, |
| 2820 |
<code>>></code>, |
| 2821 |
<code>&</code>, |
| 2822 |
<code>^</code>, |
| 2823 |
<code>|</code> and |
| 2824 |
<code>~</code> |
| 2825 |
first convert their operands to signed 64 bit integers, then perform the operations in a |
| 2826 |
standard way, then convert back to IEEE double precision floating point. In shift |
| 2827 |
operations <code><<</code>, <code>>></code>, the right hand value modulo 64 is |
| 2828 |
interpreted as the shift count. Shifting with a negative shift count raises an error. |
| 2829 |
Individiual Jsonnet implementations may place further restrictions on the range of inputs |
| 2830 |
or outputs to bitwise operations. |
| 2831 |
</li> |
| 2832 |
<li> |
| 2833 |
<b>Standard functions</b>: The following functions have standard mathematical behavior |
| 2834 |
and operate on IEEE double precision floating point: |
| 2835 |
<code>std.pow(a, b)</code>, |
| 2836 |
<code>std.floor(x)</code>, |
| 2837 |
<code>std.ceil(x)</code>, |
| 2838 |
<code>std.sqrt(x)</code>, |
| 2839 |
<code>std.sin(x)</code>, |
| 2840 |
<code>std.cos(x)</code>, |
| 2841 |
<code>std.tan(x)</code>, |
| 2842 |
<code>std.asin(x)</code>, |
| 2843 |
<code>std.acos(x)</code>, |
| 2844 |
<code>std.atan(x)</code>, |
| 2845 |
<code>std.atan2(y, x)</code>, |
| 2846 |
<code>std.log(x)</code>, |
| 2847 |
<code>std.log2(x)</code>, |
| 2848 |
<code>std.log10(x)</code>, |
| 2849 |
<code>std.exp(x)</code>, |
| 2850 |
<code>std.mantissa(x)</code>, |
| 2851 |
<code>std.exponent(x)</code> and |
| 2852 |
<code>std.modulo(a, b)</code>. |
| 2853 |
Also, <code>std.codepoint(x)</code> take a single character string, |
| 2854 |
returning the unicode codepoint as a number, and <code>std.char(x)</code> is its inverse. |
| 2855 |
</li> |
| 2856 |
</ul> |
| 2857 |
<p> |
| 2858 |
The <code>error</code> operator has no rule because we model errors (both from the language |
| 2859 |
and user-defined) as stuck execution. The semantics of <code>error</code> are that its |
| 2860 |
subterm is evaluated to a Jsonnet value. If this is a string, then that is the error that |
| 2861 |
is raised. Otherwise, it is converted to a string using \(tostring\) like during string |
| 2862 |
concatenation. The specification does not specify how the error is presented to the user, |
| 2863 |
and whether or not there is a stack trace. Error messages are meant for human inspection, |
| 2864 |
and there is therefore no need to standardize them. |
| 2865 |
</p> |
| 2866 |
<p> |
| 2867 |
Finally, the function <code>std.native(x)</code> takes a string and returns a function |
| 2868 |
configured by the user in a custom execution environment, thus its semantics cannot be |
| 2869 |
formally described here. The function <code>std.extVar(x)</code> also takes a string and |
| 2870 |
returns the value bound to that external variable at the time the Jsonnet |
| 2871 |
environment was created. |
| 2872 |
</p> |
| 2873 |
</div> |
| 2874 |
<div style="clear: both"></div> |
| 2875 |
</div> |
| 2876 |
</div> |
| 2877 |
|
| 2878 |
<div class="hgroup"> |
| 2879 |
<div class="hgroup-inline"> |
| 2880 |
<div class="panel"> |
| 2881 |
<h4 id="json_values">JSON Values</h4> |
| 2882 |
</div> |
| 2883 |
<div style="clear: both"></div> |
| 2884 |
</div> |
| 2885 |
</div> |
| 2886 |
|
| 2887 |
<div class="hgroup"> |
| 2888 |
<div class="hgroup-inline"> |
| 2889 |
<div class="panel"> |
| 2890 |
<p> |
| 2891 |
After execution, the resulting Jsonnet value is manifested into a JSON value whose |
| 2892 |
serialized form is the ultimate output. The Manifestation process removes hidden fields, |
| 2893 |
checks assertions, and forces array elements and non-hidden object fields. Attempting to |
| 2894 |
manifest a function raises an error since they do not exist in JSON. JSON values are |
| 2895 |
formalized below. |
| 2896 |
</p> |
| 2897 |
<p> |
| 2898 |
By abuse of notation, we consider two objects to be equivalent even if their fields are |
| 2899 |
re-ordered. However this is not true of array elements whose ordering is strict. |
| 2900 |
</p> |
| 2901 |
<table> |
| 2902 |
<tr> |
| 2903 |
<td><em>j</em></td> |
| 2904 |
<td>∈</td> |
| 2905 |
<td><em>JValue</em></td> |
| 2906 |
<td>=</td> |
| 2907 |
<td> |
| 2908 |
<em>Primitive</em> ∪ |
| 2909 |
<em>JObject</em> ∪ |
| 2910 |
<em>JArray</em> |
| 2911 |
</td> |
| 2912 |
</tr> |
| 2913 |
<tr> |
| 2914 |
<td></td> |
| 2915 |
<td></td> |
| 2916 |
<td><em>Primitive</em></td> |
| 2917 |
<td>::=</td> |
| 2918 |
<td> |
| 2919 |
<code>null</code> | <code>true</code> | <code>false</code> | <i>string</i> | |
| 2920 |
<i>double</i> |
| 2921 |
</td> |
| 2922 |
</tr> |
| 2923 |
<tr> |
| 2924 |
<td><em>o</em></td> |
| 2925 |
<td>∈</td> |
| 2926 |
<td><em>JObject</em></td> |
| 2927 |
<td>::=</td> |
| 2928 |
<td> |
| 2929 |
<code>{</code> { <i>string</i> : <em>j</em> } <code>}</code> |
| 2930 |
</td> |
| 2931 |
</tr> |
| 2932 |
<tr> |
| 2933 |
<td><em>a</em></td> |
| 2934 |
<td>∈</td> |
| 2935 |
<td><em>Array</em></td> |
| 2936 |
<td>::=</td> |
| 2937 |
<td> |
| 2938 |
<code>[</code> { <em>j</em> } <code>]</code> |
| 2939 |
</td> |
| 2940 |
</tr> |
| 2941 |
</table> |
| 2942 |
<p>Note that <em>JValue</em> ⊂ <em>Value</em>.</p> |
| 2943 |
</div> |
| 2944 |
<div style="clear: both"></div> |
| 2945 |
</div> |
| 2946 |
</div> |
| 2947 |
|
| 2948 |
<div class="hgroup"> |
| 2949 |
<div class="hgroup-inline"> |
| 2950 |
<div class="panel"> |
| 2951 |
<h4 id="manifestation">Manifestation</h4> |
| 2952 |
</div> |
| 2953 |
<div style="clear: both"></div> |
| 2954 |
</div> |
| 2955 |
</div> |
| 2956 |
|
| 2957 |
<div class="hgroup"> |
| 2958 |
<div class="hgroup-inline"> |
| 2959 |
<div class="panel"> |
| 2960 |
<p> |
| 2961 |
Manifestation is the conversion of a Jsonnet value into a JSON value. It is represented |
| 2962 |
with the judgement \(v⇓j\). The process requires executing arbitrary Jsonnet code |
| 2963 |
fragments, so the two semantic judgements represented by \(↓\) and \(⇓\) are mutually |
| 2964 |
recursive. Hidden fields are ignored during manifestation. Functions cannot be manifested, |
| 2965 |
so an error is raised in that case (formalized as stuck execution). |
| 2966 |
</p> |
| 2967 |
</div> |
| 2968 |
<div style="clear: both"></div> |
| 2969 |
</div> |
| 2970 |
</div> |
| 2971 |
|
| 2972 |
<div class="inverse hgroup"> |
| 2973 |
<div class="hgroup-inline"> |
| 2974 |
<div class="panel wide"> |
| 2975 |
<div class="rules"> |
| 2976 |
<div class="sequent-rule"> |
| 2977 |
\[ |
| 2978 |
\rule{manifest-value} { |
| 2979 |
j ∈ (\{\null, \true, \false\} ∪ String ∪ Number) |
| 2980 |
} { |
| 2981 |
j ⇓ j |
| 2982 |
} |
| 2983 |
\] |
| 2984 |
</div> |
| 2985 |
<div class="sequent-rule"> |
| 2986 |
\[ |
| 2987 |
\rule{manifest-object} { |
| 2988 |
o = \object{ |
| 2989 |
\assert e''_1 \ldots \assert e''_m,\ |
| 2990 |
f_1 h_1 e_1 \ldots f_n h_n e_n,\ |
| 2991 |
f'_1 :: e'_1 \ldots f'_p :: e'_p,\ |
| 2992 |
} |
| 2993 |
\\ |
| 2994 |
∀i∈\{1\ldots m\}: e''_i⟦o/\self,\{\}/\super⟧↓\_ |
| 2995 |
\\ |
| 2996 |
∀i∈\{1\ldots n\}: e_i⟦o/\self,\{\}/\super⟧↓v_i⇓j_i\ ∧\ h_i ≠ :: |
| 2997 |
} { |
| 2998 |
o ⇓ \object{f_1 : j_1 \ldots f_n : j_n} |
| 2999 |
} |
| 3000 |
\] |
| 3001 |
</div> |
| 3002 |
<div class="sequent-rule"> |
| 3003 |
\[ |
| 3004 |
\rule{manifest-array} { |
| 3005 |
∀i∈\{1\ldots n\}: e_i↓v_i⇓j_i |
| 3006 |
} { |
| 3007 |
\array{e_1 \ldots e_n} ⇓ \array{j_1 \ldots j_n} |
| 3008 |
} |
| 3009 |
\] |
| 3010 |
</div> |
| 3011 |
</div> |
| 3012 |
</div> |
| 3013 |
<div style="clear: both"></div> |
| 3014 |
</div> |
| 3015 |
</div> |
| 3016 |
|
| 3017 |
|
| 3018 |
<div class="hgroup"> |
| 3019 |
<div class="hgroup-inline"> |
| 3020 |
<div class="panel"> |
| 3021 |
</div> |
| 3022 |
<div style="clear: both"></div> |
| 3023 |
</div> |
| 3024 |
</div> |