diff options
author | Preston Pan <preston@nullring.xyz> | 2024-01-10 16:36:53 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2024-01-10 16:36:53 -0800 |
commit | 4ada155b930cb5fb96493dff3a5af8809da3b214 (patch) | |
tree | db723cecb55c51e08b4ae6f865046d892d720304 /src | |
parent | f4252fb4c1b12e4318f98e4a1936842e8b691ce0 (diff) |
add comments in both stem and also in my c code
Diffstat (limited to 'src')
-rw-r--r-- | src/builtins.c | 4 | ||||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/stem.c | 19 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/builtins.c b/src/builtins.c index 31981c3..eb4b521 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -327,7 +327,7 @@ void strquote(value_t *v) { retval->quote = init_array(10); char *s = malloc(strlen(v1->str_word->value) + 1); strcpy(s, v1->str_word->value); - parser_t *p = init_parser(s); + parser_t *p = parser_pp(s); value_t *cur; while (1) { cur = parser_get_next(p); @@ -405,7 +405,7 @@ void stemexit(value_t *v) { ht_free(WORD_TABLE, value_free); ht_free(FLIT, func_free); array_free(STACK); - free(INBUF); + free(PARSER->source); free(PARSER); array_free(EVAL_STACK); ht_free(OBJ_TABLE, func_free); @@ -49,7 +49,7 @@ int main(int argc, char **argv) { ssize_t bytes_read = getdelim(&INBUF, &len, '\0', FP); fclose(FP); - PARSER = init_parser(INBUF); + PARSER = parser_pp(INBUF); STACK = init_array(10); WORD_TABLE = init_ht(500); EVAL_STACK = init_array(10); @@ -65,7 +65,7 @@ int main(int argc, char **argv) { eval(v); } - free(INBUF); + free(PARSER->source); ht_free(WORD_TABLE, value_free); ht_free(FLIT, func_free); ht_free(OBJ_TABLE, custom_free); @@ -161,6 +161,25 @@ void parser_reset(parser_t *p, char *source) { p->c = source[0]; } +parser_t *parser_pp(char *s) { + parser_t *p = init_parser(s); + string_t *rstr = init_string(NULL); + while (p->c != '\0') { + if (p->c == '#') { + while (p->c != '\n' && p->c != '\0') { + parser_move(p); + } + } else { + string_append(rstr, p->c); + parser_move(p); + } + } + free(p->source); + parser_reset(p, rstr->value); + free(rstr); + return p; +} + void parser_move(parser_t *p) { if (p->i < strlen(p->source) && p->c != '\0') { p->i++; |