'use strict';

const _commonjsHelpers = require('./_commonjsHelpers-5bbc2693.js');

var Level_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Level;
(function (Level) {
    Level[Level["Logging"] = 0] = "Logging";
    Level[Level["Debug"] = 1] = "Debug";
    Level[Level["Warning"] = 2] = "Warning";
    Level[Level["Recoverable"] = 3] = "Recoverable";
    Level[Level["Critical"] = 4] = "Critical";
})(Level = exports.Level || (exports.Level = {}));
//# sourceMappingURL=Level.js.map
});

const Level = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Level_1);

var Message_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Message {
    constructor(description, level = Level_1.Level.Recoverable, type = "unknown", region) {
        this.description = description;
        this.level = level;
        this.type = type;
        this.region = region;
    }
    toString() {
        return Level_1.Level[this.level] + ": " + this.type + " error. " + this.description + (this.region ? " @ " + this.region.toString() : "");
    }
}
exports.Message = Message;
//# sourceMappingURL=Message.js.map
});

const Message = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Message_1);

var ConsoleHandler_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class ConsoleHandler {
    raise(message, level, type, region) {
        if (!(message instanceof Message_1.Message))
            message = new Message_1.Message(message, level, type, region);
        console.error(message.toString());
    }
}
exports.ConsoleHandler = ConsoleHandler;
//# sourceMappingURL=ConsoleHandler.js.map
});

const ConsoleHandler = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(ConsoleHandler_1);

var Position_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Position {
    constructor(line, column) {
        this.line = line;
        this.column = column;
    }
    toString() {
        return "Ln " + this.line + ", Col " + this.column;
    }
}
exports.Position = Position;
//# sourceMappingURL=Position.js.map
});

const Position = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Position_1);

var Location_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Location extends Position_1.Position {
    constructor(resource, line, column) {
        super(line, column);
        this.resource = resource;
    }
    toString() {
        return this.resource.toString() + " @ " + super.toString();
    }
}
exports.Location = Location;
//# sourceMappingURL=Location.js.map
});

const Location = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Location_1);

var Region_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Region {
    constructor(resource, start, end, content) {
        this.resource = resource;
        this.start = start;
        this.end = end;
        this.content = content;
    }
    merge(other) { return other ? new Region(this.resource, this.start, other.end, this.content ? this.content : "" + other.content ? other.content : "") : this; }
    toString() {
        let result = this.resource.toString();
        if (this.start && this.end)
            result += " (" + this.start.toString() + " - " + this.end.toString() + ") ";
        if (this.content)
            result += this.content;
        return result;
    }
}
exports.Region = Region;
//# sourceMappingURL=Region.js.map
});

const Region = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Region_1);

var _Error = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.ConsoleHandler = ConsoleHandler_1.ConsoleHandler;

exports.Level = Level_1.Level;

exports.Location = Location_1.Location;

exports.Message = Message_1.Message;

exports.Position = Position_1.Position;

exports.Region = Region_1.Region;
//# sourceMappingURL=index.js.map
});

const index$4 = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(_Error);

var User_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class User {
    constructor(name, password) {
        this.name = name;
        this.password = password;
    }
    get isEmpty() {
        return !this.name && !this.password;
    }
    toString() {
        let result = "";
        if (this.name)
            result = this.name;
        if (this.password)
            result += ":" + this.password;
        return result;
    }
    static parse(data) {
        let result;
        if (data) {
            const splitted = data.split(":", 2);
            result = new User(splitted[0], splitted[1]);
        }
        else
            result = new User();
        return result;
    }
}
exports.User = User;
//# sourceMappingURL=User.js.map
});

const User = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(User_1);

var Endpoint_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Endpoint {
    constructor(host = [], port) {
        this.host = host;
        this.port = port;
    }
    get isEmpty() {
        return this.host.length == 0 && !this.port;
    }
    toString() {
        let result = this.host.join(".");
        if (this.port)
            result += ":" + this.port.toString();
        return result;
    }
    static parse(data) {
        let result;
        if (data) {
            const splitted = data.split(":", 2);
            result = new Endpoint(splitted[0].split("."), splitted.length > 1 ? parseInt(splitted[1]) : undefined);
        }
        else
            result = new Endpoint();
        return result;
    }
}
exports.Endpoint = Endpoint;
//# sourceMappingURL=Endpoint.js.map
});

const Endpoint = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Endpoint_1);

