481
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
|
# File 'lib/oddb2xml/parslet_compositions.rb', line 481
def ParseGalenicForm.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
@@errorHandler.nrParsingErrors += 1
puts "#{File.basename(__FILE__)}:#{__LINE__}: failed parsing ==> #{string}"
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
return [name, form]
end
|