Permalink
Browse files

Allow negative enum ids even if super inefficient (encodes as 10 byte…

…s), fixes #499, fixes #500 [ci skip]
  • Loading branch information...
dcodeIO committed Nov 29, 2016
1 parent 6376983 commit 4012a00a0578185d92fb6e7d3babd059fee6d6ab
Showing with 7 additions and 5 deletions.
  1. +7 −5 src/parse.js
@@ -150,18 +150,20 @@ function parse(source, root) {
throw illegal(token, 'number');
}
function parseId(token) {
function parseId(token, acceptNegative) {
var tokenLower = lower(token);
switch (tokenLower) {
case "min": return 1;
case "max": return 0x1FFFFFFF;
case "0": return 0;
}
if (/^[1-9][0-9]*$/.test(token))
if (token.charAt(0) === '-' && !acceptNegative)
throw illegal(token, "id");
if (/^\-?[1-9][0-9]*$/.test(token))
return parseInt(token, 10);
if (/^0[x][0-9a-f]+$/.test(tokenLower))
if (/^\-?0[x][0-9a-f]+$/.test(tokenLower))
return parseInt(token, 16);
if (/^0[0-7]+$/.test(token))
if (/^\-?0[0-7]+$/.test(token))
return parseInt(token, 8);
throw illegal(token, "id");
}
@@ -357,7 +359,7 @@ function parse(source, root) {
throw illegal(token, s_name);
var name = token;
skip("=");
var value = parseId(next());
var value = parseId(next(), true);
parseInlineOptions(parent.values[name] = new Number(value)); // eslint-disable-line no-new-wrappers
}

0 comments on commit 4012a00

Please sign in to comment.