diff options
Diffstat (limited to 'src/fwdscript.c')
| -rw-r--r-- | src/fwdscript.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/fwdscript.c b/src/fwdscript.c index c1eda21..1c9cff2 100644 --- a/src/fwdscript.c +++ b/src/fwdscript.c @@ -229,6 +229,7 @@ struct fwdtoken { enum { FWDTOKEN_ID, FWDTOKEN_STR, + FWDTOKEN_NUM, FWDTOKEN_OPEN, FWDTOKEN_CLOSE, FWDTOKEN_TO, @@ -236,7 +237,10 @@ struct fwdtoken { } kind; size_t line; - char *s; + union { + char *s; + double d; + }; }; #define VEC_TYPE struct fwdtoken @@ -367,8 +371,30 @@ static int fwdscript_tokenize(struct fwdtokens *tokens, const char *buf) continue; } - /* otherwise, read until next separation */ + /* otherwise, read until next separation and check if we're + * maybe dealing with a number or a regular identifier */ const char *end = next_separator(tok); + + char *dparse = NULL; + double d = strtod(tok, &dparse); + if (end == dparse) { + /* all of the non-separators were consumed, so we have a + * number */ + struct fwdtoken num = { + .kind = FWDTOKEN_NUM, + .line = line, + .d = d + }; + + if (!fwdtokens_append(tokens, num)) { + fprintf(stderr, "failed appending num token\n"); + return -1; + } + + start = end + 1; + continue; + } + char *s = strndup(tok, end - tok); if (!s) { fprintf(stderr, "failed duping id token\n"); @@ -403,7 +429,7 @@ static int fwdscript_parse(struct fwdscript *s, const char *buf) } /* convert tokens into some kind of structure */ - todo(); + TODO(); fwdtokens_destroy(&tokens); return 0; } |
