Skip to content

Commit

Permalink
Pass through octal and binary literals as-is
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Pánek committed Sep 26, 2016
1 parent c3f5b8d commit a940a77
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ exports.Lexer = class Lexer
# Be careful not to interfere with ranges-in-progress.
numberToken: ->
return 0 unless match = NUMBER.exec @chunk

number = match[0]
lexedLength = number.length

if /^0[BOX]/.test number
@error "radix prefix in '#{number}' must be lowercase", offset: 1
else if /E/.test(number) and not /^0x/.test number
Expand All @@ -202,14 +204,12 @@ exports.Lexer = class Lexer
@error "decimal literal '#{number}' must not be prefixed with '0'", length: lexedLength
else if /^0\d+/.test number
@error "octal literal '#{number}' must be prefixed with '0o'", length: lexedLength
if octalLiteral = /^0o([0-7]+)/.exec number
numberValue = parseInt(octalLiteral[1], 8)
number = "0x#{numberValue.toString 16}"
else if binaryLiteral = /^0b([01]+)/.exec number
numberValue = parseInt(binaryLiteral[1], 2)
number = "0x#{numberValue.toString 16}"
else

numberValue = number

unless /^(0o[0-7]+)/.test(number) or /^(0b[01]+)/.test(number)
numberValue = parseFloat(number)

tag = if numberValue is Infinity then 'INFINITY' else 'NUMBER'
@token tag, number, 0, lexedLength
lexedLength
Expand Down

0 comments on commit a940a77

Please sign in to comment.