Skip to content

Commit 9f4857b

Browse files
committed
glayzzle#36 implement binary cast token
1 parent 25baed2 commit 9f4857b

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/parser.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ var parser = function(lexer) {
8686
this.tok.T_DIR,
8787
this.tok.T_NS_C,
8888
'"',
89+
'b"',
90+
'B"',
8991
'-',
9092
this.tok.T_NS_SEPARATOR
9193
],

src/parser/expr.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ module.exports = {
6565
*/
6666
,read_expr_item: function() {
6767

68-
if (this.token === this.tok.T_STRING) {
69-
var tokTxt = this.text();
70-
if (tokTxt === 'b' || tokTxt === 'B') this.token = this.tok.T_STRING_CAST;
71-
}
72-
7368
switch(this.token) {
7469

7570
case '@':

src/parser/scalar.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,38 @@ module.exports = {
3737
// TEXTS
3838
case this.tok.T_CONSTANT_ENCAPSED_STRING:
3939
var value = this.text();
40-
value = value.substring(1, value.length - 1).replace(
40+
var isBinCast = value[0] === 'b' || value[0] === 'B';
41+
if (isBinCast) {
42+
value = value.substring(2, value.length - 1);
43+
} else {
44+
value = value.substring(1, value.length - 1);
45+
}
46+
value = ['string', value.replace(
4147
/\\[rntvef"'\\\$]/g,
4248
function(seq) {
4349
return specialChar[seq];
4450
}
45-
);
51+
)];
52+
if (isBinCast) {
53+
value = ['cast', 'binary', value];
54+
}
4655
this.next();
4756
if (this.token === this.tok.T_DOUBLE_COLON) {
4857
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1151
49-
return this.read_static_getter(
50-
['string', value]
51-
);
58+
return this.read_static_getter(value);
5259
} else {
5360
// dirrect string
54-
return ['string', value];
61+
return value;
5562
}
5663
case this.tok.T_START_HEREDOC:
5764
return this.next().read_encapsed_string(
5865
this.tok.T_END_HEREDOC
5966
);
6067
case '"':
6168
return this.next().read_encapsed_string('"');
69+
case 'b"':
70+
case 'B"':
71+
return ['cast', 'binary', this.next().read_encapsed_string('"')];
6272

6373
// NUMERIC
6474
case '-': // long

0 commit comments

Comments
 (0)