Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

figuring out git

  • Loading branch information...
commit 5f3110ffe3e0e1c5cee3e5d1efff02114f85f92d 1 parent e98fe4a
@mjy authored
View
4 README.rdoc
@@ -1,6 +1,6 @@
= nexus_parser
-Description goes here.
+See the test files for usage for now, lots of examples there.
== Note on Patches/Pull Requests
@@ -14,4 +14,4 @@ Description goes here.
== Copyright
-Copyright (c) 2010 mjy. See LICENSE for details.
+Copyright (c) 2010 Matt Yoder. See LICENSE for details.
View
8 lib/lexer.rb
@@ -1,6 +1,6 @@
-class NexusFile::Lexer
+class NexusParser::Lexer
def initialize(input)
@input = input
@@ -21,7 +21,7 @@ def pop(token_class)
token = read_next_token(token_class)
@next_token = nil
if token.class != token_class
- raise(NexusFile::ParseError,"expected #{token_class.to_s} but received #{token.class.to_s} at #{@input[0..10]}...", caller)
+ raise(NexusParser::ParseError,"expected #{token_class.to_s} but received #{token.class.to_s} at #{@input[0..10]}...", caller)
else
return token
end
@@ -38,13 +38,13 @@ def read_next_token(token_class)
return @next_token
else
# now check all the tokens for a match
- NexusFile::Tokens.nexus_file_token_list.each {|t|
+ NexusParser::Tokens.nexus_file_token_list.each {|t|
return @next_token if match(t)
}
end
# no match, either end of string or lex-error
if @input != ''
- raise( NexusFile::ParseError, "Lex Error, unknown token at #{@input[0..10]}...", caller)
+ raise( NexusParser::ParseError, "Lex Error, unknown token at #{@input[0..10]}...", caller)
else
return nil
end
View
41 lib/nexus_parser.rb
@@ -7,13 +7,13 @@
# outstanding issues:
## need to resolve Tokens Labels, ValuePair, IDs
-module NexusFile
+module NexusParser
require File.expand_path(File.join(File.dirname(__FILE__), 'tokens'))
require File.expand_path(File.join(File.dirname(__FILE__), 'parser'))
require File.expand_path(File.join(File.dirname(__FILE__), 'lexer'))
-class NexusFile
+class NexusParser
attr_accessor :taxa, :characters, :sets, :codings, :vars, :notes
@@ -117,20 +117,20 @@ def note
end
-# constructs the NexusFile
+# constructs the NexusParser
class Builder
def initialize
- @nf = NexusFile.new
+ @nf = NexusParser.new
end
def stub_taxon
- @nf.taxa.push(NexusFile::Taxon.new)
+ @nf.taxa.push(NexusParser::Taxon.new)
return @nf.taxa.size
end
def stub_chr
- @nf.characters.push(NexusFile::Character.new)
+ @nf.characters.push(NexusParser::Character.new)
return @nf.characters.size
end
@@ -138,7 +138,7 @@ def code_row(taxon_index, rowvector)
@nf.characters.each_with_index do |c, i|
@nf.codings[taxon_index.to_i] = [] if !@nf.codings[taxon_index.to_i]
- @nf.codings[taxon_index.to_i][i] = NexusFile::Coding.new(:states => rowvector[i])
+ @nf.codings[taxon_index.to_i][i] = NexusParser::Coding.new(:states => rowvector[i])
# !! we must update states for a given character if the state isn't found (not all states are referenced in description !!
@@ -183,7 +183,7 @@ def update_chr(options = {} )
# need to create the characters
- raise(NexusFile::ParseError, "Can't update character of index #{@index}, it doesn't exist! This is a problem parsing the character state labels. Check the indices. It may be for this character \"#{@opt[:name]}\".") if !@nf.characters[@index]
+ raise(NexusParser::ParseError, "Can't update character of index #{@index}, it doesn't exist! This is a problem parsing the character state labels. Check the indices. It may be for this character \"#{@opt[:name]}\".") if !@nf.characters[@index]
(@nf.characters[@index].name = @opt[:name]) if @opt[:name]
@@ -223,28 +223,28 @@ def add_note(options = {})
# Why does mesquite differentiate b/w footnotes and annotations?!, apparently same data structure?
when 'TEXT' # a footnote
if @opt[:file]
- @nf.notes << NexusFile::Note.new(@opt)
+ @nf.notes << NexusParser::Note.new(@opt)
elsif @opt[:taxon] && @opt[:character] # its a cell, parse this case
@nf.codings[@opt[:taxon].to_i - 1][@opt[:character].to_i - 1].notes = [] if !@nf.codings[@opt[:taxon].to_i - 1][@opt[:character].to_i - 1].notes
- @nf.codings[@opt[:taxon].to_i - 1][@opt[:character].to_i - 1].notes << NexusFile::Note.new(@opt)
+ @nf.codings[@opt[:taxon].to_i - 1][@opt[:character].to_i - 1].notes << NexusParser::Note.new(@opt)
elsif @opt[:taxon] && !@opt[:character]
- @nf.taxa[@opt[:taxon].to_i - 1].notes << NexusFile::Note.new(@opt)
+ @nf.taxa[@opt[:taxon].to_i - 1].notes << NexusParser::Note.new(@opt)
elsif @opt[:character] && !@opt[:taxon]
- @nf.characters[@opt[:character].to_i - 1].notes << NexusFile::Note.new(@opt)
+ @nf.characters[@opt[:character].to_i - 1].notes << NexusParser::Note.new(@opt)
end
when 'AN' # an annotation, rather than a footnote, same dif
if @opt[:t] && @opt[:c]
@nf.codings[@opt[:t].to_i - 1][@opt[:c].to_i - 1].notes = [] if !@nf.codings[@opt[:t].to_i - 1][@opt[:c].to_i - 1].notes
- @nf.codings[@opt[:t].to_i - 1][@opt[:c].to_i - 1].notes << NexusFile::Note.new(@opt)
+ @nf.codings[@opt[:t].to_i - 1][@opt[:c].to_i - 1].notes << NexusParser::Note.new(@opt)
elsif @opt[:t]
- @nf.taxa[@opt[:t].to_i - 1].notes << NexusFile::Note.new(@opt)
+ @nf.taxa[@opt[:t].to_i - 1].notes << NexusParser::Note.new(@opt)
elsif @opt[:c]
- @nf.characters[@opt[:c].to_i - 1].notes << NexusFile::Note.new(@opt)
+ @nf.characters[@opt[:c].to_i - 1].notes << NexusParser::Note.new(@opt)
end
end
@@ -256,7 +256,7 @@ def nexus_file
end # end file
- # NexusFile::ParseError
+ # NexusParser::ParseError
class ParseError < StandardError
end
@@ -267,15 +267,14 @@ class ParseError < StandardError
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\;/i)
- raise(NexusFile::ParseError, "File is missing at least some required headers, check formatting.", caller)
+ raise(NexusParser::ParseError, "File is missing at least some required headers, check formatting.", caller)
end
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(@input)
- NexusFile::Parser.new(lexer, builder).parse_file
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(@input)
+ NexusParser::Parser.new(lexer, builder).parse_file
return builder.nexus_file
end
View
184 lib/parser.rb
@@ -1,5 +1,5 @@
-class NexusFile::Parser
+class NexusParser::Parser
def initialize(lexer, builder)
@lexer = lexer
@@ -7,50 +7,50 @@ def initialize(lexer, builder)
end
def parse_file
- # nf = @builder.new_nexus_file # create new local NexusFile instance, nf
+ # nf = @builder.new_nexus_file # create new local NexusParser instance, nf
blks = []
- @lexer.pop(NexusFile::Tokens::NexusStart)
+ @lexer.pop(NexusParser::Tokens::NexusStart)
- while @lexer.peek(NexusFile::Tokens::BeginBlk)
+ while @lexer.peek(NexusParser::Tokens::BeginBlk)
- @lexer.pop(NexusFile::Tokens::BeginBlk) # pop it
+ @lexer.pop(NexusParser::Tokens::BeginBlk) # pop it
- if @lexer.peek(NexusFile::Tokens::AuthorsBlk)
+ if @lexer.peek(NexusParser::Tokens::AuthorsBlk)
parse_authors_blk
# we parse these below
- elsif @lexer.peek(NexusFile::Tokens::TaxaBlk)
+ elsif @lexer.peek(NexusParser::Tokens::TaxaBlk)
- @lexer.pop(NexusFile::Tokens::TaxaBlk )
+ @lexer.pop(NexusParser::Tokens::TaxaBlk )
parse_taxa_blk
- elsif @lexer.peek(NexusFile::Tokens::ChrsBlk)
- @lexer.pop(NexusFile::Tokens::ChrsBlk)
+ elsif @lexer.peek(NexusParser::Tokens::ChrsBlk)
+ @lexer.pop(NexusParser::Tokens::ChrsBlk)
parse_characters_blk
- elsif @lexer.peek(NexusFile::Tokens::NotesBlk)
- @lexer.pop(NexusFile::Tokens::NotesBlk)
+ elsif @lexer.peek(NexusParser::Tokens::NotesBlk)
+ @lexer.pop(NexusParser::Tokens::NotesBlk)
parse_notes_blk
# we should parse this
- elsif @lexer.peek(NexusFile::Tokens::SetsBlk)
- @lexer.pop(NexusFile::Tokens::SetsBlk)
+ elsif @lexer.peek(NexusParser::Tokens::SetsBlk)
+ @lexer.pop(NexusParser::Tokens::SetsBlk)
# we don't parse these
- elsif @lexer.peek(NexusFile::Tokens::TreesBlk)
- @foo = @lexer.pop(NexusFile::Tokens::TreesBlk).value
+ elsif @lexer.peek(NexusParser::Tokens::TreesBlk)
+ @foo = @lexer.pop(NexusParser::Tokens::TreesBlk).value
- elsif @lexer.peek(NexusFile::Tokens::LabelsBlk)
- @lexer.pop(NexusFile::Tokens::LabelsBlk)
+ elsif @lexer.peek(NexusParser::Tokens::LabelsBlk)
+ @lexer.pop(NexusParser::Tokens::LabelsBlk)
- elsif @lexer.peek(NexusFile::Tokens::MqCharModelsBlk)
- @lexer.pop(NexusFile::Tokens::MqCharModelsBlk)
+ elsif @lexer.peek(NexusParser::Tokens::MqCharModelsBlk)
+ @lexer.pop(NexusParser::Tokens::MqCharModelsBlk)
- elsif @lexer.peek(NexusFile::Tokens::AssumptionsBlk)
- @lexer.pop(NexusFile::Tokens::AssumptionsBlk)
+ elsif @lexer.peek(NexusParser::Tokens::AssumptionsBlk)
+ @lexer.pop(NexusParser::Tokens::AssumptionsBlk)
- elsif @lexer.peek(NexusFile::Tokens::CodonsBlk)
- @lexer.pop(NexusFile::Tokens::CodonsBlk)
+ elsif @lexer.peek(NexusParser::Tokens::CodonsBlk)
+ @lexer.pop(NexusParser::Tokens::CodonsBlk)
end
end
@@ -60,50 +60,50 @@ def parse_file
def parse_authors_blk
# thing has non single word key/value pairs, like "AUTHOR NAME", SIGH
# for now just slurp it all up.
- @lexer.pop(NexusFile::Tokens::AuthorsBlk )
+ @lexer.pop(NexusParser::Tokens::AuthorsBlk )
#while true
- # if @lexer.peek(NexusFile::Tokens::EndBlk)
- # @lexer.pop(NexusFile::Tokens::EndBlk)
+ # if @lexer.peek(NexusParser::Tokens::EndBlk)
+ # @lexer.pop(NexusParser::Tokens::EndBlk)
# break
# else
- # while @lexer.peek(NexusFile::Tokens::ValuePair)
+ # while @lexer.peek(NexusParser::Tokens::ValuePair)
# # IMPORTANT, these are going to a general hash, there may ultimately be overlap of keys used in different blocks, this is ignored at present
- # @builder.add_var(@lexer.pop(NexusFile::Tokens::ValuePair).value)
+ # @builder.add_var(@lexer.pop(NexusParser::Tokens::ValuePair).value)
# end
- #@lexer.pop(NexusFile::Tokens::ID) if @lexer.peek(NexusFile::Tokens::ID)
+ #@lexer.pop(NexusParser::Tokens::ID) if @lexer.peek(NexusParser::Tokens::ID)
# end
#end
end
def parse_taxa_blk
- @lexer.pop(NexusFile::Tokens::Title) if @lexer.peek(NexusFile::Tokens::Title)
+ @lexer.pop(NexusParser::Tokens::Title) if @lexer.peek(NexusParser::Tokens::Title)
# need to not ignore to test against
- parse_dimensions if @lexer.peek(NexusFile::Tokens::Dimensions)
+ parse_dimensions if @lexer.peek(NexusParser::Tokens::Dimensions)
while true
- if @lexer.peek(NexusFile::Tokens::EndBlk)
- @lexer.pop(NexusFile::Tokens::EndBlk)
+ if @lexer.peek(NexusParser::Tokens::EndBlk)
+ @lexer.pop(NexusParser::Tokens::EndBlk)
break
else
- if @lexer.peek(NexusFile::Tokens::Taxlabels)
- @lexer.pop(NexusFile::Tokens::Taxlabels) if @lexer.peek(NexusFile::Tokens::Taxlabels)
+ if @lexer.peek(NexusParser::Tokens::Taxlabels)
+ @lexer.pop(NexusParser::Tokens::Taxlabels) if @lexer.peek(NexusParser::Tokens::Taxlabels)
i = 0
- while @lexer.peek(NexusFile::Tokens::Label)
- @builder.update_taxon(:index => i, :name => @lexer.pop(NexusFile::Tokens::Label).value)
+ while @lexer.peek(NexusParser::Tokens::Label)
+ @builder.update_taxon(:index => i, :name => @lexer.pop(NexusParser::Tokens::Label).value)
i += 1
end
- @lexer.pop(NexusFile::Tokens::SemiColon) if @lexer.peek(NexusFile::Tokens::SemiColon) # close of tax labels, placement of this seems dubious... but tests are working
+ @lexer.pop(NexusParser::Tokens::SemiColon) if @lexer.peek(NexusParser::Tokens::SemiColon) # close of tax labels, placement of this seems dubious... but tests are working
- elsif @lexer.peek(NexusFile::Tokens::MesquiteIDs)
+ elsif @lexer.peek(NexusParser::Tokens::MesquiteIDs)
- @lexer.pop(NexusFile::Tokens::MesquiteIDs) # trashing these for now
- elsif @lexer.peek(NexusFile::Tokens::MesquiteBlockID)
- @lexer.pop(NexusFile::Tokens::MesquiteBlockID)
+ @lexer.pop(NexusParser::Tokens::MesquiteIDs) # trashing these for now
+ elsif @lexer.peek(NexusParser::Tokens::MesquiteBlockID)
+ @lexer.pop(NexusParser::Tokens::MesquiteBlockID)
end
end
@@ -114,43 +114,43 @@ def parse_taxa_blk
def parse_characters_blk
while true
- if @lexer.peek(NexusFile::Tokens::EndBlk) # we're at the end of the block, exit after geting rid of the semi-colon
+ if @lexer.peek(NexusParser::Tokens::EndBlk) # we're at the end of the block, exit after geting rid of the semi-colon
break
else
- @lexer.pop(NexusFile::Tokens::Title) if @lexer.peek(NexusFile::Tokens::Title) # not used at present
+ @lexer.pop(NexusParser::Tokens::Title) if @lexer.peek(NexusParser::Tokens::Title) # not used at present
- parse_dimensions if @lexer.peek(NexusFile::Tokens::Dimensions)
- parse_format if @lexer.peek(NexusFile::Tokens::Format)
+ parse_dimensions if @lexer.peek(NexusParser::Tokens::Dimensions)
+ parse_format if @lexer.peek(NexusParser::Tokens::Format)
- parse_chr_state_labels if @lexer.peek(NexusFile::Tokens::CharStateLabels)
+ parse_chr_state_labels if @lexer.peek(NexusParser::Tokens::CharStateLabels)
- parse_matrix if @lexer.peek(NexusFile::Tokens::Matrix)
+ parse_matrix if @lexer.peek(NexusParser::Tokens::Matrix)
# handle "\s*OPTIONS MSTAXA = UNCERTAIN;\s\n" within a characters block (sticks in an infinite loop right now)
- @lexer.pop(NexusFile::Tokens::MesquiteIDs) if @lexer.peek(NexusFile::Tokens::MesquiteIDs) # trashing these for now
- @lexer.pop(NexusFile::Tokens::MesquiteBlockID) if @lexer.peek(NexusFile::Tokens::MesquiteBlockID) # trashing these for now
+ @lexer.pop(NexusParser::Tokens::MesquiteIDs) if @lexer.peek(NexusParser::Tokens::MesquiteIDs) # trashing these for now
+ @lexer.pop(NexusParser::Tokens::MesquiteBlockID) if @lexer.peek(NexusParser::Tokens::MesquiteBlockID) # trashing these for now
false
end
end
- @lexer.pop(NexusFile::Tokens::EndBlk)
+ @lexer.pop(NexusParser::Tokens::EndBlk)
end
# prolly pop header then fuse with parse_dimensions
def parse_format
- @lexer.pop(NexusFile::Tokens::Format)
- while @lexer.peek(NexusFile::Tokens::ValuePair)
- @builder.add_var(@lexer.pop(NexusFile::Tokens::ValuePair).value)
+ @lexer.pop(NexusParser::Tokens::Format)
+ while @lexer.peek(NexusParser::Tokens::ValuePair)
+ @builder.add_var(@lexer.pop(NexusParser::Tokens::ValuePair).value)
end
check_initialization_of_ntax_nchar
end
def parse_dimensions
- @lexer.pop(NexusFile::Tokens::Dimensions)
- while @lexer.peek(NexusFile::Tokens::ValuePair)
- @builder.add_var(@lexer.pop(NexusFile::Tokens::ValuePair).value)
+ @lexer.pop(NexusParser::Tokens::Dimensions)
+ while @lexer.peek(NexusParser::Tokens::ValuePair)
+ @builder.add_var(@lexer.pop(NexusParser::Tokens::ValuePair).value)
end
# the last value pair with a ; is automagically handled, don't try popping it again
@@ -170,33 +170,33 @@ def check_initialization_of_ntax_nchar
end
def parse_chr_state_labels
- @lexer.pop(NexusFile::Tokens::CharStateLabels)
+ @lexer.pop(NexusParser::Tokens::CharStateLabels)
while true
- if @lexer.peek(NexusFile::Tokens::SemiColon)
+ if @lexer.peek(NexusParser::Tokens::SemiColon)
break
else
opts = {}
name = ""
- index = @lexer.pop(NexusFile::Tokens::Number).value.to_i
- (name = @lexer.pop(NexusFile::Tokens::Label).value) if @lexer.peek(NexusFile::Tokens::Label) # not always given a letter
+ index = @lexer.pop(NexusParser::Tokens::Number).value.to_i
+ (name = @lexer.pop(NexusParser::Tokens::Label).value) if @lexer.peek(NexusParser::Tokens::Label) # not always given a letter
- @lexer.pop(NexusFile::Tokens::BckSlash) if @lexer.peek(NexusFile::Tokens::BckSlash)
+ @lexer.pop(NexusParser::Tokens::BckSlash) if @lexer.peek(NexusParser::Tokens::BckSlash)
- if !@lexer.peek(NexusFile::Tokens::Comma) || !@lexer.peek(NexusFile::Tokens::SemiColon)
+ if !@lexer.peek(NexusParser::Tokens::Comma) || !@lexer.peek(NexusParser::Tokens::SemiColon)
i = 0
# three kludge lines, need to figure out the label/number priority, could be issue in list order w/in tokens
- while @lexer.peek(NexusFile::Tokens::Label) || @lexer.peek(NexusFile::Tokens::Number)
- opts.update({i.to_s => @lexer.pop(NexusFile::Tokens::Label).value}) if @lexer.peek(NexusFile::Tokens::Label)
- opts.update({i.to_s => @lexer.pop(NexusFile::Tokens::Number).value.to_s}) if @lexer.peek(NexusFile::Tokens::Number)
+ while @lexer.peek(NexusParser::Tokens::Label) || @lexer.peek(NexusParser::Tokens::Number)
+ opts.update({i.to_s => @lexer.pop(NexusParser::Tokens::Label).value}) if @lexer.peek(NexusParser::Tokens::Label)
+ opts.update({i.to_s => @lexer.pop(NexusParser::Tokens::Number).value.to_s}) if @lexer.peek(NexusParser::Tokens::Number)
i += 1
end
end
- @lexer.pop(NexusFile::Tokens::Comma) if @lexer.peek(NexusFile::Tokens::Comma) # we may also have hit semicolon
+ @lexer.pop(NexusParser::Tokens::Comma) if @lexer.peek(NexusParser::Tokens::Comma) # we may also have hit semicolon
opts.update({:index => (index - 1), :name => name})
@@ -205,56 +205,56 @@ def parse_chr_state_labels
end
end
- @lexer.pop(NexusFile::Tokens::SemiColon)
+ @lexer.pop(NexusParser::Tokens::SemiColon)
end
def parse_matrix
- @lexer.pop(NexusFile::Tokens::Matrix)
+ @lexer.pop(NexusParser::Tokens::Matrix)
i = 0
while true
- if @lexer.peek(NexusFile::Tokens::SemiColon)
+ if @lexer.peek(NexusParser::Tokens::SemiColon)
break
else
- t = @lexer.pop(NexusFile::Tokens::Label).value
+ t = @lexer.pop(NexusParser::Tokens::Label).value
@builder.update_taxon(:index => i, :name => t) # if it exists its not re-added
- @builder.code_row(i, @lexer.pop(NexusFile::Tokens::RowVec).value)
+ @builder.code_row(i, @lexer.pop(NexusParser::Tokens::RowVec).value)
i += 1
end
end
- @lexer.pop(NexusFile::Tokens::SemiColon) # pop the semicolon
+ @lexer.pop(NexusParser::Tokens::SemiColon) # pop the semicolon
end
# this suck(s/ed), it needs work when a better API for Mesquite comes out
def parse_notes_blk
- # IMPORTANT - we don't parse the (CM <note>), we just strip the "(CM" ... ")" bit for now in NexusFile::Note
+ # IMPORTANT - we don't parse the (CM <note>), we just strip the "(CM" ... ")" bit for now in NexusParser::Note
@vars = {}
inf = 0
while true
inf += 1
raise "Either you have a gazillion notes or more likely parser is caught in an infinite loop inside parse_notes_block" if inf > 100000
- if @lexer.peek(NexusFile::Tokens::EndBlk)
- @lexer.pop(NexusFile::Tokens::EndBlk)
+ if @lexer.peek(NexusParser::Tokens::EndBlk)
+ @lexer.pop(NexusParser::Tokens::EndBlk)
@builder.add_note(@vars) # one still left to add
break
else
- if @lexer.peek(NexusFile::Tokens::ValuePair)
- @vars.update(@lexer.pop(NexusFile::Tokens::ValuePair).value)
+ if @lexer.peek(NexusParser::Tokens::ValuePair)
+ @vars.update(@lexer.pop(NexusParser::Tokens::ValuePair).value)
- elsif @lexer.peek(NexusFile::Tokens::Label)
+ elsif @lexer.peek(NexusParser::Tokens::Label)
if @vars[:type] # we have the data for this row write it, and start a new one
@builder.add_note(@vars)
@vars = {}
else
- @vars.update(:type => @lexer.pop(NexusFile::Tokens::Label).value)
+ @vars.update(:type => @lexer.pop(NexusParser::Tokens::Label).value)
end
- elsif @lexer.peek(NexusFile::Tokens::FileLbl)
- @lexer.pop(NexusFile::Tokens::FileLbl)
+ elsif @lexer.peek(NexusParser::Tokens::FileLbl)
+ @lexer.pop(NexusParser::Tokens::FileLbl)
@vars.update(:file => 'file') # we check for whether :file key is present and handle conditionally
end
end
@@ -264,27 +264,27 @@ def parse_notes_blk
#@vars = {}
#while true
- # break if @lexer.peek(NexusFile::Tokens::EndBlk)
+ # break if @lexer.peek(NexusParser::Tokens::EndBlk)
- # @vars.update(:type => @lexer.pop(NexusFile::Tokens::Label).value)
+ # @vars.update(:type => @lexer.pop(NexusParser::Tokens::Label).value)
# kludge to get around the funny construct that references file
- # if @lexer.peek(NexusFile::Tokens::FileLbl)
- # @lexer.pop(NexusFile::Tokens::FileLbl)
+ # if @lexer.peek(NexusParser::Tokens::FileLbl)
+ # @lexer.pop(NexusParser::Tokens::FileLbl)
# vars.update(:file => 'file') # we check for whether :file key is present and handle conditionally
# end
# while true
- # meh = @lexer.pop(NexusFile::Tokens::ValuePair)
+ # meh = @lexer.pop(NexusParser::Tokens::ValuePair)
# @vars.update(meh.value)
- # break if !@lexer.peek(NexusFile::Tokens::ValuePair)
+ # break if !@lexer.peek(NexusParser::Tokens::ValuePair)
# end
#
# @builder.add_note(@vars)
# @vars = {}
#end
- # @lexer.pop(NexusFile::Tokens::EndBlk)
+ # @lexer.pop(NexusParser::Tokens::EndBlk)
def parse_trees_blk
@@ -320,8 +320,8 @@ def parse_mesquite_blk
# parse a comma-separated list of nodes
# while true
# parse_node(parent)
- # if @lexer.peek(NexusFile::Tokens::Comma)
- # @lexer.pop(NexusFile::Tokens::Comma)
+ # if @lexer.peek(NexusParser::Tokens::Comma)
+ # @lexer.pop(NexusParser::Tokens::Comma)
# else
# break
# end
View
80 lib/tokens.rb
@@ -1,4 +1,4 @@
-module NexusFile::Tokens
+module NexusParser::Tokens
class Token
# this allows access the the class attribute regexp, without using a class variable
@@ -220,48 +220,48 @@ def initialize(str)
end
end
- # NexusFile::Tokens::NexusComment
+ # NexusParser::Tokens::NexusComment
# this list also defines priority, i.e. if tokens have overlap (which they shouldn't!!) then the earlier indexed token will match first
def self.nexus_file_token_list
- [ NexusFile::Tokens::NexusStart,
- NexusFile::Tokens::BeginBlk,
- NexusFile::Tokens::EndBlk,
- NexusFile::Tokens::AuthorsBlk,
- NexusFile::Tokens::SetsBlk,
- NexusFile::Tokens::MqCharModelsBlk,
- NexusFile::Tokens::AssumptionsBlk,
- NexusFile::Tokens::CodonsBlk,
- NexusFile::Tokens::MesquiteBlk,
- NexusFile::Tokens::TreesBlk,
- NexusFile::Tokens::LabelsBlk,
- NexusFile::Tokens::TaxaBlk,
- NexusFile::Tokens::NotesBlk,
- NexusFile::Tokens::Title,
- NexusFile::Tokens::Taxlabels,
- NexusFile::Tokens::Dimensions,
- NexusFile::Tokens::FileLbl,
- NexusFile::Tokens::Format,
- NexusFile::Tokens::Equals,
- NexusFile::Tokens::ValuePair, # this has bad overlap with Label and likely IDs (need to kill the latter, its a lesser Label)
- NexusFile::Tokens::CharStateLabels,
- NexusFile::Tokens::ChrsBlk,
- NexusFile::Tokens::Number,
- NexusFile::Tokens::Matrix,
- NexusFile::Tokens::SemiColon,
- NexusFile::Tokens::MesquiteIDs,
- NexusFile::Tokens::MesquiteBlockID,
- NexusFile::Tokens::BlkEnd,
- NexusFile::Tokens::Colon,
- NexusFile::Tokens::BckSlash,
- NexusFile::Tokens::Comma,
- NexusFile::Tokens::LParen,
- NexusFile::Tokens::RParen,
- NexusFile::Tokens::LBracket,
- NexusFile::Tokens::RBracket,
- NexusFile::Tokens::Label, # must be before RowVec
- NexusFile::Tokens::RowVec,
- NexusFile::Tokens::ID # need to trash this
+ [ NexusParser::Tokens::NexusStart,
+ NexusParser::Tokens::BeginBlk,
+ NexusParser::Tokens::EndBlk,
+ NexusParser::Tokens::AuthorsBlk,
+ NexusParser::Tokens::SetsBlk,
+ NexusParser::Tokens::MqCharModelsBlk,
+ NexusParser::Tokens::AssumptionsBlk,
+ NexusParser::Tokens::CodonsBlk,
+ NexusParser::Tokens::MesquiteBlk,
+ NexusParser::Tokens::TreesBlk,
+ NexusParser::Tokens::LabelsBlk,
+ NexusParser::Tokens::TaxaBlk,
+ NexusParser::Tokens::NotesBlk,
+ NexusParser::Tokens::Title,
+ NexusParser::Tokens::Taxlabels,
+ NexusParser::Tokens::Dimensions,
+ NexusParser::Tokens::FileLbl,
+ NexusParser::Tokens::Format,
+ NexusParser::Tokens::Equals,
+ NexusParser::Tokens::ValuePair, # this has bad overlap with Label and likely IDs (need to kill the latter, its a lesser Label)
+ NexusParser::Tokens::CharStateLabels,
+ NexusParser::Tokens::ChrsBlk,
+ NexusParser::Tokens::Number,
+ NexusParser::Tokens::Matrix,
+ NexusParser::Tokens::SemiColon,
+ NexusParser::Tokens::MesquiteIDs,
+ NexusParser::Tokens::MesquiteBlockID,
+ NexusParser::Tokens::BlkEnd,
+ NexusParser::Tokens::Colon,
+ NexusParser::Tokens::BckSlash,
+ NexusParser::Tokens::Comma,
+ NexusParser::Tokens::LParen,
+ NexusParser::Tokens::RParen,
+ NexusParser::Tokens::LBracket,
+ NexusParser::Tokens::RBracket,
+ NexusParser::Tokens::Label, # must be before RowVec
+ NexusParser::Tokens::RowVec,
+ NexusParser::Tokens::ID # need to trash this
]
end
View
7 nexus_parser.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{nexus_parser}
- s.version = "1.0.0"
+ s.version = "1.1.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["mjy"]
- s.date = %q{2010-03-17}
+ s.date = %q{2010-03-18}
s.description = %q{A full featured and extensible Nexus file parser in Ruby. }
s.email = %q{diapriid@gmail.com}
s.extra_rdoc_files = [
@@ -29,9 +29,10 @@ Gem::Specification.new do |s|
"init.rb",
"install.rb",
"lib/lexer.rb",
- "lib/nexus_file.rb",
+ "lib/nexus_parser.rb",
"lib/parser.rb",
"lib/tokens.rb",
+ "nexus_parser.gemspec",
"tasks/nexus_parser_tasks.rake",
"test/MX_test_03.nex",
"test/test.nex",
View
468 test/MX_test_03.nex
@@ -1,234 +1,234 @@
-#NEXUS
-[written Sun Apr 20 17:45:47 EDT 2008 by Mesquite version 2.0 (build i69) at procto/192.168.0.100]
-BEGIN AUTHORS;
-AUTHOR NAME = Jonathan_Coddington CODE = JC;
-END;
-
-
-BEGIN TAXA;
- TITLE 'Scharff&Coddington_1997_Araneidae';
- DIMENSIONS NTAX=10;
- TAXLABELS
- Dictyna Uloborus Deinopis Nephila&Herennia 'Nephilengys_cruentata' Meta Leucauge_venusta Pachygnatha 'Theridiosoma_01' Tetragnatha
- ;
- IDS JC1191fcddc2b128 JC1191fcddc2b129 JC1191fcddc2b130 JC1191fcddc2b131 JC1191fcddc2b132 JC1191fcddc2b133 JC1191fcddc2b134 JC1191fcddc2b135 JC1191fcddc2b137 JC1191fcddc2b136 ;
- BLOCKID JC1191fcddc0c4;
-
-END;
-
-
-BEGIN CHARACTERS;
- TITLE 'Scharff&Coddington_1997_Araneidae';
- DIMENSIONS NCHAR=10;
- FORMAT DATATYPE = STANDARD GAP = - MISSING = ? SYMBOLS = " 0 1 2 3 4 5 6 7 8 9 A";
- CHARSTATELABELS
- 1 Tibia_II / norm modified, 2 TII_macrosetae / '= TI' stronger, 3 Femoral_tuber / abs pres 'm-setae', 5 Cymbium / dorsal mesal lateral, 6 Paracymbium / abs pres, 7 Globular_tegulum / abs pres, 8 / entire w_lobe, 9 Conductor_wraps_embolus, 10 Median_apophysis / pres abs ;
- MATRIX
- Dictyna 0?00201001
- Uloborus 0?11000000
- Deinopis 0?01002???
- Nephila&Herennia 0?21010011
- 'Nephilengys_cruentata'0?(0,1)1010(0,1,2)11
- Meta 0?01A10011
- Leucauge_venusta ???--?-??-
- Pachygnatha 0?210(0,1)0011
- 'Theridiosoma_01' ??????????
- Tetragnatha 0?01011011
-
-;
- IDS JC1191fcddc3b425 JC1191fcddc3b426 JC1191fcddc3b427 JC1191fcddc3b428 JC1191fcddc3b429 JC1191fcddc3b430 JC1191fcddc3b431 JC1191fcddc3b432 JC1191fcddc3b433 JC1191fcddc3b434 ;
- BLOCKID JC1191fcddc0c0;
-
-
-END;
-BEGIN TREES;
- Title Imported_trees;
- LINK Taxa = 'Scharff&Coddington_1997_Araneidae';
- TRANSLATE
- 1 Dictyna,
- 2 Uloborus,
- 3 Deinopis,
- 4 Nephila&Herennia,
- 5 'Nephilengys_cruentata',
- 6 Meta,
- 7 Leucauge_venusta,
- 8 Pachygnatha,
- 9 'Theridiosoma_01',
- 10 Tetragnatha;
- TREE 'Imported tree 1+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
- TREE 'Imported tree 2+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
- TREE 'Imported tree 3+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
- TREE 'Imported tree 4+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
- TREE 'Imported tree 5+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
- TREE 'Imported tree 6+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
- TREE 'Imported tree 7+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
- TREE 'Imported tree 8+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
-
-END;
-
-
-BEGIN LABELS;
- CHARGROUPLABEL MM_Genitalia COLOR = (RGB 1.0 0.4 0.4) ;
- CHARGROUPLABEL Somatic COLOR = (RGB 0.6 1.0 0.33333333) ;
- CHARGROUPLABEL Spinnerets COLOR = (RGB 0.46666667 0.57254902 1.0) ;
- CHARGROUPLABEL Behavior COLOR = (RGB 1.0 0.46666667 1.0) ;
-
-
-END;
-
-BEGIN SETS;
-CHARPARTITION * UNTITLED = Somatic : 1 - 2 4, MM_Genitalia : 5 - 8 10;
-
-END;
-
-BEGIN ASSUMPTIONS;
- TYPESET * UNTITLED = unord: 1 - 10;
-
- EXSET * UNTITLED = ;
-
- WTSET * UNTITLED = 1: 1 - 10 ;
-
-END;
-
-BEGIN CODONS;
-CODESET * UNTITLED = universal: 1 - 10;
-
-
-END;
-
-BEGIN MESQUITECHARMODELS;
- ProbModelSet * UNTITLED = 'Mk1 (est.)': 1 - 10;
-END;
-
-BEGIN NOTES;
-
- TEXT TAXA = 'Scharff&Coddington_1997_Araneidae' TAXON = 2 TEXT = 'This is a footnote to taxon 2, Uloborus';
-
- TEXT TAXON = 4 CHARACTER = 8 TEXT = This_is_a_footnote_to_a_cell.;
-
- TEXT CHARACTER = 10 TEXT = This_is_footnote_to_char_10;
-
- TEXT FILE TEXT = 'Scharff, N. and J. A. Coddington. 1997. A phylogenetic analysis of the orb-weaving spider family Araneidae (Arachnida, Araneae). Zool. J. Linn. Soc. 120(4): 355?434';
-
- AN T = 4 A = JC DC = 2008.4.13.20.31.19 DM = 2008.4.13.20.31.38 ID = 01194a57d0161 I = _ TF = (CM 'This is an "annotation" to taxon 4') ;
-
- AN C = 4 A = JC DC = 2008.4.13.20.31.50 DM = 2008.4.13.20.32.10 ID = 01194a584b9f2 I = _ TF = (CM 'This is an annotation to charcter 4, that has no name.') ;
-
- AN T = 9 C = 3 A = 0 DC = 2008.4.20.17.24.36 DM = 2008.4.20.17.25.4 ID = 01196db963874 I = _ TF = (CM 'This is an annotation to chr 3, taxa 9, coded ?') ;
-
- AN T = 2 C = 6 A = JC DC = 2008.4.13.20.35.20 DM = 2008.4.13.20.35.36 ID = JC1194a5b7e1a3 I = _ TF = (CM 'This is an annotation that haa a hard return in it^n^n^n^nSo there!') ;
-
- AN T = 7 C = 10 A = 0 DC = 2008.4.20.17.25.11 DM = 2008.4.20.17.26.1 ID = 01196db9ebd25 I = _ TF = (CM 'this is an annotation^nwith several hard returns^nfor a cell of taxa 6, chr 9 (from zero)^ncoded as -') ;
-
-END;
-
-Begin MESQUITE;
- MESQUITESCRIPTVERSION 2;
- TITLE AUTO;
- tell ProjectCoordinator;
- getEmployee #mesquite.minimal.ManageTaxa.ManageTaxa;
- tell It;
- setID 0 6498976404544962919 JC1191fcddc0c4;
- tell It;
- setDefaultOrder 0 1 2 3 4 5 6 7 9 8;
- attachments ;
- endTell;
- endTell;
- getEmployee #mesquite.charMatrices.ManageCharacters.ManageCharacters;
- tell It;
- setID 0 2280451364422511229 JC1191fcddc0c0;
- checksum 0 3839411132 JC1191fcddc0c0;
- endTell;
- getEmployee #mesquite.charMatrices.BasicDataWindowCoord.BasicDataWindowCoord;
- tell It;
- showDataWindow #2280451364422511229 #mesquite.charMatrices.BasicDataWindowMaker.BasicDataWindowMaker;
- tell It;
- getWindow;
- tell It;
- getTable;
- tell It;
- columnWidth 6 55;
- columnWidth 7 23;
- endTell;
- setExplanationSize 30;
- setAnnotationSize 20;
- setFontIncAnnot 0;
- setFontIncExp 0;
- setSize 925 472;
- setLocation 357 294;
- setFont SanSerif;
- setFontSize 10;
- getToolPalette;
- tell It;
- setTool mesquite.charMatrices.BasicDataWindowMaker.BasicDataWindow.ibeam;
- endTell;
- setActive;
- setTool mesquite.charMatrices.BasicDataWindowMaker.BasicDataWindow.ibeam;
- colorCells #mesquite.charMatrices.AnnotPanel.AnnotPanel;
- tell It;
- togglePanel on;
- endTell;
- setBackground White;
- toggleShowNames off;
- toggleTight off;
- toggleShowChanges on;
- toggleSeparateLines off;
- toggleShowStates on;
- toggleAutoWCharNames off;
- toggleShowDefaultCharNames off;
- toggleConstrainCW on;
- setColumnWidth 16;
- toggleBirdsEye off;
- toggleColorsPanel off;
- birdsEyeWidth 2;
- toggleLinkedScrolling on;
- toggleScrollLinkedTables off;
- endTell;
- showWindow;
- getEmployee #mesquite.categ.StateNamesEditor.StateNamesEditor;
- tell It;
- makeWindow;
- tell It;
- setExplanationSize 30;
- setAnnotationSize 20;
- setFontIncAnnot 0;
- setFontIncExp 0;
- setSize 925 472;
- setLocation 357 294;
- setFont SanSerif;
- setFontSize 10;
- getToolPalette;
- tell It;
- setTool mesquite.categ.StateNamesEditor.StateNamesWindow.ibeam;
- endTell;
- rowsAreCharacters on;
- toggleConstrainChar on;
- toggleConstrainCharNum 3;
- togglePanel off;
- toggleSummaryPanel off;
- endTell;
- showWindow;
- endTell;
- getEmployee #mesquite.categ.StateNamesStrip.StateNamesStrip;
- tell It;
- showStrip off;
- endTell;
- getEmployee #mesquite.charMatrices.CharReferenceStrip.CharReferenceStrip;
- tell It;
- showStrip off;
- endTell;
- getEmployee #mesquite.charMatrices.ColorCells.ColorCells;
- tell It;
- setColor Red;
- removeColor off;
- endTell;
- getEmployee #mesquite.charMatrices.QuickKeySelector.QuickKeySelector;
- tell It;
- autotabOff;
- endTell;
- endTell;
- endTell;
- endTell;
-end;
-
-
+#NEXUS
+[written Sun Apr 20 17:45:47 EDT 2008 by Mesquite version 2.0 (build i69) at procto/192.168.0.100]
+BEGIN AUTHORS;
+AUTHOR NAME = Jonathan_Coddington CODE = JC;
+END;
+
+
+BEGIN TAXA;
+ TITLE 'Scharff&Coddington_1997_Araneidae';
+ DIMENSIONS NTAX=10;
+ TAXLABELS
+ Dictyna Uloborus Deinopis Nephila&Herennia 'Nephilengys_cruentata' Meta Leucauge_venusta Pachygnatha 'Theridiosoma_01' Tetragnatha
+ ;
+ IDS JC1191fcddc2b128 JC1191fcddc2b129 JC1191fcddc2b130 JC1191fcddc2b131 JC1191fcddc2b132 JC1191fcddc2b133 JC1191fcddc2b134 JC1191fcddc2b135 JC1191fcddc2b137 JC1191fcddc2b136 ;
+ BLOCKID JC1191fcddc0c4;
+
+END;
+
+
+BEGIN CHARACTERS;
+ TITLE 'Scharff&Coddington_1997_Araneidae';
+ DIMENSIONS NCHAR=10;
+ FORMAT DATATYPE = STANDARD GAP = - MISSING = ? SYMBOLS = " 0 1 2 3 4 5 6 7 8 9 A";
+ CHARSTATELABELS
+ 1 Tibia_II / norm modified, 2 TII_macrosetae / '= TI' stronger, 3 Femoral_tuber / abs pres 'm-setae', 5 Cymbium / dorsal mesal lateral, 6 Paracymbium / abs pres, 7 Globular_tegulum / abs pres, 8 / entire w_lobe, 9 Conductor_wraps_embolus, 10 Median_apophysis / pres abs ;
+ MATRIX
+ Dictyna 0?00201001
+ Uloborus 0?11000000
+ Deinopis 0?01002???
+ Nephila&Herennia 0?21010011
+ 'Nephilengys_cruentata'0?(0,1)1010(0,1,2)11
+ Meta 0?01A10011
+ Leucauge_venusta ???--?-??-
+ Pachygnatha 0?210(0,1)0011
+ 'Theridiosoma_01' ??????????
+ Tetragnatha 0?01011011
+
+;
+ IDS JC1191fcddc3b425 JC1191fcddc3b426 JC1191fcddc3b427 JC1191fcddc3b428 JC1191fcddc3b429 JC1191fcddc3b430 JC1191fcddc3b431 JC1191fcddc3b432 JC1191fcddc3b433 JC1191fcddc3b434 ;
+ BLOCKID JC1191fcddc0c0;
+
+
+END;
+BEGIN TREES;
+ Title Imported_trees;
+ LINK Taxa = 'Scharff&Coddington_1997_Araneidae';
+ TRANSLATE
+ 1 Dictyna,
+ 2 Uloborus,
+ 3 Deinopis,
+ 4 Nephila&Herennia,
+ 5 'Nephilengys_cruentata',
+ 6 Meta,
+ 7 Leucauge_venusta,
+ 8 Pachygnatha,
+ 9 'Theridiosoma_01',
+ 10 Tetragnatha;
+ TREE 'Imported tree 1+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
+ TREE 'Imported tree 2+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
+ TREE 'Imported tree 3+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
+ TREE 'Imported tree 4+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
+ TREE 'Imported tree 5+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
+ TREE 'Imported tree 6+' = (1,((2,3),(((4,5),(6,(7,(8,10)))),9)));
+ TREE 'Imported tree 7+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
+ TREE 'Imported tree 8+' = (1,((2,3),(((6,(4,5)),(7,(8,10))),9)));
+
+END;
+
+
+BEGIN LABELS;
+ CHARGROUPLABEL MM_Genitalia COLOR = (RGB 1.0 0.4 0.4) ;
+ CHARGROUPLABEL Somatic COLOR = (RGB 0.6 1.0 0.33333333) ;
+ CHARGROUPLABEL Spinnerets COLOR = (RGB 0.46666667 0.57254902 1.0) ;
+ CHARGROUPLABEL Behavior COLOR = (RGB 1.0 0.46666667 1.0) ;
+
+
+END;
+
+BEGIN SETS;
+CHARPARTITION * UNTITLED = Somatic : 1 - 2 4, MM_Genitalia : 5 - 8 10;
+
+END;
+
+BEGIN ASSUMPTIONS;
+ TYPESET * UNTITLED = unord: 1 - 10;
+
+ EXSET * UNTITLED = ;
+
+ WTSET * UNTITLED = 1: 1 - 10 ;
+
+END;
+
+BEGIN CODONS;
+CODESET * UNTITLED = universal: 1 - 10;
+
+
+END;
+
+BEGIN MESQUITECHARMODELS;
+ ProbModelSet * UNTITLED = 'Mk1 (est.)': 1 - 10;
+END;
+
+BEGIN NOTES;
+
+ TEXT TAXA = 'Scharff&Coddington_1997_Araneidae' TAXON = 2 TEXT = 'This is a footnote to taxon 2, Uloborus';
+
+ TEXT TAXON = 4 CHARACTER = 8 TEXT = This_is_a_footnote_to_a_cell.;
+
+ TEXT CHARACTER = 10 TEXT = This_is_footnote_to_char_10;
+
+ TEXT FILE TEXT = 'Scharff, N. and J. A. Coddington. 1997. A phylogenetic analysis of the orb-weaving spider family Araneidae (Arachnida, Araneae). Zool. J. Linn. Soc. 120(4): 355?434';
+
+ AN T = 4 A = JC DC = 2008.4.13.20.31.19 DM = 2008.4.13.20.31.38 ID = 01194a57d0161 I = _ TF = (CM 'This is an "annotation" to taxon 4') ;
+
+ AN C = 4 A = JC DC = 2008.4.13.20.31.50 DM = 2008.4.13.20.32.10 ID = 01194a584b9f2 I = _ TF = (CM 'This is an annotation to charcter 4, that has no name.') ;
+
+ AN T = 9 C = 3 A = 0 DC = 2008.4.20.17.24.36 DM = 2008.4.20.17.25.4 ID = 01196db963874 I = _ TF = (CM 'This is an annotation to chr 3, taxa 9, coded ?') ;
+
+ AN T = 2 C = 6 A = JC DC = 2008.4.13.20.35.20 DM = 2008.4.13.20.35.36 ID = JC1194a5b7e1a3 I = _ TF = (CM 'This is an annotation that haa a hard return in it^n^n^n^nSo there!') ;
+
+ AN T = 7 C = 10 A = 0 DC = 2008.4.20.17.25.11 DM = 2008.4.20.17.26.1 ID = 01196db9ebd25 I = _ TF = (CM 'this is an annotation^nwith several hard returns^nfor a cell of taxa 6, chr 9 (from zero)^ncoded as -') ;
+
+END;
+
+Begin MESQUITE;
+ MESQUITESCRIPTVERSION 2;
+ TITLE AUTO;
+ tell ProjectCoordinator;
+ getEmployee #mesquite.minimal.ManageTaxa.ManageTaxa;
+ tell It;
+ setID 0 6498976404544962919 JC1191fcddc0c4;
+ tell It;
+ setDefaultOrder 0 1 2 3 4 5 6 7 9 8;
+ attachments ;
+ endTell;
+ endTell;
+ getEmployee #mesquite.charMatrices.ManageCharacters.ManageCharacters;
+ tell It;
+ setID 0 2280451364422511229 JC1191fcddc0c0;
+ checksum 0 3839411132 JC1191fcddc0c0;
+ endTell;
+ getEmployee #mesquite.charMatrices.BasicDataWindowCoord.BasicDataWindowCoord;
+ tell It;
+ showDataWindow #2280451364422511229 #mesquite.charMatrices.BasicDataWindowMaker.BasicDataWindowMaker;
+ tell It;
+ getWindow;
+ tell It;
+ getTable;
+ tell It;
+ columnWidth 6 55;
+ columnWidth 7 23;
+ endTell;
+ setExplanationSize 30;
+ setAnnotationSize 20;
+ setFontIncAnnot 0;
+ setFontIncExp 0;
+ setSize 925 472;
+ setLocation 357 294;
+ setFont SanSerif;
+ setFontSize 10;
+ getToolPalette;
+ tell It;
+ setTool mesquite.charMatrices.BasicDataWindowMaker.BasicDataWindow.ibeam;
+ endTell;
+ setActive;
+ setTool mesquite.charMatrices.BasicDataWindowMaker.BasicDataWindow.ibeam;
+ colorCells #mesquite.charMatrices.AnnotPanel.AnnotPanel;
+ tell It;
+ togglePanel on;
+ endTell;
+ setBackground White;
+ toggleShowNames off;
+ toggleTight off;
+ toggleShowChanges on;
+ toggleSeparateLines off;
+ toggleShowStates on;
+ toggleAutoWCharNames off;
+ toggleShowDefaultCharNames off;
+ toggleConstrainCW on;
+ setColumnWidth 16;
+ toggleBirdsEye off;
+ toggleColorsPanel off;
+ birdsEyeWidth 2;
+ toggleLinkedScrolling on;
+ toggleScrollLinkedTables off;
+ endTell;
+ showWindow;
+ getEmployee #mesquite.categ.StateNamesEditor.StateNamesEditor;
+ tell It;
+ makeWindow;
+ tell It;
+ setExplanationSize 30;
+ setAnnotationSize 20;
+ setFontIncAnnot 0;
+ setFontIncExp 0;
+ setSize 925 472;
+ setLocation 357 294;
+ setFont SanSerif;
+ setFontSize 10;
+ getToolPalette;
+ tell It;
+ setTool mesquite.categ.StateNamesEditor.StateNamesWindow.ibeam;
+ endTell;
+ rowsAreCharacters on;
+ toggleConstrainChar on;
+ toggleConstrainCharNum 3;
+ togglePanel off;
+ toggleSummaryPanel off;
+ endTell;
+ showWindow;
+ endTell;
+ getEmployee #mesquite.categ.StateNamesStrip.StateNamesStrip;
+ tell It;
+ showStrip off;
+ endTell;
+ getEmployee #mesquite.charMatrices.CharReferenceStrip.CharReferenceStrip;
+ tell It;
+ showStrip off;
+ endTell;
+ getEmployee #mesquite.charMatrices.ColorCells.ColorCells;
+ tell It;
+ setColor Red;
+ removeColor off;
+ endTell;
+ getEmployee #mesquite.charMatrices.QuickKeySelector.QuickKeySelector;
+ tell It;
+ autotabOff;
+ endTell;
+ endTell;
+ endTell;
+ endTell;
+end;
+
+
View
423 test/test_nexus_parser.rb
@@ -2,7 +2,7 @@
require 'rubygems'
require 'ruby-debug'
-require File.expand_path(File.join(File.dirname(__FILE__), '../lib/nexus_file'))
+require File.expand_path(File.join(File.dirname(__FILE__), '../lib/nexus_parser'))
class NexusParserTest < Test::Unit::TestCase
def test_truth
@@ -10,9 +10,9 @@ def test_truth
end
end
-class Test_NexusFile_Builder < Test::Unit::TestCase
+class Test_NexusParser_Builder < Test::Unit::TestCase
def test_builder
- b = NexusFile::Builder.new
+ b = NexusParser::Builder.new
assert foo = b.nexus_file
assert_equal [], foo.taxa
assert_equal [], foo.characters
@@ -34,221 +34,221 @@ def test_begin_taxa
class Test_Lexer < Test::Unit::TestCase
def test_lexer
- lexer = NexusFile::Lexer.new("[ foo ] BEGIN taxa; BLORF end;")
- assert lexer.pop(NexusFile::Tokens::LBracket)
- assert id = lexer.pop(NexusFile::Tokens::ID)
+ lexer = NexusParser::Lexer.new("[ foo ] BEGIN taxa; BLORF end;")
+ assert lexer.pop(NexusParser::Tokens::LBracket)
+ assert id = lexer.pop(NexusParser::Tokens::ID)
assert_equal(id.value, "foo")
- assert lexer.pop(NexusFile::Tokens::RBracket)
- assert lexer.pop(NexusFile::Tokens::BeginBlk)
- assert lexer.pop(NexusFile::Tokens::TaxaBlk)
- assert foo = lexer.pop(NexusFile::Tokens::ID)
+ assert lexer.pop(NexusParser::Tokens::RBracket)
+ assert lexer.pop(NexusParser::Tokens::BeginBlk)
+ assert lexer.pop(NexusParser::Tokens::TaxaBlk)
+ assert foo = lexer.pop(NexusParser::Tokens::ID)
assert_equal("BLORF", foo.value) # truncating whitespace
- assert lexer.pop(NexusFile::Tokens::BlkEnd)
+ assert lexer.pop(NexusParser::Tokens::BlkEnd)
- lexer2 = NexusFile::Lexer.new("[ foo ] begin authors; BLORF end; [] () some crud here")
- assert lexer2.pop(NexusFile::Tokens::LBracket)
- assert id = lexer2.pop(NexusFile::Tokens::ID)
+ lexer2 = NexusParser::Lexer.new("[ foo ] begin authors; BLORF end; [] () some crud here")
+ assert lexer2.pop(NexusParser::Tokens::LBracket)
+ assert id = lexer2.pop(NexusParser::Tokens::ID)
assert_equal(id.value, "foo")
- assert lexer2.pop(NexusFile::Tokens::RBracket)
- assert lexer2.pop(NexusFile::Tokens::BeginBlk)
- assert lexer2.pop(NexusFile::Tokens::AuthorsBlk)
- assert lexer2.pop(NexusFile::Tokens::LBracket)
- assert lexer2.pop(NexusFile::Tokens::RBracket)
- assert lexer2.pop(NexusFile::Tokens::LParen)
- assert lexer2.pop(NexusFile::Tokens::RParen)
-
-
- lexer3 = NexusFile::Lexer.new("[ foo ] Begin Characters; BLORF end; [] () some crud here")
- assert lexer3.pop(NexusFile::Tokens::LBracket)
- assert id = lexer3.pop(NexusFile::Tokens::ID)
+ assert lexer2.pop(NexusParser::Tokens::RBracket)
+ assert lexer2.pop(NexusParser::Tokens::BeginBlk)
+ assert lexer2.pop(NexusParser::Tokens::AuthorsBlk)
+ assert lexer2.pop(NexusParser::Tokens::LBracket)
+ assert lexer2.pop(NexusParser::Tokens::RBracket)
+ assert lexer2.pop(NexusParser::Tokens::LParen)
+ assert lexer2.pop(NexusParser::Tokens::RParen)
+
+
+ lexer3 = NexusParser::Lexer.new("[ foo ] Begin Characters; BLORF end; [] () some crud here")
+ assert lexer3.pop(NexusParser::Tokens::LBracket)
+ assert id = lexer3.pop(NexusParser::Tokens::ID)
assert_equal(id.value, "foo")
- assert lexer3.pop(NexusFile::Tokens::RBracket)
- assert lexer3.pop(NexusFile::Tokens::BeginBlk)
- assert lexer3.pop(NexusFile::Tokens::ChrsBlk)
- assert foo = lexer3.pop(NexusFile::Tokens::ID)
+ assert lexer3.pop(NexusParser::Tokens::RBracket)
+ assert lexer3.pop(NexusParser::Tokens::BeginBlk)
+ assert lexer3.pop(NexusParser::Tokens::ChrsBlk)
+ assert foo = lexer3.pop(NexusParser::Tokens::ID)
assert_equal("BLORF", foo.value)
- assert lexer3.pop(NexusFile::Tokens::BlkEnd)
+ assert lexer3.pop(NexusParser::Tokens::BlkEnd)
- lexer4 = NexusFile::Lexer.new("Begin Characters; 123123123 end; [] () some crud here")
- assert lexer4.pop(NexusFile::Tokens::BeginBlk)
- assert lexer4.pop(NexusFile::Tokens::ChrsBlk)
- assert foo = lexer4.pop(NexusFile::Tokens::Number)
+ lexer4 = NexusParser::Lexer.new("Begin Characters; 123123123 end; [] () some crud here")
+ assert lexer4.pop(NexusParser::Tokens::BeginBlk)
+ assert lexer4.pop(NexusParser::Tokens::ChrsBlk)
+ assert foo = lexer4.pop(NexusParser::Tokens::Number)
assert_equal(123123123, foo.value)
- assert lexer4.pop(NexusFile::Tokens::BlkEnd)
+ assert lexer4.pop(NexusParser::Tokens::BlkEnd)
- lexer5 = NexusFile::Lexer.new("(0,1)")
- assert lexer5.pop(NexusFile::Tokens::LParen)
- assert foo = lexer5.pop(NexusFile::Tokens::Number)
+ lexer5 = NexusParser::Lexer.new("(0,1)")
+ assert lexer5.pop(NexusParser::Tokens::LParen)
+ assert foo = lexer5.pop(NexusParser::Tokens::Number)
assert_equal(0, foo.value)
- assert lexer5.pop(NexusFile::Tokens::Comma)
- assert foo = lexer5.pop(NexusFile::Tokens::Number)
+ assert lexer5.pop(NexusParser::Tokens::Comma)
+ assert foo = lexer5.pop(NexusParser::Tokens::Number)
assert_equal(1, foo.value)
- assert lexer5.pop(NexusFile::Tokens::RParen)
+ assert lexer5.pop(NexusParser::Tokens::RParen)
- lexer6 = NexusFile::Lexer.new(" 210(0,1)10A1\n")
- assert foo = lexer6.pop(NexusFile::Tokens::RowVec)
+ lexer6 = NexusParser::Lexer.new(" 210(0,1)10A1\n")
+ assert foo = lexer6.pop(NexusParser::Tokens::RowVec)
assert_equal(["2","1","0",["0","1"],"1","0","A","1"], foo.value)
- lexer6a = NexusFile::Lexer.new(" 21a(0 1)0b{3 4 5}(0)(1 a)\n")
- assert foo = lexer6a.pop(NexusFile::Tokens::RowVec)
+ lexer6a = NexusParser::Lexer.new(" 21a(0 1)0b{3 4 5}(0)(1 a)\n")
+ assert foo = lexer6a.pop(NexusParser::Tokens::RowVec)
assert_equal(["2", "1", "a", ["0", "1"], "0", "b", ["3", "4", "5"], "0", ["1", "a"]], foo.value)
- lexer6b = NexusFile::Lexer.new(" 201{0 1}{0 1}0100)\x0A") # *nix line ending
- assert foo = lexer6b.pop(NexusFile::Tokens::RowVec)
+ lexer6b = NexusParser::Lexer.new(" 201{0 1}{0 1}0100)\x0A") # *nix line ending
+ assert foo = lexer6b.pop(NexusParser::Tokens::RowVec)
assert_equal(["2", "0", "1", ["0", "1"], ["0", "1"], "0", "1", "0", "0"], foo.value)
- lexer6c = NexusFile::Lexer.new(" 201{0 1}{0 1}0100)\x0D\x0A") # * dos line ending
- assert foo = lexer6c.pop(NexusFile::Tokens::RowVec)
+ lexer6c = NexusParser::Lexer.new(" 201{0 1}{0 1}0100)\x0D\x0A") # * dos line ending
+ assert foo = lexer6c.pop(NexusParser::Tokens::RowVec)
assert_equal(["2", "0", "1", ["0", "1"], ["0", "1"], "0", "1", "0", "0"], foo.value)
- lexer7 = NexusFile::Lexer.new("read nothing till Nexus, not that nexus 13243 Block [] ();, this one: #nexus FOO")
- assert foo = lexer7.pop(NexusFile::Tokens::NexusStart)
+ lexer7 = NexusParser::Lexer.new("read nothing till Nexus, not that nexus 13243 Block [] ();, this one: #nexus FOO")
+ assert foo = lexer7.pop(NexusParser::Tokens::NexusStart)
assert_equal('#nexus', foo.value)
## we strip comments before parsing now
- # lexer8 = NexusFile::Lexer.new("[ foo ] Begin Characters; BLORF end; [] () some crud here")
- # assert foo = lexer8.pop(NexusFile::Tokens::NexusComment)
+ # lexer8 = NexusParser::Lexer.new("[ foo ] Begin Characters; BLORF end; [] () some crud here")
+ # assert foo = lexer8.pop(NexusParser::Tokens::NexusComment)
# assert_equal "foo", foo.value
- # assert lexer.pop(NexusFile::Tokens::Colon)
- # assert num = lexer.pop(NexusFile::Tokens::Number)
+ # assert lexer.pop(NexusParser::Tokens::Colon)
+ # assert num = lexer.pop(NexusParser::Tokens::Number)
# assert_equal(num.value, 0.0)
- # assert lexer.pop(NexusFile::Tokens::Comma)
- # assert lexer.pop(NexusFile::Tokens::SemiColon)
+ # assert lexer.pop(NexusParser::Tokens::Comma)
+ # assert lexer.pop(NexusParser::Tokens::SemiColon)
end
def test_row_vec
- lexer = NexusFile::Lexer.new("0?(0 1)10(A BD , C)1(0,1,2)1-\n")
- assert foo = lexer.pop(NexusFile::Tokens::RowVec)
+ lexer = NexusParser::Lexer.new("0?(0 1)10(A BD , C)1(0,1,2)1-\n")
+ assert foo = lexer.pop(NexusParser::Tokens::RowVec)
assert_equal(["0", "?", ["0", "1"], "1", "0", ["A", "BD", "C"], "1", ["0", "1", "2"], "1", "-"], foo.value)
end
def test_punctuation
- lexer = NexusFile::Lexer.new(',/=](\'NOT23\'[);,')
- assert lexer.peek(NexusFile::Tokens::Comma)
- assert lexer.pop(NexusFile::Tokens::Comma)
- assert lexer.pop(NexusFile::Tokens::BckSlash)
- assert lexer.pop(NexusFile::Tokens::Equals)
- assert lexer.pop(NexusFile::Tokens::RBracket)
- assert lexer.pop(NexusFile::Tokens::LParen)
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ lexer = NexusParser::Lexer.new(',/=](\'NOT23\'[);,')
+ assert lexer.peek(NexusParser::Tokens::Comma)
+ assert lexer.pop(NexusParser::Tokens::Comma)
+ assert lexer.pop(NexusParser::Tokens::BckSlash)
+ assert lexer.pop(NexusParser::Tokens::Equals)
+ assert lexer.pop(NexusParser::Tokens::RBracket)
+ assert lexer.pop(NexusParser::Tokens::LParen)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "NOT23", foo.value
- assert lexer.pop(NexusFile::Tokens::LBracket)
- assert lexer.pop(NexusFile::Tokens::RParen)
- assert lexer.pop(NexusFile::Tokens::SemiColon)
- assert lexer.pop(NexusFile::Tokens::Comma)
+ assert lexer.pop(NexusParser::Tokens::LBracket)
+ assert lexer.pop(NexusParser::Tokens::RParen)
+ assert lexer.pop(NexusParser::Tokens::SemiColon)
+ assert lexer.pop(NexusParser::Tokens::Comma)
end
def test_tax_labels
- lexer = NexusFile::Lexer.new("Taxlabels 'foo' bar blorf \"stuff things\" stuff 'and foo';")
- assert foo = lexer.pop(NexusFile::Tokens::Taxlabels)
+ lexer = NexusParser::Lexer.new("Taxlabels 'foo' bar blorf \"stuff things\" stuff 'and foo';")
+ assert foo = lexer.pop(NexusParser::Tokens::Taxlabels)
assert_equal("Taxlabels ", foo.value)
end
def test_EndBlk
- lexer = NexusFile::Lexer.new(" \n\n End ;")
- assert foo = lexer.pop(NexusFile::Tokens::EndBlk)
- lexer = NexusFile::Lexer.new("\n\nEnd;")
- assert foo = lexer.pop(NexusFile::Tokens::EndBlk)
+ lexer = NexusParser::Lexer.new(" \n\n End ;")
+ assert foo = lexer.pop(NexusParser::Tokens::EndBlk)
+ lexer = NexusParser::Lexer.new("\n\nEnd;")
+ assert foo = lexer.pop(NexusParser::Tokens::EndBlk)
- lexer = NexusFile::Lexer.new("123123 \n\nEnd;")
- assert !lexer.peek(NexusFile::Tokens::EndBlk)
- lexer = NexusFile::Lexer.new("this is not an \"end\"\n\nEnd;")
- assert !lexer.peek(NexusFile::Tokens::EndBlk)
+ lexer = NexusParser::Lexer.new("123123 \n\nEnd;")
+ assert !lexer.peek(NexusParser::Tokens::EndBlk)
+ lexer = NexusParser::Lexer.new("this is not an \"end\"\n\nEnd;")
+ assert !lexer.peek(NexusParser::Tokens::EndBlk)
end
def test_semicolon
- lexer = NexusFile::Lexer.new("; Matrix foo")
- assert lexer.peek(NexusFile::Tokens::SemiColon)
- assert foo = lexer.pop(NexusFile::Tokens::SemiColon)
+ lexer = NexusParser::Lexer.new("; Matrix foo")
+ assert lexer.peek(NexusParser::Tokens::SemiColon)
+ assert foo = lexer.pop(NexusParser::Tokens::SemiColon)
end
def test_label
- lexer = NexusFile::Lexer.new(' \'foo\' bar, blorf; "stuff things" stuff \'and foo\' 23434 ""asdf"" \'Foo_And_Stuff\' ')
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ lexer = NexusParser::Lexer.new(' \'foo\' bar, blorf; "stuff things" stuff \'and foo\' 23434 ""asdf"" \'Foo_And_Stuff\' ')
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "foo", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "bar", foo.value
- assert lexer.pop(NexusFile::Tokens::Comma)
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert lexer.pop(NexusParser::Tokens::Comma)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "blorf", foo.value
- assert lexer.pop(NexusFile::Tokens::SemiColon)
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert lexer.pop(NexusParser::Tokens::SemiColon)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "stuff things", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "stuff", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "and foo", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "23434", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal '"asdf"', foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal 'Foo_And_Stuff', foo.value
end
def test_odd_labels
- lexer = NexusFile::Lexer.new("blorf 'fan shaped, narrow base and broad tip (Selkirkiella, Kochiura)' \"\"\" foo \"\"\" '''rupununi''' '''tanzania''' '''cup-shaped''' bar blorf\n;")
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ lexer = NexusParser::Lexer.new("blorf 'fan shaped, narrow base and broad tip (Selkirkiella, Kochiura)' \"\"\" foo \"\"\" '''rupununi''' '''tanzania''' '''cup-shaped''' bar blorf\n;")
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "blorf", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "fan shaped, narrow base and broad tip (Selkirkiella, Kochiura)", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal '"" foo ""', foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "''rupununi''", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "''tanzania''", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "''cup-shaped''", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "bar", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "blorf", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::SemiColon)
+ assert foo = lexer.pop(NexusParser::Tokens::SemiColon)
end
def test_title
- lexer = NexusFile::Lexer.new( "TITLE 'Scharff&Coddington_1997_Araneidae';")
- assert foo = lexer.pop(NexusFile::Tokens::Title)
+ lexer = NexusParser::Lexer.new( "TITLE 'Scharff&Coddington_1997_Araneidae';")
+ assert foo = lexer.pop(NexusParser::Tokens::Title)
assert_equal "TITLE 'Scharff&Coddington_1997_Araneidae';", foo.value
end
def test_dimensions
input = " DIMENSIONS NCHAR= 10"
- lexer = NexusFile::Lexer.new(input)
- assert foo = lexer.pop(NexusFile::Tokens::Dimensions)
+ lexer = NexusParser::Lexer.new(input)
+ assert foo = lexer.pop(NexusParser::Tokens::Dimensions)
assert_equal "DIMENSIONS", foo.value
end
def test_format
input = " format NCHAR= 10"
- lexer = NexusFile::Lexer.new(input)
- assert foo = lexer.pop(NexusFile::Tokens::Format)
+ lexer = NexusParser::Lexer.new(input)
+ assert foo = lexer.pop(NexusParser::Tokens::Format)
assert_equal "format", foo.value
end
def test_odd_value_pair
- lexer = NexusFile::Lexer.new(" TEXT CHARACTER = 3 TEXT = A62.003;
+ lexer = NexusParser::Lexer.new(" TEXT CHARACTER = 3 TEXT = A62.003;
TEXT CHARACTER = 4 TEXT = A62.004; \n end; ")
- assert foo = lexer.pop(NexusFile::Tokens::Label)
- assert foo = lexer.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::ValuePair)
blorf = {:character => "3"}
assert_equal blorf , foo.value
- assert foo = lexer.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer.pop(NexusParser::Tokens::ValuePair)
blorf = {:text => "A62.003"}
assert_equal blorf , foo.value
- assert foo = lexer.pop(NexusFile::Tokens::Label)
+ assert foo = lexer.pop(NexusParser::Tokens::Label)
assert_equal "TEXT", foo.value
- assert foo = lexer.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer.pop(NexusParser::Tokens::ValuePair)
blorf = {:character => "4"}
assert_equal blorf , foo.value
- assert foo = lexer.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer.pop(NexusParser::Tokens::ValuePair)
blorf = {:text => "A62.004"}
assert_equal blorf , foo.value
@@ -257,92 +257,92 @@ def test_odd_value_pair
def test_value_pair
- lexer0 = NexusFile::Lexer.new(' DATATYPE=STANDARD ')
- assert foo = lexer0.pop(NexusFile::Tokens::ValuePair)
+ lexer0 = NexusParser::Lexer.new(' DATATYPE=STANDARD ')
+ assert foo = lexer0.pop(NexusParser::Tokens::ValuePair)
blorf = {:datatype => "STANDARD"}
assert_equal blorf , foo.value
- lexer = NexusFile::Lexer.new(' DATATYPE = STANDARD ')
- assert foo = lexer.pop(NexusFile::Tokens::ValuePair)
+ lexer = NexusParser::Lexer.new(' DATATYPE = STANDARD ')
+ assert foo = lexer.pop(NexusParser::Tokens::ValuePair)
blorf = {:datatype => "STANDARD"}
assert_equal blorf , foo.value
- lexer2 = NexusFile::Lexer.new(' DATATYPE ="STANDARD" ')
- assert foo = lexer2.pop(NexusFile::Tokens::ValuePair)
+ lexer2 = NexusParser::Lexer.new(' DATATYPE ="STANDARD" ')
+ assert foo = lexer2.pop(NexusParser::Tokens::ValuePair)
assert_equal blorf, foo.value
- lexer3 = NexusFile::Lexer.new('DATATYPE= "STANDARD" ')
- assert foo = lexer3.pop(NexusFile::Tokens::ValuePair)
+ lexer3 = NexusParser::Lexer.new('DATATYPE= "STANDARD" ')
+ assert foo = lexer3.pop(NexusParser::Tokens::ValuePair)
assert_equal blorf, foo.value
input= " NCHAR=10 ntaxa =10 nfoo='999' nbar = \" a b c \" ; "
- lexer4 = NexusFile::Lexer.new(input)
- assert foo = lexer4.pop(NexusFile::Tokens::ValuePair)
+ lexer4 = NexusParser::Lexer.new(input)
+ assert foo = lexer4.pop(NexusParser::Tokens::ValuePair)
smorf = {:nchar => '10'}
assert_equal smorf, foo.value
- assert foo = lexer4.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer4.pop(NexusParser::Tokens::ValuePair)
smorf = {:ntaxa => '10'}
assert_equal smorf, foo.value
- assert foo = lexer4.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer4.pop(NexusParser::Tokens::ValuePair)
smorf = {:nfoo => '999'}
assert_equal smorf, foo.value
- assert foo = lexer4.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer4.pop(NexusParser::Tokens::ValuePair)
smorf = {:nbar => 'a b c'}
assert_equal smorf, foo.value
- lexer5 = NexusFile::Lexer.new(' symbols= " a c b d 1 " ')
- assert foo = lexer5.pop(NexusFile::Tokens::ValuePair)
+ lexer5 = NexusParser::Lexer.new(' symbols= " a c b d 1 " ')
+ assert foo = lexer5.pop(NexusParser::Tokens::ValuePair)
smorf = {:symbols => 'a c b d 1'}
assert_equal smorf, foo.value
- lexer6 = NexusFile::Lexer.new(' missing = - ')
- assert foo = lexer6.pop(NexusFile::Tokens::ValuePair)
+ lexer6 = NexusParser::Lexer.new(' missing = - ')
+ assert foo = lexer6.pop(NexusParser::Tokens::ValuePair)
smorf = {:missing => '-'}
assert_equal smorf, foo.value
- lexer6a = NexusFile::Lexer.new("ntaxa=1;\n")
- assert foo = lexer6a.pop(NexusFile::Tokens::ValuePair)
+ lexer6a = NexusParser::Lexer.new("ntaxa=1;\n")
+ assert foo = lexer6a.pop(NexusParser::Tokens::ValuePair)
smorf = {:ntaxa => '1'}
assert_equal smorf, foo.value
- lexer7 = NexusFile::Lexer.new("ntaxa =1;\n")
- assert foo = lexer7.pop(NexusFile::Tokens::ValuePair)
+ lexer7 = NexusParser::Lexer.new("ntaxa =1;\n")
+ assert foo = lexer7.pop(NexusParser::Tokens::ValuePair)
smorf = {:ntaxa => '1'}
assert_equal smorf, foo.value
- lexer8 = NexusFile::Lexer.new(" ntaxa = 1 ;\n")
- assert foo = lexer8.pop(NexusFile::Tokens::ValuePair)
+ lexer8 = NexusParser::Lexer.new(" ntaxa = 1 ;\n")
+ assert foo = lexer8.pop(NexusParser::Tokens::ValuePair)
smorf = {:ntaxa => '1'}
assert_equal smorf, foo.value
- lexer9 = NexusFile::Lexer.new(" TF = (CM 'This is an annotation that haa a hard return in it^n^n^n^nSo there!') ")
- assert foo = lexer9.pop(NexusFile::Tokens::ValuePair)
+ lexer9 = NexusParser::Lexer.new(" TF = (CM 'This is an annotation that haa a hard return in it^n^n^n^nSo there!') ")
+ assert foo = lexer9.pop(NexusParser::Tokens::ValuePair)
smorf = {:tf => "(CM 'This is an annotation that haa a hard return in it^n^n^n^nSo there!')" }
assert_equal smorf, foo.value
- lexer10 = NexusFile::Lexer.new(" TF = (CM 'This is an value pair that has (parens) within the value, twice! ()') ; some stuff left here ")
- assert foo = lexer10.pop(NexusFile::Tokens::ValuePair)
+ lexer10 = NexusParser::Lexer.new(" TF = (CM 'This is an value pair that has (parens) within the value, twice! ()') ; some stuff left here ")
+ assert foo = lexer10.pop(NexusParser::Tokens::ValuePair)
smorf = {:tf => "(CM 'This is an value pair that has (parens) within the value, twice! ()')" }
assert_equal smorf, foo.value
- lexer11 = NexusFile::Lexer.new("CHARACTER = 1 TEXT = A62.001;")
- assert_equal true, !lexer11.peek(NexusFile::Tokens::SemiColon)
- assert_equal true, lexer11.peek(NexusFile::Tokens::ValuePair)
- assert foo = lexer11.pop(NexusFile::Tokens::ValuePair)
+ lexer11 = NexusParser::Lexer.new("CHARACTER = 1 TEXT = A62.001;")
+ assert_equal true, !lexer11.peek(NexusParser::Tokens::SemiColon)
+ assert_equal true, lexer11.peek(NexusParser::Tokens::ValuePair)
+ assert foo = lexer11.pop(NexusParser::Tokens::ValuePair)
smorf = {:character => "1" }
assert_equal smorf, foo.value
- assert foo = lexer11.pop(NexusFile::Tokens::ValuePair)
+ assert foo = lexer11.pop(NexusParser::Tokens::ValuePair)
end
def test_MesquiteIDs
- lexer = NexusFile::Lexer.new('IDS JC1191fcddc3b425 JC1191fcddc3b426 JC1191fcddc3b427 JC1191fcddc3b428 JC1191fcddc3b429 JC1191fcddc3b430 JC1191fcddc3b431 JC1191fcddc3b432 JC1191fcddc3b433 JC1191fcddc3b434 ;
+ lexer = NexusParser::Lexer.new('IDS JC1191fcddc3b425 JC1191fcddc3b426 JC1191fcddc3b427 JC1191fcddc3b428 JC1191fcddc3b429 JC1191fcddc3b430 JC1191fcddc3b431 JC1191fcddc3b432 JC1191fcddc3b433 JC1191fcddc3b434 ;
BLOCKID JC1191fcddc0c0;')
- assert lexer.pop(NexusFile::Tokens::MesquiteIDs)
- assert lexer.pop(NexusFile::Tokens::MesquiteBlockID)
+ assert lexer.pop(NexusParser::Tokens::MesquiteIDs)
+ assert lexer.pop(NexusParser::Tokens::MesquiteBlockID)
end
def test_TreesBlk
- lexer = NexusFile::Lexer.new("BEGIN TREES;
+ lexer = NexusParser::Lexer.new("BEGIN TREES;
Title Imported_trees;
LINK Taxa = 'Scharff&Coddington_1997_Araneidae';
TRANSLATE
@@ -377,25 +377,25 @@ def test_TreesBlk
END;")
- assert lexer.pop(NexusFile::Tokens::BeginBlk)
- assert foo = lexer.pop(NexusFile::Tokens::TreesBlk)
+ assert lexer.pop(NexusParser::Tokens::BeginBlk)
+ assert foo = lexer.pop(NexusParser::Tokens::TreesBlk)
assert_equal 'TREES', foo.value.slice(0,5)
assert_equal 'END;', foo.value.slice(-4,4)
- assert lexer.pop(NexusFile::Tokens::BeginBlk)
- assert lexer.pop(NexusFile::Tokens::LabelsBlk)
+ assert lexer.pop(NexusParser::Tokens::BeginBlk)
+ assert lexer.pop(NexusParser::Tokens::LabelsBlk)
end
def test_NotesBlk
input = "BEGIN NOTES ;"
- lexer = NexusFile::Lexer.new(input)
- assert lexer.pop(NexusFile::Tokens::BeginBlk)
- assert foo = lexer.pop(NexusFile::Tokens::NotesBlk)
+ lexer = NexusParser::Lexer.new(input)
+ assert lexer.pop(NexusParser::Tokens::BeginBlk)
+ assert foo = lexer.pop(NexusParser::Tokens::NotesBlk)
assert "NOTES", foo.value
end
def test_LabelsBlk
- lexer = NexusFile::Lexer.new("
+ lexer = NexusParser::Lexer.new("
LABELS;
CHARGROUPLABEL MM_Genitalia COLOR = (RGB 1.0 0.4 0.4) ;
CHARGROUPLABEL Somatic COLOR = (RGB 0.6 1.0 0.33333333) ;
@@ -407,29 +407,27 @@ def test_LabelsBlk
BEGIN some other block;")
- assert foo = lexer.pop(NexusFile::Tokens::LabelsBlk)
+ assert foo = lexer.pop(NexusParser::Tokens::LabelsBlk)
assert_equal 'LABELS', foo.value.slice(0,6)
assert_equal 'END;', foo.value.slice(-4,4)
end
def test_SetsBlk
- lexer = NexusFile::Lexer.new("
+ lexer = NexusParser::Lexer.new("
SETS;
CHARPARTITION * UNTITLED = Somatic : 1 - 2 4, MM_Genitalia : 5 - 8 10;
END;
BEGIN some other block;")
- assert foo = lexer.pop(NexusFile::Tokens::SetsBlk)
+ assert foo = lexer.pop(NexusParser::Tokens::SetsBlk)
assert_equal 'SETS', foo.value.slice(0,4)
assert_equal 'END;', foo.value.slice(-4,4)
end
-
-
def test_lexer_errors
- lexer = NexusFile::Lexer.new("*&")
- assert_raise(NexusFile::ParseError) {lexer.peek(NexusFile::Tokens::ID)}
+ lexer = NexusParser::Lexer.new("*&")
+ assert_raise(NexusParser::ParseError) {lexer.peek(NexusParser::Tokens::ID)}
end
end
@@ -437,7 +435,7 @@ def test_lexer_errors
class Test_Parser < Test::Unit::TestCase
def setup
# a Mesquite 2.n or higher file
- @nf = File.read('MX_test_03.nex') # MX_test_01.nex
+ @nf = File.read(File.expand_path(File.join(File.dirname(__FILE__), '../test/MX_test_03.nex')))
end
def teardown
@@ -447,7 +445,7 @@ def teardown
def test_that_file_might_be_nexus
begin
assert !parse_nexus_file("#Nexblux Begin Natrix end;")
- rescue NexusFile::ParseError
+ rescue NexusParser::ParseError
assert true
end
end
@@ -483,9 +481,9 @@ def test_taxa_block
BLOCKID JC1191fcddc0c4;
END;"
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
- NexusFile::Parser.new(lexer,builder).parse_taxa_blk
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
+ NexusParser::Parser.new(lexer,builder).parse_taxa_blk
foo = builder.nexus_file
assert_equal 10, foo.taxa.size
@@ -505,9 +503,9 @@ def test_taxa_block_without_IDS
;
END;"
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
- NexusFile::Parser.new(lexer,builder).parse_taxa_blk
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
+ NexusParser::Parser.new(lexer,builder).parse_taxa_blk
foo = builder.nexus_file
assert_equal 10, foo.taxa.size
@@ -544,8 +542,8 @@ def test_parse_characters_blk
END;"
- builder = NexusFile::Builder.new
- @lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ @lexer = NexusParser::Lexer.new(input)
# add the taxa, assumes we have them for comparison purposes, though we (shouldn't) ultimately need them
# foo.taxa = ["Dictyna", "Uloborus", "Deinopis", "Nephila&Herennia", "Nephilenygys_cruentata", "Meta", "Leucauge_venusta", "Pachygnatha", "Theridiosoma_01", "Tetragnatha"]
@@ -553,7 +551,7 @@ def test_parse_characters_blk
# stub the taxa, they would otherwise get added in dimensions or taxa block
(0..9).each{|i| builder.stub_taxon}
- NexusFile::Parser.new(@lexer,builder).parse_characters_blk
+ NexusParser::Parser.new(@lexer,builder).parse_characters_blk
foo = builder.nexus_file
assert_equal 10, foo.characters.size
@@ -595,8 +593,8 @@ def test_characters_block_without_IDs_or_title
;
END;"
- builder = NexusFile::Builder.new
- @lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ @lexer = NexusParser::Lexer.new(input)
# add the taxa, assumes we have them for comparison purposes, though we (shouldn't) ultimately need them
# foo.taxa = ["Dictyna", "Uloborus", "Deinopis", "Nephila&Herennia", "Nephilenygys_cruentata", "Meta", "Leucauge_venusta", "Pachygnatha", "Theridiosoma_01", "Tetragnatha"]
@@ -604,7 +602,7 @@ def test_characters_block_without_IDs_or_title
# stub the taxa, they would otherwise get added in dimensions or taxa block
(0..9).each{|i| builder.stub_taxon}
- NexusFile::Parser.new(@lexer,builder).parse_characters_blk
+ NexusParser::Parser.new(@lexer,builder).parse_characters_blk
foo = builder.nexus_file
assert_equal 10, foo.characters.size
@@ -630,10 +628,10 @@ def test_codings
def test_parse_dimensions
input= " DIMENSIONS NCHAR=10 ntaxa =10 nfoo='999' nbar = \" a b c \" blorf=2; "
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
- NexusFile::Parser.new(lexer,builder).parse_dimensions
+ NexusParser::Parser.new(lexer,builder).parse_dimensions
foo = builder.nexus_file
assert_equal "10", foo.vars[:nchar]
@@ -646,10 +644,10 @@ def test_parse_dimensions
def test_parse_format
input = "FORMAT DATATYPE = STANDARD GAP = - MISSING = ? SYMBOLS = \" 0 1 2 3 4 5 6 7 8 9 A\";"
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
- NexusFile::Parser.new(lexer,builder).parse_format
+ NexusParser::Parser.new(lexer,builder).parse_format
foo = builder.nexus_file
assert_equal "STANDARD", foo.vars[:datatype]
@@ -665,12 +663,12 @@ def test_parse_chr_state_labels
MATRIX
fooo 01 more stuff here that should not be hit"
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
(0..9).each{builder.stub_chr()}
- NexusFile::Parser.new(lexer,builder).parse_chr_state_labels
+ NexusParser::Parser.new(lexer,builder).parse_chr_state_labels
foo = builder.nexus_file
assert_equal 10, foo.characters.size
@@ -720,12 +718,12 @@ def test_strange_chr_state_labels
Matrix
fooo 01 more stuff here that should not be hit"
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
(0..29).each{builder.stub_chr()}
- NexusFile::Parser.new(lexer,builder).parse_chr_state_labels
+ NexusParser::Parser.new(lexer,builder).parse_chr_state_labels
foo = builder.nexus_file
@@ -746,12 +744,12 @@ def DONT_test_parse_really_long_string_of_chr_state_labels
MATRIX
fooo 01 more stuff here that should not be hit"
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
(0..147).each{builder.stub_chr()}
- NexusFile::Parser.new(lexer,builder).parse_chr_state_labels
+ NexusParser::Parser.new(lexer,builder).parse_chr_state_labels
foo = builder.nexus_file
assert_equal 10, foo.characters.size
@@ -823,24 +821,24 @@ def test_parse_notes_blk
# note the second last note note embedds parens in the value
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
# stubs
(0..9).each{builder.stub_chr()}
(0..9).each{builder.stub_taxon()}
builder.nexus_file.codings[3] = []
- builder.nexus_file.codings[3][7] = NexusFile::NexusFile::Coding.new()
+ builder.nexus_file.codings[3][7] = NexusParser::NexusParser::Coding.new()
builder.nexus_file.codings[8] = []
- builder.nexus_file.codings[8][2] = NexusFile::NexusFile::Coding.new()
+ builder.nexus_file.codings[8][2] = NexusParser::NexusParser::Coding.new()
builder.nexus_file.codings[1] = []
- builder.nexus_file.codings[1][5] = NexusFile::NexusFile::Coding.new()
+ builder.nexus_file.codings[1][5] = NexusParser::NexusParser::Coding.new()
builder.nexus_file.codings[6] = []
- builder.nexus_file.codings[6][9] = NexusFile::NexusFile::Coding.new()
+ builder.nexus_file.codings[6][9] = NexusParser::NexusParser::Coding.new()
builder.nexus_file.codings[3] = []
- builder.nexus_file.codings[3][7] = NexusFile::NexusFile::Coding.new()
+ builder.nexus_file.codings[3][7] = NexusParser::NexusParser::Coding.new()
- NexusFile::Parser.new(lexer,builder).parse_notes_blk
+ NexusParser::Parser.new(lexer,builder).parse_notes_blk
foo = builder.nexus_file
@@ -890,12 +888,12 @@ def test_notes_block_2
# note the second last note note embeds parens in the value
- builder = NexusFile::Builder.new
- lexer = NexusFile::Lexer.new(input)
+ builder = NexusParser::Builder.new
+ lexer = NexusParser::Lexer.new(input)
# stubs
(0..9).each{builder.stub_chr()}
- NexusFile::Parser.new(lexer,builder).parse_notes_blk
+ NexusParser::Parser.new(lexer,builder).parse_notes_blk
foo = builder.nexus_file
@@ -910,11 +908,10 @@ def test_notes_block_2
assert_equal 'A62.006', foo.characters[5].notes[0].note
assert_equal 'A62.007', foo.characters[6].notes[0].note
assert_equal 'A62.008', foo.characters[7].notes[0].note
- assert_equal NexusFile::NexusFile::Character, foo.characters[7].class
+ assert_equal NexusParser::NexusParser::Character, foo.characters[7].class
assert_equal 1, foo.characters[7].notes.size
end
-
def test_parse_trees_block
end
Please sign in to comment.
Something went wrong with that request. Please try again.