Skip to content

Commit

Permalink
fix: correct highlight of php heredoc strings with one word on line
Browse files Browse the repository at this point in the history
  • Loading branch information
mkslanc committed Jul 19, 2022
1 parent a194253 commit ae4564c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
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) {
Expand Down
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"
],[
Expand Down Expand Up @@ -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
Expand Up @@ -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 : ".*"
Expand Down

0 comments on commit ae4564c

Please sign in to comment.