From 8af7b7fc0a8dbe3502a7cd43c6a10fdcc6013677 Mon Sep 17 00:00:00 2001 From: peter Date: Fri, 21 Aug 2026 10:55:30 +0000 Subject: Start working on the scanner. For now, all that is implemented is some functionality which imports UTF-8 into the memory managed by aplwc, after checking that the data is in fact valid UTF-8. FossilOrigin-Name: c861e88777d8180cb7b37c11fc7016a900f9d5821a7e3c8e8aab54118d2fca94 --- src/lib/main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'src/lib/main.c') diff --git a/src/lib/main.c b/src/lib/main.c index f7cbe7d..cca1e68 100644 --- a/src/lib/main.c +++ b/src/lib/main.c @@ -30,6 +30,10 @@ aplwc_errstr_rc(enum aplwc_rc rc) return ""; case APLWC_OUT_OF_MEMORY: return "Out of memory"; + case APLWC_NOT_YET_IMPLEMENTED: + return "Not yet implemented"; + case APLWC_INVALID_UTF8: + return "Invalid UTF-8"; default: return "(unable to produce error string)"; } @@ -50,3 +54,51 @@ aplwc_errstr(struct aplwc *aplwc) return err; } + +enum aplwc_rc +aplwc_last_error(struct aplwc *aplwc) +{ + return aplwc->last_error; +} + +struct aplwc_line * +aplwc_read(struct aplwc *aplwc, const char *line) +{ + struct string *text; + struct token_list *tokens; + struct aplwc_line *ret; + + text = chars_to_string(aplwc, line); + if(text == NULL) + return NULL; + + tokens = scan_line(aplwc, text); + if(tokens == NULL) + return NULL; + + ret = memory_alloc_aplwc_line(&aplwc->memory); + if(ret == NULL) + return NULL; + + ret->aplwc = aplwc; + ret->text = text; + ret->tokens = tokens; + + return ret; +} + +void +aplwc_free_line(struct aplwc_line *line) +{ + if(line == NULL) + return; + memory_free_aplwc_line(&line->aplwc->memory, line); +} + +enum aplwc_rc +aplwc_eval(struct aplwc_line *line) +{ + line->aplwc->last_error = APLWC_OK; + eval_line(line); + return line->aplwc->last_error; +} -- cgit v1.2.3