an objc syntax highlighting library that supports multiple language? - objective-c

I come from the ruby and python worlds where we have many libraries that can syntax highlight arbitrary code from many languages. I am looking for something similar in the objc ecosystem, but i can't seem to find such, is there one available?
The equivalent libraries in Ruby would be CodeRay and Pygments for Python,
thanks in advance!

Banister,
I myself have searched for a long time for a nice and robust Cocoa Syntax Highlighter, and since I'm currently building a code-oriented text editor myself, that would be a major part of the project.
So, I found out that there are plenty of Objective-C/Cocoa -friendly Syntax Highlighting libraries/components. For a starter (for something relatively basic, that is), I would suggest you have a look at :
OkudaKit (using CSS for styling)
UKSyntaxColoredTextDocument by Uli Kusterer (pretty nice try)
However, if you really need something POWERFUL, well-tested and still Cocoa-friendly, I would definitely suggest you to try the Scintilla component (for Cocoa). The code is great, and the community (at Scintilla-Interest Group) will gladly help you iron out any issues you may encounter.
In a few words :
I'm currently using on an about-to-be-release big project and it's working beautifully for me.
Scintilla
Scintilla is a free library that provides text-editing functions, with
an emphasis on advanced features for source code editing. SciTE
(cross-platform), Geany, Notepad++ (Windows), and Notepad2 (Windows)
are examples of standalone editors based on Scintilla.
Scintilla Editing Component in use (SciTe)
Features
Scintilla supports many features to make code editing easier in
addition to syntax highlighting. The highlighting method allows the
use of different fonts, colors, styles and background colors, and is
not limited to fixed-width fonts. The control supports error
indicators, line numbering in the margin, as well as line markers such
as code breakpoints. Other features such as code folding and
autocompletion can be added.
Download Scintilla (the Cocoa support has been integrated in the main project) : http://www.scintilla.org/SciTEDownload.html
Example project (integrating Scintilla with Cocoa) :
http://bazaar.launchpad.net/~mike-lischke/scintilla-cocoa/trunk/files/head:/cocoa/ScintillaTest/
For complete documentation, have a look at : Scintilla
Documentation

Fragaria may be useful for future reference.

Related

Embeddable editor for scripting language

