| 1 | package AI::Prolog::Parser; | ||||||||||||||||||||||||||||||
| 2 | 13 | $REVISION = '$Id: Parser.pm,v 1.9 2005/08/06 23:28:40 ovid Exp $'; | |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||
| 4 | 13 | $VERSION = '0.10'; | |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Carp qw( confess croak ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Regexp::Common; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use Hash::Util 'lock_keys'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||
| 11 | # debugging stuff | ||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | use Clone; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Text::Balanced qw/extract_quotelike extract_delimited/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use aliased 'AI::Prolog::Engine'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use aliased 'AI::Prolog::KnowledgeBase'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | 13 | ▶ | use aliased 'AI::Prolog::Parser::PreProcessor'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use aliased 'AI::Prolog::Term'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use aliased 'AI::Prolog::Term::Number'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use aliased 'AI::Prolog::TermList'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use aliased 'AI::Prolog::TermList::Clause'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use aliased 'AI::Prolog::TermList::Primitive'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | 13 | my $ATOM = qr/[[:alpha:]][[:alnum:]_]*/; | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use constant NULL => 'null'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 76 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 29 | 76 | my ( $class, $string ) = @_; | |||||||||||||||||||||||||||||
| 30 | 76 | my $self = bless { | |||||||||||||||||||||||||||||
| 31 | _str => PreProcessor->process($string), | ||||||||||||||||||||||||||||||
| 32 | _posn => 0, | ||||||||||||||||||||||||||||||
| 33 | _start => 0, | ||||||||||||||||||||||||||||||
| 34 | _varnum => 0, | ||||||||||||||||||||||||||||||
| 35 | _internal => 0, | ||||||||||||||||||||||||||||||
| 36 | _vardict => {}, | ||||||||||||||||||||||||||||||
| 37 | } => $class; | ||||||||||||||||||||||||||||||
| 38 | 76 | lock_keys %$self; | |||||||||||||||||||||||||||||
| 39 | 76 | return $self; | |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub _vardict_to_string { | ||||||||||||||||||||||||||||
|
Subroutine
_vardict_to_string: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 44 | return "{" | ||||||||||||||||||||||||||||||
| 45 | . ( | ||||||||||||||||||||||||||||||
| 46 | 0 | join ', ' => map { join '=' => $_->[0], $_->[1] } | |||||||||||||||||||||||||||||
| 47 | 0 | sort { $a->[2] <=> $b->[2] } | |||||||||||||||||||||||||||||
| 48 | 0 | map { [ $_, $self->_sortable_term( $self->{_vardict}{$_} ) ] } | |||||||||||||||||||||||||||||
| 49 | 0 | keys %{ $self->{_vardict} } | |||||||||||||||||||||||||||||
| 50 | ) . "}"; | ||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub _sortable_term { | ||||||||||||||||||||||||||||
|
Subroutine
_sortable_term: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 54 | 0 | my ( $self, $term ) = @_; | |||||||||||||||||||||||||||||
| 55 | 0 | my $string = $term->to_string; | |||||||||||||||||||||||||||||
| 56 | 0 | my $number = substr $string => 1; | |||||||||||||||||||||||||||||
| 57 | 0 | return $string, $number; | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub to_string { | ||||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 62 | 0 | my $output = Clone::clone($self); | |||||||||||||||||||||||||||||
| 63 | 0 | $output->{_vardict} = $self->_vardict_to_string; | |||||||||||||||||||||||||||||
| 64 | return "{" | ||||||||||||||||||||||||||||||
| 65 | . substr( $self->{_str}, 0, $self->{_posn} ) . " ^ " | ||||||||||||||||||||||||||||||
| 66 | 0 | . substr( $self->{_str}, $self->{_posn} ) . " | " | |||||||||||||||||||||||||||||
| 67 | . $self->_vardict_to_string . " }"; | ||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub _posn { shift->{_posn} } | ||||||||||||||||||||||||||||
|
Subroutine
_posn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub _str { shift->{_str} } | ||||||||||||||||||||||||||||
|
Subroutine
_str: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _start { shift->{_start} } | ||||||||||||||||||||||||||||
|
Subroutine
_start: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub _varnum { shift->{_varnum} } | ||||||||||||||||||||||||||||
|
Subroutine
_varnum: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub _vardict { shift->{_vardict} } | ||||||||||||||||||||||||||||
|
Subroutine
_vardict: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _internal { | ||||||||||||||||||||||||||||
|
Subroutine
_internal: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 79 | 0 | $self->{_internal} = shift; | |||||||||||||||||||||||||||||
| 80 | 0 | return $self; | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | 0 | return $self->{_internal}; | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | # get the current character | ||||||||||||||||||||||||||||||
| 86 | 49367 | ▶ | sub current { | ||||||||||||||||||||||||||||
|
Subroutine
current: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 87 | 49367 | my $self = shift; | |||||||||||||||||||||||||||||
| 88 | 49367 | ▶ | return '#' if $self->empty; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 89 | 49267 | return substr $self->{_str} => $self->{_posn}, 1; | |||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | # peek at the next character | ||||||||||||||||||||||||||||||
| 93 | 5 | ▶ | sub peek { | ||||||||||||||||||||||||||||
|
Subroutine
peek: called CC=3 SCAR=11.7
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 94 | 5 | my $self = shift; | |||||||||||||||||||||||||||||
| 95 | 5 | ▶ | return '#' if $self->empty; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 96 | 5 | ▶ | return substr( $self->{_str} => ( $self->{_posn} + 1 ), 1 ) || '#'; | ||||||||||||||||||||||||||||
|
Condition50%1/2
substr($self->{'_str'}, $self->{'_posn'} + 1, 1) || '#'
MC/DC0%0/1
substr($self->{'_str'}, $self->{'_posn'} + 1, 1) || '#'
substr($self->{'_str'}, $self->{'_posn'} + 1, 1)
Truth table50%1/2
A
A= substr($self->{'_str'}, $self->{'_posn'} + 1, 1)
| |||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||
| 99 | # is the parsestring empty? | ||||||||||||||||||||||||||||||
| 100 | 49788 | ▶ | sub empty { | ||||||||||||||||||||||||||||
|
Subroutine
empty: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 101 | 49788 | my $self = shift; | |||||||||||||||||||||||||||||
| 102 | 49788 | return $self->{_posn} >= length $self->{_str}; | |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | 13 | my $LINENUM = 1; | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | 22 | ▶ | sub linenum { | ||||||||||||||||||||||||||||
|
Subroutine
linenum: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 108 | 22 | my $self = shift; | |||||||||||||||||||||||||||||
| 109 | 22 | ▶ | if (@_) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 110 | 22 | $LINENUM = shift; | |||||||||||||||||||||||||||||
| 111 | 22 | return $self; | |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||
| 113 | 0 | $LINENUM; | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | 479 | ▶ | sub advance_linenum { | ||||||||||||||||||||||||||||
|
Subroutine
advance_linenum: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 117 | 479 | my $self = shift; | |||||||||||||||||||||||||||||
| 118 | 479 | $LINENUM++; | |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | # Move a character forward | ||||||||||||||||||||||||||||||
| 122 | 13178 | ▶ | sub advance { | ||||||||||||||||||||||||||||
|
Subroutine
advance: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 123 | 13178 | my $self = shift; | |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | # print $self->current; # XXX | ||||||||||||||||||||||||||||||
| 126 | 13178 | ▶ | $self->{_posn}++ unless $self->{_posn} >= length $self->{_str}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 127 | 13178 | ▶ | $self->advance_linenum if $self->current =~ /[\r\n]/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | # all three get methods must be called before advance | ||||||||||||||||||||||||||||||
| 131 | # recognize a name (sequence of alphanumerics) | ||||||||||||||||||||||||||||||
| 132 | # XXX the java methods do not directly translate, so | ||||||||||||||||||||||||||||||
| 133 | # we need to revisit this if it breaks | ||||||||||||||||||||||||||||||
| 134 | # XXX Update: There was a subtle bug. I think | ||||||||||||||||||||||||||||||
| 135 | # I've nailed it, though. The string index was off by one | ||||||||||||||||||||||||||||||
| 136 | 1366 | ▶ | sub getname { | ||||||||||||||||||||||||||||
|
Subroutine
getname: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 137 | 1366 | my $self = shift; | |||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||
| 139 | 1366 | $self->{_start} = $self->{_posn}; | |||||||||||||||||||||||||||||
| 140 | 1366 | my $getname; | |||||||||||||||||||||||||||||
| 141 | 1366 | ▶ | if ( $self->current =~ /['"]/ ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||
| 143 | # Normally, Prolog distinguishes between single and double quoted strings | ||||||||||||||||||||||||||||||
| 144 | 3 | my $string = substr $self->{_str} => $self->{_start}; | |||||||||||||||||||||||||||||
| 145 | 3 | $getname = extract_delimited($string); | |||||||||||||||||||||||||||||
| 146 | 3 | $self->{_posn} += length $getname; | |||||||||||||||||||||||||||||
| 147 | 3 | return substr $getname => 1, length($getname) - 2; # strip the quotes | |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||||
| 150 | 1363 | my $string = substr $self->{_str} => $self->{_start}; | |||||||||||||||||||||||||||||
| 151 | 1363 | ($getname) = $string =~ /^($ATOM)/; | |||||||||||||||||||||||||||||
| 152 | 1363 | $self->{_posn} += length $getname; | |||||||||||||||||||||||||||||
| 153 | 1363 | return $getname; | |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||
| 157 | # recognize a number | ||||||||||||||||||||||||||||||
| 158 | # XXX same issues as getname | ||||||||||||||||||||||||||||||
| 159 | 309 | ▶ | sub getnum { | ||||||||||||||||||||||||||||
|
Subroutine
getnum: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 160 | 309 | my $self = shift; | |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | 309 | $self->{_start} = $self->{_posn}; | |||||||||||||||||||||||||||||
| 163 | 309 | my $string = substr $self->{_str} => $self->{_start}; | |||||||||||||||||||||||||||||
| 164 | 309 | my ($getnum) = $string =~ /^($RE{num}{real})/; | |||||||||||||||||||||||||||||
| 165 | 309 | ▶ | if ( '.' eq substr $getnum => -1, 1 ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 166 | 234 | $getnum = substr $getnum => 0, length($getnum) - 1; | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||
| 168 | 309 | $self->{_posn} += length $getnum; | |||||||||||||||||||||||||||||
| 169 | 309 | return $getnum; | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||
| 172 | # get the term corresponding to a name. | ||||||||||||||||||||||||||||||
| 173 | # if the name is new, create a new variable | ||||||||||||||||||||||||||||||
| 174 | 674 | ▶ | sub getvar { | ||||||||||||||||||||||||||||
|
Subroutine
getvar: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 175 | 674 | my $self = shift; | |||||||||||||||||||||||||||||
| 176 | 674 | my $string = $self->getname; | |||||||||||||||||||||||||||||
| 177 | 674 | my $term = $self->{_vardict}{$string}; | |||||||||||||||||||||||||||||
| 178 | 674 | ▶ | unless ($term) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 179 | 492 | $term = Term->new( $self->{_varnum}++ ); # XXX wrong _varnum? | |||||||||||||||||||||||||||||
| 180 | 492 | $self->{_vardict}{$string} = $term; | |||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||
| 182 | 674 | return ( $term, $string ); | |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||
| 185 | 13 | my $ANON = 'a'; | |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||
| 187 | 5 | ▶ | sub get_anon { | ||||||||||||||||||||||||||||
|
Subroutine
get_anon: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 188 | 5 | my $self = shift; | |||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||
| 190 | # HACK!!! | ||||||||||||||||||||||||||||||
| 191 | 5 | my $string = '___' . $ANON++; | |||||||||||||||||||||||||||||
| 192 | 5 | $self->advance; | |||||||||||||||||||||||||||||
| 193 | 5 | my $term = $self->{_vardict}{$string}; | |||||||||||||||||||||||||||||
| 194 | 5 | ▶ | unless ($term) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 195 | 5 | $term = Term->new( $self->{_varnum}++ ); # XXX wrong _varnum? | |||||||||||||||||||||||||||||
| 196 | 5 | $self->{_vardict}{$string} = $term; | |||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||
| 198 | 5 | return ( $term, $string ); | |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | # handle errors in one place | ||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub parseerror { | ||||||||||||||||||||||||||||
|
Subroutine
parseerror: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 203 | 0 | my ( $self, $character ) = @_; | |||||||||||||||||||||||||||||
| 204 | 0 | my $linenum = $self->linenum; | |||||||||||||||||||||||||||||
| 205 | 0 | croak "Unexpected character: ($character) at line number $linenum"; | |||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||
| 208 | # skips whitespace and prolog comments | ||||||||||||||||||||||||||||||
| 209 | 4967 | ▶ | sub skipspace { | ||||||||||||||||||||||||||||
|
Subroutine
skipspace: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 210 | 4967 | my $self = shift; | |||||||||||||||||||||||||||||
| 211 | 4967 | ▶ | $self->advance while $self->current =~ /[[:space:]]/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 212 | 4967 | _skipcomment($self); | |||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | # XXX Other subtle differences | ||||||||||||||||||||||||||||||
| 216 | 4967 | ▶ | sub _skipcomment { | ||||||||||||||||||||||||||||
|
Subroutine
_skipcomment: called CC=9 SCAR=33.7
| |||||||||||||||||||||||||||||||
| 217 | 4967 | my $self = shift; | |||||||||||||||||||||||||||||
| 218 | 4967 | ▶ | if ( $self->current eq '%' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 219 | 90 | ▶ | while ( $self->current ne "\n" && $self->current ne "#" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->current ne "\n" and $self->current ne "#"
MC/DC50%1/2
$self->current ne "\n" and $self->current ne "#"
$self->current ne "\n"
$self->current ne "#"
Truth table66%2/3
A and B
A= $self->current ne "\n"B= $self->current ne "#"
| |||||||||||||||||||||||||||||||
| 220 | 3060 | $self->advance; | |||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||
| 222 | 90 | $self->skipspace; | |||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||
| 224 | 4967 | ▶ | if ( $self->current eq "/" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 225 | 0 | $self->advance; | |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ( $self->current ne "*" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 227 | 0 | $self->parseerror("Expecting '*' after '/'"); | |||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||
| 229 | 0 | $self->advance; | |||||||||||||||||||||||||||||
| 230 | 0 | ▶ | while ( $self->current ne "*" && $self->current ne "#" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->current ne "*" and $self->current ne "#"
MC/DC0%0/2
$self->current ne "*" and $self->current ne "#"
$self->current ne "*"
$self->current ne "#"
Truth table0%0/3
A and B
A= $self->current ne "*"B= $self->current ne "#"
| |||||||||||||||||||||||||||||||
| 231 | 0 | $self->advance; | |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||
| 233 | 0 | $self->advance; | |||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if ( $self->current ne "/" ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 235 | 0 | $self->parseerror("Expecting terminating '/' on comment"); | |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||
| 237 | 0 | $self->advance; | |||||||||||||||||||||||||||||
| 238 | 0 | $self->skipspace; | |||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||
| 242 | # reset the variable dictionary | ||||||||||||||||||||||||||||||
| 243 | 394 | ▶ | sub nextclause { | ||||||||||||||||||||||||||||
|
Subroutine
nextclause: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 244 | 394 | my $self = shift; | |||||||||||||||||||||||||||||
| 245 | 394 | $self->{_vardict} = {}; | |||||||||||||||||||||||||||||
| 246 | 394 | $self->{_varnum} = 0; | |||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||
| 249 | # takes a hash and extends it with the clauses in the string | ||||||||||||||||||||||||||||||
| 250 | # $program is a string representing a prolog program | ||||||||||||||||||||||||||||||
| 251 | # $db is an initial program that will be augmented with the | ||||||||||||||||||||||||||||||
| 252 | # clauses parsed. | ||||||||||||||||||||||||||||||
| 253 | # class method, not an instance method | ||||||||||||||||||||||||||||||
| 254 | 22 | ▶ | sub consult { | ||||||||||||||||||||||||||||
|
Subroutine
consult: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 255 | 22 | my ( $class, $program, $db ) = @_; | |||||||||||||||||||||||||||||
| 256 | 22 | ▶ | $db ||= KnowledgeBase->new; | ||||||||||||||||||||||||||||
|
Condition66%2/3
$db ||= "AI::Prolog::KnowledgeBase"->new
MC/DC0%0/2
$db ||= "AI::Prolog::KnowledgeBase"->new
$db
"AI::Prolog::KnowledgeBase"->new
Truth table66%2/3
A ||= B
A= $dbB= "AI::Prolog::KnowledgeBase"->new
| |||||||||||||||||||||||||||||||
| 257 | 22 | my $self = $class->new($program); | |||||||||||||||||||||||||||||
| 258 | 22 | $self->linenum(1); | |||||||||||||||||||||||||||||
| 259 | 22 | $self->skipspace; | |||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | 22 | ▶ | until ( $self->empty ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 262 | 394 | my $termlist = $self->_termlist; | |||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||
| 264 | 394 | my $head = $termlist->term; | |||||||||||||||||||||||||||||
| 265 | 394 | my $body = $termlist->next; | |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | 394 | ▶ | my $is_primitive = $body && $body->isa(Primitive); | ||||||||||||||||||||||||||||
|
Condition100%3/3
$body && $body->isa('AI::Prolog::TermList::Primitive')
MC/DC100%2/2
$body && $body->isa('AI::Prolog::TermList::Primitive')
$body
$body->isa('AI::Prolog::TermList::Primitive')
Truth table100%3/3
A && B
A= $bodyB= $body->isa('AI::Prolog::TermList::Primitive')
| |||||||||||||||||||||||||||||||
| 268 | 394 | ▶ | unless ($is_primitive) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 269 | 160 | my $predicate = $head->predicate; | |||||||||||||||||||||||||||||
| 270 | 160 | $is_primitive = exists $db->{primitives}{$predicate}; | |||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||
| 272 | 394 | ▶ | my $add = $is_primitive ? 'add_primitive' : 'add_clause'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 273 | 394 | my $clause = Clause->new( $head, $body ); | |||||||||||||||||||||||||||||
| 274 | 394 | my $adding_builtins = Engine->_adding_builtins; | |||||||||||||||||||||||||||||
| 275 | 394 | ▶ | $clause->is_builtin(1) if $adding_builtins; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 276 | 394 | $db->$add( $clause, $adding_builtins ); | |||||||||||||||||||||||||||||
| 277 | 394 | $self->skipspace; | |||||||||||||||||||||||||||||
| 278 | 394 | $self->nextclause; # new set of vars | |||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||
| 280 | 22 | return $db; | |||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub resolve { | ||||||||||||||||||||||||||||
|
Subroutine
resolve: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 284 | 0 | my ( $class, $db ) = @_; | |||||||||||||||||||||||||||||
| 285 | 0 | foreach my $termlist ( values %{ $db->ht } ) { | |||||||||||||||||||||||||||||
| 286 | 0 | $termlist->resolve($db); | |||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||
| 290 | 401 | ▶ | sub _termlist { | ||||||||||||||||||||||||||||
|
Subroutine
_termlist: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||
| 291 | 401 | my ($self) = @_; | |||||||||||||||||||||||||||||
| 292 | 401 | my $termlist = TermList->new; | |||||||||||||||||||||||||||||
| 293 | 401 | my @ts = $self->_term; | |||||||||||||||||||||||||||||
| 294 | 401 | $self->skipspace; | |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||
| 296 | 401 | ▶ | if ( $self->current eq ':' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 297 | 343 | $self->advance; | |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | 343 | ▶ | if ( $self->current eq '=' ) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||
| 301 | # we're parsing a primitive | ||||||||||||||||||||||||||||||
| 302 | 234 | $self->advance; | |||||||||||||||||||||||||||||
| 303 | 234 | $self->skipspace; | |||||||||||||||||||||||||||||
| 304 | 234 | my $id = $self->getnum; | |||||||||||||||||||||||||||||
| 305 | 234 | $self->skipspace; | |||||||||||||||||||||||||||||
| 306 | 234 | $termlist->{term} = $ts[0]; | |||||||||||||||||||||||||||||
| 307 | 234 | $termlist->{next} = Primitive->new($id); | |||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||
| 309 | elsif ( $self->current ne '-' ) { | ||||||||||||||||||||||||||||||
| 310 | 0 | $self->parseerror("Expected '-' after ':'"); | |||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||
| 313 | 109 | $self->advance; | |||||||||||||||||||||||||||||
| 314 | 109 | $self->skipspace; | |||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||
| 316 | 109 | push @ts => $self->_term; | |||||||||||||||||||||||||||||
| 317 | 109 | $self->skipspace; | |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||
| 319 | 109 | ▶ | while ( $self->current eq ',' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 320 | 41 | $self->advance; | |||||||||||||||||||||||||||||
| 321 | 41 | $self->skipspace; | |||||||||||||||||||||||||||||
| 322 | 41 | push @ts => $self->_term; | |||||||||||||||||||||||||||||
| 323 | 41 | $self->skipspace; | |||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||
| 326 | 109 | my @tsl; | |||||||||||||||||||||||||||||
| 327 | 109 | for my $j ( reverse 1 .. $#ts ) { | |||||||||||||||||||||||||||||
| 328 | 150 | $tsl[$j] = $termlist->new( $ts[$j], $tsl[ $j + 1 ] ); | |||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||
| 331 | 109 | $termlist->{term} = $ts[0]; | |||||||||||||||||||||||||||||
| 332 | 109 | $termlist->{next} = $tsl[1]; | |||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||
| 335 | else { | ||||||||||||||||||||||||||||||
| 336 | 58 | $termlist->{term} = $ts[0]; | |||||||||||||||||||||||||||||
| 337 | 58 | $termlist->{next} = undef; | |||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||
| 340 | 401 | ▶ | if ( $self->current ne '.' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 341 | 0 | $self->parseerror("Expected '.' Got '@{[$self->current]}'"); | |||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||
| 343 | 401 | $self->advance; | |||||||||||||||||||||||||||||
| 344 | 401 | return $termlist; | |||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||
| 347 | # This constructor is the simplest way to construct a term. The term is given | ||||||||||||||||||||||||||||||
| 348 | # in standard notation. | ||||||||||||||||||||||||||||||
| 349 | # Example: my $term = Term->new(Parser->new("p(1,a(X,b))")); | ||||||||||||||||||||||||||||||
| 350 | 1496 | ▶ | sub _term { | ||||||||||||||||||||||||||||
|
Subroutine
_term: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||
| 351 | 1496 | my ($self) = @_; | |||||||||||||||||||||||||||||
| 352 | 1496 | my $term = Term->new( undef, 0 ); | |||||||||||||||||||||||||||||
| 353 | 1496 | my $ts = []; | |||||||||||||||||||||||||||||
| 354 | 1496 | my $i = 0; | |||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||
| 356 | 1496 | $self->skipspace; # otherwise we crash when we hit leading | |||||||||||||||||||||||||||||
| 357 | # spaces | ||||||||||||||||||||||||||||||
| 358 | 1496 | ▶ | if ( $self->current =~ /^[[:lower:]'"]$/ ) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 359 | 692 | $term->{functor} = $self->getname; | |||||||||||||||||||||||||||||
| 360 | 692 | $term->{bound} = 1; | |||||||||||||||||||||||||||||
| 361 | 692 | $term->{deref} = 0; | |||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||
| 363 | 692 | ▶ | if ( '(' eq $self->current ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 364 | 508 | $self->advance; | |||||||||||||||||||||||||||||
| 365 | 508 | $self->skipspace; | |||||||||||||||||||||||||||||
| 366 | 508 | $ts->[ $i++ ] = $self->_term; | |||||||||||||||||||||||||||||
| 367 | 508 | $self->skipspace; | |||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||
| 369 | 508 | ▶ | while ( ',' eq $self->current ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 370 | 334 | $self->advance; | |||||||||||||||||||||||||||||
| 371 | 334 | $self->skipspace; | |||||||||||||||||||||||||||||
| 372 | 334 | $ts->[ $i++ ] = $self->_term; | |||||||||||||||||||||||||||||
| 373 | 334 | $self->skipspace; | |||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||
| 376 | 508 | ▶ | if ( ')' ne $self->current ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 377 | 0 | $self->parseerror( | |||||||||||||||||||||||||||||
| 378 | 0 | "Expecting: ')'. Got (@{[$self->current]})"); | |||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||
| 381 | 508 | $self->advance; | |||||||||||||||||||||||||||||
| 382 | 508 | $term->{args} = []; | |||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||
| 384 | 508 | $term->{args}[$_] = $ts->[$_] for 0 .. ( $i - 1 ); | |||||||||||||||||||||||||||||
| 385 | 508 | $term->{arity} = $i; | |||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||
| 387 | else { | ||||||||||||||||||||||||||||||
| 388 | 184 | $term->{arity} = 0; | |||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||
| 391 | elsif ( $self->current =~ /^[[:upper:]]$/ ) { | ||||||||||||||||||||||||||||||
| 392 | 674 | $term->{bound} = 1; | |||||||||||||||||||||||||||||
| 393 | 674 | $term->{deref} = 1; | |||||||||||||||||||||||||||||
| 394 | 674 | my ( $ref, $string ) = $self->getvar; | |||||||||||||||||||||||||||||
| 395 | 674 | $term->{ref} = $ref; | |||||||||||||||||||||||||||||
| 396 | 674 | $term->{varname} = $string; | |||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||
| 398 | ▶ | elsif ( '_' eq $self->current && $self->peek =~ /^[\]\|\.;\s\,\)]$/ ) { | |||||||||||||||||||||||||||||
|
Condition66%2/3
"_" eq $self->current and $self->peek =~ /^[\]\|\.;\s\,\)]$/
MC/DC50%1/2
"_" eq $self->current and $self->peek =~ /^[\]\|\.;\s\,\)]$/
"_" eq $self->current
$self->peek =~ /^[\]\|\.;\s\,\)]$/
Truth table66%2/3
A and B
A= "_" eq $self->currentB= $self->peek =~ /^[\]\|\.;\s\,\)]$/
| |||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||
| 400 | # temporary hack to allow anonymous variables | ||||||||||||||||||||||||||||||
| 401 | # this should really be cleaned up | ||||||||||||||||||||||||||||||
| 402 | 5 | $term->{bound} = 1; | |||||||||||||||||||||||||||||
| 403 | 5 | $term->{deref} = 1; | |||||||||||||||||||||||||||||
| 404 | 5 | my ( $ref, $string ) = $self->get_anon; | |||||||||||||||||||||||||||||
| 405 | 5 | $term->{ref} = $ref; | |||||||||||||||||||||||||||||
| 406 | 5 | $term->{varname} = $string; | |||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||
| 408 | elsif ( $self->current =~ /^[-.[:digit:]]$/ ) { | ||||||||||||||||||||||||||||||
| 409 | 75 | return Number->new( $self->getnum ); | |||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||
| 411 | elsif ( '[' eq $self->current ) { | ||||||||||||||||||||||||||||||
| 412 | 23 | $self->advance; | |||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||
| 414 | 23 | ▶ | if ( ']' eq $self->current ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 415 | 3 | $self->advance; | |||||||||||||||||||||||||||||
| 416 | 3 | $term->{functor} = NULL; | |||||||||||||||||||||||||||||
| 417 | 3 | $term->{arity} = 0; | |||||||||||||||||||||||||||||
| 418 | 3 | $term->{bound} = 1; | |||||||||||||||||||||||||||||
| 419 | 3 | $term->{deref} = 0; | |||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||
| 421 | else { | ||||||||||||||||||||||||||||||
| 422 | 20 | $self->skipspace; | |||||||||||||||||||||||||||||
| 423 | 20 | $ts->[ $i++ ] = $self->_term; | |||||||||||||||||||||||||||||
| 424 | 20 | $self->skipspace; | |||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||
| 426 | 20 | ▶ | while ( ',' eq $self->current ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 427 | 25 | $self->advance; | |||||||||||||||||||||||||||||
| 428 | 25 | $self->skipspace; | |||||||||||||||||||||||||||||
| 429 | 25 | $ts->[ $i++ ] = $self->_term; | |||||||||||||||||||||||||||||
| 430 | 25 | $self->skipspace; | |||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||
| 433 | 20 | ▶ | if ( '|' eq $self->current ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 434 | 11 | $self->advance; | |||||||||||||||||||||||||||||
| 435 | 11 | $self->skipspace; | |||||||||||||||||||||||||||||
| 436 | 11 | $ts->[ $i++ ] = $self->_term; | |||||||||||||||||||||||||||||
| 437 | 11 | $self->skipspace; | |||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||
| 439 | else { | ||||||||||||||||||||||||||||||
| 440 | 9 | $ts->[ $i++ ] = $term->new( NULL, 0 ); | |||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||
| 443 | 20 | ▶ | if ( ']' ne $self->current ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 444 | 0 | $self->parseerror("Expecting ']'"); | |||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||
| 447 | 20 | $self->advance; | |||||||||||||||||||||||||||||
| 448 | 20 | $term->{bound} = 1; | |||||||||||||||||||||||||||||
| 449 | 20 | $term->{deref} = 0; | |||||||||||||||||||||||||||||
| 450 | 20 | $term->{functor} = "cons"; | |||||||||||||||||||||||||||||
| 451 | 20 | $term->{arity} = 2; | |||||||||||||||||||||||||||||
| 452 | 20 | $term->{args} = []; | |||||||||||||||||||||||||||||
| 453 | 20 | for my $j ( reverse 1 .. $i - 2 ) { | |||||||||||||||||||||||||||||
| 454 | 25 | my $term = $term->new( "cons", 2 ); | |||||||||||||||||||||||||||||
| 455 | 25 | $term->setarg( 0, $ts->[$j] ); | |||||||||||||||||||||||||||||
| 456 | 25 | $term->setarg( 1, $ts->[ $j + 1 ] ); | |||||||||||||||||||||||||||||
| 457 | 25 | $ts->[$j] = $term; | |||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||
| 459 | 20 | $term->{args}[0] = $ts->[0]; | |||||||||||||||||||||||||||||
| 460 | 20 | $term->{args}[1] = $ts->[1]; | |||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||
| 463 | elsif ( '!' eq $self->current ) { | ||||||||||||||||||||||||||||||
| 464 | 27 | $self->advance; | |||||||||||||||||||||||||||||
| 465 | 27 | return $term->CUT; | |||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||
| 467 | else { | ||||||||||||||||||||||||||||||
| 468 | 0 | $self->parseerror( | |||||||||||||||||||||||||||||
| 469 | 0 | "Term should begin with a letter, a digit, or '[', not a @{[$self->current]}" | |||||||||||||||||||||||||||||
| 470 | ); | ||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||
| 472 | 1394 | return $term; | |||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||
| 475 | 13 | 1; | |||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||
| 477 | __END__ | ||||||||||||||||||||||||||||||