proc_macro
Version:
A JavaScript implementation of proc_macros.
68 lines • 2.51 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 value (string, number).
*/
var Literal = /** @class */ (function (_super) {
__extends(Literal, _super);
function Literal(value, type) {
var _this = _super.call(this) || this;
_this.value = value;
_this.type = type;
return _this;
}
Literal.prototype.eq = function (other) {
if (other instanceof Literal) {
return other.value === this.value && other.type === this.type;
}
return false;
};
Literal.tokenize = function (token_string) {
var pointer = 0;
var type;
var tokens = token_string[pointer];
if (/\d/.test(tokens)) {
type = 'number';
while (pointer < token_string.length && /^\d+?\.{0,1}\d*?$/.test(tokens)) {
tokens += token_string[++pointer];
}
}
else if (tokens === '"' || tokens === "'") {
type = 'string';
var matching_token = tokens;
while (pointer < token_string.length && token_string[++pointer] != matching_token) { }
;
pointer++;
}
else {
throw Error("Next token is not a literal.");
}
return [new Literal(token_string.substring(0, pointer), type), token_string.substring(pointer)];
};
Literal.prototype.toParenthesisString = function () {
return "(Literal " + this.type + " " + this.value + ")";
};
Literal.prototype.toJavaScript = function () {
return this.value + " ";
};
return Literal;
}(token_1.default));
exports.default = Literal;
//# sourceMappingURL=literal.js.map