Skip to content

Commit

Permalink
Fix lexing of octal literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten Staa committed Jun 24, 2022
1 parent 6881ec8 commit 648dfb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/lexer/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ module.exports = {
} else {
this.unput(ch ? 2 : 1);
}
// @fixme check octal notation ? not usefull
} else if (ch === "o" || ch === "O") {
ch = this.input();
if (ch !== "_" && this.is_OCTAL()) {
return this.consume_ONUM();
} else {
this.unput(ch ? 2 : 1);
}
} else if (!this.is_NUM()) {
if (ch) this.unput(1);
}
Expand Down Expand Up @@ -151,4 +157,15 @@ module.exports = {
}
return this.tok.T_LNUMBER;
},
// read an octal number
consume_ONUM: function () {
while (this.offset < this.size) {
const ch = this.input();
if (!this.is_OCTAL()) {
if (ch) this.unput(1);
break;
}
}
return this.tok.T_LNUMBER;
},
};
10 changes: 10 additions & 0 deletions src/lexer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,14 @@ module.exports = {
// else
return false;
},
// check if current char can be an octal number
is_OCTAL: function () {
const ch = this._input.charCodeAt(this.offset - 1);
// 0 - 7
if (ch > 47 && ch < 56) return true;
// _ (code 95)
if (ch === 95) return true;
// else
return false;
},
};

0 comments on commit 648dfb6

Please sign in to comment.