var Authority_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class Authority {
    constructor(user = new User_1.User(), endpoint = new Endpoint_1.Endpoint()) {
        this.user = user;
        this.endpoint = endpoint;
    }
    get isEmpty() {
        return this.user.isEmpty && this.endpoint.isEmpty;
    }
    toString() {
        let result = "";
        if (!this.user.isEmpty)
            result = this.user.toString() + "@";
        if (!this.endpoint.isEmpty)
            result = result + this.endpoint.toString();
        return result;
    }
    static parse(data) {
        let result;
        if (data) {
            const splitted = data.split("@", 2);
            result = new Authority(User_1.User.parse(splitted.length == 2 ? splitted.pop() : undefined), Endpoint_1.Endpoint.parse(splitted.pop()));
        }
        return result;
    }
}
exports.Authority = Authority;
//# sourceMappingURL=Authority.js.map
});

const Authority = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Authority_1);

var Locator_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Locator {
    constructor(scheme = [], authority = new Authority_1.Authority(), path = [], query = {}, fragment) {
        this.scheme = scheme;
        this.authority = authority;
        this.path = path;
        this.query = query;
        this.fragment = fragment;
    }
    get isRelative() {
        return this.path[0] == "." || this.path[0] == "..";
    }
    get isFolder() {
        return this.path[this.path.length - 1] == "";
    }
    get folder() {
        return this.isFolder ? this : new Locator(this.scheme, this.authority, this.path.filter((value, index) => index < this.path.length - 1), this.query, this.fragment);
    }
    get name() {
        return this.path[this.path.length - 1];
    }
    get extension() {
        const splitted = this.name.split(".");
        return splitted.length > 1 ? splitted[splitted.length - 1] : "";
    }
    createArray(value, count) {
        const result = [];
        while (count-- > 0)
            result.push(value);
        return result;
    }
    normalize() {
        let skip = 0;
        const path = this.path.reverse().filter((item, index) => {
            let r = false;
            if ((item == "" || item == ".") && index < this.path.length - 1)
                r = false;
            else if (item == "..")
                skip++;
            else if (skip > 0)
                skip--;
            else
                r = true;
            return r;
        }).concat(this.createArray("..", skip)).reverse();
        return new Locator(this.scheme, this.authority, path, this.query, this.fragment);
    }
    resolve(absolute) {
        return !absolute ? this : new Locator(this.scheme.length > 0 ? this.scheme : absolute.scheme, !this.authority.isEmpty ? this.authority : absolute.authority, this.isRelative ? absolute.folder.path.concat(this.path) : this.path, this.query, this.fragment).normalize();
    }
    appendPath(path) {
        return new Locator(this.scheme, this.authority, path instanceof Array ? [...this.path, ...path] : [...this.path, path], this.query, this.fragment);
    }
    toString() {
        let result = "";
        if (this.scheme.length > 0)
            result += this.scheme.join("+") + ":";
        if (!this.authority.isEmpty)
            result += "//" + this.authority.toString();
        else if (this.scheme.length > 0)
            result += "//";
        if (this.path) {
            let path = this.path.join("/");
            if (path[0] != "." || result.length > 0)
                path = "/" + path;
            result += path;
        }
        if (Object.keys(this.query).length > 0)
            result += "?" + this.query.toString();
        if (this.fragment)
            result += "#" + this.fragment;
        return result;
    }
    static parse(data) {
        let result;
        switch (data) {
            case "":
            case null:
            case undefined:
                break;
            default:
                let hasAuthority = true;
                let scheme = [];
                let splitted = data.split("://", 2);
                if (splitted.length > 1) {
                    scheme = (splitted.shift() || "").split("+");
                    data = splitted.shift();
                }
                else if (data.slice(0, 2) == "//")
                    data = data.slice(2);
                else
                    hasAuthority = false;
                let index;
                let fragment;
                if (data && (index = data.lastIndexOf("#")) > -1) {
                    fragment = data.slice(index + 1);
                    data = data.slice(0, index);
                }
                let query = {};
                if (data && (index = data.lastIndexOf("?")) > -1) {
                    query = new Object();
                    data.slice(index + 1).split(";").forEach(element => {
                        splitted = element.split("=");
                        const key = splitted.shift();
                        const value = splitted.shift();
                        if (key && value)
                            query[key] = value;
                    });
                    data = data.slice(0, index);
                }
                let authority;
                let path = [];
                if (data) {
                    splitted = data.split("/");
                    if (splitted.length > 0) {
                        switch (splitted[0]) {
                            case ".":
                            case "..":
                                break;
                            case "":
                                splitted.shift();
                                break;
                            default:
                                if (hasAuthority)
                                    authority = Authority_1.Authority.parse(splitted.shift());
                                else
                                    splitted.unshift(".");
                                break;
                        }
                        path = splitted;
                    }
                }
                result = new Locator(scheme, authority, path, query, fragment);
                break;
        }
        return result;
    }
}
exports.Locator = Locator;
Locator.empty = new Locator(undefined, undefined, undefined, undefined, undefined);
//# sourceMappingURL=Locator.js.map
});

