You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2009/08/18 01:24:40 UTC
svn commit: r805208 - in /lucene/lucy/trunk/boilerplater:
lib/Boilerplater/Parser.pm t/600-parser.t
Author: marvin
Date: Mon Aug 17 23:24:40 2009
New Revision: 805208
URL: http://svn.apache.org/viewvc?rev=805208&view=rev
Log:
Commit LUCY-9, adding Boilerplater::Parser.
Added:
lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm (with props)
lucene/lucy/trunk/boilerplater/t/600-parser.t (with props)
Added: lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm?rev=805208&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm (added)
+++ lucene/lucy/trunk/boilerplater/lib/Boilerplater/Parser.pm Mon Aug 17 23:24:40 2009
@@ -0,0 +1,86 @@
+use strict;
+use warnings;
+
+package Boilerplater::Parser;
+use base qw( Parse::RecDescent );
+
+use Boilerplater::Parcel;
+use Carp;
+
+our $grammar = <<'END_GRAMMAR';
+
+parcel_definition:
+ 'parcel' class_name cnick(?) ';'
+ {
+ my $parcel = Boilerplater::Parser->new_parcel( \%item );
+ Boilerplater::Parser->set_parcel($parcel);
+ $parcel;
+ }
+
+class_name:
+ class_name_component ( "::" class_name_component )(s?)
+ { join('::', $item[1], @{ $item[2] } ) }
+
+class_name_component:
+ /[A-Z]+[A-Z0-9]*[a-z]+[A-Za-z0-9]*(?!\w)/
+
+cnick:
+ 'cnick'
+ /([A-Z][A-Za-z0-9]+)(?!\w)/
+ { $1 }
+
+END_GRAMMAR
+
+sub new { return shift->SUPER::new($grammar) }
+
+our $parcel = undef;
+sub set_parcel { $parcel = $_[1] }
+
+sub new_parcel {
+ my ( undef, $item ) = @_;
+ Boilerplater::Parcel->singleton(
+ name => $item->{class_name},
+ cnick => $item->{'cnick(?)'}[0],
+ );
+}
+
+1;
+
+__END__
+
+__POD__
+
+=head1 NAME
+
+Boilerplater::Parser - Parse Boilerplater header files.
+
+=head1 SYNOPSIS
+
+ my $class_def = $parser->class($class_text);
+
+=head1 DESCRIPTION
+
+Boilerplater::Parser is a combined lexer/parser which parses .bp code. It is
+not at all strict, as it relies heavily on the C parser to pick up errors such
+as misspelled type names.
+
+=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/Parser.pm
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/boilerplater/t/600-parser.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/boilerplater/t/600-parser.t?rev=805208&view=auto
==============================================================================
--- lucene/lucy/trunk/boilerplater/t/600-parser.t (added)
+++ lucene/lucy/trunk/boilerplater/t/600-parser.t Mon Aug 17 23:24:40 2009
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+use Test::More tests => 30;
+
+BEGIN { use_ok('Boilerplater::Parser') }
+
+my $parser = Boilerplater::Parser->new;
+isa_ok( $parser, "Boilerplater::Parser" );
+
+isa_ok( $parser->parcel_definition("parcel Fish;"),
+ "Boilerplater::Parcel", "parcel_definition" );
+isa_ok( $parser->parcel_definition("parcel Crustacean cnick Crust;"),
+ "Boilerplater::Parcel", "parcel_definition with cnick" );
+
+# Set and leave parcel.
+my $parcel = $parser->parcel_definition('parcel Boil;')
+ or die "failed to process parcel_definition";
+is( $Boilerplater::Parser::parcel, $parcel,
+ "parcel_definition sets internal \$parcel var" );
+
+is( $parser->class_name_component($_), $_, "class_name_component: $_" )
+ for (qw( Foo FooJr FooIII Foo4th ));
+
+ok( !$parser->class_name_component($_), "illegal class_name_component: $_" )
+ for (qw( foo fooBar Foo_Bar FOOBAR 1Foo 1FOO ));
+
+is( $parser->class_name($_), $_, "class_name: $_" )
+ for (qw( Foo Foo::FooJr Foo::FooJr::FooIII Foo::FooJr::FooIII::Foo4th ));
+
+ok( !$parser->class_name($_), "illegal class_name: $_" )
+ for (qw( foo fooBar Foo_Bar FOOBAR 1Foo 1FOO ));
+
+is( $parser->cnick(qq|cnick $_|), $_, "cnick: $_" ) for (qw( Foo FF ));
+
+ok( !$parser->cnick(qq|cnick $_|), "Illegal cnick: $_" )
+ for (qw( foo fOO 1Foo ));
+
Propchange: lucene/lucy/trunk/boilerplater/t/600-parser.t
------------------------------------------------------------------------------
svn:eol-style = native