lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r807453 - in /lucene/lucy/trunk/boilerplater: lib/Boilerplater/CBlock.pm lib/Boilerplater/Parser.pm t/401-c_block.t
Date Tue, 25 Aug 2009 01:56:58 GMT
Author: marvin
Date: Tue Aug 25 01:56:56 2009
New Revision: 807453

URL: http://svn.apache.org/viewvc?rev=807453&view=rev
Log:
Commit LUCY-24, adding Boilerplater::CBlock.

Added:
    lucene/lucy/trunk/boilerplater/lib/Boilerplater/CBlock.pm   (with props)
    lucene/lucy/trunk/boilerplater/t/401-c_block.t   (with props)
Modified:
    lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm

Added: lucene/lucy/trunk/boilerplater/lib/Boilerplater/CBlock.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/lib/Boilerplater/CBlock.pm?rev=807453&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/lib/Boilerplater/CBlock.pm (added)
+++ lucene/lucy/trunk/boilerplater/lib/Boilerplater/CBlock.pm Tue Aug 25 01:56:56 2009
@@ -0,0 +1,91 @@
+use strict;
+use warnings;
+
+package Boilerplater::CBlock;
+use Boilerplater::Util qw( verify_args );
+use Carp;
+
+our %new_PARAMS = ( contents => undef, );
+
+sub new {
+    my $either = shift;
+    verify_args( \%new_PARAMS, @_ ) or confess $@;
+    my $self = bless { %new_PARAMS, @_ }, ref($either) || $either;
+    confess("Missing required param 'contents'")
+        unless defined $self->{contents};
+    return $self;
+}
+
+# Accessors.
+sub get_contents { shift->{contents} }
+
+1;
+
+__END__
+
+__POD__
+
+=head1 NAME
+
+Boilerplater::CBlock - A block of embedded C code.
+
+=head1 DESCRIPTION
+
+CBlock exists to support embedding literal C code within .bp files:
+
+    parcel Boil;
+
+    class Foo {
+        /** Print a greeting. 
+         */
+        public inline void
+        Say_Hello(Foo *self);
+    }
+
+    __C__
+    #include <stdio.h>
+    static CHY_INLINE void
+    boil_Foo_say_hello(boil_Foo *self)
+    {
+        printf("Greetings, Earthlings.\n");
+    }
+    __END_C__
+
+=head1 METHODS
+
+=head2 new
+
+    my $c_block = Boilerplater::CBlock->new(
+        contents => $text,
+    );
+
+=over
+
+=item * B<contents> - Raw C code.
+
+=back
+
+=head2 get_contents
+
+Accessor.
+
+=head1 COPYRIGHT AND LICENSE
+
+    /**
+     * Copyright 2009 The Apache Software Foundation
+     *
+     * Licensed under the Apache License, Version 2.0 (the "License");
+     * you may not use this file except in compliance with the License.
+     * You may obtain a copy of the License at
+     *
+     *     http://www.apache.org/licenses/LICENSE-2.0
+     *
+     * Unless required by applicable law or agreed to in writing, software
+     * distributed under the License is distributed on an "AS IS" BASIS,
+     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+     * implied.  See the License for the specific language governing
+     * permissions and limitations under the License.
+     */
+
+=cut
+

Propchange: lucene/lucy/trunk/boilerplater/lib/Boilerplater/CBlock.pm
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm?rev=807453&r1=807452&r2=807453&view=diff
==============================================================================
--- lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm (original)
+++ lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm Tue Aug 25 01:56:56 2009
@@ -19,6 +19,7 @@
 use Boilerplater::Function;
 use Boilerplater::Method;
 use Boilerplater::Class;
+use Boilerplater::CBlock;
 use Carp;
 
 our $grammar = <<'END_GRAMMAR';
@@ -31,6 +32,12 @@
         $parcel;
     }
 
+embed_c:
+    '__C__'
+    /.*?(?=__END_C__)/s  
+    '__END_C__'
+    { Boilerplater::CBlock->new( contents => $item[2] ) }
+
 class_declaration:
     docucomment(?)
     exposure_specifier(?) class_modifier(s?) 'class' class_name 

Added: lucene/lucy/trunk/boilerplater/t/401-c_block.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/t/401-c_block.t?rev=807453&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/t/401-c_block.t (added)
+++ lucene/lucy/trunk/boilerplater/t/401-c_block.t Tue Aug 25 01:56:56 2009
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+use Boilerplater::CBlock;
+use Boilerplater::Parser;
+
+my $parser = Boilerplater::Parser->new;
+
+my $block = Boilerplater::CBlock->new( contents => 'int foo;' );
+isa_ok( $block, "Boilerplater::CBlock" );
+is( $block->get_contents, 'int foo;', "get_contents" );
+eval { Boilerplater::CBlock->new };
+like( $@, qr/contents/, "content required" );
+
+$block = $parser->embed_c(qq| __C__\n#define FOO 1\n__END_C__  |);
+
+isa_ok( $block, "Boilerplater::CBlock" );
+is( $block->get_contents, "#define FOO 1\n", "parse embed_c" );
+

Propchange: lucene/lucy/trunk/boilerplater/t/401-c_block.t
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message