# ngc.lang - RS274 G-Code formatting (EMC flavour)
#
#  Michael Haberler 3/2011
#
#  Originally based on the Highlight-mode file for gedit,
#  written by Jan Van Gilsen <janvangilsen(at)gmail(dot)com>.
#  Installation instructions can be found at:
#  http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Highlighting_In_Gedit
#  Version		: 0.3
#  Last Edit	: 10Th Nov 2007, by Jan Van Gilsen
#  Comment 	: Added probing and rigid tapping G-codes (new in 2.2)
#  This file is used for the syntax highlighting in the HTML output of the documentation.


environment comment delim '\([dD][eE][bB][uU][gG],' ")" begin
	variable =  '#([0-9]{4})'
	variable =  '#[0-9][0-9]?'
	variable =  '#<([^\>]+)>'
end
comment delim "(" ")"
comment start ";"

ignore = 'axes'

# Numbered parameters (#5xxx)
variable =  '#([0-9]{4})'

# Function parameter -  #1 .. #30
variable =  '#[0-9][0-9]?'

# Named parameters
variable =  '#<([^\>]+)>'

# Math functions and boolean logic
function = "cos|tan|asin|acos|atan|exp|ln|sqrt|fup|fix|abs|or",
	"xor|and|mod|gt|lt|ge|le|eq|ne|exists"
	nonsensitive

# Operators
function = '(([\/|\=\+\*])|(\])|(\[))'

# Line numbers
comment = '^[n|N]([ |\t]*[0-9]){1,5}'

# O-word lines and their keywords
preproc = '[ \t]*[o|O](([ \t]*[0-9])+|<([[:alpha:]]|_)([[:word:]]|\-)+>)[ \t]*',
	'(sub|endsub|while|endwhile|if|else|endif|do|call|break|continue|return|repeat|endrepeat|elseif)'

# G-codes
vardef GCODE = '[g|G]([ \t]*[0])*[ \t]*'
keyword = $GCODE + '1[ \t]*[07-9]'
keyword = $GCODE + '2[ \t]*[018]'
keyword = $GCODE + '3[ \t]*[03]'
keyword = $GCODE + '3[ \t]*3[ \t]*.[ \t]*1'
keyword = $GCODE + '3[ \t]*8[ \t]*.[ \t]*[2-5]*'
keyword = $GCODE + '4[ \t]*[1-3][ \t]*.[ \t]*1'
keyword = $GCODE + '4[ \t]*[0-39]'
keyword = $GCODE + '5[ \t]*[2-9]'
keyword = $GCODE + '6[ \t]*[14]'
keyword = $GCODE + '6[ \t]*.[ \t]*1'
keyword = $GCODE + '7[ \t]*[013467]'
keyword = $GCODE + '7[ \t]*.[ \t]*[12]*'
keyword = $GCODE + '8[ \t]*[0-9]'
keyword = $GCODE + '9[ \t]*[0-46-9]'
keyword = $GCODE + '9[ \t]*2[ \t]*.[ \t]*[1-3]'
keyword = $GCODE + '[0-5|7-8]'


# M-Codes
vardef MCODE = '[m|M]([ \t]*[0])*[ \t]*'
keyword = $MCODE + '1[ \t]*[0-9][ \t]*[1-9]'
keyword = $MCODE + '1[ \t]*[1-9][ \t]*0'
keyword = $MCODE + '3[ \t]*0'
keyword = $MCODE + '5[ \t]*[0-3]'
keyword = $MCODE + '6[ \t]*0'
keyword = $MCODE + '6[ \t]*[0-9]'
keyword = $MCODE + '7[ \t]*[0-3]'
keyword = $MCODE + '9[ \t]*[8-9]'
keyword = $MCODE + '[0-9]'

# Feeds & speeds
keyword = '[f|F|s|S]([ \t]*[0-9])*[ \t]*[.]?([ \t]*[0-9])*'

# T, H
keyword = '[t|T|h|H]([ \t]*[0-9])*'

# Coordinates & arguments; trailing number/expression/params formatted separately
atom = '[x|X|y|Y|z|Z|a|A|b|B|c|C|e|E|u|U|v|V|w|W|h|H|i|I|j|J|k|K|p|P|q|Q|r|R|l|L](\s*)?'


#    * A number consists of (1) an optional plus or minus sign,
#	followed by (2) zero to many digits, followed, possibly,
#	by (3) one decimal point,
#	followed by (4) zero to many digits - provided that there is at least one digit somewhere in the number.
#
#    * There are two kinds of numbers: integers and decimals. An integer does not have a decimal point in it; a decimal does.
#    * Numbers may have any number of digits, subject to the limitation on line length. Only about seventeen significant figures will be retained, however (enough for all known applications).
#    * A non-zero number with no sign as the first character is assumed to be positive.
number = '[+-]?([[:digit:]]*\.)?[[:digit:]]+'
