aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorc2024-02-24 10:23:00 -0500
committerc2024-02-24 10:23:00 -0500
commite29c41a84b299c95a49dfa429f4161eb71cf6837 (patch)
tree4e38ce92a2a026c6b8bae8d1d28dfc1b739380ef
parent78621011a21847a3b769869d434b2ada50fdad51 (diff)
Definitions now work, with any number of arguments.
-rw-r--r--src/parser.c9
-rw-r--r--test/parser.c51
2 files changed, 27 insertions, 33 deletions
diff --git a/src/parser.c b/src/parser.c
index b42d2f0..3dc26a1 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -94,14 +94,15 @@ tree_t* parser_parse_def(parser_t* parser) {
def->data.def.tag = parser_parse_tag(parser);
if (parser->token->type == TOKEN_TYPE_APPLY) {
- parser_nxt_token(parser);
+ parser_nxt_token(parser); /* Skip over apply. */
def->data.def.arg = parser_parse_darg(parser);
} else {
def->data.def.arg = NULL;
}
+ LOG_DBGF("%s <<<<<<<<<<<<,, HERE HER HERE", parser->token->val);
if (parser->token->type == TOKEN_TYPE_SET) {
- parser_nxt_token(parser);
+ parser_nxt_token(parser); /* Skip over set. */
def->data.def.val = parser_parse_expr(parser);
} else {
def->data.def.val = NULL;
@@ -133,10 +134,8 @@ tree_t* parser_parse_darg(parser_t* parser) {
darg->data.darg.tag = parser_parse_tag(parser);
- parser_nxt_token(parser);
-
if (parser->token->type == TOKEN_TYPE_LIST_DELIM) {
- parser_nxt_token(parser);
+ parser_nxt_token(parser); /* Skip over list delim. */
darg->data.darg.nxt = parser_parse_darg(parser);
} else {
darg->data.darg.nxt = NULL;
diff --git a/test/parser.c b/test/parser.c
index 30fee73..e1587fb 100644
--- a/test/parser.c
+++ b/test/parser.c
@@ -878,8 +878,6 @@ void call_many_arg() {
ASSERT(tree_cmp(parser->tree, tree) == 1);
- tree_print(tree, 0);
-
token_destroy(lexer->tokenl);
lexer_destroy(lexer);
free(pp->psrc);
@@ -957,16 +955,15 @@ void def_bare_lint() {
tree_destroy(tree);
}
-void def_add1() {
+void def_with_arg() {
tree_t* tree;
pp_t* pp;
lexer_t* lexer;
parser_t* parser;
- char src[] = ":i:add1.:i:n = +.n, 1";
+ char src[] = ":i:f.:i:x=x";
/*
-
[block]
val:
[def]
@@ -977,7 +974,7 @@ void def_add1() {
nxt:
[tag]
val:
- add1
+ f
nxt:
NULL
arg:
@@ -989,7 +986,7 @@ void def_add1() {
nxt:
[tag]
val:
- n
+ x
nxt:
NULL
nxt:
@@ -997,26 +994,11 @@ void def_add1() {
val:
[call]
target:
- +
+ x
arg:
- [carg]
- val:
- [call]
- target:
- n
- arg:
- NULL
- nxt:
- [carg]
- val:
- [lint]
- val:
- 1
- nxt:
- NULL
+ NULL
nxt:
NULL
-
*/
/* TODO: Write this test. */
@@ -1027,11 +1009,20 @@ void def_add1() {
strcpy(val0, "i");
tree_t* tree1tag = tree0tag->data.tag.nxt = tree_init(TREE_TYPE_TAG);
char* val1 = tree1tag->data.tag.val = ecalloc(2, sizeof(char));
- strcpy(val1, "n");
+ strcpy(val1, "f");
tree1tag->data.tag.nxt = NULL;
- tree0def->data.def.arg = NULL;
- tree_t* tree0lint = tree0def->data.def.val = tree_init(TREE_TYPE_LINT);
- tree0lint->data.lint.val = 3;
+ tree_t* tree0arg = tree0def->data.def.arg = tree_init(TREE_TYPE_DARG);
+ tree_t* tree2tag = tree0arg->data.darg.tag = tree_init(TREE_TYPE_TAG);
+ char* val2 = tree2tag->data.tag.val = ecalloc(2, sizeof(char));
+ strcpy(val2, "i");
+ tree_t* tree3tag = tree2tag->data.tag.nxt = tree_init(TREE_TYPE_TAG);
+ char* val3 = tree3tag->data.tag.val = ecalloc(2, sizeof(char));
+ strcpy(val3, "x");
+ tree3tag->data.tag.nxt = NULL;
+ tree_t* tree0call = tree0def->data.def.val = tree_init(TREE_TYPE_CALL);
+ char* target0 = tree0call->data.call.target = ecalloc(2, sizeof(char));
+ strcpy(target0, "x");
+ tree0call->data.call.arg = NULL;
tree->data.block.nxt = NULL;
pp = pp_init(src);
@@ -1045,6 +1036,9 @@ void def_add1() {
ASSERT(tree_cmp(parser->tree, tree) == 1);
+ tree_print(tree, 0);
+ tree_print(parser->tree, 0);
+
token_destroy(lexer->tokenl);
lexer_destroy(lexer);
free(pp->psrc);
@@ -1071,6 +1065,7 @@ int main() {
cargumented_call_of_lint();
call_many_arg();
def_bare_lint();
+ def_with_arg();
TEST_REPORT;