Update stdlib and ||| fix

This commit is contained in:
Dave Cunningham 2018-01-22 22:47:14 -05:00
parent eedf6760ad
commit 741f9f06a2
14 changed files with 24950 additions and 15199 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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
l.acceptN(3) // Skip "||\n"
l.acceptN(2) // Skip "||"
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() {
cb.WriteRune(r)
}

View File

@ -24,6 +24,13 @@ limitations under the License.
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)::
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, 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)::
std.makeArray(to - from + 1, function(i) i + from),
@ -163,6 +196,8 @@ limitations under the License.
running
else if arr[i] == null then
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
aux(arr, i + 1, false, running + arr[i]) tailstrict
else

View File

@ -1,6 +1,6 @@
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,

View File

@ -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,

View File

@ -1,6 +1,6 @@
RUNTIME ERROR: Assertion failed.  !=
-------------------------------------------------
<std>:649:13-56 function <anonymous>
<std>:684:13-56 function <anonymous>
error "Assertion failed. " + a + " != " + b,

View File

@ -5,7 +5,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
{ 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);
@ -13,7 +13,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
<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
@ -21,7 +21,7 @@ RUNTIME ERROR: Attempt to use super when there is no super class.
<builtin> builtin function <primitiveEquals>
-------------------------------------------------
<std>:981:12-40 function <anonymous>
<std>:1016:12-40 function <anonymous>
if !std.primitiveEquals(ta, tb) then

View File

@ -1,6 +1,6 @@
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) + ".",

View File

@ -1,21 +1,21 @@
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)
-------------------------------------------------
<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
-------------------------------------------------
<std>:616:13-54 function <anonymous>
<std>:651:13-54 function <anonymous>
format_codes_arr(codes, [vals], 0, 0, ""),
-------------------------------------------------
<std>:148:13-29 function <anonymous>
<std>:181:13-29 function <anonymous>
std.format(a, b)

View File

@ -1,6 +1,6 @@
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) + ".",

View File

@ -1,21 +1,21 @@
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)
-------------------------------------------------
<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
-------------------------------------------------
<std>:612:13-52 function <anonymous>
<std>:647:13-52 function <anonymous>
format_codes_arr(codes, vals, 0, 0, "")
-------------------------------------------------
<std>:148:13-29 function <anonymous>
<std>:181:13-29 function <anonymous>
std.format(a, b)

View File

@ -1,16 +1,16 @@
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);
-------------------------------------------------
<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);
-------------------------------------------------
<std>:454:30-33 thunk from <function <format_code>>
<std>:489:30-33 thunk from <function <format_code>>
std.toString(val)
@ -20,17 +20,17 @@ RUNTIME ERROR: Not enough values to format, got 1
-------------------------------------------------
... (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;
-------------------------------------------------
<std>:612:13-52 function <anonymous>
<std>:647:13-52 function <anonymous>
format_codes_arr(codes, vals, 0, 0, "")
-------------------------------------------------
<std>:148:13-29 function <anonymous>
<std>:181:13-29 function <anonymous>
std.format(a, b)

View File

@ -1,16 +1,16 @@
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);
-------------------------------------------------
<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);
-------------------------------------------------
<std>:454:30-33 thunk from <function <format_code>>
<std>:489:30-33 thunk from <function <format_code>>
std.toString(val)
@ -20,17 +20,17 @@ RUNTIME ERROR: Not enough values to format, got 1
-------------------------------------------------
... (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;
-------------------------------------------------
<std>:616:13-54 function <anonymous>
<std>:651:13-54 function <anonymous>
format_codes_arr(codes, [vals], 0, 0, ""),
-------------------------------------------------
<std>:148:13-29 function <anonymous>
<std>:181:13-29 function <anonymous>
std.format(a, b)

View File

@ -1,39 +1,39 @@
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 "
+ 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);
-------------------------------------------------
<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, " ");
-------------------------------------------------
<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;
-------------------------------------------------
... (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;
-------------------------------------------------
<std>:612:13-52 function <anonymous>
<std>:647:13-52 function <anonymous>
format_codes_arr(codes, vals, 0, 0, "")
-------------------------------------------------
<std>:148:13-29 function <anonymous>
<std>:181:13-29 function <anonymous>
std.format(a, b)