after12am / toyscript

A small programing language for pythonian works on your browser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

simplify code using ternary operator in lexer.js

after12am opened this issue · comments

Lexer.prototype.consume = function() {
    if (this.c == '\n' || this.c == '\r') {
        this.column = 1;
    } else {
        this.column++;
    }
    this.p++;
    if (this.p < this.source.length) {
        this.c = this.source[this.p];
    } else {
        this.c = Token.EOF;
    }
}

like this:

this.column = (this.c == '\n' || this.c == '\r') ? 1 : this.column + 1;
this.p++;
this.c = (this.p < this.source.length) ? this.source[this.p] : Token.EOF;