const Locator = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Locator_1);

var Uri = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.Authority = Authority_1.Authority;

exports.Endpoint = Endpoint_1.Endpoint;

exports.Locator = Locator_1.Locator;

exports.User = User_1.User;
//# sourceMappingURL=index.js.map
});

const index$3 = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Uri);

var Device_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Device {
}
exports.Device = Device;
//# sourceMappingURL=Device.js.map
});

const Device = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Device_1);

var InDevice_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class InDevice extends Device_1.Device {
}
exports.InDevice = InDevice;
//# sourceMappingURL=InDevice.js.map
});

const InDevice = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(InDevice_1);

var Reader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Reader extends InDevice_1.InDevice {
    static addOpener(open, priority) {
        if (!priority)
            priority = 0;
        Reader.openers.push({ open, priority });
        Reader.openers = Reader.openers.sort((left, right) => right.priority - left.priority);
    }
    static open(locator) {
        let result;
        let i = 0;
        do
            result = Reader.openers[i++].open(locator);
        while (!result && i < Reader.openers.length);
        return result;
    }
}
exports.Reader = Reader;
Reader.openers = [];
//# sourceMappingURL=Reader.js.map
});

const Reader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Reader_1);

var BufferedReader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });



var Reader_2 = Reader_1;
exports.Reader = Reader_2.Reader;
class BufferedReader extends Reader_1.Reader {
    constructor(backend) {
        super();
        this.backend = backend;
        this.buffer = [];
        this.lastContent = "";
        this.lastMark = this.locationValue = this.backend.location;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return !!this.backend; }
    get opened() { return !!this.backend; }
    get isEmpty() { return (this.buffer.length == 0 || this.buffer[0].data == "\0") && this.backend.isEmpty; }
    get resource() {
        const location = this.location;
        return location ? location.resource : Uri.Locator.empty;
    }
    get location() {
        return this.locationValue;
    }
    get region() {
        return new _Error.Region(this.resource, this.lastMark, this.location, this.lastContent);
    }
    close() {
        return this.backend.close();
    }
    peek(length) {
        if (!length)
            length = 1;
        let next;
        while (length > this.buffer.length && (next = this.backend.read()))
            this.buffer.push({ data: next, location: this.backend.location });
        return this.buffer.length == 0 ? undefined : this.buffer.slice(0, length > this.buffer.length ? this.buffer.length : length).map(value => value.data).join("");
    }
    read(length) {
        if (!length)
            length = 1;
        const result = this.peek(length);
        if (result && result.length > 0) {
            this.locationValue = this.buffer[result.length - 1].location;
            this.buffer.splice(0, result.length);
            this.lastContent += result;
        }
        return result;
    }
    peekIs(value, count) {
        let result;
        if (value)
            if (typeof (value) == "string") {
                const v = value;
                while (count && count-- > 0)
                    value += v;
                result = this.peek(value.length) == value ? value : undefined;
            }
            else if (value.length > 0 && !(result = this.peekIs(value[0])) && value.length)
                result = this.peekIs(value.slice(1));
        return result;
    }
    readIf(value) {
        let result;
        if (value)
            if (typeof (value) == "string")
                result = this.peek(value.length) == value && this.read(value.length) || undefined;
            else if (value.length > 0 && !(result = this.readIf(value[0])) && value.length)
                result = this.readIf(value.slice(1));
        return result;
    }
    readAll() {
        let result = "";
        while (this.peek())
            result += this.read();
        return result != "" ? result : undefined;
    }
    mark() {
        const result = this.region;
        this.lastMark = this.location;
        this.lastContent = "";
        return result;
    }
    static create(backend) {
        return backend ? new BufferedReader(backend) : undefined;
    }
}
exports.BufferedReader = BufferedReader;
//# sourceMappingURL=BufferedReader.js.map
});

const BufferedReader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(BufferedReader_1);

