PHP syntax highlighting

573 views
Skip to first unread message

Adam Jimenez

unread,
Mar 6, 2010, 3:29:30 AM3/6/10
to bes...@googlegroups.com
Hi,

Is anyone working on PHP syntax highlighting that can be plugged into Bespin Embedded?

--
Best regards,
Adam Jimenez

ShiftCreate Limited
http://www.shiftcreate.com
e. ad...@shiftcreate.com
t. 020 8123 3766
m. 07969 689 484
skype: adamjjimenez
twitter: adamjimenez1

shiftcreate.com is the trading name of Shiftcreate Limited.
Registered in England Company No. 05862941 registered offices:
25 Berkeley Close, Ware, Herts, SG12 0BP

Julian Viereck

unread,
Mar 6, 2010, 5:23:49 AM3/6/10
to bes...@googlegroups.com
There isn't a PHP highlighter yet, but it should be simple enough to take the current JS highlighter and just replace the keywords from Javascript with the PHP ones.


Cheers

Julian


--
You received this message because you are subscribed to the Google Groups "Bespin" group.
To post to this group, send email to bes...@googlegroups.com.
To unsubscribe from this group, send email to bespin+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/bespin?hl=en.

Adam Jimenez

unread,
Mar 6, 2010, 5:36:43 AM3/6/10
to bes...@googlegroups.com
Are there plans to officially support PHP. I get a feeling it's not going to be that simple. I think it's going to be way beyond me.

Kevin Dangoor

unread,
Mar 6, 2010, 10:20:23 PM3/6/10
to bes...@googlegroups.com
On Sat, Mar 6, 2010 at 5:36 AM, Adam Jimenez <adam.j...@gmail.com> wrote:
Are there plans to officially support PHP. I get a feeling it's not going to be that simple. I think it's going to be way beyond me.


My take on it is this: PHP is important, but it's not core to Bespin. It is exactly the kind of thing that I'd like to see lovingly supported in a plugin by someone who cares about PHP.

By the way, someone looking to create a PHP highlighter may find useful bits in the Pygments PHP lexer:

http://dev.pocoo.org/projects/pygments/browser/pygments/lexers/web.py

Kevin

--
Kevin Dangoor

work: http://labs.mozilla.com/
email: k...@blazingthings.com
blog: http://www.BlueSkyOnMars.com

Julian Viereck

unread,
Mar 7, 2010, 2:26:28 AM3/7/10
to bes...@googlegroups.com
It is exactly the kind of thing that I'd like to see lovingly supported in a plugin by someone who cares about PHP.

I tried to implement a basic PHP highlighter yesterday. The php highlighter itself was implemented quickly, but the problem I've focus was, that I have to tell the HTML highlighter to start the PHP context and stop it again. I tried to follow the way Patrick did it with the JS highlighter, but he uses a lot of states, that confused me.

Julian

Adam Jimenez

unread,
Mar 8, 2010, 7:08:59 AM3/8/10
to bes...@googlegroups.com
Hi Julian,

Good on you for having a go. This is the sort of reason why I thought PHP wouldn't be that simple.
Unlike JS, PHP can go anywhere. In the middle of script tags - in the middle of tag attributes - literally anywhere. Plus you can enter and exit PHP anywhere you like. I hope some clever person cracks this. I'd be more than willing to test and attempt to debug.

Patrick Walton

unread,
Mar 8, 2010, 1:11:38 PM3/8/10
to bes...@googlegroups.com, Adam Jimenez
On 3/8/10 4:08 AM, Adam Jimenez wrote:
> Hi Julian,
>
> Good on you for having a go. This is the sort of reason why I thought
> PHP wouldn't be that simple.
> Unlike JS, PHP can go anywhere. In the middle of script tags - in the
> middle of tag attributes - literally anywhere. Plus you can enter and
> exit PHP anywhere you like. I hope some clever person cracks this. I'd
> be more than willing to test and attempt to debug.

I've talked about the possibility of having the standard syntax
highlighter able to be in multiple states at the same time. Then you'd
be able to have a state that looks something like this (pseudocode):

maybePHP: [
{
regex: /<\?php>/,
then: 'start:php endPHP'
},
{
regex: /[^<]+/
}
],

endPHP: ...

And you'd be in that state at the same time the main HTML highlighter is
running. This would support PHP.

The other advantage of having the syntax highlighter support multiple
states would be to get "pattern"-like functionality, as Julian mentioned
earlier.

Patrick

Julian Viereck

unread,
Mar 8, 2010, 1:28:33 PM3/8/10
to bes...@googlegroups.com
> The other advantage of having the syntax highlighter support multiple states would be to get "pattern"-like functionality, as Julian mentioned earlier.

This is not a good use case for patterns, as there a no states within patterns...

What about this:

Optional to each syntax highlighter, you can define a state which starts the highlighter and stops it again, for instance something that matches

<?php

starts always the php highlighter. If you then can match

?>

the php highlighter is stopped. This is independent from the current syntax highlighter state (if in quotes or just plain text).

In the html highlighter could be a section like

canHave: [php, css, js].

This makes the html highlighter care of php highlighter and kicks it in if there is a <?php.

Julian

Reply all
Reply to author
Forward
0 new messages