indexes in slices. Fix string conversion issue with bare "+" and "-".
Fix lexing of exponent expressions such that "1e" is not a number.
static void evalSlice(naContext ctx, naRef src, naRef dst, naRef idx)
{
if(!IS_VEC(src)) ERR(ctx, "cannot slice non-vector");
- naVec_append(dst, naVec_get(src, vbound(ctx, src, idx, 0)));
+ naVec_append(dst, naVec_get(src, checkVec(ctx, src, idx)));
}
static void evalSlice2(naContext ctx, naRef src, naRef dst,
static void genSlice(struct Parser* p, struct Token* t)
{
- if(!t) naParseError(p, "empty slice expression", -1);
+ if(!t || t->type==TOK_EMPTY) naParseError(p, "empty slice expression", -1);
if(t->type == TOK_COLON) {
if(LEFT(t)) genExpr(p, LEFT(t)); else emit(p, OP_PUSHNIL);
if(RIGHT(t)) genExpr(p, RIGHT(t)); else emit(p, OP_PUSHNIL);
return i;
}
+#define ISNUM(c) ((c) >= '0' && (c) <= '9')
+
static int lexNumLiteral(struct Parser* p, int index)
{
int len = p->len, i = index;
unsigned char* buf = (unsigned char*)p->buf;
double d;
- if(i+1<len && buf[i+1] == 'x') return lexHexLiteral(p, index+2);
+ if(buf[0] == '0' && i+1<len && buf[i+1] == 'x')
+ return lexHexLiteral(p, index+2);
while(i<len && buf[i] >= '0' && buf[i] <= '9') i++;
if(i<len && buf[i] == '.') {
i++;
while(i<len && buf[i] >= '0' && buf[i] <= '9') i++;
}
- if(i<len && (buf[i] == 'e' || buf[i] == 'E')) {
+ if(i+1<len && (buf[i] == 'e' || buf[i] == 'E') && ISNUM(buf[i+1])) {
i++;
if(i<len
&& (buf[i] == '-' || buf[i] == '+')
return best;
}
-#define ISNUM(c) ((c) >= '0' && (c) <= '9')
void naLex(struct Parser* p)
{
int i = 0;
int i=0, fraclen=0;
double sgn=1, val, frac=0, exp=0;
- // Special case, "." is not a number, even though "1." and ".0" are.
- if(len == 1 && s[0] == '.')
- return 0;
+ if(len == 1 && (*s=='.' || *s=='-' || *s=='+')) return 0;
// Strip off the leading negative sign first, so we can correctly
// parse things like -.xxx which would otherwise confuse