Sha256: 9a25120178c818897fd7135f9a78d269e93c346b5da4116b1abe1a09407ef298

Contents?: true

Size: 950 Bytes

Versions: 7

Compression:

Stored size: 950 Bytes

Contents

require 'hilbert/lexer/formula_lexer'

module Hilbert
  module Parser
    module FormulaParser
      include Lexer::Tokens

      def self.execute(str)
        lexed = Lexer::FormulaLexer.new(str)
        time = Time.now
        loop do
          fail "I'm so sorry, something wrong. Please feel free to report this." if Time.now > time + 10
          case lexed.token_str
          when /:EXP(\d+)/
            new_ope = $meta_info.lang == :ruby ? '**' : '^'
            lexed.parsed!(new_ope, $1)
          when /:MUL(\d+)/
            sss = StringScanner.new(lexed.get_value($1))
            ary = []
            until sss.eos?
              [/pi/, /[1-9a-z]/].each do |rgx2|
                ary << sss[0] if sss.scan(rgx2)
              end
            end
            parsed = ary.join(' * ')

            lexed.parsed!(parsed, $1)
          else
            break
          end
        end
        lexed.values.join
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hilbert-0.0.2700400 lib/hilbert/parser/formula_parser.rb
hilbert-0.0.2700320 lib/hilbert/parser/formula_parser.rb
hilbert-0.0.2700300 lib/hilbert/parser/formula_parser.rb
hilbert-0.0.2700210 lib/hilbert/parser/formula_parser.rb
hilbert-0.0.2700110 lib/hilbert/parser/formula_parser.rb
hilbert-0.0.2700100 lib/hilbert/parser/formula_parser.rb
hilbert-0.0.2700001 lib/hilbert/parser/formula_parser.rb