Nasal: require 0o as prefix for octal numbers.

Using just 0 as prefix for octal number can lead to confusion
where numbers could be interpreted the wrong way (oct instead of
dec).
Lets follow the same convention as Python 3 and Ecma 262 level 6
and use '0o' as prefix which can not be confused inadvertently.
This commit is contained in:
Thomas Geymayer
2014-07-14 18:51:11 +02:00
parent d9df10fe10
commit a5e99ea996
3 changed files with 14 additions and 10 deletions

View File

@@ -72,9 +72,13 @@ static void runNumTests( double (TestContext::*test_double)(const std::string&),
BOOST_CHECK_CLOSE((c.*test_int)("-1e7"), -1e7, 1e-5);
BOOST_CHECK_CLOSE((c.*test_int)("2E07"), 2e07, 1e-5);
BOOST_CHECK_EQUAL((c.*test_int)("0755"), 0755);
BOOST_CHECK_EQUAL((c.*test_int)("0055"), 055);
BOOST_CHECK_EQUAL((c.*test_int)("-0155"), -0155);
BOOST_CHECK_EQUAL((c.*test_int)("0755"), 755);
BOOST_CHECK_EQUAL((c.*test_int)("0055"), 55);
BOOST_CHECK_EQUAL((c.*test_int)("-0155"), -155);
BOOST_CHECK_EQUAL((c.*test_int)("0o755"), 0755);
BOOST_CHECK_EQUAL((c.*test_int)("0o055"), 055);
BOOST_CHECK_EQUAL((c.*test_int)("-0o155"), -0155);
BOOST_CHECK_EQUAL((c.*test_int)("0x755"), 0x755);
BOOST_CHECK_EQUAL((c.*test_int)("0x055"), 0x55);

View File

@@ -273,11 +273,11 @@ static int lexNumLiteral(struct Parser* p, int index)
unsigned char* buf = (unsigned char*)p->buf;
double d;
if(buf[i] == '0') {
if(i+2<len && buf[i+1] == 'x' && ISHEX(buf[i+2]))
if( buf[i] == '0' && i + 2 < len ) {
if( buf[i+1] == 'x' && ISHEX(buf[i+2]) )
return lexIntLiteral(p, index+2, 16);
if(i+1<len && ISNUM(buf[i+1]) )
return lexIntLiteral(p, index+1, 8);
if( buf[i+1] == 'o' && ISNUM(buf[i+2]) )
return lexIntLiteral(p, index+2, 8);
}
while(i<len && ISNUM(buf[i])) i++;

View File

@@ -166,9 +166,9 @@ static int readsigned(unsigned char* s, int len, int i, double* v)
if(i >= len) { *v = 0; return len; }
if(s[i] == '+') { i++; }
else if(s[i] == '-') { i++; sgn = -1; }
if(s[i] == '0') {
i++; base = 8;
if( i < len && s[i] == 'x' ) { i++; base = 16; }
if(s[i] == '0' && ++i < len) {
if( s[i] == 'x' ) { i++; base = 16; }
if( s[i] == 'o' ) { i++; base = 8; }
}
i2 = readint(s, len, i, &val, base);
if(i0 == i && i2 == i) {