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

js.prompto.grammar.IdentifierList.js Maven / Gradle / Ivy

var ObjectList = require("../utils/ObjectList").ObjectList;
var Dialect = require("../parser/Dialect").Dialect;

function IdentifierList(item) {
    ObjectList.call(this);
	item = item || null;
	if(item!==null) {
		this.add(item);
	}
	return this;
}

IdentifierList.prototype = Object.create(ObjectList.prototype);
IdentifierList.prototype.constructor = IdentifierList;


IdentifierList.parse = function(ids) {
    var result = new IdentifierList();
	ids.split(",").forEach(function(part) {
        result.add(part);
    });
	return result;
};

IdentifierList.prototype.names = function() {
    return this.map(function(id) { return id.name; } );
};

IdentifierList.prototype.toDialect = function(writer, finalAnd) {
    finalAnd = finalAnd || false;
    switch(writer.dialect) {
        case Dialect.E:
            this.toEDialect(writer, finalAnd);
            break;
        case Dialect.O:
            this.toODialect(writer);
            break;
        case Dialect.M:
            this.toMDialect(writer);
            break;
    }
};

IdentifierList.prototype.toEDialect = function(writer, finalAnd) {
    switch(this.length) {
        case 0:
            return;
        case 1:
            writer.append(this[0].name);
            break;
        default:
            for(var i=0;i0) {
        this.forEach(function(id) {
            writer.append(id.name);
            writer.append(", ");
        });
        writer.trimLast(2);
    }
};

IdentifierList.prototype.toMDialect = function(writer) {
    this.toODialect(writer);
};

exports.IdentifierList = IdentifierList;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy