// Generated by purs version 0.12.5
"use strict";
var Control_Alt = require("../Control.Alt/index.js");
var Control_Applicative = require("../Control.Applicative/index.js");
var Control_Apply = require("../Control.Apply/index.js");
var Control_Bind = require("../Control.Bind/index.js");
var Control_Category = require("../Control.Category/index.js");
var Control_Monad = require("../Control.Monad/index.js");
var Control_Monad_State = require("../Control.Monad.State/index.js");
var Control_Monad_State_Class = require("../Control.Monad.State.Class/index.js");
var Control_Monad_State_Trans = require("../Control.Monad.State.Trans/index.js");
var Control_Monad_Trans_Class = require("../Control.Monad.Trans.Class/index.js");
var Data_Eq = require("../Data.Eq/index.js");
var Data_Function = require("../Data.Function/index.js");
var Data_Identity = require("../Data.Identity/index.js");
var Data_List = require("../Data.List/index.js");
var Data_List_Types = require("../Data.List.Types/index.js");
var Data_Maybe = require("../Data.Maybe/index.js");
var Data_Ord = require("../Data.Ord/index.js");
var Data_Unit = require("../Data.Unit/index.js");
var Text_Parsing_Parser = require("../Text.Parsing.Parser/index.js");
var Text_Parsing_Parser_Combinators = require("../Text.Parsing.Parser.Combinators/index.js");
var Text_Parsing_Parser_Pos = require("../Text.Parsing.Parser.Pos/index.js");
var Text_Parsing_Parser_String = require("../Text.Parsing.Parser.String/index.js");
var Opt = (function () {
    function Opt(value0, value1) {
        this.value0 = value0;
        this.value1 = value1;
    };
    Opt.create = function (value0) {
        return function (value1) {
            return new Opt(value0, value1);
        };
    };
    return Opt;
})();
var symbol = function (dictMonad) {
    return function (name) {
        return Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(dictMonad))(Data_List.many(Text_Parsing_Parser.alternativeParserT(dictMonad))(Text_Parsing_Parser.lazyParserT)(Text_Parsing_Parser_String.oneOf(Text_Parsing_Parser_String.stringLikeString)(dictMonad)([ " ", "\x09" ])))(Text_Parsing_Parser_String.string(Text_Parsing_Parser_String.stringLikeString)(dictMonad)(name));
    };
};
var sourceLine = function (v) {
    return v.line;
};
var sourceColumn = function (v) {
    return v.column;
};
var setSourceLine = function (v) {
    return function (l) {
        return {
            line: l,
            column: v.column
        };
    };
};
var runIndent = Data_Function.flip(Control_Monad_State.evalState)(Text_Parsing_Parser_Pos.initialPos);
var put$prime = function (p) {
    return Control_Monad_Trans_Class.lift(Text_Parsing_Parser.monadTransParserT)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))(Control_Monad_State_Class.put(Control_Monad_State_Trans.monadStateStateT(Data_Identity.monadIdentity))(p));
};
var many1 = function (dictMonad) {
    return function (p) {
        return Control_Apply.lift2(Text_Parsing_Parser.applyParserT(dictMonad))(Data_List_Types.Cons.create)(p)(Data_List.many(Text_Parsing_Parser.alternativeParserT(dictMonad))(Text_Parsing_Parser.lazyParserT)(p));
    };
};
var getPosition = function (dictMonad) {
    return Control_Monad_State_Class.gets(Text_Parsing_Parser.monadStateParserT(dictMonad))(function (v) {
        return v.value1;
    });
};
var get$prime = Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Control_Monad_Trans_Class.lift(Text_Parsing_Parser.monadTransParserT)(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))(Control_Monad_State_Class.get(Control_Monad_State_Trans.monadStateStateT(Data_Identity.monadIdentity))))(function (v) {
    return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(v);
});
var withPos = function (x) {
    return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(get$prime)(function (v) {
        return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(getPosition(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(function (v1) {
            return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(put$prime(v1))(x))(function (v2) {
                return Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(put$prime(v))(Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(v2));
            });
        });
    });
};
var biAp = function (f) {
    return function (c) {
        return function (v1) {
            return function (v2) {
                return c(f(v1))(f(v2));
            };
        };
    };
};
var checkIndent = Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(get$prime)(function (v) {
    return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(getPosition(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(function (v1) {
        var $44 = biAp(sourceColumn)(Data_Eq.eq(Data_Eq.eqInt))(v1)(v);
        if ($44) {
            return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Data_Unit.unit);
        };
        return Text_Parsing_Parser.fail(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("indentation doesn't match");
    });
});
var block = function (p) {
    return withPos(Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Data_List.many(Text_Parsing_Parser.alternativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Text_Parsing_Parser.lazyParserT)(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(checkIndent)(p)))(function (v) {
        return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(v);
    }));
};
var block1 = function (p) {
    return withPos(Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(many1(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(checkIndent)(p)))(function (v) {
        return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(v);
    }));
};
var indented = Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(getPosition(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(function (v) {
    return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(get$prime)(function (v1) {
        var $49 = biAp(sourceColumn)(Data_Ord.lessThanOrEq(Data_Ord.ordInt))(v)(v1);
        if ($49) {
            return Text_Parsing_Parser.fail(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("not indented");
        };
        return Control_Bind.discard(Control_Bind.discardUnit)(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(put$prime(setSourceLine(v1)(sourceLine(v))))(function () {
            return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Data_Unit.unit);
        });
    });
});
var withBlock = function (f) {
    return function (a) {
        return function (p) {
            return withPos(Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(a)(function (v) {
                return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Text_Parsing_Parser_Combinators.optionMaybe(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(indented)(block(p))))(function (v1) {
                    if (v1 instanceof Data_Maybe.Nothing) {
                        return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(f(v)(Data_List_Types.Nil.value));
                    };
                    if (v1 instanceof Data_Maybe.Just) {
                        return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(f(v)(v1.value0));
                    };
                    throw new Error("Failed pattern match at Text.Parsing.Indent (line 112, column 5 - line 114, column 32): " + [ v1.constructor.name ]);
                });
            }));
        };
    };
};
var withBlock$prime = withBlock(Data_Function.flip(Data_Function["const"]));
var indented$prime = Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(getPosition(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(function (v) {
    return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(get$prime)(function (v1) {
        var $56 = biAp(sourceColumn)(Data_Ord.lessThanOrEq(Data_Ord.ordInt))(v)(v1);
        if ($56) {
            return Text_Parsing_Parser.fail(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("not indented");
        };
        return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Data_Unit.unit);
    });
});
var sameLine = Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(getPosition(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(function (v) {
    return Control_Bind.bind(Text_Parsing_Parser.bindParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(get$prime)(function (v1) {
        var $59 = biAp(sourceLine)(Data_Eq.eq(Data_Eq.eqInt))(v)(v1);
        if ($59) {
            return Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Data_Unit.unit);
        };
        return Text_Parsing_Parser.fail(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("over one line");
    });
});
var sameOrIndented = Control_Alt.alt(Text_Parsing_Parser.altParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(sameLine)(indented);
var indentAp = function (a) {
    return function (b) {
        return Control_Monad.ap(Text_Parsing_Parser.monadParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(a)(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(sameOrIndented)(b));
    };
};
var indentMany = function (a) {
    return function (b) {
        return Control_Monad.ap(Text_Parsing_Parser.monadParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(a)(Data_List.many(Text_Parsing_Parser.alternativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Text_Parsing_Parser.lazyParserT)(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(sameOrIndented)(b)));
    };
};
var indentNoAp = function (a) {
    return function (b) {
        return Control_Apply.lift2(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Data_Function["const"])(a)(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(sameOrIndented)(b));
    };
};
var indentAngles = function (p) {
    return withPos(indentAp(indentNoAp(Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Control_Category.identity(Control_Category.categoryFn)))(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("<")))(indentNoAp(p)(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))(">"))));
};
var indentBraces = function (p) {
    return withPos(indentAp(indentNoAp(Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Control_Category.identity(Control_Category.categoryFn)))(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("{")))(indentNoAp(p)(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("}"))));
};
var indentBrackets = function (p) {
    return withPos(indentAp(indentNoAp(Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Control_Category.identity(Control_Category.categoryFn)))(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("[")))(indentNoAp(p)(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("]"))));
};
var indentParens = function (p) {
    return withPos(indentAp(indentNoAp(Control_Applicative.pure(Text_Parsing_Parser.applicativeParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(Control_Category.identity(Control_Category.categoryFn)))(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))("(")))(indentNoAp(p)(symbol(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))(")"))));
};
var indentOp = function (a) {
    return function (v) {
        return Control_Monad.ap(Text_Parsing_Parser.monadParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(a)(Text_Parsing_Parser_Combinators.option(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity))(v.value0)(Control_Apply.applySecond(Text_Parsing_Parser.applyParserT(Control_Monad_State_Trans.monadStateT(Data_Identity.monadIdentity)))(sameOrIndented)(v.value1)));
    };
};
module.exports = {
    runIndent: runIndent,
    withBlock: withBlock,
    "withBlock'": withBlock$prime,
    block: block,
    block1: block1,
    indented: indented,
    "indented'": indented$prime,
    sameLine: sameLine,
    sameOrIndented: sameOrIndented,
    checkIndent: checkIndent,
    withPos: withPos,
    indentAp: indentAp,
    indentNoAp: indentNoAp,
    indentMany: indentMany,
    indentOp: indentOp,
    Opt: Opt
};
