Howto:Syntax highlighting for Nasal: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(Segregated alternatives for Notepad++.)
No edit summary
(18 intermediate revisions by 12 users not shown)
Line 1: Line 1:
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, and it can be a sort of "guide" to the language, highlighting functions or keywords that are builtin, so you can quickly check if it is "type" or "typeof" by typing each. It also makes understanding other people's code easier, since you have all of the parts visually separated out, like loops, strings, constants, and builtin functions.
There's '''[[Nasal]] syntax-highlighting''' support available for some editors, which is a big advantage, as it makes Nasal coding much easier.


== Notepad++ ==
Syntax highlighting can often point to syntax errors and so reduce the number of tedious time-consuming and unproductive [[FlightGear]] runs. It can also be a sort of "guide" to the language, highlighting functions or keywords that are builtin, so you can quickly check if it is "type" or "typeof" by typing each. In addition makes understanding other people's code easier, since you have all of the parts visually separated out, like loops, strings, constants, and builtin functions.
[[File:Highlight parse.png|400px|thumb|Screenshot of Nasal support for Notepad++]]
 
Provides comprehensive syntax highlighting and a function list parser with support for hierarchical display of both inline and out-of-body class member functions.
== Atom ==
* [http://gitorious.org/nasal-npp-support/nasal-npp Gitorious repository for download and instructions]
Script is available from [https://github.com/www2000/atom-language-nasal Github] and can also be found in the [https://atom.io/packages/language-nasal Atom's packages repository].
{{-}}
 
'''Alternative:'''
Manual installation:
* [http://superuser.com/questions/62474/notepad-custom-syntax-highlighting-setting-where-to-look-for-it Instructions are here]
 
* [http://dl.dropbox.com/u/1463693/nasal.xml Download here]
# Download the latest release from https://github.com/www2000/atom-language-nasal
# Unpack the tar.bz2
# Copy/move the language-nasal package to ~/.atom/packages
 
For installation from atom's packages repository:
 
# Open Atom
# Go to Preferences Edit -> Preferences or {{key press|Ctrl|+}},
# Click on packages and search for nasal
# Click install for Language Nasal
 
== Emacs ==
[[File:Emacs-nasal-syntax-highlighting.png|400px|thumb|Nasal syntax highlighting in GNU Emacs]]
 
There is a Emacs major mode for Nasal available here: https://github.com/andyross/nasal/blob/master/misc/nasal-mode.el
 
Under Linux just drop the file where you have the rest of your manually installed packages and add the following to your .emacs file:
<nowiki>(require 'nasal-mode)</nowiki>
 
If you don't have a directory to place your manually installed packages, put the file in the directory ''~/.emacs.d/lisp/'' (create it if it doesn't exist) and then put the following in your .emacs file before the ''require'':
<nowiki>;; Tell emacs where is your personal elisp lib dir
(add-to-list 'load-path "~/.emacs.d/lisp/")</nowiki>
 
Reload .emacs via <code>'''M-x''' load-file</code> or by restarting Emacs.
 
== Geany ==
 
A syntax highlighting solution for [https://www.geany.org/ Geany], a lean text editor/IDE is available from [https://forum.flightgear.org/viewtopic.php?f=30&t=36838#p360677 this thread] in the FlightGear forum.
 
== gedit ==
[[File:Philosopher's nasal highlighting in gEdit.jpeg|400px|thumb|Screen shot illustrating syntax highlighting in gedit]]
 
'''Philosopher''' on the FlightGear Forum has created syntax highlighting for gedit, a popular and simple text editor for Mac OS X, Linux, and Windows.
 
<!--http://theomegahangar.flymerlion.com/downloads/nasal.lang -->
To install, copy the ''nasal.lang'' file <!--from the link above or--> from the first post of the forum topic {{forum link|p=164133}} and:
 
* If you use Mac, move it into your ''Applications/gedit/Contents/Resources/share/gtksourceview-X.0/language specs'' folder.
* For Linux, move it into your ''/usr/share/gtksourceview-X.0/language-specs'' folder.
 
In the same post given above, there are instructions for how to edit ''xml.lang'' (in the same directory) to add the embedded XML content support (with this minor edit, Nasal highlighting will be used inside of certain tags, instead of plain text).
 
For "snippets" support, nasal.xml from the above post has to be moved into ''/usr/share/gedit/plugins/snippets/'' folder or installed using the "import" feature. See this image for more details:
 
[[:File:Install nasal snippets in gedit.png|how to import Nasal snippets]].
{{-}}
{{-}}


Line 22: Line 66:
Get it here: https://sourceforge.net/projects/fgscheduleview/files/jedit/catalog.zip/download
Get it here: https://sourceforge.net/projects/fgscheduleview/files/jedit/catalog.zip/download


== gedit ==
== KDE Editors ==
There's a highlighting definition for nasal available at '''opendesktop.org''' (https://www.opendesktop.org/p/1187022/)
 
Download the file and copy it into:
:~/.kde4/share/apps/katepart/syntax/ (for KDE4)
:or
:~/.local/share/katepart5/syntax/ (for KF5 pre 5.29)
:or
:~/.local/share/org.kde.syntax.highlighting/syntax/ (for current KF5 versions)
 
(you can create the folders if they don't exist yet).


[[File:Philosopher's nasal highlighting in gEdit.jpeg|400px|thumb|Screen shot illustrating syntax highlighting in gedit]]
Note that the syntax highlighting in KDE doesn't set colors, it just identifies structural elements, colors are defined by the '''schemas''' used by each editor, thus you get consistent highlighting between different languages.


'''Philosopher''' on the FlightGear Forum has created syntax highlighting for gedit, a popular and simple text editor for Mac OS X, Linux, and Windows.
The highlighting file should work with all editors based on the katepart: KWrite, Kate, and the editor component of KDevelop.


<!--http://theomegahangar.flymerlion.com/downloads/nasal.lang -->
== Notepad++ ==
To install, copy the ''nasal.lang'' file <!--from the link above or--> from the first post of the forum topic [http://www.flightgear.org/forums/viewtopic.php?f=30&t=17265#p164133] and:
[[File:Highlight parse.png|400px|thumb|Screenshot of Nasal support for Notepad++]]
Provides comprehensive syntax highlighting and a function list parser with support for hierarchical display of both inline and out-of-body class member functions.
* [http://github.com/Slaiyer/nasal-npp GitHub repository for download and instructions]


* If you use Mac, move it into your ''Applications/gedit/Contents/Resources/share/gtksourceview-X.0/language specs'' folder.
'''Alternative (syntax highlighting only):'''
* For Linux, move it into your ''/usr/share/gtksourceview-X.0/language-specs'' folder.
* [http://dl.dropbox.com/u/1463693/nasal.xml Download here]
** [http://superuser.com/questions/62474/notepad-custom-syntax-highlighting-setting-where-to-look-for-it Instructions are here]
{{-}}


In the same post given above, there are instructions for how to edit ''xml.lang'' (in the same directory) to add the embedded XML content support (with this minor edit, Nasal highlighting will be used inside of certain tags, instead of plain text).
== Sublime Text 2 ==
[[File:Sublime Text 2 syntax highlighting.png|400px|thumb|Sublime Text 2 syntax highlighting]]


For "snippets" support, nasal.xml from the above post has to be moved into ''/usr/share/gedit/plugins/snippets/'' folder or installed using the "import" feature. See this image for more details: [[:File:Install nasal snippets in gedit.png|how to import Nasal snippets]].
Scripts and installation instructions are here: https://github.com/freevryheid/nasal
{{-}}


== Vim ==
== Vim ==
One such editor is the free vim or its gui variant gvim.  
[[File:Vim-nasal-syntax-highlighting.png|400px|thumb|Screen shot illustrating syntax highlighting in Vim]]
 
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/.  
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)
The syntax definition file comes with the FlightGear code ({{flightgear file|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.)
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.)
{{-}}
== Visual Studio Code ==
[[File:Vscode-sintaxhighlight.jpg|thumb|Screen shot illustrating syntax highlighting in VSCode]]
[https://code.visualstudio.com Visual Studio Code] is a source-code editor developed by Microsoft for Windows, Linux and macOS. Its open source and free.


[[File:Vim-nasal-syntax-highlighting.png|400px|thumb|Screen shot illustrating syntax highlighting in Vim]]
The nasal extension is available from [https://github.com/RenanMsV/nasal-vscode Github] and can also be found in the [https://marketplace.visualstudio.com/items?itemName=RenanMsV.nasal-lang VSCode's marketplace].
It supports basic syntax highlighting and snippets to improve development speed.


==KDE Editors==
For installation from the marketplace:
There's a highlighting definition for nasal available at '''kde-files.org''' (http://kde-files.org/content/show.php/Nasal+highlighting?content=154555)


Download the file and copy it into ~/.kde4/share/apps/katepart/syntax/ (you can create the folders if they don't exist yet).
# Open VSCode
# Go to File -> Preferences -> Extensions or {{key press|Ctrl|Shift|X}},
# Search for nasal
# Click install for Nasal-lang


Note that the syntax highlighting in KDE doesn't set colors, it just identifies structural elements, colors are defined by the '''schemas''' used by each editor, thus you get consistent highlighting between different languages.
Manual installation:


The highlighting file should work with all editors based on the katepart: KWrite, Kate, and the editor component of KDevelop.
# Download the latest release from the repository, it should be a .vsix file.
# Install the extension manually by doing the command 'code --install-extension path_to_extension.vsix'


== Sublime Text 2 ==
{{-}}
Scripts and installation instructions are here: https://github.com/freevryheid/nasal
[[File:Sublime Text 2 syntax highlighting.png|400px|thumb|Sublime Text 2 syntax highlighting]]


== Other editors ==
== 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:
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:


* TextMate [http://flightgear.org/forums/viewtopic.php?f=30&t=12495&p=128116&hilit=syntax+nasal#p127828]
* TextMate {{forum link|hilit=syntax+nasal|p=127828}}
* SciTe [http://flightgear.org/forums/viewtopic.php?f=30&t=9260&p=94521&hilit=syntax+nasal#p94521]
* SciTe {{forum link|hilit=syntax+nasal|p=94521}}


== FlightGear Wiki ==
== FlightGear Wiki ==
{{Note|As of 02/2016, we do not currently have a dedicated Nasal module available [http://wiki.flightgear.org/FlightGear_wiki:Village_pump/Archive_2016#Nasal_Syntaxhighlighting]}}
{{main article|Help:Formatting#Syntax highlighting}}
{{main article|Help:Formatting#Syntax highlighting}}


Line 85: Line 156:


== Syntax highlighting test ==
== Syntax highlighting test ==
Just a collection of keywords, etc. to test whether highlighting works (you can copy this to test your own highlighting):
Just a collection of keywords, etc. to test whether highlighting works (you can copy this to test your own highlighting):
<syntaxhighlight lang="nasal">
<syntaxhighlight lang="nasal">
Line 118: Line 188:
%$@&^|\`
%$@&^|\`
</syntaxhighlight>
</syntaxhighlight>
== Related content ==
* {{forum url|p=164155}}
* {{forum url|t=12495}}
* {{forum url|t=15972}}
* {{forum url|t=9812}}


[[Category:Nasal howto]]
[[Category:Nasal howto]]
== Related ==
* http://www.flightgear.org/forums/viewtopic.php?f=30&t=17265&p=164155#p164155
* http://www.flightgear.org/forums/viewtopic.php?f=30&t=12495
* http://www.flightgear.org/forums/viewtopic.php?f=30&t=15972
* http://www.flightgear.org/forums/viewtopic.php?f=30&t=9812

Revision as of 18:27, 29 January 2020

There's Nasal syntax-highlighting support available for some editors, which is a big advantage, as it makes Nasal coding much easier.

Syntax highlighting can often point to syntax errors and so reduce the number of tedious time-consuming and unproductive FlightGear runs. It can also be a sort of "guide" to the language, highlighting functions or keywords that are builtin, so you can quickly check if it is "type" or "typeof" by typing each. In addition makes understanding other people's code easier, since you have all of the parts visually separated out, like loops, strings, constants, and builtin functions.

Atom

Script is available from Github and can also be found in the Atom's packages repository.

Manual installation:

  1. Download the latest release from https://github.com/www2000/atom-language-nasal
  2. Unpack the tar.bz2
  3. Copy/move the language-nasal package to ~/.atom/packages

For installation from atom's packages repository:

  1. Open Atom
  2. Go to Preferences Edit -> Preferences or Ctrl++,
  3. Click on packages and search for nasal
  4. Click install for Language Nasal

Emacs

Nasal syntax highlighting in GNU Emacs

There is a Emacs major mode for Nasal available here: https://github.com/andyross/nasal/blob/master/misc/nasal-mode.el

Under Linux just drop the file where you have the rest of your manually installed packages and add the following to your .emacs file:

(require 'nasal-mode)

If you don't have a directory to place your manually installed packages, put the file in the directory ~/.emacs.d/lisp/ (create it if it doesn't exist) and then put the following in your .emacs file before the require:

;; Tell emacs where is your personal elisp lib dir
(add-to-list 'load-path "~/.emacs.d/lisp/")

Reload .emacs via M-x load-file or by restarting Emacs.

Geany

A syntax highlighting solution for Geany, a lean text editor/IDE is available from this thread in the FlightGear forum.

gedit

Screen shot illustrating syntax highlighting in gedit

Philosopher on the FlightGear Forum has created syntax highlighting for gedit, a popular and simple text editor for Mac OS X, Linux, and Windows.

To install, copy the nasal.lang file from the first post of the forum topic [1] This is a link to the FlightGear forum. and:

  • If you use Mac, move it into your Applications/gedit/Contents/Resources/share/gtksourceview-X.0/language specs folder.
  • For Linux, move it into your /usr/share/gtksourceview-X.0/language-specs folder.

In the same post given above, there are instructions for how to edit xml.lang (in the same directory) to add the embedded XML content support (with this minor edit, Nasal highlighting will be used inside of certain tags, instead of plain text).

For "snippets" support, nasal.xml from the above post has to be moved into /usr/share/gedit/plugins/snippets/ folder or installed using the "import" feature. See this image for more details:

how to import Nasal snippets.

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: https://sourceforge.net/projects/fgscheduleview/files/jedit/catalog.zip/download

KDE Editors

There's a highlighting definition for nasal available at opendesktop.org (https://www.opendesktop.org/p/1187022/)

Download the file and copy it into:

~/.kde4/share/apps/katepart/syntax/ (for KDE4)
or
~/.local/share/katepart5/syntax/ (for KF5 pre 5.29)
or
~/.local/share/org.kde.syntax.highlighting/syntax/ (for current KF5 versions)

(you can create the folders if they don't exist yet).

Note that the syntax highlighting in KDE doesn't set colors, it just identifies structural elements, colors are defined by the schemas used by each editor, thus you get consistent highlighting between different languages.

The highlighting file should work with all editors based on the katepart: KWrite, Kate, and the editor component of KDevelop.

Notepad++

Screenshot of Nasal support for Notepad++

Provides comprehensive syntax highlighting and a function list parser with support for hierarchical display of both inline and out-of-body class member functions.

Alternative (syntax highlighting only):


Sublime Text 2

Sublime Text 2 syntax highlighting

Scripts and installation instructions are here: https://github.com/freevryheid/nasal

Vim

Screen shot illustrating syntax highlighting in Vim

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 (flightgear/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.)

Visual Studio Code

Screen shot illustrating syntax highlighting in VSCode

Visual Studio Code is a source-code editor developed by Microsoft for Windows, Linux and macOS. Its open source and free.

The nasal extension is available from Github and can also be found in the VSCode's marketplace. It supports basic syntax highlighting and snippets to improve development speed.

For installation from the marketplace:

  1. Open VSCode
  2. Go to File -> Preferences -> Extensions or Ctrl+ Shift+X,
  3. Search for nasal
  4. Click install for Nasal-lang

Manual installation:

  1. Download the latest release from the repository, it should be a .vsix file.
  2. Install the extension manually by doing the command 'code --install-extension path_to_extension.vsix'


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

Note  As of 02/2016, we do not currently have a dedicated Nasal module available [4]

1rightarrow.png See Help:Formatting#Syntax highlighting for the main article about this subject.

Using the <syntaxhighight> tag with a lang="nasal" attribute, we can have highlighting right here on the wiki. Use enclose="div" to wrap the text, if it happens to be particularly wide.

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

Which renders into:

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

Syntax highlighting test

Just a collection of keywords, etc. to test whether highlighting works (you can copy this to test your own highlighting):

# this is a comment
# operators (if applicable):
!a ? a+b - c/d*e : f~g; expr1 and expr2 or expr3;
# Builtin functions, strings
print('Hello World!');
die("We have an error, Houston!", arg[0]);
cmdarg().getNode("setting").getValue();
streq(typeof(id(keys(hash))),10);
# Loopoids
foreach (var a; ["haha", {command:"NASAL!"}, me]) {
    if(0) break;
    elsif(1) continue;
    else return;
    while(1) sprintf("%s%s\n%s=%f", "Spam", "spam", "spam", 0e-0);
    for (var i=0; i < 0.00; i += 0x0) printf("%d", int(i));
    forindex(var o; a) (func {
        var o = o;
        setlistener("/", func print(o), 1, 2);
    })();
}
# String escaping stress tests:
'\a\b\c\"\\\?' # none of these
"\e\?\'\f\a" # none of these
'\'' # this one
"\"\r\n\t\\\t" # and all of these
# And optionally string formatting:
"%s%%s%.0f%8d" # the second "s" shouldn't be highlighted, otherwise everything else
# Syntax error!:
%$@&^|\`

Related content