All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.prompto.statement.RaiseStatement.js Maven / Gradle / Ivy

var SimpleStatement = require("./SimpleStatement").SimpleStatement;
var CategoryType = require("../type/CategoryType").CategoryType;
var VoidType = require("../type/VoidType").VoidType;
var SyntaxError = require("../error/SyntaxError").SyntaxError;
var UserError = require("../error/UserError").UserError;
var Dialect = require("../parser/Dialect").Dialect;
var Identifier = require("../grammar/Identifier").Identifier;

function RaiseStatement(expression) {
	SimpleStatement.call(this);
	this.expression = expression;
	return this;
}

RaiseStatement.prototype = Object.create(SimpleStatement.prototype);
RaiseStatement.prototype.constructor = RaiseStatement;

RaiseStatement.prototype.toString = function() {
	return "raise " + this.expression.toString();
};

RaiseStatement.prototype.equals = function(obj) {
	if(obj==this) {
		return true;
	} else if(!(obj instanceof RaiseStatement)) {
		return false;
	} else {
		return this.expression.equals(other.expression);
	}
};

RaiseStatement.prototype.check = function(context) {
	var type = this.expression.check(context);
	if(!new CategoryType(new Identifier("Error")).isAssignableFrom(context, type)) {
		throw new SyntaxError(type.name + " does not extend Error");
	}
	return VoidType.instance;
};

RaiseStatement.prototype.interpret = function(context) {
	throw new UserError(this.expression);
};

RaiseStatement.prototype.toDialect = function(writer) {
    switch(writer.dialect) {
        case Dialect.E:
        case Dialect.M:
            writer.append("raise ");
            break;
        case Dialect.O:
            writer.append("throw ");
            break;
    }
    this.expression.toDialect(writer);
};

exports.RaiseStatement = RaiseStatement;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy