Skip to content

Commit

Permalink
Update stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarzowski authored and sparkprime committed Dec 12, 2018
1 parent d7fa222 commit 7012604
Show file tree
Hide file tree
Showing 13 changed files with 63,425 additions and 68,844 deletions.
132,168 changes: 63,364 additions & 68,804 deletions ast/stdast.go

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions std/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ limitations under the License.
local lower_a_code = std.codepoint('a');
local addDigit(aggregate, char) =
local code = std.codepoint(char);
local digit = if code > lower_a_code then
local digit = if code >= lower_a_code then
code - lower_a_code + 10
else if code > upper_a_code then
else if code >= upper_a_code then
code - upper_a_code + 10
else
code - zero_code;
Expand All @@ -81,6 +81,8 @@ 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];
if str[0] == '-' then
-parse_nat(str[1:], 10)
else
Expand Down Expand Up @@ -147,9 +149,9 @@ limitations under the License.
acc + str[start_index:curr_index]
else if found_at(curr_index) then
local new_index = curr_index + std.length(from);
replace_after(new_index, new_index, acc + str[start_index:curr_index] + to)
replace_after(new_index, new_index, acc + str[start_index:curr_index] + to) tailstrict
else
replace_after(start_index, curr_index + 1, acc);
replace_after(start_index, curr_index + 1, acc) tailstrict;

// if from_len==1, then we replace by splitting and rejoining the
// string which is much faster than recursing on replace_after
Expand Down Expand Up @@ -853,7 +855,7 @@ limitations under the License.
'\\t'
else
local cp = std.codepoint(ch);
if cp < 32 || (cp >= 126 && cp <= 159) then
if cp < 32 || (cp >= 127 && cp <= 159) then
'\\u%04x' % [cp]
else
ch;
Expand Down Expand Up @@ -1245,4 +1247,23 @@ limitations under the License.
if isContent(std.prune(a[x]))
} else
a,

findSubstr(pat, str)::
if std.type(pat) != 'string' then
error 'findSubstr first parameter should be a string, got ' + std.type(pat)
else if std.type(str) != 'string' then
error 'findSubstr second parameter should be a string, got ' + std.type(str)
else
local pat_len = std.length(pat);
local str_len = std.length(str);
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)),

find(value, arr)::
if std.type(arr) != 'array' then
error 'find second parameter should be an array, got ' + std.type(arr)
else
std.filter(function(i) arr[i] == value, std.range(0, std.length(arr) - 1)),
}
2 changes: 1 addition & 1 deletion testdata/assert_equal4.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: Assertion failed. {"x": 1} != {"x": 2}
-------------------------------------------------
<std>:780:7-50 function <anonymous>
<std>:782:7-50 function <anonymous>

error 'Assertion failed. ' + a + ' != ' + b,

Expand Down
2 changes: 1 addition & 1 deletion testdata/assert_equal5.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ RUNTIME ERROR: Assertion failed.
!=

-------------------------------------------------
<std>:780:7-50 function <anonymous>
<std>:782:7-50 function <anonymous>

error 'Assertion failed. ' + a + ' != ' + b,

Expand Down
2 changes: 1 addition & 1 deletion testdata/assert_equal6.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: Assertion failed.  !=
-------------------------------------------------
<std>:780:7-50 function <anonymous>
<std>:782:7-50 function <anonymous>

error 'Assertion failed. ' + a + ' != ' + b,

Expand Down
2 changes: 1 addition & 1 deletion testdata/percent_bad.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: Operator % cannot be used on types number and string.
-------------------------------------------------
<std>:227:7-94 function <anonymous>
<std>:229:7-94 function <anonymous>

error 'Operator % cannot be used on types ' + std.type(a) + ' and ' + std.type(b) + '.',

Expand Down
8 changes: 4 additions & 4 deletions testdata/percent_bad2.golden
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
RUNTIME ERROR: Too many values to format: 1, expected 0
-------------------------------------------------
<std>:650:11-86 function <format_codes_arr>
<std>:652:11-86 function <format_codes_arr>

error ('Too many values to format: ' + std.length(arr) + ', expected ' + j)

-------------------------------------------------
<std>:656:11-59 function <format_codes_arr>
<std>:658:11-59 function <format_codes_arr>

format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict

-------------------------------------------------
<std>:747:7-48 function <anonymous>
<std>:749:7-48 function <anonymous>

format_codes_arr(codes, [vals], 0, 0, ''),

-------------------------------------------------
<std>:225:7-23 function <anonymous>
<std>:227:7-23 function <anonymous>

std.format(a, b)

Expand Down
2 changes: 1 addition & 1 deletion testdata/percent_bad3.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: Operator % cannot be used on types function and number.
-------------------------------------------------
<std>:227:7-94 function <anonymous>
<std>:229:7-94 function <anonymous>

error 'Operator % cannot be used on types ' + std.type(a) + ' and ' + std.type(b) + '.',

Expand Down
8 changes: 4 additions & 4 deletions testdata/percent_format_str4.golden
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
RUNTIME ERROR: Too many values to format: 2, expected 1
-------------------------------------------------
<std>:650:11-86 function <format_codes_arr>
<std>:652:11-86 function <format_codes_arr>