I'm looking for a good editor that is embeddable into application (using either QT or GTK toolkit if needed), and would allow editing of scripts with:
Code completion
Inline documentation / context sensitive documentation
Syntax highlighting
Any language is fine (Scheme, Lua, Python etc.) as long as I can get good - noob friendly editor for it which I can embed into my application (so licence is also a concern, I'd hate to have to licence whole project as GPL and AGPL - I'd like to keep project on MIT/BSD license)
Any suggestions?
scintilla is made to be embedded. And, as far as I remember, works with GTK and QT. But it needs probably a bit of customization in order to get Code completion and Inline documentation / context sensitive documentation to work.
I'm not sure if this would work, but http://www.ubuntugeek.com/gummi-simple-latex-editor-written-in-pythongtk.html. It seems to be an open-source, MIT-licenced LaTeX editor. I haven't used it before, nor embedded it, but in theory you could embed it (unless of course n00bs don't know latex...)

Can I incorporate XCode's text editor into my own program for text highlighting?

I'm trying to have a text box that has syntax highlighting. To avoid the hassel and rework of implementing my own highlighter, is it possible to incorporate and use XCode's editor? Similar to how QuickLook shows the contents of files.
You can't.
QuickLook asks a plugin how to render. Xcode's QuickLook plugin for source files uses Xcode's own library, which is not open source.
Here are a few open source initiatives that provide syntax highlighting in Cocoa.
Xcode 4 hilighting I think is now based on Clang, Clang/LLVM is a new compiler technology that has many goals that traditional compilers have not tried to achieve, the feature of use to you is the compiler is not a single monolithic compiler but instead a collection of libraries, you can pitch and choose which libraries you want to use, the one you would be interested in is libclang which takes c/c++.Objective-C source code and turns it into a symbolic tree, it then turn that into the llvm internal representation, you should be able to get the symbolic tree representation, which you can then use to hi-light source code. You can get more information about clang from here, one possible issue is that libclang may only be available on Macs with Xcode installed.

Are there any text-editors/IDEs that support languages generically?

I'm looking for an editor/IDE that can provide features that are nice to have while coding (example: being able to click-through to function definitions) for languages that it is not specifically built for. By these, I have in mind languages designed for a very specific purpose and often only used by a small community. In other words, ones that would not have native support in most software.
I realize this would require a fair bit of fairy dust but I don't think it's out of the scope of what's possible. Basically, the editor would have to be smart enough to recognize the commonly used syntax and semantics that many declarative languages have in common. It's quite possible this would require some amount of configuration.
Does something like this exist? If not, what challenges do you think there would be in creating it?
If you need only the feature to jump of to the definition of a specific function or class, then VIM (and many other editors, like Emacs, Epsilon and JOE) can read the jump location from the ctags file. You just have to write a ctags file generator for your custom language.
For programmable editors (like VIM, Emacs, Epsilon, Eclipse and gedit), you can write your own plugin for your custom language, but it may quickly become time-consuming and a maintenance nightmare, because new versions of editors tend to change the plugin interface.
Please note that adding support for syntax highlighting is usually much easier than adding ctags-like support for symbol lookups. More advanced features, like refactoring and context-sensitive symbol completion (like Ctrl-Space and Tab in modern IDEs) are even harder to implement.
GNU Emacs has a pretty good infrastructure for this sort of thing. Until recently Haskell was a relatively unknown language used primarily by researchers. Nevertheless, in a few thousand lines of Emacs Lisp, we have
Syntax highlighting with colors
Automatic indentation
Package support
Automatic highlighting of type and other information when placing the cursor over library functions
Meta-dot on an identifier to jump to its definition (through the standard emacs tags mechanism)
The nice thing about Emacs is that (a) there are many models to follow, and (b) you can build up the environment gradually, starting with those aspects that are most important to you.
I'm suprised no one has mentioned Notepad++ yet:
http://notepad-plus-plus.org/
It offers syntax support for a great many languages and offers the user to add new languages, and an active community that adds many languages that are not included out-of-the-box.
Most good IDE's are language agnostic and supports several if not many programming languages. If you are talking about DSL's, eclipse has a solution that seems pretty awsome - Xtext
EditPadPro comes with a set of tools that allow you to build your own syntax highlighting, code folding and file navigation schemes, based on a very powerful regex syntax. So if your language is not among the many that have already been provided out-of-the-box or can be downloaded off the website, you can roll your own quite easily (and share it with the community).
Visual Studio is designed to allow for this, but it requires the language to add explicit support. For example, Delphi Prism will install into Visual Studio, and provide full language support.
This is far above and beyond "configuration", however, and requires quite a bit of custom development to support.
SciTE and Scintilla offer a generic editor/platform for different languages. The library contains several parsers that work with many programming languages and you can reuse one of these for your own language to add formatting and syntax highlighting.
They don't offer advanced features like click-throughs, but you could build it on top of the library.
Visual Studio and Eclipse also support language plug-ins.
Zeus is a language neutral IDE for the Windows platform and it provides this go to definition/declaration functionality for any language supported by ctags.
To make it work you just create a Zeus project/workspace and then add the files to this workspace.

How to create an Eclipse editor plugin with syntax checking and coloring as fast as possible?

I'm working on a project that requires me to create a series of editors for languages that are quite different. The syntaxes are defined by us.
I'm looking for a solution for this.
Is there a shortcut to take in this problem?
You could use XText:
a framework for development of textual domain specific languages (DSLs).
Just describe your very own DSL using Xtext's simple EBNF grammar language and the generator will create a parser, an AST-meta model (implemented in EMF) as well as a full-featured Eclipse text editor from that.
Alternatives to XText are Rascal or Spoofax, both less popular than XText but interesting for they support more general context-free grammars, among other things. Nice to check out.
If you are looking for a more low level, programmable solution, then Eclipse's IDE Meta-tooling platform is a good choice (IMP).
What IMP gives you is API to connect your existing parsers to Eclipse without much hassle. You need to implement an IParseController interface, to call your parser and ITokenIterator to produce tokens and some other interface to assign fonts to each kind of token.
The aforementioned Rascal and Spoofax are both build on top of IMP.
Not mentioned is DLTK (proposed also in Tutorial regarding the development of a custom Eclipse editor)
There are Ruby, bash that are implemented with it.

Do you draw a distinction between text editors and IDEs?

I've seen several responses to questions asking for IDEs where text editors were suggested and vice-versa. That makes me think that people treat them as the same thing, where I draw clear distinctions.
How do you define "text editor" and "IDE"?
Do you see a difference between the two tools?
Note that I accepted an answer which I think best addressed the concepts of "text editor" and "IDE". However, it's just my personal opinion of what best addresses the question and I will continue to check in on this question from time to time to see if there's a better answer and I will accept that one.
The confusion arises from the fact that a text editor is a core component of every IDE. But, an IDE has much more than just a text editor; it also has interfaces to compilers, debuggers, profilers, reference material, and more.
Many text editors have plugins or other flexible extension mechanisms, often including the ability to "wrap" external tools like those I mentioned above. The key difference, IMHO, is the "I" in IDE - integrated. An IDE is (again, IMHO) something that's purposefully designed to support a specific set of tools, one of which is a text editor.
I use both and I suggest you do too. Sometimes an IDE can make development faster - like code completion and refactoring support. Fast find of files and symbols, functions, classes in project not to mention project management features. Sometimes they'll manage the build for you. Maybe it has a built in debugger (a good built in debugger is worth gold). How about code snippets and file templates. Sometimes an IDE will help you build GUI interfaces and data stores. I've seen ones that help you build regexps and run SQL queries.
These (IMO) are all sugar. I also use a plain text editor (although I really appreciate code syntax coloring nowadays) and roll most of that other stuff myself. Some of the newer text editors are creeping into IDE territory (e.g. TextMate) since they are extensible enough to allow for most of the above paragraphs niceties.
In 90% of the cases I use what I am given or what the majority of the teams uses (I am a contractor). This reduces the build conflicts that can arise if you decide to go it on your own. By learning to use IDE's, text editors and everything in between you will stay flexible and able to cope with whatever is thrown at you.
I do, but it's more in the way you use them than a difference in the software itself. Some software is used as an IDE by some, but a mere text editor by others. Some software can only be a text editor, some is difficult to use as only a text editor, and some can be easily used as both.
I would say that such stalwarts as Vi(m) and Emacs are used by some as text editors and some as IDEs. Things like eclipse, visual studio, etc only really make sense as IDEs and things like notepad can hardly be anything but a text editor.
I would say if you stay in your text editor to do other things - compile, debug, etc - then you're using it more like an IDE. Quite where I'd draw the line, I'm not sure.
The obvious difference is the "I" from the IDE. IDE's are an integrated platform that allows not only editing, but debugging, file management for your project, and usually cool features like syntax highlighting and code completion. oh yeah, and integration of tools and compilers, as well as source control.
To me, a text editor is light weight tool used to edit text based documents. There is no mark up or formatting of the text other than defining the "system" font for the editor. Useful tools can still be part of a text editor, like a folder tree, syntax highlighting, even cmd line execution of compilers. In the end though, all it does it allow you edit the text in a document. It will not display it to you in a different way. ie: it will not show you a grid when viewing an XML document
An IDE is much more robust and is generally specific to a language or framework.
you know, before i started writing this answer, i had a clear line between a text editor and an IDE. But now, i'm thinking they are one in the same. I mean really and IDE like VS is just a glorified text editor. And a text editor like Textpad is an IDE with a much smaller budget for development of features.
I guess the real answer is, an IDE is backed by a large company or group expanding it's features in many different directions. But a text editor is built by a small group of people, with just enough features to get by.
If you look at Kate, the text editor and Kdevelop, the IDE the main difference is that Kdevelop supports project management (CVS/Subversion) and build scripts, whereas Kate does not.
Personally where I think the 'line' is drawn between IDE's and Text Editors is knowledge of the end program, rather than just knowledge of it's source code.
As examples:
Can it compile your code into a binary? It's an IDE
Does it have an integrated debugger? It's an IDE
In order to have an integrated debugger it needs to know about either the binary compiled program, or in the case of scripting languages, the in-memory interpretation of the program as it runs.
Note: Things like intellisense don't rely on your code being compiled into anything, so I wouldn't say that intellisense implies IDE
Note 2: Many text editors like textmate have plugin systems which can be extended to build your project. This does not make them an IDE, as they are simply shelling out to a plugin, they don't have any knowledge about the building itself.