Update cpp-jsonnet submodule and stdlib

Current go-jsonnet is not really 0.12.1 - it even
reports 0.12.0. This brings all the good stuff
from recent cpp-jsonnet commits and actually syncs
the version.
This commit is contained in:
Stanisław Barzowski 2019-03-04 14:37:12 +01:00 committed by Dave Cunningham
parent c1743b9a2a
commit 9348a5d2b1
4 changed files with 19552 additions and 14534 deletions

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit f4647c6309f2e635807f3103eb1b61e40dab6310
Subproject commit d1da2275b6684dde0d9c4029dca56136fea9adbe

View File

@ -81,21 +81,21 @@ limitations under the License.
std.foldl(addDigit, std.stringChars(str), 0),
parseInt(str)::
assert std.isString(str): 'Expected string, got ' + std.type(str);
assert std.length(str) > 0 && str != "-": 'Not an integer: "%s"' % [str];
assert std.isString(str) : 'Expected string, got ' + std.type(str);
assert std.length(str) > 0 && str != '-' : 'Not an integer: "%s"' % [str];
if str[0] == '-' then
-parse_nat(str[1:], 10)
else
parse_nat(str, 10),
parseOctal(str)::
assert std.isString(str): 'Expected string, got ' + std.type(str);
assert std.length(str) > 0: 'Not an octal number: ""';
assert std.isString(str) : 'Expected string, got ' + std.type(str);
assert std.length(str) > 0 : 'Not an octal number: ""';
parse_nat(str, 8),
parseHex(str)::
assert std.isString(str): 'Expected string, got ' + std.type(str);
assert std.length(str) > 0: 'Not hexadecimal: ""';
assert std.isString(str) : 'Expected string, got ' + std.type(str);
assert std.length(str) > 0 : 'Not hexadecimal: ""';
parse_nat(str, 16),
split(str, c)::
@ -921,8 +921,8 @@ limitations under the License.
std.join('', lines);
aux(value, [], ''),
manifestYamlDoc(value)::
local aux(v, in_object, path, cindent) =
manifestYamlDoc(value, indent_array_in_object=false)::
local aux(v, path, cindent) =
if v == true then
'true'
else if v == false then
@ -937,7 +937,7 @@ limitations under the License.
'""'
else if v[len - 1] == '\n' then
local split = std.split(v, '\n');
std.join('\n' + cindent, ['|'] + split[0:std.length(split) - 1])
std.join('\n' + cindent + ' ', ['|'] + split[0:std.length(split) - 1])
else
std.escapeStringJson(v)
else if std.type(v) == 'function' then
@ -946,28 +946,71 @@ limitations under the License.
if std.length(v) == 0 then
'[]'
else
local params(value) =
if std.isArray(value) && std.length(value) > 0 then {
// While we could avoid the new line, it yields YAML that is
// hard to read, e.g.:
// - - - 1
// - 2
// - - 3
// - 4
new_indent: cindent + ' ',
space: '\n' + self.new_indent,
} else if std.isObject(value) && std.length(value) > 0 then {
new_indent: cindent + ' ',
// In this case we can start on the same line as the - because the indentation
// matches up then. The converse is not true, because fields are not always
// 1 character long.
space: ' ',
} else {
// In this case, new_indent is only used in the case of multi-line strings.
new_indent: cindent,
space: ' ',
};
local range = std.range(0, std.length(v) - 1);
local actual_indent = if in_object then cindent[2:] else cindent;
local parts = [aux(v[i], false, path + [i], cindent) for i in range];
(if in_object then '\n' + actual_indent else '')
+ '- ' + std.join('\n' + actual_indent + '- ', parts)
local parts = [
'-' + param.space + aux(v[i], path + [i], param.new_indent)
for i in range
for param in [params(v[i])]
];
std.join('\n' + cindent, parts)
else if std.type(v) == 'object' then
if std.length(v) == 0 then
'{}'
else
local new_indent = cindent + ' ';
local params(value) =
if std.isArray(value) && std.length(value) > 0 then {
// Not indenting allows e.g.
// ports:
// - 80
// instead of
// ports:
// - 80
new_indent: if indent_array_in_object then cindent + ' ' else cindent,
space: '\n' + self.new_indent,
} else if std.isObject(value) && std.length(value) > 0 then {
new_indent: cindent + ' ',
space: '\n' + self.new_indent,
} else {
// In this case, new_indent is only used in the case of multi-line strings.
new_indent: cindent,
space: ' ',
};
local lines = [
std.escapeStringJson(k) + ': ' + aux(v[k], true, path + [k], new_indent)
std.escapeStringJson(k) + ':' + param.space + aux(v[k], path + [k], param.new_indent)
for k in std.objectFields(v)
for param in [params(v[k])]
];
(if in_object then '\n' + cindent else '') + std.join('\n' + cindent, lines);
aux(value, false, [], ''),
std.join('\n' + cindent, lines);
aux(value, [], ''),
manifestYamlStream(value)::
manifestYamlStream(value, indent_array_in_object=false)::
if std.type(value) != 'array' then
error 'manifestYamlStream only takes arrays, got ' + std.type(value)
else
'---\n' + std.join('\n---\n', [std.manifestYamlDoc(e) for e in value]) + '\n...\n',
'---\n' + std.join(
'\n---\n', [std.manifestYamlDoc(e, indent_array_in_object) for e in value]
) + '\n...\n',
manifestPython(o)::
@ -1119,8 +1162,22 @@ limitations under the License.
std.length(std.setInter([x], arr, keyF)) > 0,
setUnion(a, b, keyF=id)::
// NOTE: order matters, values in `a` win due to sort being stable
std.set(a + b, keyF),
// NOTE: order matters, values in `a` win
local aux(a, b, i, j, acc) =
if i >= std.length(a) then
acc + b[j:]
else if j >= std.length(b) then
acc + a[i:]
else
local ak = keyF(a[i]);
local bk = keyF(b[j]);
if ak == bk then
aux(a, b, i + 1, j + 1, acc + [a[i]]) tailstrict
else if ak < bk then
aux(a, b, i + 1, j, acc + [a[i]]) tailstrict
else
aux(a, b, i, j + 1, acc + [b[j]]) tailstrict;
aux(a, b, 0, 0, []),
setInter(a, b, keyF=id)::
local aux(a, b, i, j, acc) =
@ -1140,7 +1197,7 @@ limitations under the License.
if i >= std.length(a) then
acc
else if j >= std.length(b) then
aux(a, b, i + 1, j, acc + [a[i]]) tailstrict
acc + a[i:]
else
if keyF(a[i]) == keyF(b[j]) then
aux(a, b, i + 1, j + 1, acc) tailstrict
@ -1259,7 +1316,7 @@ limitations under the License.
if pat_len == 0 || str_len == 0 || pat_len > str_len then
[]
else
std.filter(function(i) str[i:i+pat_len] == pat, std.range(0, str_len - pat_len)),
std.filter(function(i) str[i:i + pat_len] == pat, std.range(0, str_len - pat_len)),
find(value, arr)::
if std.type(arr) != 'array' then

2
vm.go
View File

@ -191,5 +191,5 @@ func SnippetToAST(filename string, snippet string) (ast.Node, error) {
// Version returns the Jsonnet version number.
func Version() string {
return "v0.12.0"
return "v0.12.1"
}