aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
authorMel <mel@rnrd.eu>2026-05-28 01:06:31 +0200
committerMel <mel@rnrd.eu>2026-05-28 01:06:31 +0200
commit351433f3f7dc3f1051a9875402502663fe8a0be8 (patch)
tree95ddeb3cdc87746da195c558c20260bd92d7a865 /boot
parent7dda10e54ebf303509cb7dcf7a3c60ec2de399d2 (diff)
downloadcatskill-351433f3f7dc3f1051a9875402502663fe8a0be8.tar.zst
catskill-351433f3f7dc3f1051a9875402502663fe8a0be8.zip
Allow no arguments for calls and constructs
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot')
-rw-r--r--boot/catboot.c2
-rw-r--r--boot/parse.c17
-rw-r--r--boot/tests/parse/empty_argument_groups.cskt22
3 files changed, 37 insertions, 4 deletions
diff --git a/boot/catboot.c b/boot/catboot.c
index e340d48..b96a167 100644
--- a/boot/catboot.c
+++ b/boot/catboot.c
@@ -40,7 +40,7 @@ read_file(const ascii* path)
const unknown* file_data =
mmap(nil, stat_info.st_size, mmap_prot, mmap_flags, file_descriptor, 0);
- return string_from_static_c_string(file_data);
+ return string_new(file_data, stat_info.st_size);
}
void
diff --git a/boot/parse.c b/boot/parse.c
index 3ea4939..56d767a 100644
--- a/boot/parse.c
+++ b/boot/parse.c
@@ -153,6 +153,7 @@ parser_new(struct Parser* p, struct Lexer* lexer, struct Source_File source_file
memset(p->lookahead, 0, sizeof(p->lookahead));
p->source_file = source_file;
p->had_errors = false;
+ p->context = (struct Parser_Context){ 0 };
}
bool
@@ -467,10 +468,18 @@ parser_function_header_node(struct Parser* p, struct Parser_Error* error)
}
struct Tree_Argument_Group
-parser_argument_group_node(struct Parser* p, struct Parser_Error* error)
+parser_argument_group_node(struct Parser* p, enum Token_Kind close, struct Parser_Error* error)
{
Array(struct String) argument_names = array_new(struct String, 32);
struct Tree_Expression *arguments_head = nil, *arguments_current = nil;
+
+ if (parser_probe(p, close)) {
+ // empty argument list
+ return (struct Tree_Argument_Group){
+ .arguments = nil, .argument_names = argument_names
+ };
+ }
+
for (;;) {
// check if we have a named argument.
struct String name = string_empty();
@@ -1036,7 +1045,8 @@ parser_expression_postfix_call(
CHECK(parser_need(p, TOKEN_ROUND_OPEN, error));
parser_unglue(p);
- struct Tree_Argument_Group argument_group = parser_argument_group_node(p, error);
+ struct Tree_Argument_Group argument_group =
+ parser_argument_group_node(p, TOKEN_ROUND_CLOSE, error);
if (!parser_error_is_none(error)) {
parser_error_wrap(error, PARSER_ERROR_EXPECTED_ARGUMENTS);
return nil;
@@ -1057,7 +1067,8 @@ parser_expression_postfix_construct(
CHECK(parser_need(p, TOKEN_CURLY_OPEN, error));
parser_unglue(p);
- struct Tree_Argument_Group argument_group = parser_argument_group_node(p, error);
+ struct Tree_Argument_Group argument_group =
+ parser_argument_group_node(p, TOKEN_CURLY_CLOSE, error);
if (!parser_error_is_none(error)) {
parser_error_wrap(error, PARSER_ERROR_EXPECTED_ARGUMENTS);
return nil;
diff --git a/boot/tests/parse/empty_argument_groups.cskt b/boot/tests/parse/empty_argument_groups.cskt
new file mode 100644
index 0000000..d5ac18a
--- /dev/null
+++ b/boot/tests/parse/empty_argument_groups.cskt
@@ -0,0 +1,22 @@
+calls and constructs should accept empty argument lists,
+but also not fail on any other argument passing styles.
+
+<<<
+
+greet()
+make{}
+greet(1)
+greet(1, 2)
+greet(x = 5)
+make{x = 1, y = 2}
+greet(1, x = 5)
+
+>>>
+
+(expr (call (expr (name greet))))
+(expr (construct (expr (name make))))
+(expr (call (expr (name greet)) (arg (expr 1))))
+(expr (call (expr (name greet)) (arg (expr 1)) (arg (expr 2))))
+(expr (call (expr (name greet)) (named arg 'x' (expr 5))))
+(expr (construct (expr (name make)) (named arg 'x' (expr 1)) (named arg 'y' (expr 2))))
+(expr (call (expr (name greet)) (arg (expr 1)) (named arg 'x' (expr 5))))