error ('Too many values to format: ' + std.length(arr) + ', expected ' + j)

-------------------------------------------------
<std>:656:11-59 function <format_codes_arr>
<std>:658:11-59 function <format_codes_arr>

format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict

-------------------------------------------------
<std>:743:7-46 function <anonymous>
<std>:745:7-46 function <anonymous>

format_codes_arr(codes, vals, 0, 0, '')

-------------------------------------------------
<std>:225:7-23 function <anonymous>
<std>:227:7-23 function <anonymous>

std.format(a, b)

Expand Down
14 changes: 7 additions & 7 deletions testdata/percent_format_str5.golden
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
RUNTIME ERROR: Not enough values to format, got 1
-------------------------------------------------
<std>:683:15-74 thunk <val> from <function <format_codes_arr>>
<std>:685:15-74 thunk <val> from <function <format_codes_arr>>

error 'Not enough values to format, got ' + std.length(arr);

-------------------------------------------------
<std>:688:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>
<std>:690:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>

format_code(val, code, tmp.fw, tmp2.prec, j2);

-------------------------------------------------
<std>:558:22-25 thunk from <function <format_code>>
<std>:560:22-25 thunk from <function <format_code>>

std.toString(val)

-------------------------------------------------
<std>:558:9-26 function <format_code>
<std>:560:9-26 function <format_code>

std.toString(val)

-------------------------------------------------
... (skipped 10 frames)
-------------------------------------------------
<std>:699:11-64 function <format_codes_arr>
<std>:701:11-64 function <format_codes_arr>

format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;

-------------------------------------------------
<std>:743:7-46 function <anonymous>
<std>:745:7-46 function <anonymous>

format_codes_arr(codes, vals, 0, 0, '')

-------------------------------------------------
<std>:225:7-23 function <anonymous>
<std>:227:7-23 function <anonymous>

std.format(a, b)

Expand Down
14 changes: 7 additions & 7 deletions testdata/percent_format_str6.golden
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
RUNTIME ERROR: Not enough values to format, got 1
-------------------------------------------------
<std>:683:15-74 thunk <val> from <function <format_codes_arr>>
<std>:685:15-74 thunk <val> from <function <format_codes_arr>>

error 'Not enough values to format, got ' + std.length(arr);

-------------------------------------------------
<std>:688:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>
<std>:690:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>

format_code(val, code, tmp.fw, tmp2.prec, j2);

-------------------------------------------------
<std>:558:22-25 thunk from <function <format_code>>
<std>:560:22-25 thunk from <function <format_code>>

std.toString(val)

-------------------------------------------------
<std>:558:9-26 function <format_code>
<std>:560:9-26 function <format_code>

std.toString(val)

-------------------------------------------------
... (skipped 10 frames)
-------------------------------------------------
<std>:699:11-64 function <format_codes_arr>
<std>:701:11-64 function <format_codes_arr>

format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;

-------------------------------------------------
<std>:747:7-48 function <anonymous>
<std>:749:7-48 function <anonymous>

format_codes_arr(codes, [vals], 0, 0, ''),

-------------------------------------------------
<std>:225:7-23 function <anonymous>
<std>:227:7-23 function <anonymous>

std.format(a, b)

Expand Down
14 changes: 7 additions & 7 deletions testdata/percent_format_str7.golden
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
RUNTIME ERROR: Format required number at 0, got string
-------------------------------------------------
<std>:(561:11)-(562:47) function <format_code>
<std>:(563:11)-(564:47) function <format_code>

error 'Format required number at '
+ i + ', got ' + std.type(val)

-------------------------------------------------
<std>:688:15-60 thunk <s> from <function <format_codes_arr>>
<std>:690:15-60 thunk <s> from <function <format_codes_arr>>

format_code(val, code, tmp.fw, tmp2.prec, j2);

-------------------------------------------------
<std>:693:24-25 thunk from <thunk <s_padded> from <function <format_codes_arr>>>
<std>:695:24-25 thunk from <thunk <s_padded> from <function <format_codes_arr>>>

pad_left(s, tmp.fw, ' ');

-------------------------------------------------
<std>:473:30-33 thunk from <thunk from <function <pad_left>>>
<std>:475:30-33 thunk from <thunk from <function <pad_left>>>

padding(w - std.length(str), s) + str;

-------------------------------------------------
... (skipped 7 frames)
-------------------------------------------------
<std>:699:11-64 function <format_codes_arr>
<std>:701:11-64 function <format_codes_arr>

format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;

-------------------------------------------------
<std>:743:7-46 function <anonymous>
<std>:745:7-46 function <anonymous>

format_codes_arr(codes, vals, 0, 0, '')

-------------------------------------------------
<std>:225:7-23 function <anonymous>
<std>:227:7-23 function <anonymous>

std.format(a, b)

Expand Down
2 changes: 1 addition & 1 deletion testdata/percent_mod_int5.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: Division by zero.
-------------------------------------------------
<std>:223:7-23 builtin function <modulo>
<std>:225:7-23 builtin function <modulo>

std.modulo(a, b)

Expand Down

0 comments on commit 7012604

Please sign in to comment.