From 86a65e695b9dc1fb7a20094204339f5bf168fb92 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 25 Aug 2026 20:56:55 +0000 Subject: Start working on modules, including a built-in "boot" module FossilOrigin-Name: 4829dbeb2071fe0be41ded66a61ba2e156119a47def8a23415b8227a00d53ce7 --- src/lib/syntax.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) (limited to 'src/lib/syntax.c') diff --git a/src/lib/syntax.c b/src/lib/syntax.c index c3452f2..f930973 100644 --- a/src/lib/syntax.c +++ b/src/lib/syntax.c @@ -59,6 +59,11 @@ single_sym(struct scan_state *state, struct token *token) switch(peek(state)){ case 0x2190: token->tag = TOKEN_TAG_LEFT_ARROW; break; case 0x22C4: token->tag = TOKEN_TAG_DIAMOND; break; + case 0x2207: token->tag = TOKEN_TAG_DEL; break; + case 0x2336: token->tag = TOKEN_TAG_IBEAM; break; + case '\n': token->tag = TOKEN_TAG_NEWLINE; break; + case '(': token->tag = TOKEN_TAG_LEFT_PAREN; break; + case ')': token->tag = TOKEN_TAG_RIGHT_PAREN; break; default: return 0; } @@ -83,6 +88,21 @@ identifier(struct scan_state *state, struct token *token) return 1; } +static int +keyword(struct scan_state *state, struct token *token) +{ + uint32_t c; + if(peek(state) != ':') + return 0; + + do + c = advance(state); + while(is_letter(c)); + + token->tag = TOKEN_TAG_KEYWORD; + return 1; +} + static int number(struct scan_state *state, struct token *token) { @@ -125,14 +145,25 @@ number(struct scan_state *state, struct token *token) return 1; } -static int -newline(struct scan_state *state, struct token *token) +static int +text(struct scan_state *state, struct token *token) { - if(peek(state) != '\n') + uint32_t c; + + c = peek(state); + if(c != '\'') return 0; - advance(state); - token->tag = TOKEN_TAG_NEWLINE; + do + c = advance(state); + while((c != '\n') && (c != 0) && (c != '\'')); + + if(c == '\'') + advance(state); + else + return 0; + + token->tag = TOKEN_TAG_TEXT; return 1; } @@ -143,8 +174,9 @@ next_token(struct scan_state *state, struct token *token) int (*scans[])(struct scan_state *, struct token *token) = { single_sym, identifier, + keyword, number, - newline + text, }; skip_space(state); @@ -198,7 +230,7 @@ scan(struct string *text, struct token_list *tokens) } struct token_list * -scan_line(struct aplwc *aplwc, struct string *text) +scan_string(struct aplwc *aplwc, struct string *text, int oneline) { enum aplwc_rc rc; struct token_list *tokens; @@ -218,7 +250,7 @@ scan_line(struct aplwc *aplwc, struct string *text) tokens->length = n; scan(text, tokens); - for(i = 0; i < n; i++){ + for(i = 0; oneline && (i < n); i++){ if(tokens->tokens[i].tag != TOKEN_TAG_NEWLINE) continue; -- cgit v1.2.3