grammar MathMy
rule math_exp_full (paren_exp / primary) rest:(op math_exp)+ <Extract::Tree::Math> end rule naked_exp primary rest:(op math_exp)* <Extract::Tree::Math> end rule paren_exp "(" math_exp ")" <Extract::Tree::ParenMath> end rule math_exp (paren_exp / naked_exp) rest:(op math_exp)* <Extract::Tree::Math> end rule num "-"? [0-9]+ ("." [0-9]+)? <Extract::Tree::Num> end rule op ("+" / "-" / "*" / "/" / "^") <Extract::Tree::Operator> end rule primary num end
end