2 var Parser
= require("./parser");
4 var array_
= Array
.prototype;
6 module
.exports
= parseNumber
;
7 function parseNumber(callback
, options
) {
8 return parseDigits(function (digits
) {
10 return parseConvert(callback
, digits
.join(""), options
);
17 var digits
= "0123456789";
18 var parseDigit
= function (callback
) {
19 return function (character
) {
20 if (character
!== "" && digits
.indexOf(character
) !== -1) {
21 return callback(character
);
23 return callback()(character
);
28 function parseConvert(callback
, number
, options
) {
29 return Parser
.countPrimes(function (primes
) {
30 return callback(convert(number
, primes
, options
));
34 function convert(string
, alt
, options
) {
37 var duodecimal
= options
.duodecimal
;
38 var font
= options
.font
;
39 var makeColumn
= font
.makeColumn
;
41 radix
= duodecimal
? 12 : 10;
43 radix
= duodecimal
? 10 : 12;
46 var number
= parseInt(string
, 10);
47 var string
= number
.toString(radix
).split("");
48 return string
.map(function (character
) {
49 var column
= makeColumn(""+parseInt(character
, 12));
51 column
.addError("Numbers can only be parsed in either decimal or dudecimal.");
57 var parseDigits
= Parser
.makeParseSome(parseDigit
);