Issues with PHP highlighter

SyntaxEditor for Windows Forms Forum

Posted 18 years ago by Kasper
Avatar
Hi,

I'm having a few problems with the PHP highlighter of SyntaxEditor. I come from using another control (SynEdit) for several years, so my customers have become used to certain things working. I have a couple of issues, but I will start out with this simple one. In PHP, it's okay to have variables within a double quoted string, like this:

echo "Hi this is a $test of variables";

The $test should be highlighted as a variable, even though it's within the string. How can this be done with SyntaxEditor? I have tried editing PHP.xml, but without luck so far. I hope you can help me :)

Comments (9)

Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Sure, that's easy... you can modify the string state to have these pattern groups:
<PatternGroups>
    <RegexPatternGroup TokenKey="DoubleQuoteStringVariableToken" PatternValue="\$ (_ | {AlphaMacro})({WordMacro})*" Style="VariableStyle" />
    <RegexPatternGroup TokenKey="DoubleQuoteStringEscapedCharacterToken" PatternValue="\\." />
    <RegexPatternGroup TokenKey="DoubleQuoteStringWhitespaceToken" PatternValue="{WhitespaceMacro}+" IsWhitespace="True" />
    <RegexPatternGroup TokenKey="DoubleQuoteStringWordToken" PatternValue="\w+" />
    <RegexPatternGroup TokenKey="DoubleQuoteStringDefaultToken" PatternValue="[^\&quot;\$]" />
</PatternGroups>


Actipro Software Support

Posted 18 years ago by Kasper
Avatar
Hi,

>Sure, that's easy... you can modify the string state to have these pattern groups:

That's exactly what I tried, but it didn't work. I guess my Regular Expression was not as good as your, although I tested it in RegexBuddy where it worked fine. Oh well, thank you :)

Now, on to the next problem. Have a look at the following piece of HTML, with PHP blended in to it:

<input type="text" name="test" value="<?= $testVar; ?>" />

This is perfectly valid, yet the PHP is not colored, probably because it's within an HTML tag. Once again, the solution might be simple, or it might not even be possible (which would be a shame though). I'm just not sure how to solve it best, so I hope you can help me once again :)
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You'd probably just have to make a PHP child state and allow it to be called from the StartTagAttributeStringValueState in the HTML definition.


Actipro Software Support

Posted 18 years ago by Kasper
Avatar
Hi,

I'm sorry, but I'm still no expert on this. Could you possibly provide a bit more details on how to do it? :)
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Take a look at the HTML definition at like the ASPDirectiveCodeState block. Copy it and change that to the proper delimiters for PHP. Then have it call your PHP language file instead. Then reference the new state you made as a ChildState in the StartTagAttributeStringValueState. There are examples of it all throughout the HTML definition so that should get you going.


Actipro Software Support

Posted 18 years ago by Kasper
Avatar
Thank you so much! I had of course already defined a PHPDirectiveCodeState, so I simply added it to the ChildStates of StartTagAttributeValueState and StartTagAttributeState. Now it works brilliantly! :)

Sorry for all the questions, but I'm still learning how to properly use the languages of SyntaxEditor. It can be a bit tricky, even with the good documentation included :)
Posted 18 years ago by Kasper
Avatar
I'm having another minor issue here. I have already defined the PHPDirectiveCodeState as a ChildState to the StartTagAttributeStringValueState, which means that something like this works fine:

<div class="<?= $class; ?>">
However, have a look at this one:

<div class="test_<?= $class; ?>">
Because the PHP block is not the first part of the value, it's ignored. I don't really get why though, but I'm sure there is some logical explanation, but is there a way to fix it as well? :)
Posted 18 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The lexical parser is greedy so once it starts matching a pattern it will not stop until the end. Therefore it is probably matching string attribute contents and is not looking to end on a < character. The HTML def probably has a regex that says match one or more tokens that aren't a quote character. Add a < character to the set as well. That will cause it to break there.


Actipro Software Support

Posted 18 years ago by Kasper
Avatar
Thank you, that seems to work :)
The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.