ngc 0.2.6

Library to parse G-code (LinuxCNC dialect)
Documentation
// Copyright (c) 2019-2021 Georg Brandl.  Licensed under the Apache License,
// Version 2.0 <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0>
// or the MIT license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at
// your option. This file may not be copied, modified, or distributed except
// according to those terms.

WHITESPACE = _{ " " | "\t" }

file     = _{ (line ~ NEWLINE)* ~ EOI }
comment  = _{ "(" ~ (!")" ~ !NEWLINE ~ ANY)* ~ ")" | ";" ~ (!NEWLINE ~ ANY)* }
line     =  { percent | blockdel? ~ comment* ~ (word | par_assign)* }
blockdel =  { "/" }
percent  =  { "%" }

// argument word syntax

word   =  { letter ~ value ~ comment* }
letter =  { ASCII_ALPHA }
value  =  { op_un* ~ (num | par_ref | expr_brack | expr_atan | expr_exist | expr_call) }
num    =  { (ASCII_DIGIT+ ~ ("." ~ ASCII_DIGIT*)? | "." ~ ASCII_DIGIT+) }

// parameter syntax

par_assign =  { par_ref ~ "=" ~ value ~ comment* }
par_ref    =  { "#" ~ ("<" ~ par_name ~ ">" | value) }
par_num    =  { ASCII_DIGIT+ }
par_name   =  { (!">" ~ ANY)+ }

// expression syntax

expr_brack = _{ "[" ~ expr ~ "]" }
expr       =  { expr_cmp ~ (op_log ~ expr_cmp)* }
expr_cmp   =  { expr_add ~ (op_cmp ~ expr_add)* }
expr_add   =  { expr_mul ~ (op_add ~ expr_mul)* }
expr_mul   =  { expr_unop ~ (op_mul ~ expr_unop)* }
expr_unop  =  { op_un ~ expr_unop | expr_pow }
expr_pow   =  { expr_atom ~ (op_pow ~ expr_atom)* }
expr_atom  =  { expr_atan | expr_exist | expr_call | num | par_ref | expr_brack }
expr_atan  =  { ^"ATAN" ~ expr_brack ~ "/" ~ expr_brack }
expr_exist =  { ^"EXISTS" ~ "[" ~ par_ref ~ "]" }
expr_call  =  { expr_fn ~ expr_brack }
expr_fn    =  { ^"ABS" | ^"ACOS" | ^"ASIN" | ^"COS" | ^"EXP" | ^"FIX" |
                ^"FUP" | ^"ROUND" | ^"LN" | ^"SIN" | ^"SQRT" | ^"TAN" }

// operators

op_pow  =  { "**" }
op_mul  =  { "*" | "/" | ^"MOD" }
op_add  =  { "+" | "-" }
op_cmp  =  { ^"EQ" | ^"NE" | ^"GT" | ^"GE" | ^"LT" | ^"LE" }
op_log  =  { ^"AND" | ^"OR" | ^"XOR" }
op_un   =  { "+" | "-" }