[javascriptlint-commit] SF.net SVN: javascriptlint:[317] trunk
Status: Beta
Brought to you by:
matthiasmiller
From: <mat...@us...> - 2013-09-30 20:54:01
|
Revision: 317 http://sourceforge.net/p/javascriptlint/code/317 Author: matthiasmiller Date: 2013-09-30 20:53:58 +0000 (Mon, 30 Sep 2013) Log Message: ----------- Fix number parsing. Modified Paths: -------------- trunk/jsengine/structs.py trunk/jsengine/tokenizer/__init__.py trunk/tests/warnings/useless_comparison.js Modified: trunk/jsengine/structs.py =================================================================== --- trunk/jsengine/structs.py 2013-09-28 19:39:16 UTC (rev 316) +++ trunk/jsengine/structs.py 2013-09-30 20:53:58 UTC (rev 317) @@ -125,7 +125,12 @@ else: assert fn_args is None if self.kind == kind.NUMBER: - self.dval = float(self.atom) + if self.atom.lower().startswith('0x'): + self.dval = int(self.atom, 16) + elif self.atom.startswith('0') and self.atom.isdigit(): + self.dval = int(self.atom, 8) + else: + self.dval = float(self.atom) def start_pos(self): return self.startpos Modified: trunk/jsengine/tokenizer/__init__.py =================================================================== --- trunk/jsengine/tokenizer/__init__.py 2013-09-28 19:39:16 UTC (rev 316) +++ trunk/jsengine/tokenizer/__init__.py 2013-09-30 20:53:58 UTC (rev 317) @@ -378,27 +378,32 @@ s = c # TODO stream.watch_reads() if c == '0' and stream.readif(1, 'xX'): + # Hex while stream.readif(1, _HEX_DIGITS): pass - return Token(tok.NUMBER, atom=stream.get_watched_reads()) - - if c != '.': + elif c == '0' and stream.readif(1, _DIGITS): + # Octal while stream.readif(1, _DIGITS): pass - stream.readif(1, '.') + else: + # Decimal + if c != '.': + while stream.readif(1, _DIGITS): + pass + stream.readif(1, '.') - while stream.readif(1, _DIGITS): - pass - - if stream.readif(1, 'eE'): - stream.readif(1, '+-') - stream.require(_DIGITS) while stream.readif(1, _DIGITS): pass - if stream.peekchr(_IDENT): - return Token(tok.ERROR) + if stream.readif(1, 'eE'): + stream.readif(1, '+-') + stream.require(_DIGITS) + while stream.readif(1, _DIGITS): + pass + if stream.peekchr(_IDENT): + return Token(tok.ERROR) + atom = s + stream.get_watched_reads() return Token(tok.NUMBER, atom=atom) Modified: trunk/tests/warnings/useless_comparison.js =================================================================== --- trunk/tests/warnings/useless_comparison.js 2013-09-28 19:39:16 UTC (rev 316) +++ trunk/tests/warnings/useless_comparison.js 2013-09-30 20:53:58 UTC (rev 317) @@ -60,4 +60,10 @@ return; if (i == 3 == j == 3) /*warning:useless_comparison*/ return; + + // Test bases + if (010 == 8) /*warning:useless_comparison*/ /*warning:octal_number*/ + return; + if (0xA == 10) /*warning:useless_comparison*/ + return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |