You are not logged in.

#1 2012-02-01 14:58:51

sas
Member
Registered: 2009-11-24
Posts: 155

nano syntax highlighting: GNU makefiles

May I present, another highlighting syntax for the nano editor... This time for GNU makefiles.

Code & Instructions:
# GNU makefile highlighting

syntax "mk" "(\.mk|(^|/)(GNU)?[Mm]akefile)$"

# default text
color magenta "^.*$"
# rules: command
color brightblack "^ *[^:=' ][^:=']+*::?[^=;][^;]*;\s*@"
# rules: dependency list
icolor yellow "^ *[^:=' ][^:=']+*::?[^=;][^;]*(;|$)"
# rules: target list
icolor brightyellow "^ *[^:=' ][^:=']*:"
color brightgreen "^ *\.(PHONY|SUFFIXES|DEFAULT|PRECIOUS|IGNORE|SILENT|EXPORT_ALL_VARIABLES)\s*:"
# variable definitions
icolor brightcyan "^ *(override )?[a-z0-9_][a-z0-9_-]*\s*[:+]?="
color brightblue "^ *((AR|AS|C0|CPP|CXX|LD)(FLAGS)?|(C|F|G|L|P|R|Y)FLAGS|BISON|CC|C?TANGLE|C?WEAVE|FC|FLEX|GET|INSTALL|LEX|MAKE(INFO|FILES|LEVEL|FLAGS)?|PC|RANLIB|RM|SHELL|SUFFIXES|TEX|TEXI2DVI|VPATH|YACCR?)\s*[:+]?="
icolor magenta START="^ *(override )?define" END="endef"
icolor brightcyan "^ *(override( define)?|define) [a-z0-9_-]+"
# directives
icolor cyan "^ *ifdef [a-z0-9_-]+"
color brightblack "^ *ifn?eq \(.*\)\s*$"
color magenta "^ *ifn?eq \(([^(){}]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])+"
color brightblack "^ *ifn?eq \(([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])*,"
color magenta "^ *ifn?eq \(([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])+"
color brightblack "^ *(include|ifn?(eq|def)|else|end(e|i)f|override( define)?|define|vpath)( \(?|$)"
# punctuation
color brightwhite "[:+=;]"
# rules: command
icolor magenta "^[^a-z0-9_., $§'"´`\\(){}/+~*%&^°=?-].*$"
color brightblack "^\s*@"
# function calls
icolor green "\$[({][a-z-]+ ([^(){}]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])+[)}]"
icolor magenta "\$[({][a-z-]+ ([^(){}]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])+"
icolor green "\$[({](foreach|subst) ([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])+,([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])*,"
icolor magenta "\$[({](foreach|subst) ([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])*,([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])*"
icolor green "\$[({][a-z-]+ ([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])*,"
icolor magenta "\$[({][a-z-]+ ([^(){},]|[({]([^(){}]|[({][^(){}]+[)}])+[)}])*"
icolor cyan "\$[({](foreach|origin) [a-z0-9_-]+"
icolor green "\$[({]"
color green "\$[({](subst|patsubst|strip|findstring|filter(-out)?|sort|(not)?dir|suffix|basename|add(suf|pre)fix|join|words?|firstword|wildcard|foreach|origin|shell) "
# variable references
icolor cyan "\$[a-z_][a-z0-9_]*" "\$\([a-z0-9_-]+\)" "\$\{[a-z0-9_-]+\}"
icolor magenta "\$\$[a-z_][a-z0-9_]*" "\$\$\([a-z0-9_-]+\)" "\$\$\{[a-z0-9_-]+\}"
icolor cyan "\$[({]\$[({][a-z0-9_-]+[)}][)}]"
color blue "\$([@%<?^+*]|\([@*%<^?][DF]\))"
color blue "\$[({]((AR|AS|C0|CPP|CXX|LD)(FLAGS)?|(C|F|G|L|P|R|Y)FLAGS|BISON|CC|C?TANGLE|C?WEAVE|FC|FLEX|GET|INSTALL|LEX|MAKE(INFO|FILES|LEVEL|FLAGS)?|PC|RANLIB|RM|SHELL|SUFFIXES|TEX|TEXI2DVI|VPATH|YACCR?)[)}]"
color blue "\$((AR|AS|C0|CPP|CXX|LD)(FLAGS)?|(C|F|G|L|P|R|Y)FLAGS|BISON|CC|C?TANGLE|C?WEAVE|FC|FLEX|GET|INSTALL|LEX|MAKE(INFO|FILES|LEVEL|FLAGS)?|PC|RANLIB|RM|SHELL|SUFFIXES|TEX|TEXI2DVI|VPATH|YACCR?)"
# comments
color white "^\s*#.*$"
color white "#([^"'\\]|"[^"\\]*(\\.[^"\\]*)*"|['`][^']*'||\>'\<)*$"

To install, save the above above code snippet as a file called mk.nanorc in the folder /usr/share/nano/ (or /usr/local/share/nano/ or similar if you feel strongly about the /usr <--> /usr/local separation), and then add the following to the end of the file /etc/nanorc:

## GNU makefiles
include "/usr/share/nano/mk.nanorc"

Nano will then use it to highlight all files that are called makefile / Makefile / GNUmakefile, or have the .mk filename suffix.
To use it for highlighting a makefile with a different filename, you can manually activate it using nano's -Y command line switch, like so:

nano -Y mk path/to/myMakefile
Screenshot:

Here's a screenshot of this highlighting definition used on a demo file that includes various makefile-snippets to show off different syntax features:

makefile.png

See Also:

Offline

#2 2012-02-01 16:40:41

doug piston
Member
From: Seattle
Registered: 2011-09-11
Posts: 387
Website

Re: nano syntax highlighting: GNU makefiles

You sir, are my hero.

Offline

Board footer

Powered by FluxBB