[language-php] Add a firstLineRegex

…so that the grammar-choosing logic picks the modern Tree-sitter grammar more consistently.
This commit is contained in:
Andrew Dupont 2024-05-18 16:04:25 -07:00
parent 55e869c786
commit 8bf199ad72

View File

@ -5,6 +5,15 @@ parser: 'tree-sitter-php'
injectionRegex: 'php|PHP'
# The TextMate grammar has an elaborate `firstLineMatch` pattern defined with
# Oniguruma; it catches hashbang syntax and complex vim/emacs modelines along
# with the typical `<?php` prefix.
#
# We can't compete with all that, but we can catch obvious instances of
# shebangs and `<?php`s. In fact, we must, or else the TextMate grammar will be
# ranked higher for certain files.
firstLineRegex: '^\\s*<\\?(?:php|PHP|=|\\s|$)|^\\#!.*(?:\\s|\\/)php\\d?'
treeSitter:
parserSource: 'github:tree-sitter/tree-sitter-php#b569a5f2c0d592e67430520d1a0e1f765d83ceb0'
grammar: 'tree-sitter/tree-sitter-php.wasm'