var fs_browser = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (_commonjsHelpers.commonjsGlobal && _commonjsHelpers.commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
function close(fd) {
    return __awaiter(this, void 0, void 0, function* () { });
}
exports.close = close;
function fsync(fd) {
    return __awaiter(this, void 0, void 0, function* () { });
}
exports.fsync = fsync;
function open(path, flags, mode) {
    return __awaiter(this, void 0, void 0, function* () { return 0; });
}
exports.open = open;
function write(fd, buffer, offset, encoding) {
    return __awaiter(this, void 0, void 0, function* () { return { bytesWritten: 0 }; });
}
exports.write = write;
function lstatSync(path, options) { return { isDirectory: () => false }; }
exports.lstatSync = lstatSync;
function readdirSync(path) { return []; }
exports.readdirSync = readdirSync;
function readFileSync(path, encoding) { return ""; }
exports.readFileSync = readFileSync;
//# sourceMappingURL=fs.browser.js.map
});

const fs_browser$1 = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(fs_browser);

var path_browser = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const sep = "/";
exports.sep = sep;
//# sourceMappingURL=path.browser.js.map
});

const path_browser$1 = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(path_browser);

var StringReader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (_commonjsHelpers.commonjsGlobal && _commonjsHelpers.commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });



class StringReader extends Reader_1.Reader {
    constructor(content, resource) {
        super();
        this.content = content;
        this.resource = resource;
        this.tabSize = 2;
        this.count = 0;
        this.line = 1;
        this.column = 1;
        this.lastContent = "";
        this.readable = true;
        this.content += "\0";
        this.lastPosition = this.location;
    }
    get opened() { return this.count + 1 >= this.content.length; }
    get isEmpty() { return this.opened; }
    get location() { return new _Error.Location(this.resource, this.line, this.column); }
    get region() { return new _Error.Region(this.resource, this.lastPosition, this.location, this.lastContent); }
    close() {
        return __awaiter(this, void 0, void 0, function* () {
            const result = !(yield this.isEmpty);
            if (result)
                this.count = this.content.length;
            return result;
        });
    }
    read() {
        let result;
        if (this.count < this.content.length)
            result = this.content.charAt(this.count);
        else if (this.count == this.content.length)
            result = undefined;
        this.count++;
        if (result) {
            switch (result) {
                case "\n":
                    this.line++;
                    this.column = 1;
                    break;
                case "\t":
                    this.column += this.tabSize;
                    break;
                default:
                    this.column++;
                    break;
            }
            this.lastContent += result;
        }
        return result;
    }
    mark() {
        const result = this.region;
        this.lastPosition = this.location;
        this.lastContent = "";
        return result;
    }
    static create(content, resource) {
        return content != undefined ? new StringReader(content, resource || Uri.Locator.empty) : undefined;
    }
}
exports.StringReader = StringReader;
//# sourceMappingURL=StringReader.js.map
});

const StringReader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(StringReader_1);

var FileReader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });





class FileReader extends Reader_1.Reader {
    constructor(backend) {
        super();
        this.backend = backend;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return this.backend.opened; }
    get isEmpty() { return this.backend.isEmpty; }
    get resource() { return this.backend ? this.backend.resource : Uri.Locator.empty; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        return this.backend.close();
    }
    read() { return this.backend.read(); }
    mark() { return this.backend.mark(); }
    static open(resource) {
        let backend;
        if (resource && (resource.scheme.length == 0 || resource.scheme.length == 1 && resource.scheme[0] == "file"))
            try {
                backend = StringReader_1.StringReader.create(fs_browser.readFileSync((resource.isRelative ? "" : path_browser.sep) + resource.path.join(path_browser.sep), "utf-8"), resource);
            }
            catch (error) {
                console.log(`Failed to open file: ${resource.toString()}`);
            }
        return backend ? new FileReader(backend) : undefined;
    }
}
exports.FileReader = FileReader;
Reader_1.Reader.addOpener(p => FileReader.open(p), 10);
//# sourceMappingURL=FileReader.js.map
});

const FileReader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(FileReader_1);

var FolderReader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (_commonjsHelpers.commonjsGlobal && _commonjsHelpers.commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });






