How To Add New Language In Ace

1,918 views
Skip to first unread message

Rison

unread,
Jun 21, 2011, 11:00:48 AM6/21/11
to Ajax.org Cloud9 Editor (Ace)
Hi,

I need to create realtime syntax editor for verilog and I am thinking
to go with ace. I've been looking around. I see that the syntax
highlight rules are inside lib/mode folder. But even if I delete this
folder in the server, the javascript code highlight and correction
works fine. How is this possible?

So is the only js required inside src? So how can I define new
highlight and correction rules for a new language? Is it just by
editing this one js inside src folder since those inside lib/mode
doesn't seem to create any effect. Please help and thanks in advance.

Michael Connors

unread,
Jun 21, 2011, 11:24:37 AM6/21/11
to ace-d...@googlegroups.com


So is the only js required inside src? So how can I define new
highlight and correction rules for a new language? Is it just by
editing this one js inside src folder since those inside lib/mode
doesn't seem to create any effect. Please help and thanks in advance.

I think you would develop your mode in the lib/mode folder. Then you run the node.js build tool thing and you end up with a file for your new mode in the src directory. 

There is a little in the readme file about how to build it. It seems to require node.js and a node.js package manager.

Hai Dang

unread,
Jun 22, 2011, 1:47:12 AM6/22/11
to Ajax.org Cloud9 Editor (Ace)
As Connors already mentioned, to build your own mode you should look
at the lib folder using node.js
The ones in src folder are packaged Ace, that is they are already
built and ready to be embedded in to any page, thus won't be using
anything from the lib folder.

Rison

unread,
Jun 22, 2011, 1:54:10 AM6/22/11
to Ajax.org Cloud9 Editor (Ace)
Thanks for the replies Hai and Michael. So how can I pack a new
language? And how to use node.js. Sorry, I am new to this. Thanks for
your help.

Michael Connors

unread,
Jun 22, 2011, 5:02:43 AM6/22/11
to ace-d...@googlegroups.com
On 22 June 2011 07:54, Rison <rison...@gmail.com> wrote:
Thanks for the replies Hai and Michael. So how can I pack a new
language? And how to use node.js. Sorry, I am new to this. Thanks for
your help.

Here is what I did (on Ubuntu Linux):

Install Node:

tar -xvf node-v0.4.8.tar.gz 
cd node-v0.4.8/
./configure 
make
sudo make install 

Install the package manager:
chmod u+x install.sh
./install.sh

Then change to the directory that ace is in:
cd ace/
sudo npm link .
git submodule update --init --recursive

Then after you make changes to your new mode:

./Makefile.dryice.js normal

I think you don't actually use node for anything except the build tools. I am new to ace though, so I could be wrong. I am still trying to figure out how to build a mode that extends html myself.

Rison

unread,
Jun 22, 2011, 6:26:29 AM6/22/11
to Ajax.org Cloud9 Editor (Ace)
Thanks for all your help. This is to make the mode package of the new
language, right? So I should make changes in javascript.js and
javascript_highlight_rules.js, for example, inside lib directory and
use nodejs to make the new js file, right? And should I change ace.js?

On Jun 22, 2:02 pm, Michael Connors <connor...@gmail.com> wrote:
> On 22 June 2011 07:54, Rison <risonsi...@gmail.com> wrote:
>
> > Thanks for the replies Hai and Michael. So how can I pack a new
> > language? And how to use node.js. Sorry, I am new to this. Thanks for
> > your help.
>
> Here is what I did (on Ubuntu Linux):
>
> Install Node:
>
> wgethttp://nodejs.org/dist/node-v0.4.8.tar.gz
> tar -xvf node-v0.4.8.tar.gz
> cd node-v0.4.8/
> ./configure
> make
> sudo make install
>
> Install the package manager:
> curlhttp://npmjs.org/install.sh

Hai Dang

unread,
Jun 23, 2011, 2:28:07 AM6/23/11
to Ajax.org Cloud9 Editor (Ace)
I'm new too Ace too, but it seems like what Michael said, node.js is
used to test and build Ace.

You just need to make changes to javascript.js and
javascript_highlight_rules.js in the lib folder like you suggested. No
need to change other files. You can also add a new mode with new file
names, like myLanguage.js and myLanguage_highlight_rules.js

Now you have 2 choice:
+ you can run Ace with node.js without packaging it. To do that check
out the readme file, "Running Ace" part. This is often used for
testing directly.
+ or just package it using Makefile.dryice.js (Michael posted, also in
the readme, "Package Ace" part). the result files will be in build/src
folder, and can run alone by added it to a html file. You can also do
testing with this.

If you're adding a totally new mode, you need to register it by:
+ if you're running Ace with node.js using the index.html, which is
the demo, you should modify demo/demo.js. Just copy other modes, like
this
var myLanguageMode = require("ace/mode/myLanguage").Mode;
+ if you're packaging Ace, modify Makefile.dryice.js. It's simple,
again, just look at how they did it with other modes (https://
github.com/ajaxorg/ace/blob/master/Makefile.dryice.js#L222)


If you have problem building, check if you have downloaded pilot and
cockpit in support folder.

Rison

unread,
Jun 23, 2011, 10:57:46 AM6/23/11
to Ajax.org Cloud9 Editor (Ace), Hai Dang
Thank you Hai for your detailed explanation. I will try this and will
report the results. Also I don't have anything inside my cockpit and
pilot folders. I will download this now. Thanks for notifying. Thank
you ace community.

Hai Dang

unread,
Jun 24, 2011, 3:24:56 AM6/24/11
to Ajax.org Cloud9 Editor (Ace)
Hey Rison, I just found this official wiki and I think it can help:

https://github.com/ajaxorg/ace/wiki/Creating-or-Extending-an-Edit-Mode

The most important part is extending a mode using inheritance. Great!
Also it has a thorough guide about changing the highlighter style.

On Jun 23, 9:57 pm, Rison <risonsi...@gmail.com> wrote:
> Thank you Hai for your detailed explanation. I will try this and will
> report the results. Also I don't have anything inside my cockpit and
> pilot folders. I will download this now. Thanks for notifying. Thank
> you ace community.
>

Rison

unread,
Jun 25, 2011, 1:05:57 AM6/25/11
to Ajax.org Cloud9 Editor (Ace)
Thanks Hai.
Reply all
Reply to author
Forward
0 new messages