Top Level Namespace

Defined Under Namespace

Modules: NexusParser

Instance Method Summary collapse

Instance Method Details

#parse_nexus_file(input) ⇒ Object



296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/nexus_parser.rb', line 296

def parse_nexus_file(input)
  @input = input
  @input.gsub!(/\[[^\]]*\]/,'')  # strip out all comments BEFORE we parse the file
  # quickly peek at the input, does this look like a Nexus file?
  if !(@input =~ /\#Nexus/i) || !(@input =~ /Begin/i) || !(@input =~ /Matrix/i) || !(@input =~ /(end|endblock)\;/i)
    raise(NexusParser::ParseError, "File is missing at least some required headers, check formatting.", caller)
  end

  builder = NexusParser::Builder.new
  lexer = NexusParser::Lexer.new(@input)
  NexusParser::Parser.new(lexer, builder).parse_file

  return builder.nexus_file
end