class FolderReader extends Reader_1.Reader {
    constructor(files) {
        super();
        this.files = files;
        this.tabSizeValue = 2;
        this.lastLocation = new _Error.Location(Uri.Locator.empty, 0, 0);
    }
    get tabSize() { return this.tabSizeValue; }
    set tabSize(size) {
        this.tabSizeValue = size;
        if (this.current)
            this.current.tabSize = size;
    }
    get readable() { return this.current != undefined && this.current.readable || this.files.length > 0; }
    get opened() { return this.current != undefined || this.files.length > 0; }
    get isEmpty() { return this.files.length == 0 && (!this.current || this.current.isEmpty); }
    get resource() { return this.current ? this.current.resource : this.lastLocation.resource; }
    get location() { return this.current ? this.current.location : this.lastLocation; }
    get region() { return this.current ? this.current.region : new _Error.Region(this.resource); }
    close() {
        return __awaiter(this, void 0, void 0, function* () {
            return this.current != undefined && (yield this.current.close());
        });
    }
    read() {
        let result;
        if (!this.current && this.files.length > 0) {
            this.current = FileReader_1.FileReader.open(this.files.shift());
            this.current.tabSize = this.tabSize;
        }
        if (this.current) {
            result = this.current.read();
            if (result == undefined || result == "\0") {
                this.current.close();
                this.current = undefined;
            }
        }
        this.lastLocation = this.location;
        return result;
    }
    mark() { return this.current ? this.current.mark() : new _Error.Region(this.resource); }
    static getFiles(folder, filetype, ignoreFiles = []) {
        let result = [];
        const files = fs_browser.readdirSync(folder);
        files.forEach(file => {
            const filename = folder + path_browser.sep + file;
            if (ignoreFiles.indexOf(filename) == -1) {
                if (fs_browser.lstatSync(filename).isDirectory())
                    result = result.concat(FolderReader.getFiles(filename, filetype, ignoreFiles));
                else if (file.length > filetype.length && file.lastIndexOf(filetype, file.length - filetype.length) === file.length - filetype.length)
                    result.push(filename);
            }
        });
        return result;
    }
    static open(resource) {
        let files;
        try {
            if (resource && (resource.scheme.length == 0 || resource.scheme.length == 1 && resource.scheme[0] == "file") && resource.isFolder || resource.name.match("*"))
                files = FolderReader.getFiles((resource.isRelative ? "" : path_browser.sep) + resource.folder.path.join(path_browser.sep), resource.extension);
        }
        catch (error) {
        }
        return files ? new FolderReader(files.map(f => new Uri.Locator(["file"], undefined, f.split(path_browser.sep)))) : undefined;
    }
}
exports.FolderReader = FolderReader;
Reader_1.Reader.addOpener((resource) => FolderReader.open(resource), 0);
//# sourceMappingURL=FolderReader.js.map
});

const FolderReader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(FolderReader_1);

var Enumerator_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function* generate(next) {
    let result;
    while ((result = next()) != undefined)
        yield result;
}
function isIterator(item) {
    return item.next instanceof Function;
}
function* merge(left, right) {
    let result;
    while (!(result = left.next()).done)
        yield result.value;
    if (isIterator(right))
        while (!(result = right.next()).done)
            yield result.value;
    else
        yield right;
}
class Enumerator {
    constructor(backend) {
        this.iterator = backend instanceof Function ? generate(backend) : backend;
    }
    get length() {
        let result = 0;
        while (!this.next().done)
            result++;
        return result;
    }
    get last() {
        return this.nextValue && !this.nextValue.done ? this.nextValue.value : undefined;
    }
    fetch() {
        const result = this.next();
        return result.done ? undefined : result.value;
    }
    next(value) {
        return this.nextValue = this.iterator.next(value);
    }
    append(item) {
        return new Enumerator(merge(this, item));
    }
    map(mapping) {
        return new Enumerator(() => {
            const item = this.fetch();
            return (item != undefined) ? mapping(item) : undefined;
        });
    }
    reduce(reduce, result) {
        const item = this.fetch();
        return item ? this.reduce(reduce, reduce(result, item)) : result;
    }
    apply(apply) {
        const item = this.fetch();
        if (item) {
            apply(item);
            this.apply(apply);
        }
    }
    filter(filter) {
        return new Enumerator(() => {
            let item;
            do
                item = this.fetch();
            while (item != undefined && !filter(item));
            return item;
        });
    }
    toArray() {
        const item = this.fetch();
        let result;
        if (!item)
            result = [];
        else {
            result = this.toArray();
            result.unshift(item);
        }
        return result;
    }
    static from(backend) {
        return new Enumerator(backend);
    }
}
exports.Enumerator = Enumerator;
Enumerator.empty = Enumerator.from(() => undefined);
//# sourceMappingURL=Enumerator.js.map
});

const Enumerator = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Enumerator_1);

var Enumerable_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

