Skip to content

Commit

Permalink
#108 - disable T_YIELD_FROM, T_SPACESHIP and T_COALESCE
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiriac committed Dec 28, 2017
1 parent 641ab89 commit 9b9ccc6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ var engine = function(options) {
this.ast = new AST();
this.parser = new parser(this.lexer, this.ast);
if (options && typeof options === 'object') {
// disable php7 from lexer if already disabled from parser
if (options.parser && options.parser.php7 === false) {
if (!options.lexer) {
options.lexer = {};
}
options.lexer.php7 = false;
}
combine(options, this);
}
};
Expand Down
1 change: 1 addition & 0 deletions src/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var lexer = function(engine) {
this.mode_eval = false;
this.asp_tags = false;
this.short_tags = true;
this.php7 = true;
this.yyprevcol = 0;
this.keywords = {
"__class__": this.tok.T_CLASS_C,
Expand Down
6 changes: 3 additions & 3 deletions src/lexer/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
var id = this.keywords[token];
if (typeof id !== 'number') {
if (token === 'yield') {
if (this.tryMatch(' from')) {
if (this.php7 && this.tryMatch(' from')) {
this.consume(5);
id = this.tok.T_YIELD_FROM;
} else {
Expand Down Expand Up @@ -151,7 +151,7 @@ module.exports = {
return '!';
},
'?': function() {
if (this._input[this.offset] === '?') {
if (this.php7 && this._input[this.offset] === '?') {
this.input();
return this.tok.T_COALESCE;
}
Expand All @@ -173,7 +173,7 @@ module.exports = {
return this.tok.T_SL;
} else if (nchar === '=') {
this.input();
if (this._input[this.offset] === '>') {
if (this.php7 && this._input[this.offset] === '>') {
this.input();
return this.tok.T_SPACESHIP;
} else {
Expand Down

0 comments on commit 9b9ccc6

Please sign in to comment.