proc_macro
Version:
A JavaScript implementation of proc_macros.
56 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Abstract definition of a parsing token.
*/
var Token = /** @class */ (function () {
function Token() {
}
/**
* Method that attempts to tokenize the next char(s).
* @param _ The string to try to tokenize.
* @event TokenizeError If the next char(s) cannot be tokenized, an error is produced.
*/
Token.tokenize = function (_) {
throw Error("Tokenize not implemented for this token. Please implement it.");
};
/**
* Checks if the structure can be tokenized.
* @param tokenString The string trying to tokenize.
*/
Token.canTokenize = function (tokenString) {
try {
this.tokenize(tokenString);
return true;
}
catch (e) {
return false;
}
};
/**
* Method that attempts to parse the next token into this token.
* @throws If the next token(s) cannot be parsed, an error is produced.
*/
Token.parse = function (tokenStream) {
var nextToken = tokenStream.shiftNext();
if (nextToken === undefined)
throw tokenStream.error("No token to parse.");
return nextToken.next;
};
/**
* Checks if the class can be parsed.
* @param tokenStream The TokenStream trying to parse.
*/
Token.canParse = function (tokenStream) {
try {
this.parse(tokenStream.clone());
return true;
}
catch (e) {
return false;
}
};
return Token;
}());
exports.default = Token;
//# sourceMappingURL=token.js.map