From bf9eec6b2365f82333dffa385a9105c3825d1921 Mon Sep 17 00:00:00 2001 From: Adam Jimenez Date: Mon, 2 Jun 2014 23:26:59 +0100 Subject: [PATCH] fix "{$foo->bar}"."{$foo->bar($a)}"."{$foo->bar(&$a, $b)}"; --- lib/ace/mode/php/php.js | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/ace/mode/php/php.js b/lib/ace/mode/php/php.js index ed23f641..74af47c2 100644 --- a/lib/ace/mode/php/php.js +++ b/lib/ace/mode/php/php.js @@ -717,34 +717,52 @@ PHP.Lexer = function( src, ini ) { var re; if ( curlyOpen > 0) { - re = /^([^\\\$"{}\]\)]|\\.)+/g; + re = /^([^\\\$"{}\]\)\->]|\\.)+/g; } else { re = /^([^\\\$"{]|\\.|{[^\$]|\$(?=[^a-zA-Z_\x7f-\uffff]))+/g;; } + var type, match2; while(( match = result.match( re )) !== null ) { - - if (result.length === 1) { throw new Error(match); } + + type = 0; - - - results.push([ - parseInt(( curlyOpen > 0 ) ? PHP.Constants.T_CONSTANT_ENCAPSED_STRING : PHP.Constants.T_ENCAPSED_AND_WHITESPACE, 10), - match[ 0 ].replace(/\n/g,"\\n").replace(/\r/g,""), - line - ]); + if( curlyOpen > 0 ){ + if( match2 = match[0].match(/^[\[\]\;\:\?\(\)\!\.\,\>\<\=\+\-\/\*\|\&\{\}\@\^\%\"\'\$\~]/) ){ + results.push(match2[0]); + }else{ + type = PHP.Constants.T_STRING; + } + }else{ + type = PHP.Constants.T_ENCAPSED_AND_WHITESPACE; + } + + if( type ){ + results.push([ + parseInt(type, 10), + match[ 0 ].replace(/\n/g,"\\n").replace(/\r/g,""), + line + ]); + } line += match[ 0 ].split('\n').length - 1; result = result.substring( match[ 0 ].length ); + } + if( curlyOpen > 0 && result.match(/^\->/) !== null ) { + results.push([ + parseInt(PHP.Constants.T_OBJECT_OPERATOR, 10), + '->', + line + ]); + result = result.substring( 2 ); } if( result.match(/^{\$/) !== null ) { - results.push([ parseInt(PHP.Constants.T_CURLY_OPEN, 10), "{",