From 46192472bd8df22548e22e13aa55b9ac76a14745 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 28 Apr 2020 13:34:30 -0700 Subject: fix: allow for identifiers that start with numbers --- sys/libbio/io/newick.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'sys') diff --git a/sys/libbio/io/newick.c b/sys/libbio/io/newick.c index 81b5195..fb8e763 100644 --- a/sys/libbio/io/newick.c +++ b/sys/libbio/io/newick.c @@ -67,8 +67,13 @@ static struct Token lex(io·Peeker s, void* fp) { -#define isvalidchar(C) (' ' < (C) && (C) < ':') || (':' < (C) && (C) <= '~') - +#define isvalidchar(C) ((C) == '!') || \ + ('\"' < (C) && (C) < '\'') || \ + (')' < (C) && (C) < '+') || \ + (',' < (C) && (C) < ':') || \ + (':' < (C) && (C) < '[') || \ + ((C) == '\\') || \ + (']' < (C) && (C) <= '~') byte *c; struct Token tok; static byte b[1024]; @@ -105,7 +110,8 @@ lex(io·Peeker s, void* fp) while (isdigit(*c)) { NUM: *(++c) = s.get(fp); } - if (*c == '.') goto NUM; + if (*c == '.') goto NUM; + if (isvalidchar(*c)) goto IDENT; s.unget(fp, *c); Assert(c - b < 1024); @@ -116,17 +122,17 @@ lex(io·Peeker s, void* fp) return tok; default: + IDENT: while (isvalidchar(*c)) { *(++c) = s.get(fp); } - printf("ended on character %c\n", *c); - s.unget(fp, *c); Assert(c - b < 1024); *c = '\0'; tok.kind = tok·ident; tok.lit.s = b; + printf("setting name to '%s'\n", b); return tok; } #undef isvalidchar @@ -199,8 +205,9 @@ parse(struct Parser *p) goto ERROR; } p->root = root; - - break; + // NOTE(nnoll): We don't want to override the state of p->tok here! + // Jump straight to grabbing next token. + continue; case tok·rparen: p->lev--; -- cgit v1.2.1