mirror of
https://github.com/google/go-jsonnet.git
synced 2025-09-29 17:31:02 +02:00
Update stdlib and ||| fix
This commit is contained in:
parent
eedf6760ad
commit
741f9f06a2
40028
ast/stdast.go
40028
ast/stdast.go
File diff suppressed because it is too large
Load Diff
@ -577,12 +577,22 @@ func (l *lexer) lexSymbol() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r == '|' && strings.HasPrefix(l.input[l.pos.byteNo:], "||\n") {
|
if r == '|' && strings.HasPrefix(l.input[l.pos.byteNo:], "||") {
|
||||||
commentStartLoc := l.tokenStartLoc
|
commentStartLoc := l.tokenStartLoc
|
||||||
l.acceptN(3) // Skip "||\n"
|
l.acceptN(2) // Skip "||"
|
||||||
var cb bytes.Buffer
|
var cb bytes.Buffer
|
||||||
|
|
||||||
// Skip leading blank lines
|
// Skip whitespace
|
||||||
|
for r = l.next(); r == ' ' || r == '\t' || r == '\r'; r = l.next() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip \n
|
||||||
|
if r != '\n' {
|
||||||
|
return l.makeStaticErrorPoint("Text block requires new line after |||.",
|
||||||
|
commentStartLoc)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process leading blank lines before calculating stringBlockIndent
|
||||||
for r = l.next(); r == '\n'; r = l.next() {
|
for r = l.next(); r == '\n'; r = l.next() {
|
||||||
cb.WriteRune(r)
|
cb.WriteRune(r)
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,13 @@ limitations under the License.
|
|||||||
|
|
||||||
local std = self,
|
local std = self,
|
||||||
|
|
||||||
|
isString(v):: std.type(v) == "string",
|
||||||
|
isNumber(v):: std.type(v) == "number",
|
||||||
|
isBoolean(v):: std.type(v) == "boolean",
|
||||||
|
isObject(v):: std.type(v) == "object",
|
||||||
|
isArray(v):: std.type(v) == "array",
|
||||||
|
isFunction(v):: std.type(v) == "function",
|
||||||
|
|
||||||
toString(a)::
|
toString(a)::
|
||||||
if std.type(a) == "string" then a else "" + a,
|
if std.type(a) == "string" then a else "" + a,
|
||||||
|
|
||||||
@ -98,6 +105,32 @@ limitations under the License.
|
|||||||
aux(str, delim, i2, arr, v + c) tailstrict;
|
aux(str, delim, i2, arr, v + c) tailstrict;
|
||||||
aux(str, c, 0, [], ""),
|
aux(str, c, 0, [], ""),
|
||||||
|
|
||||||
|
strReplace(str, from, to)::
|
||||||
|
assert std.type(str) == "string";
|
||||||
|
assert std.type(from) == "string";
|
||||||
|
assert std.type(to) == "string";
|
||||||
|
assert from != "" : "'from' string must not be zero length.";
|
||||||
|
|
||||||
|
// Cache for performance.
|
||||||
|
local str_len = std.length(str);
|
||||||
|
local from_len = std.length(from);
|
||||||
|
|
||||||
|
// True if from is at str[i].
|
||||||
|
local found_at(i) = str[i:i + from_len] == from;
|
||||||
|
|
||||||
|
// Return the remainder of 'str' starting with 'start_index' where
|
||||||
|
// all occurrences of 'from' after 'curr_index' are replaced with 'to'.
|
||||||
|
local replace_after(start_index, curr_index, acc) =
|
||||||
|
if curr_index > str_len then
|
||||||
|
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)
|
||||||
|
else
|
||||||
|
replace_after(start_index, curr_index + 1, acc);
|
||||||
|
|
||||||
|
replace_after(0, 0, ""),
|
||||||
|
|
||||||
range(from, to)::
|
range(from, to)::
|
||||||
std.makeArray(to - from + 1, function(i) i + from),
|
std.makeArray(to - from + 1, function(i) i + from),
|
||||||
|
|
||||||
@ -163,6 +196,8 @@ limitations under the License.
|
|||||||
running
|
running
|
||||||
else if arr[i] == null then
|
else if arr[i] == null then
|
||||||
aux(arr, i + 1, first, running) tailstrict
|
aux(arr, i + 1, first, running) tailstrict
|
||||||
|
else if std.type(arr[i]) != std.type(sep) then
|
||||||
|
error "expected %s but arr[%d] was %s " % [std.type(sep), i, std.type(arr[i])]
|
||||||
else if first then
|
else if first then
|
||||||
aux(arr, i + 1, false, running + arr[i]) tailstrict
|
aux(arr, i + 1, false, running + arr[i]) tailstrict
|
||||||
else
|
else
|
||||||
|
2
testdata/assert_equal4.golden
vendored
2
testdata/assert_equal4.golden
vendored
@ -1,6 +1,6 @@
|
|||||||
RUNTIME ERROR: Assertion failed. {"x": 1} != {"x": 2}
|
RUNTIME ERROR: Assertion failed. {"x": 1} != {"x": 2}
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:649:13-56 function <anonymous>
|
<std>:684:13-56 function <anonymous>
|
||||||
|
|
||||||
error "Assertion failed. " + a + " != " + b,
|
error "Assertion failed. " + a + " != " + b,
|
||||||
|
|
||||||
|
2
testdata/assert_equal5.golden
vendored
2
testdata/assert_equal5.golden
vendored
@ -2,7 +2,7 @@ RUNTIME ERROR: Assertion failed.
|
|||||||
!=
|
!=
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:649:13-56 function <anonymous>
|
<std>:684:13-56 function <anonymous>
|
||||||
|
|
||||||
error "Assertion failed. " + a + " != " + b,
|
error "Assertion failed. " + a + " != " + b,
|
||||||
|
|
||||||
|
2
testdata/assert_equal6.golden
vendored
2
testdata/assert_equal6.golden
vendored
@ -1,6 +1,6 @@
|
|||||||
RUNTIME ERROR: Assertion failed. [31m !=
|
RUNTIME ERROR: Assertion failed. [31m !=
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:649:13-56 function <anonymous>
|
<std>:684:13-56 function <anonymous>
|
||||||
|
|
||||||
error "Assertion failed. " + a + " != " + b,
|
error "Assertion failed. " + a + " != " + b,
|
||||||
|
|
||||||
|
6
testdata/object_invariant7.golden
vendored
6
testdata/object_invariant7.golden
vendored
@ -5,7 +5,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
|
|||||||
{ x: 5, assert super.x == 5 }
|
{ x: 5, assert super.x == 5 }
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:979:29-30 thunk from <thunk <ta> from <function <anonymous>>>
|
<std>:1014:29-30 thunk from <thunk <ta> from <function <anonymous>>>
|
||||||
|
|
||||||
local ta = std.type(a);
|
local ta = std.type(a);
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
|
|||||||
<builtin> builtin function <type>
|
<builtin> builtin function <type>
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:981:33-35 thunk from <function <anonymous>>
|
<std>:1016:33-35 thunk from <function <anonymous>>
|
||||||
|
|
||||||
if !std.primitiveEquals(ta, tb) then
|
if !std.primitiveEquals(ta, tb) then
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
|
|||||||
<builtin> builtin function <primitiveEquals>
|
<builtin> builtin function <primitiveEquals>
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:981:12-40 function <anonymous>
|
<std>:1016:12-40 function <anonymous>
|
||||||
|
|
||||||
if !std.primitiveEquals(ta, tb) then
|
if !std.primitiveEquals(ta, tb) then
|
||||||
|
|
||||||
|
2
testdata/percent_bad.golden
vendored
2
testdata/percent_bad.golden
vendored
@ -1,6 +1,6 @@
|
|||||||
RUNTIME ERROR: Operator % cannot be used on types number and string.
|
RUNTIME ERROR: Operator % cannot be used on types number and string.
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:150:13-100 function <anonymous>
|
<std>:183:13-100 function <anonymous>
|
||||||
|
|
||||||
error "Operator % cannot be used on types " + std.type(a) + " and " + std.type(b) + ".",
|
error "Operator % cannot be used on types " + std.type(a) + " and " + std.type(b) + ".",
|
||||||
|
|
||||||
|
8
testdata/percent_bad2.golden
vendored
8
testdata/percent_bad2.golden
vendored
@ -1,21 +1,21 @@
|
|||||||
RUNTIME ERROR: Too many values to format: 1, expected 0
|
RUNTIME ERROR: Too many values to format: 1, expected 0
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:519:21-95 function <format_codes_arr>
|
<std>:554:21-95 function <format_codes_arr>
|
||||||
|
|
||||||
error ("Too many values to format: " + std.length(arr) + ", expected " + j)
|
error ("Too many values to format: " + std.length(arr) + ", expected " + j)
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:525:21-69 function <format_codes_arr>
|
<std>:560:21-69 function <format_codes_arr>
|
||||||
|
|
||||||
format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict
|
format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:616:13-54 function <anonymous>
|
<std>:651:13-54 function <anonymous>
|
||||||
|
|
||||||
format_codes_arr(codes, [vals], 0, 0, ""),
|
format_codes_arr(codes, [vals], 0, 0, ""),
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:148:13-29 function <anonymous>
|
<std>:181:13-29 function <anonymous>
|
||||||
|
|
||||||
std.format(a, b)
|
std.format(a, b)
|
||||||
|
|
||||||
|
2
testdata/percent_bad3.golden
vendored
2
testdata/percent_bad3.golden
vendored
@ -1,6 +1,6 @@
|
|||||||
RUNTIME ERROR: Operator % cannot be used on types function and number.
|
RUNTIME ERROR: Operator % cannot be used on types function and number.
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:150:13-100 function <anonymous>
|
<std>:183:13-100 function <anonymous>
|
||||||
|
|
||||||
error "Operator % cannot be used on types " + std.type(a) + " and " + std.type(b) + ".",
|
error "Operator % cannot be used on types " + std.type(a) + " and " + std.type(b) + ".",
|
||||||
|
|
||||||
|
8
testdata/percent_format_str4.golden
vendored
8
testdata/percent_format_str4.golden
vendored
@ -1,21 +1,21 @@
|
|||||||
RUNTIME ERROR: Too many values to format: 2, expected 1
|
RUNTIME ERROR: Too many values to format: 2, expected 1
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:519:21-95 function <format_codes_arr>
|
<std>:554:21-95 function <format_codes_arr>
|
||||||
|
|
||||||
error ("Too many values to format: " + std.length(arr) + ", expected " + j)
|
error ("Too many values to format: " + std.length(arr) + ", expected " + j)
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:525:21-69 function <format_codes_arr>
|
<std>:560:21-69 function <format_codes_arr>
|
||||||
|
|
||||||
format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict
|
format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:612:13-52 function <anonymous>
|
<std>:647:13-52 function <anonymous>
|
||||||
|
|
||||||
format_codes_arr(codes, vals, 0, 0, "")
|
format_codes_arr(codes, vals, 0, 0, "")
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:148:13-29 function <anonymous>
|
<std>:181:13-29 function <anonymous>
|
||||||
|
|
||||||
std.format(a, b)
|
std.format(a, b)
|
||||||
|
|
||||||
|
12
testdata/percent_format_str5.golden
vendored
12
testdata/percent_format_str5.golden
vendored
@ -1,16 +1,16 @@
|
|||||||
RUNTIME ERROR: Not enough values to format, got 1
|
RUNTIME ERROR: Not enough values to format, got 1
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:552:29-88 thunk <val> from <function <format_codes_arr>>
|
<std>:587:29-88 thunk <val> from <function <format_codes_arr>>
|
||||||
|
|
||||||
error "Not enough values to format, got " + std.length(arr);
|
error "Not enough values to format, got " + std.length(arr);
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:557:41-44 thunk from <thunk <s> from <function <format_codes_arr>>>
|
<std>:592:41-44 thunk from <thunk <s> from <function <format_codes_arr>>>
|
||||||
|
|
||||||
format_code(val, code, tmp.fw, tmp2.prec, j2);
|
format_code(val, code, tmp.fw, tmp2.prec, j2);
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:454:30-33 thunk from <function <format_code>>
|
<std>:489:30-33 thunk from <function <format_code>>
|
||||||
|
|
||||||
std.toString(val)
|
std.toString(val)
|
||||||
|
|
||||||
@ -20,17 +20,17 @@ RUNTIME ERROR: Not enough values to format, got 1
|
|||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
... (skipped 14 frames)
|
... (skipped 14 frames)
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:568:21-74 function <format_codes_arr>
|
<std>:603:21-74 function <format_codes_arr>
|
||||||
|
|
||||||
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
|
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:612:13-52 function <anonymous>
|
<std>:647:13-52 function <anonymous>
|
||||||
|
|
||||||
format_codes_arr(codes, vals, 0, 0, "")
|
format_codes_arr(codes, vals, 0, 0, "")
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:148:13-29 function <anonymous>
|
<std>:181:13-29 function <anonymous>
|
||||||
|
|
||||||
std.format(a, b)
|
std.format(a, b)
|
||||||
|
|
||||||
|
12
testdata/percent_format_str6.golden
vendored
12
testdata/percent_format_str6.golden
vendored
@ -1,16 +1,16 @@
|
|||||||
RUNTIME ERROR: Not enough values to format, got 1
|
RUNTIME ERROR: Not enough values to format, got 1
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:552:29-88 thunk <val> from <function <format_codes_arr>>
|
<std>:587:29-88 thunk <val> from <function <format_codes_arr>>
|
||||||
|
|
||||||
error "Not enough values to format, got " + std.length(arr);
|
error "Not enough values to format, got " + std.length(arr);
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:557:41-44 thunk from <thunk <s> from <function <format_codes_arr>>>
|
<std>:592:41-44 thunk from <thunk <s> from <function <format_codes_arr>>>
|
||||||
|
|
||||||
format_code(val, code, tmp.fw, tmp2.prec, j2);
|
format_code(val, code, tmp.fw, tmp2.prec, j2);
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:454:30-33 thunk from <function <format_code>>
|
<std>:489:30-33 thunk from <function <format_code>>
|
||||||
|
|
||||||
std.toString(val)
|
std.toString(val)
|
||||||
|
|
||||||
@ -20,17 +20,17 @@ RUNTIME ERROR: Not enough values to format, got 1
|
|||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
... (skipped 14 frames)
|
... (skipped 14 frames)
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:568:21-74 function <format_codes_arr>
|
<std>:603:21-74 function <format_codes_arr>
|
||||||
|
|
||||||
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
|
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:616:13-54 function <anonymous>
|
<std>:651:13-54 function <anonymous>
|
||||||
|
|
||||||
format_codes_arr(codes, [vals], 0, 0, ""),
|
format_codes_arr(codes, [vals], 0, 0, ""),
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:148:13-29 function <anonymous>
|
<std>:181:13-29 function <anonymous>
|
||||||
|
|
||||||
std.format(a, b)
|
std.format(a, b)
|
||||||
|
|
||||||
|
14
testdata/percent_format_str7.golden
vendored
14
testdata/percent_format_str7.golden
vendored
@ -1,39 +1,39 @@
|
|||||||
RUNTIME ERROR: Format required number at 0, got string
|
RUNTIME ERROR: Format required number at 0, got string
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:(457:21)-(458:57) function <format_code>
|
<std>:(492:21)-(493:57) function <format_code>
|
||||||
|
|
||||||
error "Format required number at "
|
error "Format required number at "
|
||||||
+ i + ", got " + std.type(val)
|
+ i + ", got " + std.type(val)
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:557:29-74 thunk <s> from <function <format_codes_arr>>
|
<std>:592:29-74 thunk <s> from <function <format_codes_arr>>
|
||||||
|
|
||||||
format_code(val, code, tmp.fw, tmp2.prec, j2);
|
format_code(val, code, tmp.fw, tmp2.prec, j2);
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:562:38-39 thunk from <thunk <s_padded> from <function <format_codes_arr>>>
|
<std>:597:38-39 thunk from <thunk <s_padded> from <function <format_codes_arr>>>
|
||||||
|
|
||||||
pad_left(s, tmp.fw, " ");
|
pad_left(s, tmp.fw, " ");
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:369:36-39 thunk from <thunk from <function <pad_left>>>
|
<std>:404:36-39 thunk from <thunk from <function <pad_left>>>
|
||||||
|
|
||||||
padding(w - std.length(str), s) + str;
|
padding(w - std.length(str), s) + str;
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
... (skipped 11 frames)
|
... (skipped 11 frames)
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:568:21-74 function <format_codes_arr>
|
<std>:603:21-74 function <format_codes_arr>
|
||||||
|
|
||||||
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
|
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:612:13-52 function <anonymous>
|
<std>:647:13-52 function <anonymous>
|
||||||
|
|
||||||
format_codes_arr(codes, vals, 0, 0, "")
|
format_codes_arr(codes, vals, 0, 0, "")
|
||||||
|
|
||||||
-------------------------------------------------
|
-------------------------------------------------
|
||||||
<std>:148:13-29 function <anonymous>
|
<std>:181:13-29 function <anonymous>
|
||||||
|
|
||||||
std.format(a, b)
|
std.format(a, b)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user