/ docs / src / source-highlight / ngc.lang
ngc.lang
 1  # ngc.lang - RS274 G-Code formatting (EMC flavour)
 2  #
 3  #  Michael Haberler 3/2011
 4  #
 5  #  originally based on the Highlight-mode file for gedit,
 6  #  written by Jan Van Gilsen <janvangilsen(at)gmail(dot)com>
 7  #  Installation instructions can be found at:
 8  #  http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Highlighting_In_Gedit
 9  #  Version		: 0.3
10  #  Last Edit	: 10Th Nov 2007, by Jan Van Gilsen
11  #  Comment 	: added probing and rigid tapping G-codes (new in 2.2)
12  
13  
14  environment comment delim '\([dD][eE][bB][uU][gG],' ")" begin
15  	variable =  '#([0-9]{4})'
16  	variable =  '#[0-9][0-9]?'
17  	variable =  '#<([^\>]+)>'
18  end
19  comment delim "(" ")"
20  comment start ";"
21  
22  
23  # numbered parameters (#5xxx)
24  variable =  '#([0-9]{4})'
25  
26  # function parameter -  #1 .. #30
27  variable =  '#[0-9][0-9]?'
28  
29  # named parameters
30  variable =  '#<([^\>]+)>'
31  
32  # math functions and boolean logic
33  function = "cos|tan|asin|acos|atan|exp|ln|sqrt|fup|fix|abs|or",
34  	"xor|and|mod|gt|lt|ge|le|eq|ne|exists"
35  	nonsensitive
36  
37  # operators
38  function = '(([-/|\=\+\*])|(\])|(\[))'
39  
40  # line numbers
41  comment = '^[n|N]([ |\t]*[0-9]){1,5}'
42  
43  # O-word lines and their keywords
44  preproc = '[ \t]*[o|O](([ \t]*[0-9])+|<([[:alpha:]]|_)([[:word:]]|\-)+>)[ \t]*',
45  	'(sub|endsub|while|endwhile|if|else|endif|do|call|break|continue|return|repeat|endrepeat|elseif)'
46  
47  # G codes
48  vardef GCODE = '[g|G]([ \t]*[0])*[ \t]*'
49  keyword = $GCODE + '1[ \t]*[07-9]'
50  keyword = $GCODE + '2[ \t]*[018]'
51  keyword = $GCODE + '3[ \t]*[03]'
52  keyword = $GCODE + '3[ \t]*3[ \t]*.[ \t]*1'
53  keyword = $GCODE + '3[ \t]*8[ \t]*.[ \t]*[2-5]'
54  keyword = $GCODE + '4[ \t]*[1-3][ \t]*.[ \t]*1'
55  keyword = $GCODE + '4[ \t]*[0-39]'
56  keyword = $GCODE + '5[ \t]*[3-9]'
57  keyword = $GCODE + '6[ \t]*[14]'
58  keyword = $GCODE + '6[ \t]*.[ \t]*1'
59  keyword = $GCODE + '7[ \t]*6'
60  keyword = $GCODE + '8[ \t]*[0-9]'
61  keyword = $GCODE + '9[ \t]*[0-489]'
62  keyword = $GCODE + '9[ \t]*2[ \t]*.[ \t]*[1-3]'
63  keyword = $GCODE + '[0-5]'
64  
65  
66  # M-Codes
67  vardef MCODE = '[m|M]([ \t]*[0])*[ \t]*'
68  keyword = $MCODE + '5[ \t]*[0-3]'
69  keyword = $MCODE + '3[ \t]*0'
70  keyword = $MCODE + '6[ \t]*0'
71  keyword = $MCODE + '6[ \t]*[0-9]'
72  keyword = $MCODE + '7[ \t]*[0-3]'
73  keyword = $MCODE + '1[ \t]*[0-9][ \t]*[1-9]'
74  keyword = $MCODE + '1[ \t]*[1-9][ \t]*0'
75  keyword = $MCODE + '[0-9]'
76  
77  # Feeds & speeds
78  keyword = '[f|F|s|S]([ \t]*[0-9])*[ \t]*[.]?([ \t]*[0-9])*'
79  
80  # T, H
81  keyword = '[t|T|h|H]([ \t]*[0-9])*'
82  
83  # Coordinates & arguments; trailing number/expression/params formatted separately
84  atom = '[x|X|y|Y|z|Z|a|A|b|B|c|C|u|U|v|V|w|W|i|I|j|J|k|K|p|P|q|Q|r|R|l|L](\s*)?'
85  
86  
87  #    * A number consists of (1) an optional plus or minus sign,
88  #	followed by (2) zero to many digits, followed, possibly,
89  #	by (3) one decimal point,
90  #	followed by (4) zero to many digits - provided that there is at least one digit somewhere in the number.
91  #
92  #    * There are two kinds of numbers: integers and decimals. An integer does not have a decimal point in it; a decimal does.
93  #    * 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).
94  #    * A non-zero number with no sign as the first character is assumed to be positive.
95  number = '[+-]?([[:digit:]]*\.)?[[:digit:]]+'