aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-28 13:34:30 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-28 13:34:30 -0700
commit46192472bd8df22548e22e13aa55b9ac76a14745 (patch)
treebded46721aecb8c983bc33209376315f31d908b1 /sys
parent4eabf5d72c6b01bbf11180280ef9d28d5fe587bf (diff)
fix: allow for identifiers that start with numbers
Diffstat (limited to 'sys')
-rw-r--r--sys/libbio/io/newick.c21
1 files changed, 14 insertions, 7 deletions
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--;