From: Tara L Andrews Date: Fri, 16 Aug 2013 07:28:22 +0000 (+0200) Subject: XML parsers should accept already-parsed XML object too X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=dead25cac72e5ea3a9cd362b999af2d66d62d6e4;p=scpubgit%2Fstemmatology.git XML parsers should accept already-parsed XML object too --- diff --git a/base/lib/Text/Tradition/Parser/CTE.pm b/base/lib/Text/Tradition/Parser/CTE.pm index 70248d5..bcde6e6 100644 --- a/base/lib/Text/Tradition/Parser/CTE.pm +++ b/base/lib/Text/Tradition/Parser/CTE.pm @@ -121,14 +121,22 @@ sub parse { # Finally, add explicit witness paths, remove the base paths, and remove # the app/anchor tags. - _expand_all_paths( $c ); + try { + _expand_all_paths( $c ); + } catch( $err ) { + throw( $err ); + } # Save the text for each witness so that we can ensure consistency # later on unless( $opts->{'nocalc'} ) { - $tradition->collation->text_from_paths(); - $tradition->collation->calculate_ranks(); - $tradition->collation->flatten_ranks(); + try { + $tradition->collation->text_from_paths(); + $tradition->collation->calculate_ranks(); + $tradition->collation->flatten_ranks(); + } catch( $err ) { + throw( $err ); + } } } @@ -157,6 +165,8 @@ sub _remove_formatting { $doc = $parser->parse_string( $opts->{'string'} ); } elsif ( exists $opts->{'file'} ) { $doc = $parser->parse_file( $opts->{'file'} ); + } elsif ( exists $opts->{'xmlobj'} ) { + $doc = $opts->{'xmlobj'}; } else { warn "Could not find string or file option to parse"; return; @@ -402,7 +412,7 @@ sub _attach_transposition { } $success = 1; } else { - say STDERR "ERROR: lemma and transposed sequence different lengths?!" + throw( "Lemma at $found and transposed sequence different lengths?!" ); } } else { say STDERR "WARNING: Unable to find $reftxt in base text for transposition"; @@ -468,7 +478,7 @@ sub interpret { my @end = split( /\s+/, $2 ); if( scalar( @begin ) + scalar ( @end ) > scalar( @words ) ) { # Something is wrong and we can't do the splice. - say STDERR "ERROR: $lemma is too short to accommodate $oldreading"; + throw( "$lemma is too short to accommodate $oldreading" ); } else { splice( @words, 0, scalar @begin, @begin ); splice( @words, -(scalar @end), scalar @end, @end ); diff --git a/base/lib/Text/Tradition/Parser/GraphML.pm b/base/lib/Text/Tradition/Parser/GraphML.pm index 63305ac..63f695d 100644 --- a/base/lib/Text/Tradition/Parser/GraphML.pm +++ b/base/lib/Text/Tradition/Parser/GraphML.pm @@ -46,6 +46,8 @@ sub graphml_parse { $doc = $parser->parse_string( $opts->{'string'} ); } elsif ( exists $opts->{'file'} ) { $doc = $parser->parse_file( $opts->{'file'} ); + } elsif ( exists $opts->{'xmlobj'} ) { + $doc = $opts->{'xmlobj'}; } else { warn "Could not find string or file option to parse"; return; diff --git a/base/lib/Text/Tradition/Parser/TEI.pm b/base/lib/Text/Tradition/Parser/TEI.pm index 3e3c47e..3b0649f 100644 --- a/base/lib/Text/Tradition/Parser/TEI.pm +++ b/base/lib/Text/Tradition/Parser/TEI.pm @@ -108,6 +108,8 @@ sub parse { $doc = $parser->parse_string( $opts->{'string'} ); } elsif ( exists $opts->{'file'} ) { $doc = $parser->parse_file( $opts->{'file'} ); + } elsif ( exists $opts->{'xmlobj'} ) { + $doc = $opts->{'xmlobj'}; } else { warn "Could not find string or file option to parse"; return;