Skip to content

Commit 648dfb6

Browse files
author
Maarten Staa
committed
Fix lexing of octal literals.
1 parent 6881ec8 commit 648dfb6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/lexer/numbers.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ module.exports = {
3535
} else {
3636
this.unput(ch ? 2 : 1);
3737
}
38-
// @fixme check octal notation ? not usefull
38+
} else if (ch === "o" || ch === "O") {
39+
ch = this.input();
40+
if (ch !== "_" && this.is_OCTAL()) {
41+
return this.consume_ONUM();
42+
} else {
43+
this.unput(ch ? 2 : 1);
44+
}
3945
} else if (!this.is_NUM()) {
4046
if (ch) this.unput(1);
4147
}
@@ -151,4 +157,15 @@ module.exports = {
151157
}
152158
return this.tok.T_LNUMBER;
153159
},
160+
// read an octal number
161+
consume_ONUM: function () {
162+
while (this.offset < this.size) {
163+
const ch = this.input();
164+
if (!this.is_OCTAL()) {
165+
if (ch) this.unput(1);
166+
break;
167+
}
168+
}
169+
return this.tok.T_LNUMBER;
170+
},
154171
};

src/lexer/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,14 @@ module.exports = {
9999
// else
100100
return false;
101101
},
102+
// check if current char can be an octal number
103+
is_OCTAL: function () {
104+
const ch = this._input.charCodeAt(this.offset - 1);
105+
// 0 - 7
106+
if (ch > 47 && ch < 56) return true;
107+
// _ (code 95)
108+
if (ch === 95) return true;
109+
// else
110+
return false;
111+
},
102112
};

0 commit comments

Comments
 (0)