Skip to content

Commit

Permalink
Improve coverage for parsing SPARQL Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
kasei committed Feb 12, 2016
1 parent df091c2 commit 91a9293
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions lib/AtteanX/Parser/SPARQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ sub _RW_Query {
next if ($self->_Query_test);
last;
} else {
if ($self->update and not $self->_peek_token) {
last;
}
die "Syntax error: Expected query type with input <<$self->{tokens}>>";
}

Expand Down Expand Up @@ -453,7 +456,9 @@ sub _DeleteUpdate {
foreach my $s (@st) {
if ($s->does('Attean::API::QuadPattern')) {
push(@quads, $s);
push(@patterns, Attean::Algebra::Graph->new( graph => $s->graph, children => [$s] ));
my $tp = $s->as_triple_pattern;
my $bgp = Attean::Algebra::BGP->new( triples => [$tp] );
push(@patterns, Attean::Algebra::Graph->new( graph => $s->graph, children => [$bgp] ));
} else {
push(@triples, $s);
}
Expand Down Expand Up @@ -603,38 +608,33 @@ sub _LoadUpdate {

sub _CreateGraph {
my $self = shift;
$self->_expected_token(KEYWORD< 'CREATE');
$self->_expected_token(KEYWORD, 'CREATE');
my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
$self->_expected_token(KEYWORD< 'GRAPH');
$self->_expected_token(KEYWORD, 'GRAPH');
$self->_IRIref;
my ($graph) = splice( @{ $self->{_stack} } );
die "unimplemented";
my $pat = RDF::Query::Algebra::Create->new( $graph );
my $pat = Attean::Algebra::Create->new( silent => $silent, graph => $graph );
$self->_add_patterns( $pat );
$self->{build}{method} = 'CREATE';
}

sub _ClearGraphUpdate {
my $self = shift;
$self->_expected_token(KEYWORD< 'CLEAR');
$self->_expected_token(KEYWORD, 'CLEAR');
my $silent = $self->_optional_token(KEYWORD, 'SILENT') ? 1 : 0;
if ($self->_optional_token(KEYWORD, 'GRAPH')) {
$self->_IRIref;
my ($graph) = splice( @{ $self->{_stack} } );
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( $graph );
my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'GRAPH', graph => $graph);
$self->_add_patterns( $pat );
} elsif ($self->_optional_token(KEYWORD, 'DEFAULT')) {
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( RDF::Trine::Node::Nil->new );
my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'DEFAULT');
$self->_add_patterns( $pat );
} elsif ($self->_optional_token(KEYWORD, 'NAMED')) {
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( Attean::IRI->new(value => 'tag:[email protected],2010-01-01:RT:NAMED') );
my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'NAMED');
$self->_add_patterns( $pat );
} elsif ($self->_optional_token(KEYWORD, 'ALL')) {
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( Attean::IRI->new(value => 'tag:[email protected],2010-01-01:RT:ALL') );
my $pat = Attean::Algebra::Clear->new(silent => $silent, target => 'ALL');
$self->_add_patterns( $pat );
}
$self->{build}{method} = 'CLEAR';
Expand All @@ -647,20 +647,16 @@ sub _DropGraph {
if ($self->_optional_token(KEYWORD, 'GRAPH')) {
$self->_IRIref;
my ($graph) = splice( @{ $self->{_stack} } );
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( $graph );
my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'GRAPH', graph => $graph);
$self->_add_patterns( $pat );
} elsif ($self->_optional_token(KEYWORD, 'DEFAULT')) {
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( RDF::Trine::Node::Nil->new );
my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'DEFAULT');
$self->_add_patterns( $pat );
} elsif ($self->_optional_token(KEYWORD, 'NAMED')) {
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( Attean::IRI->new(value => 'tag:[email protected],2010-01-01:RT:NAMED') );
my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'NAMED');
$self->_add_patterns( $pat );
} elsif ($self->_optional_token(KEYWORD, 'ALL')) {
die "unimplemented";
my $pat = RDF::Query::Algebra::Clear->new( Attean::IRI->new(value => 'tag:[email protected],2010-01-01:RT:ALL') );
my $pat = Attean::Algebra::Clear->new(drop => 1, silent => $silent, target => 'ALL');
$self->_add_patterns( $pat );
}
$self->{build}{method} = 'CLEAR';
Expand Down

0 comments on commit 91a9293

Please sign in to comment.