Skip to content
5,212 changes: 2,606 additions & 2,606 deletions BOOTSTRAP/cli.c

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions PLUGINS/FRONTEND/LSTS/lsts-smart-tokenize.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let lsts-tokenize-string(file-path: String, text: String): List<Token> = (

let push-newline = false;
let tokens = [] : List<String>;
while non-zero(text) {match text {
while non-zero(text) { match text {
"\s".. rest => text = rest;
"\t".. rest => text = rest;
"\n".. rest => (
Expand Down Expand Up @@ -101,7 +101,9 @@ let lsts-tokenize-string(file-path: String, text: String): List<Token> = (
# "in File \{rest.file-name-of-token}, "
# "Line \{rest.line-of-token}, "
# "Column \{rest.column-of-token}.");
rest => ( fail("Unrecognized Token in File \{file-path}: \{clone-rope(rest[0_sz])}"); );
rest => (
fail("Unrecognized Token in File \{file-path}: \{clone-rope(rest[0_sz])}");
);
}; };

let internal-tokens = [] : List<Token>;
Expand Down
1 change: 1 addition & 0 deletions lib/std/maybe.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let .get-or(m: Maybe<x>, default: x): x = (

# Don't add this to lib2, it is just a backwards compatibility feature
let .get-or(m: x, default: x): x = m;
let .get-or-panic(m: x): x = m;

let .get-or-panic(m: Maybe<x>): x = (
match m {
Expand Down
18 changes: 10 additions & 8 deletions lib2/core/common-macros.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,21 @@ deprecated macro (rl"match-pats-arm"(term,rl"macro::lhs-prefix-or-suffix"( rest,

deprecated macro (rl"match-pats-arm"(term,rl"macro::lhs-prefix-or-suffix"( rl"macro::lhs-bind"(rl":Variable:"(b), rl":Literal:"(l)), rest ))) ((
$"let"(uuid(v))(term);
$"if"(uuid(v).has-prefix(l)) (
$"let"(b)(uuid(v).remove-prefix(l));
(match-pats-arm(uuid(v)[b.length:],rest))
) (branchfalse())
$"let"(uuid(s))(uuid(v).remove-prefix(l));
$"let"(uuid(p))(uuid(v).get-prefix(l));
$"if"(uuid(p).is-some and uuid(s).is-some)
($"let"(b)(uuid(p).get-or-panic); match-pats-arm(uuid(s).get-or-panic,rest))
(branchfalse())
));


deprecated macro (rl"match-pats-arm"(term,rl"macro::lhs-prefix-or-suffix"( rest, rl"macro::lhs-bind"(rl":Variable:"(b), rl":Literal:"(l)) ))) ((
$"let"(uuid(v))(term);
$"if"(uuid(v).has-suffix(l)) (
$"let"(b)(uuid(v).remove-suffix(l));
(match-pats-arm(uuid(v)[:b.length],rest))
) (branchfalse())
$"let"(uuid(s))(uuid(v).remove-suffix(l));
$"let"(uuid(p))(uuid(v).get-suffix(l));
$"if"(uuid(p).is-some and uuid(s).is-some)
($"let"(b)(uuid(p).get-or-panic); match-pats-arm(uuid(s).get-or-panic,rest))
(branchfalse())
));

deprecated macro (rl"match-pats-arm"( term, rl":Tag:"(l)(lt)(x1) )) ((
Expand Down
7 changes: 6 additions & 1 deletion lib2/core/list.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ let hash(t: List<x>): U64 = (
);

let .into(l: List<x>, tt: Type<String>): String = (
"[..TODO..List.into(String)..]"
let s = "[";
for list li in l {
if s.length > 1 then s = s + ",";
s = s + li.into(type(String));
};
s + "]";
);

# new allocations = 0
Expand Down
21 changes: 11 additions & 10 deletions lib2/core/regex.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let .has-prefix(text: String, rgx: Regex): Bool = (
# TODO: fix this mess. The preprocessor is unpacking these erroneously
# macros 2.0 doesn't have this problem, but this code still needs to be updated after swapping
let a1 = &rgx as C<"regex_t">[];
let a2 = text.data.data as C<"char">[];
let a2 = (text.data.data + text.start-offset) as C<"char">[];
let a3 = 0 as C<"size_t">;
let a4 = 0 as C<"regmatch_t">[];
let a5 = 0 as C<"int">;
Expand Down Expand Up @@ -45,11 +45,10 @@ let $"=="(text: CString, rgx: Regex): Bool = (
(status as U64)==0 and matches[0].rm_so==0 and matches[0].rm_eo==text.length
);

# TODO remove (this method name is a misnomer), correct name is ".get-prefix"
let .remove-prefix(text: String, rgx: Regex): String = (
let .remove-prefix(text: String, rgx: Regex): String? = (
let matches = () : C<"regmatch_t">[1];
let a1 = &rgx as C<"regex_t">[];
let a2 = text.data.data as C<"char">[];
let a2 = (text.data.data + text.start-offset) as C<"char">[];
let a3 = 1 as C<"size_t">;
let a4 = matches as C<"regmatch_t">[];
let a5 = 0 as C<"int">;
Expand All @@ -60,14 +59,15 @@ let .remove-prefix(text: String, rgx: Regex): String = (
a4,
a5
);
if matches[0].rm_so != 0 then fail(".remove-prefix regex did not match the prefix");
text[0_i64 : matches[0].rm_eo as I64]
if matches[0].rm_so != 0 then (None : String?)
else if matches[0].rm_eo == 0 then (None : String?)
else Some(text[matches[0].rm_eo as I64 : ])
);

let .get-prefix(text: String, rgx: Regex): String = (
let .get-prefix(text: String, rgx: Regex): String? = (
let matches = () : C<"regmatch_t">[1];
let a1 = &rgx as C<"regex_t">[];
let a2 = text.data.data as C<"char">[];
let a2 = (text.data.data + text.start-offset) as C<"char">[];
let a3 = 1 as C<"size_t">;
let a4 = matches as C<"regmatch_t">[];
let a5 = 0 as C<"int">;
Expand All @@ -78,6 +78,7 @@ let .get-prefix(text: String, rgx: Regex): String = (
a4,
a5
);
if matches[0].rm_so != 0 then fail(".get-prefix regex did not match the prefix");
text[0_i64 : matches[0].rm_eo as I64]
if matches[0].rm_so != 0 then (None : String?)
else if matches[0].rm_eo == 0 then (None : String?)
else Some(text[0_i64 : matches[0].rm_eo as I64])
);
15 changes: 11 additions & 4 deletions lib2/core/string.lsts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ let .into(cs: CString, tt: Type<String>): String = (
# }
# ```
let .into(s: String, tt: Type<CString>): CString = (
s.data.retain;
s.data.data as CString
let s-length = s.length;
let od = mk-owned-data(type(U8), s-length+1);
let si = 0_sz;
while si < s-length {
od.push(s[si] as U8);
si = si + 1;
};
od.push(0);
od.data as CString
);

let $"[:]"(x: String, low: U64, hi: U64): String = x[low as I64 : hi as I64];
Expand Down Expand Up @@ -135,8 +142,8 @@ let $"+"(l: String, r: String): String = (
let r-length = r.length;
let cs-length = l-length + r-length;
let od = mk-owned-data(type(U8), cs-length);
memcpy(od.data as C<"void">[], l.data.data as C<"void">[], l-length as USize);
memcpy((od.data + l-length) as C<"void">[], r.data.data as C<"void">[], r-length as USize);
memcpy(od.data as C<"void">[], (l.data.data + l.start-offset) as C<"void">[], l-length as USize);
memcpy((od.data + l-length) as C<"void">[], (r.data.data + r.start-offset) as C<"void">[], r-length as USize);
String(0 as USize, cs-length, od)
);

Expand Down
32 changes: 32 additions & 0 deletions tests/promises/string/prefix.lsts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

import lib/std/minimal.lsts;

assert( "\sa".remove-prefix("\s") == Some("a") );
assert( "a".remove-prefix("\s") == (None : String?) );

assert( "\ta".remove-prefix("\t") == Some("a") );
assert( "a".remove-prefix("\t") == (None : String?) );

assert( "\na".remove-prefix("\n") == Some("a") );
assert( "a".remove-prefix("\n") == (None : String?) );

assert( "__a".remove-prefix("__") == Some("a") );
assert( "a".remove-prefix("__") == (None : String?) );

assert( "'a-".remove-prefix(r/^'[a-z]{1,3}/) == Some("-") );
assert( "-".remove-prefix(r/^'[a-z]{1,3}/) == (None : String?) );

assert( "'a-".remove-prefix(r/^'[a-z]{1,3}/) == Some("-") );
assert( "-".remove-prefix(r/^'[a-z]{1,3}/) == (None : String?) );

assert( "\"a\"a".remove-prefix(r/^[r]?[cl]?["]([^"\\]|([\\].))*["]/) == Some("a") );
assert( "a".remove-prefix(r/^[r]?[cl]?["]([^"\\]|([\\].))*["]/) == (None : String?) );

assert( "abc-d=".remove-prefix(r/^[a-zA-Z0-9_-]+/) == Some("=") );
assert( "=".remove-prefix(r/^[a-zA-Z0-9_-]+/) == (None : String?) );

assert( "import ".remove-prefix(r/^[a-zA-Z0-9_-]+/) == Some(" ") );
assert( " ".remove-prefix(r/^[a-zA-Z0-9_-]+/) == (None : String?) );

assert( " import "[1_u64:].remove-prefix(r/^[a-zA-Z0-9_-]+/) == Some(" ") );
assert( " "[1_u64:].remove-prefix(r/^[a-zA-Z0-9_-]+/) == (None : String?) );
Loading