Permalink
Browse files

Make js2-mode happy

See #64
  • Loading branch information...
1 parent 495ce97 commit 57458b87b04e40a4eb279fd9d54562a45fe6e115 Jonas Westerlund committed Feb 1, 2014
Showing with 44 additions and 44 deletions.
  1. +44 −44 lib/parser.js
View
@@ -49,20 +49,20 @@ ParseError.prototype.__proto__ = Error.prototype;
* @param {Buffer?} buffer
* @property {Buffer} buffer
* @property {number} index
- * @property {number} char
+ * @property {number} chr
*/
function Parser(buffer) {
this.buffer = null;
this.index = 0;
- this.char = END_OF_FILE;
+ this.chr = END_OF_FILE;
if (Buffer.isBuffer(buffer)) {
this.buffer = buffer;
- this.char = buffer[0];
+ this.chr = buffer[0];
}
}
Parser.prototype.advance = function() {
- this.char = this.buffer[++this.index] || END_OF_FILE;
+ this.chr = this.buffer[++this.index] || END_OF_FILE;
};
/** @param {Buffer} buffer
@@ -72,7 +72,7 @@ Parser.prototype.advance = function() {
Parser.prototype.parse = function(buffer) {
this.buffer = buffer;
this.index = 0;
- this.char = buffer[0];
+ this.chr = buffer[0];
const msg = this.parseMessage();
this.reset();
return msg;
@@ -81,7 +81,7 @@ Parser.prototype.parse = function(buffer) {
Parser.prototype.reset = function() {
this.buffer = null;
this.index = 0;
- this.char = END_OF_FILE;
+ this.chr = END_OF_FILE;
};
/** Parse a complete message.
@@ -105,11 +105,11 @@ Parser.prototype.parsePrefix = function() {
this.advance();
const start = this.index;
while (true) {
- const char = this.char;
- if (char === SPACE) {
+ const chr = this.chr;
+ if (chr === SPACE) {
return server(this.buffer.toString(null, start, this.index));
}
- if (char === EXCLAMATION_MARK || char === COMMERCIAL_AT) {
+ if (chr === EXCLAMATION_MARK || chr === COMMERCIAL_AT) {
return this.parsePerson(this.buffer.toString(null, start, this.index));
}
this.advance();
@@ -123,25 +123,25 @@ Parser.prototype.parsePrefix = function() {
Parser.prototype.parsePerson = function(nick) {
let user = null;
let host = null;
- if (this.char === EXCLAMATION_MARK) {
+ if (this.chr === EXCLAMATION_MARK) {
this.advance();
const start = this.index;
while (true) {
- if (this.char === COMMERCIAL_AT) {
+ if (this.chr === COMMERCIAL_AT) {
break;
}
- if (isTerminating(this.char)) {
+ if (isTerminating(this.chr)) {
this.throwParseError("premature end of input while parsing message prefix");
}
this.advance();
}
user = this.buffer.toString(null, start, this.index);
}
- if (this.char === COMMERCIAL_AT) {
+ if (this.chr === COMMERCIAL_AT) {
this.advance();
const start = this.index;
while (true) {
- if (this.char === SPACE) {
+ if (this.chr === SPACE) {
break;
}
this.advance();
@@ -154,13 +154,13 @@ Parser.prototype.parsePerson = function(nick) {
/** @return {string} */
Parser.prototype.parseCommand = function() {
const start = this.index;
- if (isNumber(this.char)) {
+ if (isNumber(this.chr)) {
this.advance();
this.advance();
this.advance();
return this.buffer.toString(null, start, this.index);
}
- while (isLetter(this.char)) {
+ while (isLetter(this.chr)) {
this.advance();
}
const command = this.buffer.toString(null, start, this.index);
@@ -173,7 +173,7 @@ Parser.prototype.parseParams = function() {
while (true) {
params.push(this.parseParam());
this.skipSpaces();
- if (isTerminating(this.char) || this.isEndOfBuffer()) {
+ if (isTerminating(this.chr) || this.isEndOfBuffer()) {
break;
}
}
@@ -183,10 +183,10 @@ Parser.prototype.parseParams = function() {
/** @return {string} */
Parser.prototype.parseParam = function() {
const start = this.index;
- const isTrailing = this.char === COLON;
+ const isTrailing = this.chr === COLON;
while (true) {
- if (isTerminating(this.char) ||
- (!isTrailing && this.char === SPACE) ||
+ if (isTerminating(this.chr) ||
+ (!isTrailing && this.chr === SPACE) ||
this.isEndOfBuffer()) {
break;
}
@@ -205,16 +205,16 @@ Parser.prototype.parseMode = function() {
map.set(PLUS_SIGN, []);
map.set(HYPHEN_MINUS, []);
while (true) {
- const char = this.char;
- if (!(char === PLUS_SIGN || char === HYPHEN_MINUS)) {
+ const chr = this.chr;
+ if (!(chr === PLUS_SIGN || chr === HYPHEN_MINUS)) {
this.throwParseError(format("expected '%s' or '%s'",
PLUS_SIGN.toString(16), HYPHEN_MINUS.toString(16)));
}
- const sign = char;
+ const sign = chr;
const arr = map.get(sign);
this.advance();
- while (isLetter(this.char)) {
- arr.push(String.fromCharCode(this.char));
+ while (isLetter(this.chr)) {
+ arr.push(String.fromCharCode(this.chr));
this.advance();
}
if (this.isEndOfBuffer()) {
@@ -228,15 +228,15 @@ Parser.prototype.parseMode = function() {
* @return {Channel}
*/
Parser.prototype.parseChannel = function() {
- const prefix = this.char;
+ const prefix = this.chr;
if (!(prefix === EXCLAMATION_MARK || prefix === NUMBER_SIGN ||
prefix === AMPERSAND || prefix === PLUS_SIGN)) {
this.throwParseError(format("expected one of '%s', '%s', '%s', or '%s'",
printCC(EXCLAMATION_MARK), printCC(NUMBER_SIGN),
printCC(AMPERSAND), printCC(PLUS_SIGN)));
}
while (true) {
- const chr = this.char;
+ const chr = this.chr;
if (chr === SPACE || chr === BELL || chr === COMMA || chr === COLON) {
this.throwParseError("can not be used in channel name");
}
@@ -250,12 +250,12 @@ Parser.prototype.parseChannel = function() {
/** @return {boolean} */
Parser.prototype.isPrefix = function() {
- return this.char === COLON && this.index === 0;
+ return this.chr === COLON && this.index === 0;
};
/** @return {boolean} */
Parser.prototype.isEndOfMessage = function() {
- return this.char === CARRIAGE_RETURN &&
+ return this.chr === CARRIAGE_RETURN &&
this.buffer[this.index + 1] === LINE_FEED;
};
@@ -266,7 +266,7 @@ Parser.prototype.isEndOfBuffer = function() {
/** Advance until next non-space char. */
Parser.prototype.skipSpaces = function() {
- while (this.char === SPACE) {
+ while (this.chr === SPACE) {
this.advance();
}
};
@@ -277,37 +277,37 @@ Parser.prototype.skipSpaces = function() {
Parser.prototype.throwParseError = function(expected) {
const expectation = expected ? "; " + expected : "";
const message = format("Unexpected char '%s' at index %d%s",
- printCC(this.char), this.index, expectation);
+ printCC(this.chr), this.index, expectation);
throw new ParseError(message);
};
-/** @param {number} char
+/** @param {number} chr
* @return {boolean}
*/
-function isLetter(char) {
- return (0x41 <= char && char <= 0x5A) ||
- (0x61 <= char && char <= 0x7A);
+function isLetter(chr) {
+ return (0x41 <= chr && chr <= 0x5A) ||
+ (0x61 <= chr && chr <= 0x7A);
}
-/** @param {number} char
+/** @param {number} chr
* @return {boolean}
*/
-function isNumber(char) {
- return 0x30 <= char && char <= 0x39;
+function isNumber(chr) {
+ return 0x30 <= chr && chr <= 0x39;
}
-/** @param {number} char
+/** @param {number} chr
* @return {boolean}
*/
-function isAlphaNumeric(char) {
- return isLetter(char) || isNumber(char);
+function isAlphaNumeric(chr) {
+ return isLetter(chr) || isNumber(chr);
}
-/** @param {number} char
+/** @param {number} chr
* @return {boolean}
*/
-function isTerminating(char) {
- return char === CARRIAGE_RETURN || char === LINE_FEED;
+function isTerminating(chr) {
+ return chr === CARRIAGE_RETURN || chr === LINE_FEED;
}
// Convenience functions.

0 comments on commit 57458b8

Please sign in to comment.