Sha256: 16b09125577e04781c31f97426faf8377c5a57ddc3f1b867403900b2f3e0f126

Contents?: true

Size: 709 Bytes

Versions: 2

Compression:

Stored size: 709 Bytes

Contents

module Unitwise
  module Expression
    class Transformer < Parslet::Transform
      rule(integer: simple(:i)) { i.to_i }
      rule(fixnum: simple(:f)) { f.to_f }

      rule(prefix_code: simple(:c)) { Prefix.find(c) }
      rule(atom_code: simple(:c)) { Atom.find(c) }
      rule(term: subtree(:h)) { Term.new(h) }

      rule(operator: simple(:o), right: simple(:r)) do
        o == '/' ? r ** -1 : r
      end

      rule(left: simple(:l), operator: simple(:o), right: simple(:r)) do
        o == '/' ? l / r : l * r
      end

      rule(left: simple(:l)) { l }

      rule(group: { nested: simple(:n) , exponent: simple(:e)}) { n ** e }

      rule(group: { nested: simple(:n) }) { n }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
unitwise-0.3.0 lib/unitwise/expression/transformer.rb
unitwise-0.2.2 lib/unitwise/expression/transformer.rb