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@lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to