"use strict"; const { either, wholeMatch, optional, oneOrMore, until, EndOfInput } = require("./operations"); function* Newline() { yield "\n"; } function* Digits() { return yield /[0-9]+/; } function* Integer() { return parseInt(yield wholeMatch(Digits)); } function* Decimal() { // NOTE: this gets converted to a floating point value! let decimalString = yield wholeMatch(function* () { yield Digits; yield optional(function* () { yield "."; yield Digits; }); }); return parseFloat(decimalString); } function* Playlist() { return yield either([ MediaPlaylist ]); } function* MediaPlaylist() { yield "#EXTM3U"; yield Newline; yield "#EXT-X-TARGETDURATION:"; let targetDuration = yield Integer; yield Newline; yield Newline; let items = yield oneOrMore(function* () { yield "#EXTINF:"; let duration = yield Decimal; yield ","; yield Newline; let url = yield until(Newline); yield either([ EndOfInput, Newline ]); return { url, duration }; }); return { targetDuration, items }; } module.exports = { Playlist };