Compiler-Parser

 view release on metacpan or  search on metacpan

lib/Compiler/Parser/AST.pm  view on Meta::CPAN

        my $parent = $node->parent;
        next unless $parent;
        foreach my $branch (@{$parent->branches}, 'next') {
            my $child = $parent->{$branch};
            next unless ($child && $child == $node);
            $parent->{$branch} = $node->next;
        }
    }
}

sub walk(&$) {
    my ($ast, $callback);
    if (ref $_[0] eq 'Compiler::Parser::AST') {
        ($ast, $callback) = @_;
    } elsif (ref $_[1] eq 'Compiler::Parser::AST') {
        ($callback, $ast) = @_;
    }
    $ast->__walk($ast->root, $callback);
}

sub __walk {

t/app/Plack/Builder.t  view on Meta::CPAN


    $app;
}

# DSL goes here
our $_add = our $_add_if = our $_mount = sub {
    Carp::croak("enable/mount should be called inside builder {} block");
};

sub enable         { $_add->(@_) }
sub enable_if(&$@) { $_add_if->(@_) }

sub mount {
    my $self = shift;
    if (Scalar::Util::blessed($self)) {
        $self->_mount(@_);
    }else{
        $_mount->($self, @_);
    }
}

sub builder(&) {
    my $block = shift;

    my $self = __PACKAGE__->new;

    my $mount_is_called;
    my $urlmap = Plack::App::URLMap->new;
    local $_mount = sub {
        $mount_is_called++;
        $urlmap->map(@_);
        $urlmap;

t/app/Plack/Runner.t  view on Meta::CPAN

        env      => $ENV{PLACK_ENV},
        loader   => 'Plack::Loader',
        includes => [],
        modules  => [],
        default_middleware => 1,
        @_,
    }, $class;
}

# delay the build process for reloader
sub build(&;$) {
    my $block = shift;
    my $app   = shift || sub { };
    return sub { $block->($app->()) };
}

sub parse_options {
    my $self = shift;

    local @ARGV = @_;

t/inc/Test/Compiler/Parser.pm  view on Meta::CPAN

    return \%property;
}

sub check_property {
    my ($property, @branches) = @_;
    foreach (@branches) {
        Carp::confess "needs $_ property" unless (exists $property->{$_});
    }
}

sub branch(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Branch';
}

sub leaf($) {
    my $token_data = shift;
    return bless {
        token_data => $token_data
    }, 'Compiler::Parser::Node::Leaf';
}

sub list(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::List';
}

sub dereference(&) {
    my $property = get_property(@_);
    check_property($property, qw/expr/);
    return bless $property, 'Compiler::Parser::Node::Dereference';
}

sub code_dereference(&) {
    my $property = get_property(@_);
    check_property($property, qw/name/);
    check_property($property, qw/args/);
    return bless $property, 'Compiler::Parser::Node::CodeDereference';
}

sub array(&) {
    my $property = get_property(@_);
    check_property($property, qw/idx/);
    return bless $property, 'Compiler::Parser::Node::Array';
}

sub array_ref(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::ArrayRef';
}

sub hash(&) {
    my $property = get_property(@_);
    check_property($property, qw/key/);
    return bless $property, 'Compiler::Parser::Node::Hash';
}

sub hash_ref(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::HashRef';
}

sub package(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Package';
}

sub function(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Function';
}

sub return(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Return';
}

sub function_call(&) {
    my $property = get_property(@_);
    check_property($property, qw/args/);
    return bless $property, 'Compiler::Parser::Node::FunctionCall';
}

sub single_term_operator(&) {
    my $property = get_property(@_);
    check_property($property, qw/expr/);
    return bless $property, 'Compiler::Parser::Node::SingleTermOperator';
}

sub foreach_stmt(&) {
    my $property = get_property(@_);
    check_property($property, qw/cond/);
    check_property($property, qw/true_stmt/);
    return bless $property, 'Compiler::Parser::Node::ForeachStmt';
}

sub while_stmt(&) {
    my $property = get_property(@_);
    check_property($property, qw/expr/);
    check_property($property, qw/true_stmt/);
    return bless $property, 'Compiler::Parser::Node::WhileStmt';
}

sub if_stmt(&) {
    my $property = get_property(@_);
    check_property($property, qw/expr/);
    check_property($property, qw/true_stmt/);
    return bless $property, 'Compiler::Parser::Node::IfStmt';
}

sub else_stmt(&) {
    my $property = get_property(@_);
    check_property($property, qw/stmt/);
    return bless $property, 'Compiler::Parser::Node::ElseStmt';
}

sub three_term_operator(&) {
    my $property = get_property(@_);
    check_property($property, qw/cond/);
    check_property($property, qw/true_expr/);
    check_property($property, qw/false_expr/);
    return bless $property, 'Compiler::Parser::Node::ThreeTermOperator';
}

sub block(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Block';
}

sub regexp(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Regexp';
}

sub reg_replace(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::RegReplace';
}

sub module(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Module';
}

sub reg_prefix(&) {
    my $property = get_property(@_);
    check_property($property, qw/expr/);
    return bless $property, 'Compiler::Parser::Node::RegPrefix';
}

sub do_stmt(&) {
    my $property = get_property(@_);
    check_property($property, qw/stmt/);
    return bless $property, 'Compiler::Parser::Node::DoStmt';
}

sub handle(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::Handle';
}

sub handle_read(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::HandleRead';
}

sub control_stmt(&) {
    my $property = get_property(@_);
    return bless $property, 'Compiler::Parser::Node::ControlStmt';
}

1;



( run in 0.828 second using v1.01-cache-2.11-cpan-49f99fa48dc )