Skip to content

Instantly share code, notes, and snippets.

@corecode
Created October 16, 2014 22:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save corecode/58606f3178c4c301627a to your computer and use it in GitHub Desktop.
Save corecode/58606f3178c4c301627a to your computer and use it in GitHub Desktop.
<gerber> = (command <newline>)*;
<command> = (<'%'> command-content <'%'>) | command-content;
<command-content> = (func | parameter) <'*'>;
(* <trivial> = #'(?s).*'; *) (* 10 ms *)
(* <trivial> = #'(?>\r|\n|%[^%]++%|[^*%\r\n][^*]*+[*])++'; *) (* 10 ms *)
(* <trivial> = #'(?>\r|\n|%[^%]++%|[^*%\r\n][^*]*+[*])'+; *) (* 160 ms *)
<func> = operation-func | mode-func;
<operation-func> = coord-func (* interpolate | move | flash *) | mode-interpolate | eof;
<mode-func> = apperture | comment | region | quadrant;
interpolate = coordinate <#'D0?+1'>;
move = coordinate-xy <#'D0?+2'>;
flash = coordinate-xy <#'D0?+3'>;
(*coord-func = #'(?>[XYIJ][+-]?+[0-9]++)*+D0?+[123]'; *) (* 2700 ms *)
coord-func = #'(?>(?>[XYIJ][+-]?+[0-9]++)*+D0?+[123](?=[*]))(?:[*]\n?(?>[XYIJ][+-]?+[0-9]++)*+D0?+[123](?=[*]))*+'; (* 2700 ms *)
mode-interpolate = linear | arc;
linear = <#'G0?+1'> (interpolate | move)?;
arc = (arc-cw | arc-ccw) coordinate (interpolate | move);
arc-cw = <#'G0?+2'>;
arc-ccw = <#'G0?+3'>;
apperture = <'D'> apperture-number;
apperture-number = #'[1-9][0-9]++';
quadrant = single-quadrant | multi-quadrant;
single-quadrant = <'G74'>;
multi-quadrant = <'G75'>;
region = region-on | region-off;
region-on = <'G36'>;
region-off = <'G37'>;
<comment> = <#'G0?+4[^*]*+'>;
eof = <'M02'>;
<parameter> = format | unit-mode | apperture-def | attribute;
format = <'FS'> omission-format notation-format x-number-format y-number-format;
<omission-format> = omit-leading | omit-trailing;
omit-leading = <'L'>;
omit-trailing = <'T'>;
<notation-format> = notation-abs | notation-inc;
notation-abs = <'A'>;
notation-inc = <'I'>;
x-number-format = <'X'> number-format;
y-number-format = <'Y'> number-format;
number-format = #'[0-7][0-7]';
<unit-mode> = <'MO'> (inch-mode | metric-mode);
inch-mode = <'IN'>;
metric-mode = <'MM'>;
apperture-def = <'ADD'> apperture-number apperture-name apperture-modifiers?;
apperture-name = circle | rectangle | oblong | poly;
circle = <'C'>;
rectangle = <'R'>;
oblong = <'O'>;
poly = <'P'>;
apperture-modifiers = <','> apperture-modifier (<'X'> apperture-modifier)*;
apperture-modifier = decimal;
<attribute> = file-attrib | apperture-attrib;
file-attrib = <'TF'> generic-attrib;
apperture-attrib = <'TA'> generic-attrib
generic-attrib = name <','> string;
<coordinate> = coordinate-x? coordinate-y? coordinate-xoff? coordinate-yoff?;
<coordinate-xy> = coordinate-x? coordinate-y?;
coordinate-x = <'X'> integer;
coordinate-y = <'Y'> integer;
coordinate-xoff = <'I'> integer;
coordinate-yoff = <'J'> integer;
integer = #'[+-]?+[0-9]++';
decimal = #'[+-]?+[0-9]++([.][0-9]*+)?+';
<name> = #'[a-zA-Z_$.][a-zA-Z_$.0-9]*+';
<string> = #'[a-zA-Z0-9_+/!?<>"\'(){}.\|&@#,;-]++';
newline = #'[\r\n]*+';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment