Skip to content

Commit

Permalink
Fix number parsing for bases between 2 and 9.
Browse files Browse the repository at this point in the history
Allow multisyms to have number keys.
  • Loading branch information
bakpakin committed Jan 2, 2019
1 parent 122312d commit 29ec30c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/core/multisym.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ static JanetSlot multisym_parse_part(JanetCompiler *c, const uint8_t *sympart, i
if (sympart[0] == ':') {
return janetc_cslot(janet_symbolv(sympart, len));
} else {
return janetc_resolve(c, janet_symbol(sympart + 1, len - 1));
double index;
int err;
index = janet_scan_number(sympart + 1, len - 1, &err);
if (err) {
/* not a number */
return janetc_resolve(c, janet_symbol(sympart + 1, len - 1));
} else {
/* is a number */
return janetc_cslot(janet_wrap_number(index));
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/core/strtod.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ double janet_scan_number(
if (str + 1 < end && str[0] == '0' && str[1] == 'x') {
base = 16;
str += 2;
} else if (str + 1 < end &&
str[0] >= '0' && str[0] <= '9' &&
str[1] == 'r') {
base = str[0] - '0';
str += 2;
} else if (str + 2 < end &&
str[0] >= '0' && str[0] <= '9' &&
str[1] >= '0' && str[1] <= '9' &&
Expand Down

0 comments on commit 29ec30c

Please sign in to comment.