| 1 | # | ||||||||||||||||||||||||||||
| 2 | # This file is part of Soar-Production | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # This software is copyright (c) 2012 by Nathan Glenn. | ||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | package Soar::Production; | ||||||||||||||||||||||||||||
| 10 | # ABSTRACT: REPRESENT SOAR PRODUCTIONS | ||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Soar::Production::Parser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Exporter::Easy ( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | OK => [qw(prods_from prods_from_file)] | |||||||||||||||||||||||||||
| 19 | 3 | ); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 3 | our $VERSION = '0.03'; # VERSION | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | my $parser = Soar::Production::Parser->new; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | #if run as a script, prints the name of every production in an input file. | ||||||||||||||||||||||||||||
| 28 | 3 | ▶ | unless(caller){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | my $prods = prods_from_file( $ARGV[0] ); | |||||||||||||||||||||||||||
| 30 | 0 | for my $prod (@$prods){ | |||||||||||||||||||||||||||
| 31 | 0 | print $prod->name . "\n"; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 1 | my ($class, $text) = @_; | |||||||||||||||||||||||||||
| 38 | 1 | my $prod = bless $parser->parse_text($text), $class; | |||||||||||||||||||||||||||
| 39 | 1 | return $prod; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # sub as_text { | ||||||||||||||||||||||||||||
| 43 | # my ($class) = @_; | ||||||||||||||||||||||||||||
| 44 | # # return tree_to_text($class) | ||||||||||||||||||||||||||||
| 45 | # } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 4 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 4 | my ($prod, $name) = @_; | |||||||||||||||||||||||||||
| 50 | # print Dumper $prod; | ||||||||||||||||||||||||||||
| 51 | 4 | ▶ | $prod->{name} = $name | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | if($name); | ||||||||||||||||||||||||||||
| 53 | 4 | return $prod->{name}; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | sub prods_from_file{ | ||||||||||||||||||||||||||
|
Subroutine
prods_from_file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 1 | my ($file) = @_; | |||||||||||||||||||||||||||
| 59 | 1 | return prods_from( file => $file ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub prods_from {## no critic (RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
prods_from: called CC=3 SCAR=11.6
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 1 | my (%args) = @_; | |||||||||||||||||||||||||||
| 65 | $args{text} or $args{file} | ||||||||||||||||||||||||||||
| 66 | 1 | ▶ | or croak 'Must specify parameter \'file\' or \'text\' to extract productions.'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"text"} or $args{"file"}
MC/DC0%0/2
$args{"text"} or $args{"file"}
$args{"text"}
$args{"file"}
Truth table33%1/3
A or B
A= $args{"text"}B= $args{"file"}
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | my $parses = $parser->productions(@_, parse => 1); | |||||||||||||||||||||||||||
| 69 | 1 | my @prods = map { bless $_ } @$parses; ## no critic(ProhibitOneArgBless) | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | return \@prods; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 3 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||