errors.js 621 B

12345678910111213141516171819202122
  1. exports.error = function(options) {
  2. return new Error(options);
  3. };
  4. var Error = function(options) {
  5. this.expected = options.expected;
  6. this.actual = options.actual;
  7. this._location = options.location;
  8. };
  9. Error.prototype.describe = function() {
  10. var locationDescription = this._location ? this._location.describe() + ":\n" : "";
  11. return locationDescription + "Expected " + this.expected + "\nbut got " + this.actual;
  12. };
  13. Error.prototype.lineNumber = function() {
  14. return this._location.lineNumber();
  15. };
  16. Error.prototype.characterNumber = function() {
  17. return this._location.characterNumber();
  18. };