function isIterable(other) {
    return other == null ? false : typeof other[Symbol.iterator] === "function";
}
class Enumerable {
    constructor(get) {
        this.get = get;
    }
    get length() {
        return this.get().length;
    }
    get first() {
        return this.get().fetch();
    }
    get last() {
        return this.get().last;
    }
    getEnumerator() {
        return new Enumerator_1.Enumerator(this.get());
    }
    [Symbol.iterator]() {
        return this.getEnumerator();
    }
    append(item) {
        return new Enumerable(() => this.get().append(item));
    }
    map(mapping) {
        return new Enumerable(() => this.get().map(mapping));
    }
    reduce(reduce, result) {
        return this.get().reduce(reduce, result);
    }
    apply(apply) {
        this.get().apply(apply);
    }
    filter(filter) {
        return new Enumerable(() => this.get().filter(filter));
    }
    toArray() {
        return this.getEnumerator().toArray();
    }
    static from(get) {
        return isIterable(get) ? new Enumerable(() => new Enumerator_1.Enumerator(get[Symbol.iterator]())) : new Enumerable(() => {
            const r = get();
            return r instanceof Enumerator_1.Enumerator ? r : new Enumerator_1.Enumerator(r);
        });
    }
}
exports.Enumerable = Enumerable;
Enumerable.empty = Enumerable.from([]);
//# sourceMappingURL=Enumerable.js.map
});

const Enumerable = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Enumerable_1);

var ArrayEnumerator_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class ArrayEnumerator extends Enumerator_1.Enumerator {
    constructor(backend) {
        super(() => this.position < this.backend.length ? this.backend[this.position++] : undefined);
        this.backend = backend;
        this.position = 0;
    }
}
exports.ArrayEnumerator = ArrayEnumerator;
//# sourceMappingURL=ArrayEnumerator.js.map
});

const ArrayEnumerator = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(ArrayEnumerator_1);

var BufferedEnumerator_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class BufferedEnumerator extends Enumerator_1.Enumerator {
    constructor(backend) {
        super(() => {
            const result = this.peek(0);
            if (this.buffer.length > 0)
                this.buffer.shift();
            return result;
        });
        this.backend = backend;
        this.buffer = [];
    }
    peek(position) {
        if (!position)
            position = 0;
        let next;
        while (position > this.buffer.length - 1 && (next = this.backend.fetch()))
            this.buffer.push(next);
        return position > this.buffer.length - 1 ? undefined : this.buffer[position];
    }
}
exports.BufferedEnumerator = BufferedEnumerator;
//# sourceMappingURL=BufferedEnumerator.js.map
});

const BufferedEnumerator = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(BufferedEnumerator_1);

var _String = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class String {
    static padLeft(value, paddingCharacter, width) {
        return String.pad(value, paddingCharacter, width, true);
    }
    static padRight(value, paddingCharacter, width) {
        return String.pad(value, paddingCharacter, width, false);
    }
    static pad(value, paddingCharacter, width, padLeft) {
        let padding = "";
        const count = width - value.length;
        for (let i = 0; i < count; i++)
            padding += paddingCharacter;
        return padLeft ? padding + value : value + padding;
    }
}
exports.String = String;
//# sourceMappingURL=String.js.map
});

const _String$1 = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(_String);

var Utilities = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.Enumerator = Enumerator_1.Enumerator;

exports.Enumerable = Enumerable_1.Enumerable;

exports.ArrayEnumerator = ArrayEnumerator_1.ArrayEnumerator;

exports.BufferedEnumerator = BufferedEnumerator_1.BufferedEnumerator;

exports.String = _String.String;
//# sourceMappingURL=index.js.map
});

const index$2 = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Utilities);

var OutDevice_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class OutDevice extends Device_1.Device {
}
exports.OutDevice = OutDevice;
//# sourceMappingURL=OutDevice.js.map
});

const OutDevice = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(OutDevice_1);

var Writer_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (_commonjsHelpers.commonjsGlobal && _commonjsHelpers.commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });



class Writer extends OutDevice_1.OutDevice {
    constructor() {
        super(...arguments);
        this.newLineSymbol = "\n";
    }
    write(message) {
        return __awaiter(this, void 0, void 0, function* () {
            return message instanceof Utilities.Enumerator ? this.writeImplementation(message) :
                message instanceof Array ? this.writeImplementation(new Utilities.ArrayEnumerator(message)) :
                    this.writeImplementation(new Utilities.ArrayEnumerator([message]));
        });
    }
    writeLine(message) {
        return __awaiter(this, void 0, void 0, function* () {
            return message instanceof Utilities.Enumerator ? this.writeImplementation(message.append(this.newLineSymbol)) :
                message instanceof Array ? this.writeImplementation(new Utilities.ArrayEnumerator([...message, this.newLineSymbol])) :
                    message ? this.writeImplementation(new Utilities.ArrayEnumerator([message, this.newLineSymbol])) :
                        this.writeImplementation(new Utilities.ArrayEnumerator([this.newLineSymbol]));
        });
    }
    static addOpener(open, priority) {
        if (!priority)
            priority = 0;
        Writer.openers.push({ open, priority });
        Writer.openers = Writer.openers.sort((left, right) => right.priority - left.priority);
    }
    static open(resource) {
        return __awaiter(this, void 0, void 0, function* () {
            let result;
            if (typeof (resource) == "string") {
                const r = Uri.Locator.parse(resource);
                result = r ? yield Writer.open(r) : undefined;
            }
            else {
                let i = 0;
                do
                    result = yield Writer.openers[i++].open(resource);
                while (!result && i < Writer.openers.length);
            }
            return result;
        });
    }
}
exports.Writer = Writer;
Writer.openers = [];
//# sourceMappingURL=Writer.js.map
});

