ABNF-Grammar

 view release on metacpan or  search on metacpan

lib/ABNF/Generator/Honest.pm  view on Meta::CPAN

method _reference($rule, $recursion) {
	return $self->_generateChain($rule->{name}, $recursion);
}

method _group($rule, $recursion) {
	my @result = ();
	foreach my $elem ( @{$rule->{value}} ) {
		push(@result, $self->_generateChain($elem, $recursion));
	}

	return {class => "Sequence", value => \@result};
}

method _choice($rule, $recursion) {
	$recursion->{level}++;
	my @result = ();
	if ( $recursion->{level} < $RECURSION_LIMIT ) {
		foreach my $choice ( @{$rule->{value}} ) {
			push(@result, $self->_generateChain($choice, $recursion));
		}
	} else {
		$recursion->{choices} ||= {};
		my $candidate = reduce {
			if ( not exists($recursion->{choices}->{$a}) ) {
				$b
			} elsif ( not exists($recursion->{choices}->{$b}) ) {
				$a
			} else {
				$recursion->{choices}->{$a} <=> $recursion->{choices}->{$b} 
			}
		} @{$rule->{value}};
		$recursion->{choices}->{$candidate}++;
		push(@result, $self->_generateChain( $candidate, $recursion));
		$recursion->{choices}->{$candidate}--;
	}
	$recursion->{level}--;

	return {class => "Choice", value => \@result};
}

method _rule($rule, $recursion) {
	return $self->_generateChain($rule->{value}, $recursion);
}

=pod

=head1 $honest->C<withoutArguments>($name, $tail="")

Return a string starts like command $name and without arguments if command may have no arguments.

Return an empty string otherwise.

$tail is a string added to result if it absent.

dies if there is no command like $rule.

=cut

method withoutArguments(Str $name, Str $tail="") {
	my $result = $self->SUPER::withoutArguments($name, $tail);
	return $self->{_validator}->validate($name, $result) ? $result : "";
}

=pod

=head1 FUNCTIONS

=head1 C<Honest>()

Return __PACKAGE__ to reduce class name :3

=cut

func Honest() {
	return __PACKAGE__;
}

1;

=pod

=head1 AUTHOR / COPYRIGHT / LICENSE

Copyright (c) 2013 Arseny Krasikov <nyaapa@cpan.org>.

This module is licensed under the same terms as Perl itself.

=cut



( run in 0.645 second using v1.01-cache-2.11-cpan-140bd7fdf52 )