Handle nowdocs in PHP

This commit is contained in:
Andrew Dupont 2024-01-05 12:18:22 -08:00
parent ad8a215c77
commit 58b9cc1865
2 changed files with 26 additions and 1 deletions

View File

@ -303,7 +303,8 @@
(encapsed_string
(escape_sequence) @constant.character.escape.php)
(heredoc) @string.unquoted.heredoc.php
[(heredoc) (nowdoc)] @string.unquoted.heredoc.php
[
"abstract"

View File

@ -73,6 +73,9 @@ exports.activate = function () {
includeAdjacentWhitespace: true
});
// TODOs and URLs
// ==============
const TODO_PATTERN = /\b(TODO|FIXME|CHANGED|XXX|IDEA|HACK|NOTE|REVIEW|NB|BUG|QUESTION|COMBAK|TEMP|DEBUG|OPTIMIZE|WARNING)\b/;
const HYPERLINK_PATTERN = /\bhttps?:/
@ -104,6 +107,9 @@ exports.activate = function () {
});
}
// HEREDOCS and NOWDOCS
// ====================
atom.grammars.addInjectionPoint('text.html.php', {
type: 'heredoc',
language(node) {
@ -118,6 +124,24 @@ exports.activate = function () {
}
});
atom.grammars.addInjectionPoint('text.html.php', {
type: 'nowdoc',
language(node) {
let id = node.firstNamedChild;
if (id.type !== 'heredoc_start') return null;
return id.text;
},
content(node) {
let body = node.children.find(c => c.type === 'nowdoc_body');
let results = body.children.filter(c => c.type === 'nowdoc_string');
return results;
}
});
// PHPDoc
// ======
atom.grammars.addInjectionPoint('text.html.php', {
type: 'comment',
language(node) {