proc_macro
Version:
A JavaScript implementation of proc_macros.
56 lines • 2.35 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var token_1 = __importDefault(require("./token"));
/**
* A punctuation that is used in programming.
*/
var Punct = /** @class */ (function (_super) {
__extends(Punct, _super);
function Punct(char, spacing) {
var _this = _super.call(this) || this;
if (char.length !== 1)
throw Error("FATAL ERROR: Expected punctuation to be a single character. Use the `joint` spacing if punctuation should be joint.");
_this.char = char;
_this.spacing = spacing;
return _this;
}
Punct.prototype.eq = function (other) {
if (other instanceof Punct) {
return other.char === this.char && other.spacing === this.spacing;
}
return false;
};
Punct.tokenize = function (token_string) {
var _a = [token_string.substring(0, 1), token_string.substring(1)], char = _a[0], next_token_string = _a[1];
if (!/^[^\d\w\s\(\)\{\}\[\]\'\"\`]$/.test(char)) {
throw Error("Next token is not a punctuation.");
}
var spacing = Punct.canTokenize(next_token_string) ? 'joint' : 'alone';
return [new Punct(char, spacing), next_token_string];
};
Punct.prototype.toParenthesisString = function () {
return "(Punct " + this.spacing + " '" + this.char + "')";
};
Punct.prototype.toJavaScript = function () {
return this.char + ((this.spacing === 'joint') ? '' : ' ');
};
return Punct;
}(token_1.default));
exports.default = Punct;
//# sourceMappingURL=punct.js.map