What is the best way to implement source code parsing in Cocoa?

I am working on a Cocoa Application, which should be able to parse and extract source code written in languages ​​such as Objective-C, SQL, JavaScript, Python, etc. The text should also be editable (using NSTextView, for example).

Please advise what is the best way to implement this feature on Mac OS X 10.5.

No need to support autocomplete and other advanced features. Simple formatting by keywords, lines, #includes and numbers, but with excellent performance, is fine.

It would also be great if the language setting was supported.

Thank!

+18
objective-c cocoa syntax-highlighting nstextview
Apr 16 '09 at 3:00
source share
5 answers

In preparing a project that would require something similar, Ive found the following (but did not evaluate them in depth):

  • / Developer / Examples / OpenGL / Cocoa / GLSLEditorSample implements syntax highlighting.
  • IDEKit , "an open source environment that provides editing of the programmer’s source code, including syntax coloring, pop-up functions and split frames", This has not been updated for some time (it supports compatibility 10.2 and 10.3 and comes with the Project Builder project - it can be converted with using Xcode 2.5).
  • UKSyntaxColoredTextDocument .
+16
Apr 16 '09 at 17:54
source share

I would advise Aruman's second tip, especially looking at Uli UKSyntaxColoredTextDocument, as this will point you in the right direction as to which classes, etc. you will need to find out.

This is another great source of information:

http://www.cocoadev.com/index.pl?ImplementSyntaxHighlighting

Good luck - syntax highlighting is hard to understand, but lots of fun along the way!

+6
Apr 16 '09 at 23:08
source share

I had to look for a syntax highlighting solution for Cocoa recently and after searching Stack Overflow, Google and GitHub could not find anything modern, simple reuse and still in active development.

It seems that these days most syntax markers are written for the web. Fortunately, it’s actually quite simple to embed them in a WebView for use in any Cocoa application. Communication with the editor can be done through the WebKit protocol WebScriptObject .

Here's a sample shell for Cocoa's popular CodeMirror JavaScript text editor: https://github.com/swisspol/CodeMirrorView

+2
Dec 30 '14 at 20:50
source share

You can use Pyigs, which is written in python, to generate HTML source code, which can then be presented in a web view.

(Note that this is reflected in the comment below - this answer was to the original question, which did not mention the editable text.)

+1
Apr 16 '09 at 7:54
source share

You can use flex as described (in German) here [1]. Here you can find an example of this approach [2].

[1] http://www.osxentwicklerforum.de/thread.php?postid=14764 [2] http://objectiveous.github.com/davenport/

+1
Apr 18 '09 at 19:56
source share



All Articles