js-slang
Version:
Javascript-based implementations of Source, written in Typescript
48 lines • 1.6 kB
JavaScript
/**
* A generic mapper for all languages.
* If required, maps the final result produced by js-slang to
* the required representation for the language.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.mapResult = exports.Representation = void 0;
const types_1 = require("../types");
const scheme_mapper_1 = require("./scheme/scheme-mapper");
/**
* A representation of a value in a language.
* This is used to represent the final value produced by js-slang.
* It is separate from the actual value of the result.
*/
class Representation {
constructor(representation) {
this.representation = representation;
}
toString() {
return this.representation;
}
}
exports.Representation = Representation;
function mapResult(context) {
switch (context.chapter) {
case types_1.Chapter.SCHEME_1:
case types_1.Chapter.SCHEME_2:
case types_1.Chapter.SCHEME_3:
case types_1.Chapter.SCHEME_4:
case types_1.Chapter.FULL_SCHEME:
return x => {
if (x.status === 'finished') {
return (0, scheme_mapper_1.mapResultToScheme)(x);
}
else if (x.status === "error") {
context.errors = context.errors.map(scheme_mapper_1.mapErrorToScheme);
}
return x;
};
default:
// normally js-slang.
// there is no need for a mapper in this case.
return x => x;
}
}
exports.mapResult = mapResult;
//# sourceMappingURL=mapper.js.map
;