Skip to content

Commit

Permalink
Merge pull request #4847 from mkslanc/php-heredoc-highlight
Browse files Browse the repository at this point in the history
fix: Correct highlight of PHP heredoc strings with one word on line
andrewnester authored Jul 19, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents da96818 + ae4564c commit df70368
Showing 4 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion demo/kitchen-sink/mini_require.js
Original file line number Diff line number Diff line change
@@ -503,7 +503,7 @@
if (!/^\w+:/.test(path)) path = host + path;
var onLoad = function(e, val) {
if (e) return processLoadQueue({id: id, path: path});
if (!/^(\s|\/\*([^*]|[*](?!\/))*\*\/|\/\/.*\n)*define\(function\(require/.test(val))
if (!/^(\s|\/\*([^*]|[*](?!\/))*\*\/|\/\/.*[\r]?\n)*define\(function\(require/.test(val))
val = "define(function(require, exports, module){" + val + "\n});"
nextModule = {name: id};
/* eslint no-eval:0 */
9 changes: 9 additions & 0 deletions lib/ace/mode/_test/text_php.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<?php
$bar = <<<EOD
highlightingWithNoSpaces
doesn't break
EOD;

lorem('ipsum', <<<TEST
foo bar
TEST
);

function nfact($n) {
if ($n == 0) {
39 changes: 38 additions & 1 deletion lib/ace/mode/_test/tokens_php.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,43 @@
[[
"php-start",
["support.php_tag","<?php"]
],[
["php-heredoc","EOD"],
["variable","$bar"],
["text"," "],
["keyword.operator","="],
["text"," "],
["markup.list","<<<EOD"]
],[
["php-heredoc","EOD"],
["string","highlightingWithNoSpaces"]
],[
["php-heredoc","EOD"],
["string","doesn't break"]
],[
"php-start",
["markup.list","EOD"],
["punctuation.operator",";"]
],[
"php-start"
],[
["php-heredoc","TEST"],
["identifier","lorem"],
["paren.lparen","("],
["string","'ipsum'"],
["punctuation.operator",","],
["text"," "],
["markup.list","<<<TEST"]
],[
["php-heredoc","TEST"],
["string","foo bar"]
],[
"php-start",
["markup.list","TEST"]
],[
"php-start",
["paren.rparen",")"],
["punctuation.operator",";"]
],[
"php-start"
],[
@@ -169,4 +206,4 @@
["constant.language.escape.reference.xml","&js;"]
],[
"start"
]]
]]
9 changes: 6 additions & 3 deletions lib/ace/mode/php_highlight_rules.js
Original file line number Diff line number Diff line change
@@ -1018,15 +1018,18 @@ sql_regcase'.split('|')
],
"heredoc" : [
{
onMatch : function(value, currentSate, stack) {
if (stack[1] != value)
onMatch : function(value, currentState, stack) {
if (stack[1] != value) {
this.next = "";
return "string";
}
stack.shift();
stack.shift();
this.next = this.nextState;
return "markup.list";
},
regex : "^\\w+(?=;?$)",
next: "start"
nextState: "start"
}, {
token: "string",
regex : ".*"

0 comments on commit df70368

Please sign in to comment.