Sha256: 915f0740a6fa632c260872bc82ea6a33b85a88e73aba029b3dbd0006aab21069

Contents?: true

Size: 977 Bytes

Versions: 6

Compression:

Stored size: 977 Bytes

Contents

module Qlang
  module Parser
    # FIX:
    module FormulaParser
      def execute(lexed)
        ss = StringScanner.new(lexed)
        result = ''
        until ss.eos?
          { EXP: /\^/, BFUNC: /sin|cos|tan|log/, MUL: /(pi|[1-9a-z]){2,}/, SNGL: /(pi|[1-9a-z])/, OTHER: /([^\^1-9a-z]|^pi)+/ }.each do |token , rgx|
            if ss.scan(rgx)
              item = case token
              when :EXP
                $type == :Ruby ? '**' : '^'
              when :MUL
                sss = StringScanner.new(ss[0])
                ary = []
                until sss.eos?
                  [/pi/, /[1-9a-z]/].each do |rgx2|
                    ary << sss[0] if sss.scan(rgx2)
                  end
                end
                ary.join(' * ')
              else
                ss[0]
              end
              result += item
              break
            end
          end
        end
        result
      end
      module_function :execute
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
qlang-0.0.27180000 lib/qlang/parser/formula_parser.rb
qlang-0.0.27100000 lib/qlang/parser/formula_parser.rb
qlang-0.0.27000000 lib/qlang/parser/formula_parser.rb
qlang-0.0.27 lib/qlang/parser/formula_parser.rb
qlang-0.0.14142135 lib/qlang/parser/formula_parser.rb
qlang-0.0.1414213 lib/qlang/parser/formula_parser.rb