@rightcapital/phpdoc-parser
Version:
TypeScript version of PHPDoc parser with support for intersection types and generics
45 lines (44 loc) • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParserException = void 0;
const lexer_1 = require("../lexer/lexer");
class ParserException extends Error {
constructor(currentTokenValue, currentTokenType, currentOffset, expectedTokenType, expectedTokenValue = null, currentTokenLine = null) {
super();
this.currentTokenValue = currentTokenValue;
this.currentTokenType = currentTokenType;
this.currentOffset = currentOffset;
this.expectedTokenType = expectedTokenType;
this.expectedTokenValue = expectedTokenValue;
this.currentTokenLine = currentTokenLine;
this.message = `Unexpected token ${this.formatValue(currentTokenValue)}, expected ${lexer_1.Lexer.TOKEN_LABELS[expectedTokenType]}${expectedTokenValue !== null
? ` (${this.formatValue(expectedTokenValue)})`
: ''} at offset ${currentOffset}${currentTokenLine === null ? '' : ` on line ${currentTokenLine}`}`;
}
getCurrentTokenValue() {
return this.currentTokenValue;
}
getCurrentTokenType() {
return this.currentTokenType;
}
getCurrentOffset() {
return this.currentOffset;
}
getExpectedTokenType() {
return this.expectedTokenType;
}
getExpectedTokenValue() {
return this.expectedTokenValue;
}
getCurrentTokenLine() {
return this.currentTokenLine;
}
formatValue(value) {
const json = JSON.stringify(value);
if (!json) {
throw new Error('JSON encoding error');
}
return json;
}
}
exports.ParserException = ParserException;