Howto:Syntax highlighting for Nasal: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
Line 46: Line 46:
* TextMate [http://flightgear.org/forums/viewtopic.php?f=30&t=12495&p=128116&hilit=syntax+nasal#p127828]
* TextMate [http://flightgear.org/forums/viewtopic.php?f=30&t=12495&p=128116&hilit=syntax+nasal#p127828]
* SciTe [http://flightgear.org/forums/viewtopic.php?f=30&t=9260&p=94521&hilit=syntax+nasal#p94521]
* SciTe [http://flightgear.org/forums/viewtopic.php?f=30&t=9260&p=94521&hilit=syntax+nasal#p94521]
* gEdit (Linux) : Using the 'Octave' highlighting mode, most of the nasal functions work.


== FlightGear Wiki ==
== FlightGear Wiki ==

Revision as of 12:04, 16 August 2012

There's Nasal syntax-highlighting support available for some editors, which is a big advantage, as it makes Nasal coding much easier. It can often point to syntax errors and so reduce the number of tedious time-consuming and unproductive FlightGear runs.

Notepad++

http://dl.dropbox.com/u/1463693/nasal.xml

Instructions are here: http://superuser.com/questions/62474/notepad-custom-syntax-highlighting-setting-where-to-look-for-it

jEdit

There's a syntax highlighting mode for jEdit, programmer's text editor

Included are some of Nasal's internal functions and those functions currently implemented in NasalSys.cxx To use, add the content of the catalog inside your own catalog (do NOT overwrite the file) and nasal.xml in /home/USER/.jedit/modes

Restart jEdit and you can use it. Current extension is .nas, you can add your own extension and functions. This mode is heavily based on the Javascript mode.

Get it here: http://www.jedit.org/

gEdit

Screen shot illustrating syntax highlighting in gEdit

Philosopher on the FlightGear Forum has created a syntax highlighter for gEdit- a popular and simple Text Editor for Mac OSX and Linux.

http://theomegahangar.flymerlion.com/downloads/nasal.lang

Download the nasal.lang file from the link above and:

If you use Mac, move it into your Applications/gedit/Contents/Resources/share/gtksourceview-2.0/language specs folder. And for linux, move it into your /usr/share/gtksourceview-X.0/language-specs folder.

Vim

It also makes understanding other people's code easier. One such editor is the free vim or its gui variant gvim.

It's not for everyone but it's free, and testing it doesn't hurt: http://www.vim.org/.

The syntax definition file comes with the FlightGear code (http://gitorious.org/fg/flightgear/blobs/next/scripts/syntax/nasal.vim). Highlighting works even for Nasal embedded in XML files (type ":set ft=nasal", where ft stands for file-type)

Here's an example, which demonstrates a short code segment with three syntax errors as well as the highlighting of a matching pair of parentheses (yellow) and trailing spaces (blue x). (The leading blue dots aren't on by default. They help to spot tab crimes.)

Screen shot illustrating syntax highlighting in Vim

Other editors

Nasal being syntactically very close to other programming languages like C, Php or JavaScript, you can get some usable highlighting even without real Nasal support:

FlightGear Wiki

A common approach in code examples on the wiki is to use php syntax highlighting beween <syntaxhighlight>:

<syntaxhighlight lang="php">
# hello.nas
print('Hello World!');
</syntaxhighlight>

Which renders into:

# hello.nas
print('Hello World!');

Related