Author:ptrace
Comitter:ptrace
Date:2026-08-16 07:22:05 UTC
diff --git a/0x2_Lexer.jai b/0x2_Lexer.jai
index d035496..559d118 100644
--- a/0x2_Lexer.jai
+++ b/0x2_Lexer.jai
@@ -67,12 +67,18 @@ match_grammar :: (
return a, b;
}
consume_including :: (token: $T/Type.[ string, u8 ]) -> string #expand {
return consume_including(`index, `source, token);
/** Allocates memory. You have to manage that.
If you do not want an allocation, pass `allocate = false`.
*/
consume_including :: (token: $T/Type.[ string, u8 ], $allocate := true) -> string #expand {
return consume_including(`index, `source, token, allocate=allocate);
}
consume_till :: (token: $T/Type.[ string, u8 ]) -> string #expand {
return consume_till(`index, `source, token);
/** Allocates memory. You have to manage that.
If you do not want an allocation, pass `allocate = false`.
*/
consume_till :: (token: $T/Type.[ string, u8 ], $allocate := true) -> string #expand {
return consume_till(`index, `source, token, allocate=allocate);
}
@@ -207,72 +213,53 @@ match_grammar :: (
return true, advanced;
}
/** Allocates memory. You have to manage that.
If you do not want an allocation, pass `allocate = false`.
*/
consume_including :: inline (
match_index: int,
data: string,
char: u8
)
-> string
{
return consume_till(match_index, data, char, true);
}
consume_including :: inline (
match_index: int,
data: string,
substring: string
char_or_string: $T/Type.[ string, u8 ],
$allocate := true
)
-> string
{
return consume_till(match_index, data, substring, true);
return consume_till(match_index, data, char_or_string, true, allocate);
}
/** Allocates memory. You have to manage that.
If you do not want an allocation, pass `allocate = false`.
*/
consume_till :: (
pos: int,
data: string,
char: u8,
char_or_string: $T/Type.[ string, u8 ],
include := false,
$allocate := true
)
-> string
{
keyword_count := 1;
idx := pos;
offset := ifx include then keyword_count else 0;
while idx < data.count {
window := data[idx];
if window == char {
consumed := slice(data, pos, idx - pos + offset);
return copy_string(consumed);
}
idx += 1;
#if T == u8 {
keyword_count := 1;
} else {
keyword_count := char_or_string.count;
}
return "";
}
consume_till :: (
pos: int,
data: string,
substring: string,
include := false
)
-> string
{
keyword_count := substring.count;
count := pos;
offset := ifx include then keyword_count else 0;
while count < data.count {
window := slice(data, count, keyword_count);
#if T == u8 {
window := data[idx];
} else {
window := slice(data, count, keyword_count);
}
if window == substring {
if window == char_or_string {
consumed := slice(data, pos, count - pos + offset);
return copy_string(consumed);
#if allocate then return copy_string(consumed);
else return consumed;
}
count += 1;
diff --git a/tests/seccomp.jai b/tests/seccomp.jai
index f74c0d9..cfbd11f 100644
--- a/tests/seccomp.jai
+++ b/tests/seccomp.jai
@@ -64,7 +64,7 @@ SECCOMP_ALLOWED_SYSCALLS :: string.[
sec_seccomp_init :: () {
SECCOMP_TEMPLATE :: "had_error |= seccomp_rule_add(ctx, .ALLOW, .%);";
SECCOMP_TEMPLATE :: "had_error |= seccomp_rule_add(ctx, .ALLOW, .%);\n";
#if SECCOMP_ARMED {
/** Tell seccomp what to do if a violation happened. */