Creating custom language injection for Regexp String in PHP
Hey all.
PHPStorm is bundled with a Language Injection for Regexp using the <<<REGEXP HEREDOC expression. I would like to also have it auto detect Regexp written in strings. For this I tried to create a custom language injection entry (see attached export).
Unfortunately, my attempt does not seem to work but I also don't understand why it wouldn't work, so I'm interested if anyone has any idea on this.
Things I want to match:
$var = "/someregex/";
preg_match("@someregexp@i","haystack",$matches);
So to this end I added the following:
+ phpLiteralExpression().withText(string().matchesBrics("^[/#@].*[/#@][gi]?$"))
Which I expected to work but doesn't... what am I doing wrong? I at first also wanted the ending group [/#@] to match using a backreference for the first group (as "([/#@])" and "\1" or "$1") but this syntax wasn't accepted and as such also didn't work :-/
Attachment(s):
regex_lang-injection.xml
Please sign in to leave a comment.
Hi there,
You are missing one important thing: the fact that no regex is used to describe matching string. It looks similar, but it is not a regex and this "^[/#@].*[/#@][gi]?$" simply will not work. Regex is simply too slow to be used here.
ATM you can only manually inject RegEx in such places as you edit them (Alt+Enter while standing inside the string).
Other than that: http://youtrack.jetbrains.com/issue/WI-1640
Aha... so do you happen to have a link to a reference page where the syntax is explained? Because I've been browsing the webhelp (http://www.jetbrains.com/phpstorm/webhelp/language-injection-settings-generic-php.html, and google) but haven't found a clear guide.
*updated*
This seems to at least work for me, even though the solution might not be for everyone (and would still like to have a backreference for the ending delimiter)
+ phpLiteralExpression().withText(string().matchesBrics("(/|#|@|!).*(/|#|@|!)(i|m|s|x|e|A|D|S|U|X|J|u)*"))
*updated 2*
The above solution actually matches all strings... so I definitely don't get how it works ;-]
Message was edited by: Doqnach .
I do not, unfortunately.
Maybe this one will be just a little bit better for your needs: http://www.jetbrains.com/phpstorm/webhelp/regular-expression-syntax-reference.html .
Dear Liubov,
Unfortunately not. I am looking for documentation on the syntax used for building your own language injection triggers. As Andriy stated these are not actually regexp, but I can't find what their syntax is supposed to be (other than looking at the one for SQL and rewriting that like I showed in my previous post).
We don't consider this a "user serviceable" part..
Anyway http://www.brics.dk/automaton/faq.html
plus we do some pre-processing in "matchesBrics": ' ' is replaced with <whitespacechar> and any UPPERCASE_CHAR with a group [cC].