derw
Version:
An Elm-inspired language that transpiles to TypeScript
135 lines (134 loc) • 4.19 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.patternHasGaps = exports.patternGapPositions = exports.destructureLength = exports.prefixLines = void 0;
const List = __importStar(require("../stdlib/List"));
function prefixLines(body, indent) {
function lineFn(line) {
if (line.trim() === "") {
return line;
}
else {
return `${" ".repeat(indent)}${line}`;
}
}
return (function (y) {
return y.join("\n");
})(List.map(lineFn, body.split("\n")));
}
exports.prefixLines = prefixLines;
function partLength(part, index) {
switch (part.kind) {
case "Destructure": {
return 1;
}
case "StringValue": {
return 1;
}
case "FormatStringValue": {
return 1;
}
case "EmptyList": {
return 0;
}
case "Value": {
if (index === 0) {
return 1;
}
else {
return 0;
}
;
}
}
}
function destructureLength(pattern) {
return List.foldl(function (x, y) {
return x + y;
}, 0, List.indexedMap(partLength, pattern.parts));
}
exports.destructureLength = destructureLength;
function GapPositionInfo(args) {
return Object.assign({}, args);
}
function patternGapPositions(pattern) {
function folder(part, info) {
switch (part.kind) {
case "Value": {
if (info.i > 0) {
return {
i: info.i - 1,
positions: [info.i, ...info.positions]
};
}
else {
return Object.assign(Object.assign({}, info), { i: info.i - 1 });
}
;
}
default: {
return Object.assign(Object.assign({}, info), { i: info.i - 1 });
}
}
}
return (function (y) {
return y.positions;
})(List.foldr(folder, {
i: pattern.parts.length - 1,
positions: []
}, pattern.parts));
}
exports.patternGapPositions = patternGapPositions;
function patternHasGaps(pattern) {
function hasGap(index, xs) {
switch (xs.length) {
case xs.length: {
if (xs.length >= 1) {
const [x, ...ys] = xs;
switch (x.kind) {
case "Value": {
if (index > 0) {
return true;
}
else {
return hasGap(index + 1, ys);
}
;
}
default: {
return hasGap(index + 1, ys);
}
}
;
}
}
default: {
return false;
}
}
}
return hasGap(0, pattern.parts);
}
exports.patternHasGaps = patternHasGaps;