kasei / attean

A Perl Semantic Web Framework
19 stars 10 forks source link

Parse a string to a pattern #82

Closed kjetilk closed 8 years ago

kjetilk commented 8 years ago

It would be great to be able to parse a string like

?s <http://example.org/m/p> ?o .

and get an Attean::TriplePattern object from it somehow. Nice to have it for quads too.

Could be done by returning something I can pass to the constructor too. :-)

kjetilk commented 8 years ago

Got this stacktrace:

    #   Failed test 'Parsing pattern '?s <http://example.org/m/p> ?o .''
    #   at /usr/share/perl5/Try/Tiny.pm line 72.
Expecting PREFIXNAME but found DOT before  at /home/kjetil/dev/attean/lib/AtteanX/Parser/SPARQL.pm line 3628, <$fh> line 1.
        AtteanX::Parser::SPARQL::_expected_token('AtteanX::Parser::SPARQL=HASH(0xac626f0)', 19) called at /home/kjetil/dev/attean/lib/AtteanX/Parser/SPARQL.pm line 3189
        AtteanX::Parser::SPARQL::_PrefixedName('AtteanX::Parser::SPARQL=HASH(0xac626f0)') called at /home/kjetil/dev/attean/lib/AtteanX/Parser/SPARQL.pm line 3181
        AtteanX::Parser::SPARQL::_IRIref('AtteanX::Parser::SPARQL=HASH(0xac626f0)') called at /home/kjetil/dev/attean/lib/AtteanX/Parser/SPARQL.pm line 2631
        AtteanX::Parser::SPARQL::_GraphTerm('AtteanX::Parser::SPARQL=HASH(0xac626f0)') called at /home/kjetil/dev/attean/lib/AtteanX/Parser/SPARQL.pm line 2580
        AtteanX::Parser::SPARQL::_VarOrTerm('AtteanX::Parser::SPARQL=HASH(0xac626f0)') called at /home/kjetil/dev/attean/lib/AtteanX/Parser/SPARQL.pm line 2559
        AtteanX::Parser::SPARQL::_GraphNode('AtteanX::Parser::SPARQL=HASH(0xac626f0)') called at /home/kjetil/dev/attean/lib/AtteanX/Parser/SPARQL.pm line 215
        AtteanX::Parser::SPARQL::parse_nodes('AtteanX::Parser::SPARQL=HASH(0xac626f0)', '?s <http://example.org/m/p> ?o .') called at /home/kjetil/dev/attean/lib/Attean/API/Binding.pm line 269
        Attean::API::TripleOrQuadPattern::parse('Attean::TriplePattern', '?s <http://example.org/m/p> ?o .') called at t/planner-with-tpf-cache.t line 91
kjetilk commented 8 years ago

seems it didn't expect a trailing dot terminating the triple pattern.

I could fix that in my end with a regexp if it isn't appropriate to fix in the parser.