parseNumber()

in lib/lexer.js [230:278]


  parseNumber() {
    let start = this.loc();
    let v = '';
    let type = 'integer';
    if (this.peek === '-') { //optionalSign
      v += '-';
      this.getch();
    }

    v += this.decimalLit();
    let fraction = this.optionalFraction();
    if (fraction) {
      type = 'float';
    }
    v += fraction;
    //optionalType
    if (this.peek === 'f') {
      this.getch();
      type = 'float';
      return new NumberLiteral(parseFloat(v), type, {
        start,
        end: this.loc()
      });
    } else if (this.peek === 'd') {
      this.getch();
      type = 'double';
      return new NumberLiteral(parseFloat(v), type, {
        start,
        end: this.loc()
      });
    } else if (this.peek === 'L') {
      this.getch();
      type = 'long';
      return new NumberLiteral(parseInt(v), type, {
        start,
        end: this.loc()
      });
    } 
    if (type === 'integer') {
      return new NumberLiteral(parseInt(v), type, {
        start,
        end: this.loc()
      });
    } 
    return new NumberLiteral(parseFloat(v), type, {
      start,
      end: this.loc()
    });
  }