[MacRuby-devel] syntax highlighting

Laurent Sansonetti lsansonetti at apple.com
Mon Jan 10 13:08:20 PST 2011


Hi Joel,

For simplicity, I recommend to use the ripper extension for that. It has a lexer API. I don't know if there is sample code available, but the API itself isn't very difficult to understand and use. Look for the Ripper::Lexer class.

Based on the returned tokens, you can then colorize your text storage by yourself (assuming you're using an NSTextView).

This is probably not a very good solution if you want to colorize a large amount of text every time the user changes it, but for small snippets, it should be okay. You can also schedule the lexing in a separate thread/GCD queue and colorize the storage from the main thread, grouping all the changes between -beginEditing / -endEditing calls, for better performance.

Laurent

On Jan 10, 2011, at 10:00 AM, Joel Reymont wrote:

> Is there anything I can piggyback on to implement syntax highlighting in a Cocoa editing window?
> 
> Is there some Ruby lexing code, for example, that I can reuse?
> 
> 	Thanks, Joel
> 
> ---
> http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
> 
> 
> 
> 
> 
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20110110/d54ca1d2/attachment-0001.html>


More information about the MacRuby-devel mailing list