Module: Hilbert::Parser::FormulaParser

Includes:
Lexer::Tokens
Defined in:
lib/hilbert/parser/formula_parser.rb

Constant Summary

Constants included from Lexer::Tokens

Lexer::Tokens::ANYSP, Lexer::Tokens::ANYSTR, Lexer::Tokens::BICO, Lexer::Tokens::BRCS, Lexer::Tokens::BRCT, Lexer::Tokens::CLN, Lexer::Tokens::CMA, Lexer::Tokens::COND, Lexer::Tokens::CONJ, Lexer::Tokens::DEFLOGIC, Lexer::Tokens::DIFF_SYM, Lexer::Tokens::DISJ, Lexer::Tokens::DIV, Lexer::Tokens::E, Lexer::Tokens::EMBEDDED_FUNC, Lexer::Tokens::EQL, Lexer::Tokens::EVALOGIC, Lexer::Tokens::EXP, Lexer::Tokens::FLO, Lexer::Tokens::FORMULA, Lexer::Tokens::FUNCCN, Lexer::Tokens::FUNCCV, Lexer::Tokens::FUNCCVN, Lexer::Tokens::FUNCV, Lexer::Tokens::INF, Lexer::Tokens::INT, Lexer::Tokens::INTE_SYM, Lexer::Tokens::LBRCS, Lexer::Tokens::LBRCT, Lexer::Tokens::LDARW, Lexer::Tokens::LIM_SYM, Lexer::Tokens::LPRN, Lexer::Tokens::LSARW, Lexer::Tokens::MUL, Lexer::Tokens::NEGA, Lexer::Tokens::NLIN, Lexer::Tokens::NONL, Lexer::Tokens::NUM, Lexer::Tokens::NUMS_BY_CMA, Lexer::Tokens::NUMS_BY_SP, Lexer::Tokens::NUMS_BY_SP_BY_SCLN_OR_NELN, Lexer::Tokens::OPE, Lexer::Tokens::PI, Lexer::Tokens::PLS, Lexer::Tokens::PRN, Lexer::Tokens::PROVAR, Lexer::Tokens::RBRCS, Lexer::Tokens::RBRCT, Lexer::Tokens::RDARW, Lexer::Tokens::RPRN, Lexer::Tokens::RSARW, Lexer::Tokens::SCLN, Lexer::Tokens::SCLN_OR_NELN, Lexer::Tokens::SGM_SYM, Lexer::Tokens::SPC, Lexer::Tokens::SPCS, Lexer::Tokens::SUB, Lexer::Tokens::USER_FUNC, Lexer::Tokens::VAR, Lexer::Tokens::VARNUM, Lexer::Tokens::VARNUMS_BY_CMA, Lexer::Tokens::VARS_BY_CMA

Class Method Summary collapse

Class Method Details

.execute(str) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/hilbert/parser/formula_parser.rb', line 8

def self.execute(str)
  lexed = Lexer::FormulaLexer.new(str)
  time = Time.now
  loop do
    if Time.now > time + 10
      fail <<-ERROR
I'm so sorry, something wrong. Please feel free to report this. [DEBUG CODE31]

========== DEBUG INFO ==========
str: #{str}
lexed.token_str: #{lexed.token_str}

ERROR
    end
    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