babelute
Version:
Internal Domain Specific (Multi)Modeling javascript framework
81 lines (61 loc) • 3.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _lexem = require('../lexem');
var _lexem2 = _interopRequireDefault(_lexem);
var _babelute = require('../babelute');
var _babelute2 = _interopRequireDefault(_babelute);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // removed in production
/**
* @author Gilles Coomans
* @licence MIT
* @copyright 2017 Gilles Coomans
*/
/**
* A FirstLevel is a Babelute that has exactly same api than its corresponding Babelute (from a DSL) but where every compounds methods has been replaced by its "atomic" equivalent.
* (Same concept than 'first-level of understanding', as if we where stupid by always understanding only first literal sens of words.)
*
* It provides sentences and lexems without any interpretation, and that could be really useful : e.g.
* - to see sentence as "editable document" and/or for allowing meta-writing of sentences
* - to obtain the full AST of babelute sentences
*
* @access protected
*/
var FirstLevel = function (_Babelute) {
_inherits(FirstLevel, _Babelute);
/**
* construct a firstlevel babelute instance
* @param {?Array} lexems array of lexems for init. (only for internal use)
*/
function FirstLevel(lexems) {
_classCallCheck(this, FirstLevel);
var _this = _possibleConstructorReturn(this, (FirstLevel.__proto__ || Object.getPrototypeOf(FirstLevel)).call(this, lexems));
_this.__first_level_babelute__ = true;
return _this;
}
/**
* return a FirstLevelMethod aka a method that only append an atom (lexicon, name, args)
* @param {String} lexiconName the lexicon name of the appended atom
* @param {String} lexemName the lexem name of the appended atom
* @return {Function} a function that append the atom
*/
_createClass(FirstLevel, null, [{
key: 'getFirstLevelMethod',
value: function getFirstLevelMethod(lexiconName, lexemName) {
return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
this._lexems.push(new _lexem2.default(lexiconName, lexemName, args));
return this;
};
}
}]);
return FirstLevel;
}(_babelute2.default);
exports.default = FirstLevel;