Skip to content

Commit

Permalink
fully allow upper-case letters in variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
codeplea committed Mar 3, 2021
1 parent 8d7ebbb commit 61af1dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,10 @@ TinyExpr parses the following grammar:

In addition, whitespace between tokens is ignored.

Valid variable names consist of a lower case letter followed by any combination
of: lower case letters *a* through *z*, the digits *0* through *9*, and
underscore. Constants can be integers, decimal numbers, or in scientific
notation (e.g. *1e3* for *1000*). A leading zero is not required (e.g. *.5*
for *0.5*)
Valid variable names consist of a letter followed by any combination of:
letters, the digits *0* through *9*, and underscore. Constants can be integers,
decimal numbers, or in scientific notation (e.g. *1e3* for *1000*). A leading
zero is not required (e.g. *.5* for *0.5*)


## Functions supported
Expand Down
5 changes: 3 additions & 2 deletions smoke.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ void test_syntax() {
{"1*2(+4", 4},
{"1*2(1+4", 4},
{"a+5", 1},
{"A+5", 1},
{"Aa+5", 1},
{"!+5", 1},
{"_a+5", 1},
{"#a+5", 1},
{"1^^5", 3},
{"1**5", 3},
{"sin(cos5", 8},
Expand Down
2 changes: 1 addition & 1 deletion tinyexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void next_token(state *s) {
s->type = TOK_NUMBER;
} else {
/* Look for a variable or builtin function call. */
if (s->next[0] >= 'a' && s->next[0] <= 'z') {
if (isalpha(s->next[0])) {
const char *start;
start = s->next;
while (isalpha(s->next[0]) || isdigit(s->next[0]) || (s->next[0] == '_')) s->next++;
Expand Down

0 comments on commit 61af1dd

Please sign in to comment.