const Writer = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Writer_1);

var Indenter_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

class Indenter extends Writer_1.Writer {
    constructor(backend) {
        super();
        this.backend = backend;
        this.autoFlush = true;
        this.indentionSymbol = "\t";
        this.indentionCount = 0;
        this.indentNext = false;
    }
    get resource() { return this.backend.resource; }
    get opened() { return this.backend.opened; }
    get writable() { return this.backend.writable; }
    flush() {
        return this.backend.flush();
    }
    close() {
        return this.backend.close();
    }
    increase() {
        this.indentionCount++;
        return true;
    }
    decrease() {
        this.indentionCount--;
        return this.indentionCount >= 0;
    }
    getIndention() {
        return this.indentionSymbol.repeat(this.indentionCount);
    }
    writeImplementation(buffer) {
        const result = [];
        let item;
        let next = buffer.fetch();
        if (next)
            do {
                item = next;
                next = buffer.fetch();
                if (this.indentNext)
                    item = this.getIndention() + item;
                this.indentNext = item.endsWith(this.newLineSymbol);
                item = item.replace(this.newLineSymbol, this.newLineSymbol + this.getIndention());
                if (this.indentNext)
                    item = item.substring(0, item.length - this.indentionCount * this.indentionSymbol.length);
                result.push(this.backend.write(item));
            } while (next);
        return Promise.all(result).then(r => r.reduce((previous, current) => previous && current, true));
    }
}
exports.Indenter = Indenter;
//# sourceMappingURL=Indenter.js.map
});

const Indenter = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(Indenter_1);

var PrefixReader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class PrefixReader extends Reader_1.Reader {
    constructor(backend, prefix) {
        super();
        this.prefix = prefix;
        this.done = false;
        this.backend = backend instanceof BufferedReader_1.BufferedReader ? backend : BufferedReader_1.BufferedReader.create(backend);
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return this.backend.opened; }
    get isEmpty() { return this.done || this.backend.isEmpty; }
    get resource() { return this.backend.resource; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        return this.backend.close();
    }
    read() {
        let result;
        if (!this.done) {
            result = this.backend.read();
            this.done = result == "\n" && !this.backend.readIf(this.prefix) && !this.backend.peekIs("\n");
        }
        return result;
    }
    mark() { return this.backend.mark(); }
    static create(backend, prefix) {
        return backend && prefix ? new PrefixReader(backend, prefix) : backend;
    }
}
exports.PrefixReader = PrefixReader;
//# sourceMappingURL=PrefixReader.js.map
});

const PrefixReader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(PrefixReader_1);

var FileWriter_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
var __awaiter = (_commonjsHelpers.commonjsGlobal && _commonjsHelpers.commonjsGlobal.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });



class FileWriter extends Writer_1.Writer {
    constructor(resource, descriptor) {
        super();
        this.resource = resource;
        this.descriptor = descriptor;
        this.autoFlush = false;
    }
    get opened() { return this.descriptor > 0; }
    get writable() { return this.descriptor > 0; }
    flush() {
        return __awaiter(this, void 0, void 0, function* () {
            let result = true;
            try {
                yield fs_browser.fsync(this.descriptor);
            }
            catch (error) {
                result = false;
            }
            return result;
        });
    }
    close() {
        return __awaiter(this, void 0, void 0, function* () {
            let result = this.opened;
            if (result) {
                try {
                    yield fs_browser.close(this.descriptor);
                }
                catch (error) {
                    result = false;
                }
                this.descriptor = 0;
            }
            return result;
        });
    }
    writeImplementation(buffer) {
        return __awaiter(this, void 0, void 0, function* () {
            let result = true;
            const content = Buffer.from(buffer.reduce((r, item) => r + item, ""));
            try {
                const r = yield fs_browser.write(this.descriptor, content, 0, "utf8");
                result = r.bytesWritten == content.length;
            }
            catch (error) {
                result = false;
            }
            return result && (!this.autoFlush || (yield this.flush()));
        });
    }
    static open(resource) {
        return __awaiter(this, void 0, void 0, function* () {
            let backend;
            if (resource && (resource.scheme.length == 0 || resource.scheme.length == 1 && resource.scheme[0] == "file"))
                try {
                    backend = yield fs_browser.open((resource.isRelative ? "" : path_browser.sep) + resource.path.join(path_browser.sep), "w");
                }
                catch (error) {
                    backend = undefined;
                }
            return backend ? new FileWriter(resource, backend) : undefined;
        });
    }
}
exports.FileWriter = FileWriter;
Writer_1.Writer.addOpener(FileWriter.open);
//# sourceMappingURL=FileWriter.js.map
});

