diff --git a/src/index.js b/src/index.js index a9ecf85bb..a86b24059 100644 --- a/src/index.js +++ b/src/index.js @@ -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); } }; diff --git a/src/lexer.js b/src/lexer.js index 7cb31f57c..3ee3be033 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -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, diff --git a/src/lexer/tokens.js b/src/lexer/tokens.js index 96e0f635e..2cccf4723 100644 --- a/src/lexer/tokens.js +++ b/src/lexer/tokens.js @@ -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 { @@ -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; } @@ -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 {