lib/qlang/parser.rb in qlang-0.0.27180000 vs lib/qlang/parser.rb in qlang-0.0.27182000

- old
+ new

@@ -11,10 +11,13 @@ require 'qlang/parser/integral_parser' require 'qlang/parser/formula_parser' module Qlang module Parser + include Lexer::Tokens + SYM = '\w+' + ONEHASH = "#{ANYSP}#{SYM}#{CLN}#{ANYSP}#{VARNUM}#{ANYSP}" # sdf: 234 def execute(lexed) time = Time.now until lexed.token_str =~ /\A(:NLIN\d|:R\d)+\z/ fail "I'm so sorry, something wrong. Please feel free to report this." if Time.now > time + 10 @@ -34,52 +37,66 @@ when :integral IntegralParser.execute(token_val) when :def_func FuncParser.execute(token_val) end - lexed.parsed!(token_position, parsed) + lexed.parsed!(parsed, token_position) - when /:LPRN\d(:CONT\d):RPRN\d/ - cont_token_with_num = $1 - cont_lexed = Lexer::ContLexer.new(lexed.get_value(cont_token_with_num)) + when /:LPRN(\d):CONT\d:RPRN(\d)/ + tokens_range = $1.to_i..$2.to_i + token_val = lexed.lexeds[tokens_range.to_a[1]][:CONT] - cont = "(#{cont_lexed.values.join(' ')})" - lexed.squash_with_prn(cont_token_with_num, cont) + cont_lexed = Lexer::ContLexer.new(token_val) + cont = cont_lexed.values.join(' ') + lexed.parsed!(cont.parentheses, tokens_range) - when /:LBRC\d(:CONT\d):RBRC\d/ - cont_token_with_num = $1 - cont_lexed = Lexer::ContLexer.new(lexed.get_value(cont_token_with_num)) + when /:LBRC(\d):CONT\d:RBRC(\d)/ + tokens_range = $1.to_i..$2.to_i + token_val = lexed.lexeds[tokens_range.to_a[1]][:CONT] - case cont_lexed.token_str - when /(:SYM\d:CLN\d(:STR\d|:NUM\d|:R\d):CMA)*(:SYM\d:CLN\d(:STR\d|:NUM\d|:R\d))/ - cont = ListParser.execute(cont_lexed) - else - cont = "{#{cont_lexed.values.join(' ')}}" - end - lexed.squash_with_prn(cont_token_with_num, cont) + cont = case token_val + when %r@#{ONEHASH}(#{CMA}#{ONEHASH})*@ + ListParser.execute(token_val) + else + token_val + end - when /:eval_func\d/ - cont_token_with_num = $& - cont = lexed.get_value(cont_token_with_num) - lexed.squash_with_prn(cont_token_with_num, cont) + lexed.parsed!(cont, tokens_range) - when /:differential\d/ - cont_token_with_num = $& - cont = lexed.get_value(cont_token_with_num) + when /:eval_func(\d)/ + token_val = lexed.get_value($1) + lexed.parsed!(token_val.parentheses, $1) + + when /:differential(\d)/ + token_position = $1.to_i + cont = lexed.get_value(token_position) cont =~ /(d\/d[a-zA-Z]) (.*)/ cont = "#{$1}(#{FormulaParser.execute($2)})" # FIX: Refactor #cont.gsub!(/(d\/d[a-zA-Z]) (.*)/, "\1(\2)") - lexed.squash_with_prn(cont_token_with_num, cont) - when /:CONT\d/ - lexed.ch_token($&, :R) + lexed.parsed!(cont.parentheses, token_position) + when /:CONT(\d)/ + lexed.parsed!(lexed.get_value($1), $1) end - - lexed.squash_to_cont($1, 2) if lexed.token_str =~ /(:CONT\d|:R\d)(:CONT\d|:R\d)/ + lexed.squash!(($1.to_i)..($1.to_i+1)) if lexed.token_str =~ /(?::CONT|:R)(\d)(?::CONT|:R)(\d)/ end - lexed.fix_r_txt! - lexed.values.join + LangEqualizer.execute( + lexed.values.join + ) end module_function :execute + + # FIXIT + class LangEqualizer + def self.execute(str) + case $meta_info.lang + when :ruby + str.gsub(/\^/, '**') + else + str + end + end + end + end end