"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _charsBundle = _interopRequireDefault(require("./chars-bundle.js"));
var _flowBundle = _interopRequireDefault(require("./flow-bundle.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/*
 * Masala Parser
 * https://github.com/masala/masala-parser
 *
 * Copyright (c) 2016-2025 Didier Plaindoux & Nicolas Zozol
 * Licensed under the LGPL2 license.
 */

// unit -> Parser number char
function number() {
  // [-+]?\d+([.]\d+)?([eE][+-]?\d+)?
  var join = function join(r) {
      return r.join('');
    },
    joinOrEmpty = function joinOrEmpty(r) {
      return r.map(join).orElse('');
    },
    digits = digit().rep().map(join),
    integer = _charsBundle["default"].charIn('+-').opt().then(digits).array().map(function (r) {
      return r[0].orElse('') + r[1];
    }),
    _float = integer.then(_charsBundle["default"]["char"]('.').then(digits).opt().map(joinOrEmpty)).then(_charsBundle["default"].charIn('eE').then(integer).opt().map(joinOrEmpty)).array().map(function (r) {
      return r[0] + r[1] + r[2];
    });
  return _float.map(function (r) {
    return parseFloat(r, 10);
  });
}

// unit -> Parser char int
function digit() {
  return _flowBundle["default"].satisfy(function (v) {
    return '0' <= v && v <= '9';
  }).map(function (c) {
    return parseInt(c);
  });
}
function digits() {
  return digit().rep().map(function (v) {
    return parseInt(v.join(''));
  });
}
function integer() {
  // [-+]?\d+
  var join = function join(r) {
      return r.join('');
    },
    digits = digit().rep().map(join),
    integer = _charsBundle["default"].charIn('+-').opt().then(digits).array().map(function (r) {
      return r[0].orElse('') + r[1];
    });
  return integer.map(function (i) {
    return parseInt(i, 10);
  });
}
var _default = exports["default"] = {
  number: number,
  digit: digit,
  digits: digits,
  integer: integer
};
//# sourceMappingURL=numbers-bundle.js.map