line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Copyright (c) 2006 IBM Corporation. |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# All rights reserved. This program and the accompanying materials |
5
|
|
|
|
|
|
|
# are made available under the terms of the Eclipse Public License v1.0 |
6
|
|
|
|
|
|
|
# which accompanies this distribution, and is available at |
7
|
|
|
|
|
|
|
# http://www.eclipse.org/legal/epl-v10.html |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# File: $Source: /var/lib/cvs/ODO/lib/ODO/Query/Simple/Parser.pm,v $ |
10
|
|
|
|
|
|
|
# Created by: Stephen Evanchik( evanchik@us.ibm.com ) |
11
|
|
|
|
|
|
|
# Created on: 11/29/2006 |
12
|
|
|
|
|
|
|
# Revision: $Id: Parser.pm,v 1.2 2009-11-25 17:53:53 ubuntu Exp $ |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Contributors: |
15
|
|
|
|
|
|
|
# IBM Corporation - initial API and implementation |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
package ODO::Query::Simple::Parser; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
1286
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
20
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
5
|
use base qw/ODO/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
5
|
use ODO::Exception; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
79
|
|
25
|
1
|
|
|
1
|
|
6
|
use vars qw /$VERSION/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
84
|
|
26
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.2 $ =~ /: (\d+)\.(\d+)/; |
27
|
1
|
|
|
1
|
|
1869
|
use Parse::RecDescent; |
|
1
|
|
|
|
|
53940
|
|
|
1
|
|
|
|
|
7
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our $PARSER = undef; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 NAME |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
ODO::Ontology::Query::Simple::Parser |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 SYNOPSIS |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 INTERNALS |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=over |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item $GRAMMAR |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
our $GRAMMAR=q( |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
{ |
50
|
|
|
|
|
|
|
use ODO::Node; |
51
|
|
|
|
|
|
|
use ODO::Statement; |
52
|
|
|
|
|
|
|
use ODO::Query::Simple; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
StatementPatternClause: StatementPattern(s /,/) { $return = $item[1]; } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
StatementPattern: '(' VarOrURI ',' VarOrURI ',' VarOrConst ')' |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
$return = ODO::Query::Simple->new(s=> $item[2], p=> $item[4], o=> $item[6]); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Variable: /(^[?](\w|[-.])+)/ |
63
|
|
|
|
|
|
|
{ |
64
|
|
|
|
|
|
|
$return = $item{'__PATTERN1__'}; |
65
|
|
|
|
|
|
|
chomp($return); |
66
|
|
|
|
|
|
|
$return =~ s/^[?]//; |
67
|
|
|
|
|
|
|
$return = ODO::Node::Variable->new($return); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
VarOrURI: Variable |
71
|
|
|
|
|
|
|
| URI |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
VarOrConst: |
74
|
|
|
|
|
|
|
Variable |
75
|
|
|
|
|
|
|
| Const |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Const: URI |
78
|
|
|
|
|
|
|
| NumericLiteral { $return = ODO::Node::Literal->new($item[1]); } |
79
|
|
|
|
|
|
|
| TextLiteral { $return = ODO::Node::Literal->new($item[1]); } |
80
|
|
|
|
|
|
|
| BooleanLiteral { $return = ODO::Node::Literal->new($item[1]); } |
81
|
|
|
|
|
|
|
| NullLiteral { $return = ODO::Node::Literal->new($item[1]); } |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
URI: '<' URIChars '>' { $return = $item[2]; } |
84
|
|
|
|
|
|
|
{ |
85
|
|
|
|
|
|
|
$return = ODO::Node::Resource->new($item[2]); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
| QName |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
$return = ODO::Node::Resource->new($item[1]); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
push @{ $::QNames }, $return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
QName: NSPrefix ':' LocalPart { $return = $item[1] . ':' . $item[3]; } |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
NSPrefix: idchars { $return = $item[1]; } |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
LocalPart: /[^ \t<>(),.;'"+=]+/ { $return = $item{'__PATTERN1__'}; } |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
NumericLiteral: |
101
|
|
|
|
|
|
|
/([0-9]+)/ { $return = $item{'__PATTERN1__'}; chomp($return); } |
102
|
|
|
|
|
|
|
| /(([0-9])*'.'([0-9])+('e'('+'|'-')?([0-9])+)?)/ { $return = $item{'__PATTERN1__'}; chomp($return); 1; } |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
NullLiteral: /null/i { $return = 'null'; } |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
TextLiteral: /"/ idchars /"/ { $return = $item[1]; } |
107
|
|
|
|
|
|
|
| /'/ idchars /'/ { $return = $item[1]; } |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
BooleanLiteral: /true|false/i { $return = lc($item{'__PATTERN1__'}); } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
idchars: /(([a-zA-Z0-9]|[\-_\.])+)/ { $return = $item{'__PATTERN1__'}; chomp($return); } |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
URIChars: /([A-Za-z0-9]|[:.\-_\/#])+/ { $return = $item{'__PATTERN1__'}; chomp($return); } |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
); |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=over |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item parse( $query_string ) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub parse { |
126
|
1
|
|
|
1
|
1
|
2872
|
my ($self, $query_string) = @_; |
127
|
|
|
|
|
|
|
|
128
|
1
|
|
|
|
|
5
|
chomp($query_string); |
129
|
|
|
|
|
|
|
|
130
|
1
|
50
|
|
|
|
18
|
$PARSER = new Parse::RecDescent($GRAMMAR) |
131
|
|
|
|
|
|
|
unless(UNIVERSAL::isa($PARSER, 'Parse::RecDescent')); |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
115671
|
return $PARSER->StatementPatternClause($query_string); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=back |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Copyright (c) 2006 IBM Corporation. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
All rights reserved. This program and the accompanying materials |
143
|
|
|
|
|
|
|
are made available under the terms of the Eclipse Public License v1.0 |
144
|
|
|
|
|
|
|
which accompanies this distribution, and is available at |
145
|
|
|
|
|
|
|
http://www.eclipse.org/legal/epl-v10.html |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
1; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |