Sha256: d93cf0d2cd51e7bf851429306d38f30a2154ed78c16e9fbf94d349dc92017a55

Contents?: true

Size: 612 Bytes

Versions: 3

Compression:

Stored size: 612 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(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

3 entries across 3 versions & 1 rubygems

Version Path
unitwise-0.2.1 lib/unitwise/expression/transformer.rb
unitwise-0.2.0 lib/unitwise/expression/transformer.rb
unitwise-0.1.0 lib/unitwise/expression/transformer.rb