From 5bb556038dfbdd2878fe1907196d84c3a536da08 Mon Sep 17 00:00:00 2001 From: Lewis Van Winkle Date: Mon, 28 Nov 2016 18:20:10 -0600 Subject: [PATCH] Added support for underscore in variable names. --- test.c | 4 ++-- tinyexpr.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test.c b/test.c index e976d95..b86a83f 100644 --- a/test.c +++ b/test.c @@ -237,7 +237,7 @@ void test_nans() { void test_variables() { double x, y, test; - te_variable lookup[] = {{"x", &x}, {"y", &y}, {"test", &test}}; + te_variable lookup[] = {{"x", &x}, {"y", &y}, {"te_st", &test}}; int err; @@ -253,7 +253,7 @@ void test_variables() { lok(expr3); lok(!err); - te_expr *expr4 = te_compile("test+5", lookup, 3, &err); + te_expr *expr4 = te_compile("te_st+5", lookup, 3, &err); lok(expr4); lok(!err); diff --git a/tinyexpr.c b/tinyexpr.c index 58717c2..6c3cb7a 100644 --- a/tinyexpr.c +++ b/tinyexpr.c @@ -207,7 +207,7 @@ void next_token(state *s) { if (s->next[0] >= 'a' && s->next[0] <= 'z') { const char *start; start = s->next; - while ((s->next[0] >= 'a' && s->next[0] <= 'z') || (s->next[0] >= '0' && s->next[0] <= '9')) s->next++; + while ((s->next[0] >= 'a' && s->next[0] <= 'z') || (s->next[0] >= '0' && s->next[0] <= '9') || (s->next[0] == '_')) s->next++; const te_variable *var = find_lookup(s, start, s->next - start); if (!var) var = find_builtin(start, s->next - start);