482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
|
# File 'lib/oddb2xml/parslet_compositions.rb', line 482
def self.from_string(string)
return nil if string.nil?
stripped = string.gsub(/^"|["\n]+$/, "")
return nil unless stripped
puts "ParseGalenicForm.from_string #{string}" if VERBOSE_MESSAGES
parser = GalenicFormParser.new
transf = GalenicFormTransformer.new
begin
if defined?(RSpec)
ast = transf.apply(parser.parse_with_debug(string))
puts "#{File.basename(__FILE__)}:#{__LINE__}: ==> " if VERBOSE_MESSAGES
pp ast if VERBOSE_MESSAGES
else
ast = transf.apply(parser.parse(string))
end
rescue Parslet::ParseFailed => error
@@error_handler.nrParsingErrors ||= 0
@@error_handler.nrParsingErrors += 1
puts "#{File.basename(__FILE__)}:#{__LINE__}: failed parsing ==> #{string} #{error}"
return nil
end
return [] unless ast
form = ast[:galenic_form] ? ast[:galenic_form].to_s.sub(/^\/\s+/, "") : nil
name = ast[:prepation_name] ? ast[:prepation_name].to_s.strip : nil
[name, form]
end
|