Sha256: e88982acdbe43253a63122aff2a0887cd340355b76a0955124ce75510db3cd21

Contents?: true

Size: 946 Bytes

Versions: 8

Compression:

Stored size: 946 Bytes

Contents

require 'qlang/lexer/formula_lexer'

module Qlang
  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

8 entries across 8 versions & 2 rubygems

Version Path
hilbert-0.0.2700000 lib/qlang/parser/formula_parser.rb
qlang-0.0.27182124 lib/qlang/parser/formula_parser.rb
qlang-0.0.27182123 lib/qlang/parser/formula_parser.rb
qlang-0.0.27182122 lib/qlang/parser/formula_parser.rb
qlang-0.0.27182121 lib/qlang/parser/formula_parser.rb
qlang-0.0.27182120 lib/qlang/parser/formula_parser.rb
qlang-0.0.27182110 lib/qlang/parser/formula_parser.rb
qlang-0.0.27182100 lib/qlang/parser/formula_parser.rb