const FileWriter = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(FileWriter_1);

var TillReader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class TillReader extends Reader_1.Reader {
    constructor(backend, endMark) {
        super();
        this.endMark = endMark;
        this.done = false;
        this.backend = backend instanceof BufferedReader_1.BufferedReader ? backend : BufferedReader_1.BufferedReader.create(backend);
        this.done = this.backend.peekIs(this.endMark) != undefined;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return !this.done && this.backend.opened; }
    get isEmpty() { return this.done || this.backend.isEmpty; }
    get resource() { return this.backend.resource; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        const result = !this.done;
        if (result)
            this.done = true;
        return Promise.resolve(result);
    }
    read() {
        let result;
        if (!this.done) {
            result = this.backend.read();
            this.done = this.backend.peekIs(this.endMark) != undefined;
        }
        return result;
    }
    mark() { return this.backend.mark(); }
    static create(backend, endMark) {
        return backend && endMark ? new TillReader(backend, endMark) : backend;
    }
}
exports.TillReader = TillReader;
//# sourceMappingURL=TillReader.js.map
});

const TillReader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(TillReader_1);

var UntilReader_1 = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });


class UntilReader extends Reader_1.Reader {
    constructor(backend, endMark) {
        super();
        this.endMark = endMark;
        this.done = -1;
        this.backend = backend instanceof BufferedReader_1.BufferedReader ? backend : BufferedReader_1.BufferedReader.create(backend);
        const peeked = this.backend.peekIs(this.endMark);
        if (peeked)
            this.done = peeked.length;
    }
    get tabSize() { return this.backend.tabSize; }
    set tabSize(size) { this.backend.tabSize = size; }
    get readable() { return this.backend.readable; }
    get opened() { return !this.done && this.backend.opened; }
    get isEmpty() { return this.done == 0 || this.backend.isEmpty; }
    get resource() { return this.backend.resource; }
    get location() { return this.backend.location; }
    get region() { return this.backend.region; }
    close() {
        const result = this.done > 0;
        if (result)
            this.done = 0;
        return Promise.resolve(result);
    }
    read() {
        let result;
        if (this.done != 0) {
            result = this.backend.read();
            let peeked;
            if (this.done > 0)
                this.done--;
            else if (peeked = this.backend.peekIs(this.endMark))
                this.done = peeked.length;
        }
        return result;
    }
    mark() { return this.backend.mark(); }
    static create(backend, endMark) {
        return backend && endMark ? new UntilReader(backend, endMark) : backend;
    }
}
exports.UntilReader = UntilReader;
//# sourceMappingURL=UntilReader.js.map
});

const UntilReader = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(UntilReader_1);

var IO = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.BufferedReader = BufferedReader_1.BufferedReader;

exports.Device = Device_1.Device;

exports.FileReader = FileReader_1.FileReader;

exports.FolderReader = FolderReader_1.FolderReader;

exports.Indenter = Indenter_1.Indenter;

exports.InDevice = InDevice_1.InDevice;

exports.OutDevice = OutDevice_1.OutDevice;

exports.PrefixReader = PrefixReader_1.PrefixReader;

exports.Reader = Reader_1.Reader;

exports.StringReader = StringReader_1.StringReader;

exports.FileWriter = FileWriter_1.FileWriter;

exports.TillReader = TillReader_1.TillReader;

exports.UntilReader = UntilReader_1.UntilReader;

exports.Writer = Writer_1.Writer;
//# sourceMappingURL=index.js.map
});

const index$1 = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(IO);

var build = _commonjsHelpers.createCommonjsModule(function (module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

exports.Error = _Error;

exports.IO = IO;

exports.Uri = Uri;

exports.Utilities = Utilities;
//# sourceMappingURL=index.js.map
});

const index = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(build);

exports.build = build;
