This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag PEVANS
in repository libparser-mgc-perl.

commit 9f7f4eeb3ee0503afe9c32650ee9f4b829fa455e
Author: Paul Evans <leon...@leonerd.org.uk>
Date:   Tue Jul 19 20:37:03 2011 +0000

    Import of PEVANS/Parser-MGC-0.09 from CPAN.
    
    gitpan-cpan-distribution: Parser-MGC
    gitpan-cpan-version:      0.09
    gitpan-cpan-path:         PEVANS/Parser-MGC-0.09.tar.gz
    gitpan-cpan-author:       PEVANS
    gitpan-cpan-maturity:     released
---
 Build.PL                                 |  1 +
 Changes                                  |  5 ++++
 LICENSE                                  | 22 +++++++++--------
 MANIFEST                                 |  8 +++---
 META.json                                | 42 ++++++++++++++++++++++++++++++++
 META.yml                                 |  9 +++----
 Makefile.PL                              |  2 +-
 README                                   | 13 ++++++++--
 lib/Parser/MGC.pm                        | 42 +++++++++++++++++++++++++++++---
 t/04where.t                              | 24 +++++++++++++-----
 t/12token_number.t                       | 37 ++++++++++++++++++++++++++++
 t/{12token_string.t => 13token_string.t} |  0
 t/{13token_ident.t => 14token_ident.t}   |  0
 t/{14token_kw.t => 15token_kw.t}         |  0
 14 files changed, 174 insertions(+), 31 deletions(-)

diff --git a/Build.PL b/Build.PL
index 37b3b3e..e8ef8db 100644
--- a/Build.PL
+++ b/Build.PL
@@ -12,6 +12,7 @@ my $build = Module::Build->new(
       'File::Temp' => 0,
       'Test::More' => 0,
    },
+   auto_configure_requires => 0, # Don't add M::B to configure_requires
    license => 'perl',
    create_makefile_pl => 'traditional',
    create_license => 1,
diff --git a/Changes b/Changes
index 028062a..4d45998 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
 Revision history for Parser-MGC
 
+0.09    CHANGES:
+         * Added ->pos accessor and ->fail_from to throw failures from other
+           locations
+         * Added ->token_number as a convenience for int or float
+
 0.08    CHANGES:
          * Give ->list_of and ->sequence_of proper failure-handling semantics
          * Added ->generic_token
diff --git a/LICENSE b/LICENSE
index c441828..254d384 100644
--- a/LICENSE
+++ b/LICENSE
@@ -18,15 +18,16 @@ This is free software, licensed under:
 
   The GNU General Public License, Version 1, February 1989
 
-                   GNU GENERAL PUBLIC LICENSE
-                    Version 1, February 1989
+                    GNU GENERAL PUBLIC LICENSE
+                     Version 1, February 1989
 
  Copyright (C) 1989 Free Software Foundation, Inc.
-                59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
+                    51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
-                           Preamble
+                            Preamble
 
   The license agreements of most software companies try to keep users
 at the mercy of those companies.  By contrast, our General Public
@@ -67,7 +68,7 @@ authors' reputations.
   The precise terms and conditions for copying, distribution and
 modification follow.
 
-                   GNU GENERAL PUBLIC LICENSE
+                    GNU GENERAL PUBLIC LICENSE
    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 
   0. This License Agreement applies to any program or other work which
@@ -185,7 +186,7 @@ make exceptions for this.  Our decision will be guided by 
the two goals
 of preserving the free status of all derivatives of our free software and
 of promoting the sharing and reuse of software generally.
 
-                           NO WARRANTY
+                            NO WARRANTY
 
   9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
@@ -207,9 +208,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE 
WITH ANY OTHER
 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGES.
 
-                    END OF TERMS AND CONDITIONS
+                     END OF TERMS AND CONDITIONS
 
-       Appendix: How to Apply These Terms to Your New Programs
+        Appendix: How to Apply These Terms to Your New Programs
 
   If you develop a new program, and you want it to be of the greatest
 possible use to humanity, the best way to achieve this is to make it
@@ -235,8 +236,9 @@ the exclusion of warranty; and each file should have at 
least the
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software Foundation,
-    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA  02110-1301 
USA
+
 
 Also add information on how to contact you by electronic and paper mail.
 
diff --git a/MANIFEST b/MANIFEST
index 680ae36..10cfb7e 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -9,6 +9,7 @@ lib/Parser/MGC.pm
 LICENSE
 Makefile.PL
 MANIFEST                       This list of files
+META.json
 META.yml
 README
 t/00use.t
@@ -21,9 +22,10 @@ t/06substring.t
 t/07generic_token.t
 t/10token_int.t
 t/11token_float.t
-t/12token_string.t
-t/13token_ident.t
-t/14token_kw.t
+t/12token_number.t
+t/13token_string.t
+t/14token_ident.t
+t/15token_kw.t
 t/20maybe.t
 t/21scope_of.t
 t/22list_of.t
diff --git a/META.json b/META.json
new file mode 100644
index 0000000..defc4a3
--- /dev/null
+++ b/META.json
@@ -0,0 +1,42 @@
+{
+   "abstract" : "build simple recursive-descent parsers",
+   "author" : [
+      "Paul Evans <leon...@leonerd.org.uk>"
+   ],
+   "dynamic_config" : 1,
+   "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 
2.110930",
+   "license" : [
+      "perl_5"
+   ],
+   "meta-spec" : {
+      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec";,
+      "version" : "2"
+   },
+   "name" : "Parser-MGC",
+   "prereqs" : {
+      "build" : {
+         "requires" : {
+            "File::Temp" : 0,
+            "Test::More" : 0
+         }
+      },
+      "runtime" : {
+         "requires" : {
+            "File::Slurp" : 0
+         }
+      }
+   },
+   "provides" : {
+      "Parser::MGC" : {
+         "file" : "lib/Parser/MGC.pm",
+         "version" : "0.09"
+      }
+   },
+   "release_status" : "stable",
+   "resources" : {
+      "license" : [
+         "http://dev.perl.org/licenses/";
+      ]
+   },
+   "version" : "0.09"
+}
diff --git a/META.yml b/META.yml
index ab5e98d..86e65a3 100644
--- a/META.yml
+++ b/META.yml
@@ -5,9 +5,8 @@ author:
 build_requires:
   File::Temp: 0
   Test::More: 0
-configure_requires:
-  Module::Build: 0.36
-generated_by: 'Module::Build version 0.3607'
+dynamic_config: 1
+generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 
2.110930'
 license: perl
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -16,9 +15,9 @@ name: Parser-MGC
 provides:
   Parser::MGC:
     file: lib/Parser/MGC.pm
-    version: 0.08
+    version: 0.09
 requires:
   File::Slurp: 0
 resources:
   license: http://dev.perl.org/licenses/
-version: 0.08
+version: 0.09
diff --git a/Makefile.PL b/Makefile.PL
index 50ff6cc..19524c4 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -1,4 +1,4 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.3607
+# Note: this file was auto-generated by Module::Build::Compat version 0.3800
 use ExtUtils::MakeMaker;
 WriteMakefile
 (
diff --git a/README b/README
index b293800..2ed87dd 100644
--- a/README
+++ b/README
@@ -117,15 +117,21 @@ METHODS
     invocations may split a single token across the buffer boundaries, and
     cause parse failures.
 
+  $pos = $parser->pos
+    Returns the current parse position, as a charcter offset from the
+    beginning of the file or string.
+
   ( $lineno, $col, $text ) = $parser->where
     Returns the current parse position, as a line and column number, and the
     entire current line of text. The first line is numbered 1, and the first
     column is numbered 0.
 
   $parser->fail( $message )
+  $parser->fail_from( $pos, $message )
     Aborts the current parse attempt with the given message string. The
-    failure message will include the current line and column position, and
-    the line of input that failed.
+    failure message will include the line and column position, and the line
+    of input that failed at the current parse position, or a position
+    earlier obtained using the "pos" method.
 
   $eos = $parser->at_eos
     Returns true if the input string is at the end of the string.
@@ -351,6 +357,9 @@ TOKEN PARSING METHODS
     decimal point, possibly followed by an exponent specified by "e"
     followed by an integer. The numerical value is then returned.
 
+  $number = $parser->token_number
+    Expects to find a number expressed in either of the above forms.
+
   $str = $parser->token_string
     Expects to find a quoted string, and consumes it. The string should be
     quoted using """ or "'" quote marks.
diff --git a/lib/Parser/MGC.pm b/lib/Parser/MGC.pm
index c9748ad..ea9ff2f 100644
--- a/lib/Parser/MGC.pm
+++ b/lib/Parser/MGC.pm
@@ -8,7 +8,7 @@ package Parser::MGC;
 use strict;
 use warnings;
 
-our $VERSION = '0.08';
+our $VERSION = '0.09';
 
 use Carp;
 
@@ -247,6 +247,19 @@ sub from_reader
    return $result;
 }
 
+=head2 $pos = $parser->pos
+
+Returns the current parse position, as a charcter offset from the beginning of
+the file or string.
+
+=cut
+
+sub pos
+{
+   my $self = shift;
+   return pos $self->{str};
+}
+
 =head2 ( $lineno, $col, $text ) = $parser->where
 
 Returns the current parse position, as a line and column number, and
@@ -281,9 +294,12 @@ sub where
 
 =head2 $parser->fail( $message )
 
+=head2 $parser->fail_from( $pos, $message )
+
 Aborts the current parse attempt with the given message string. The failure
-message will include the current line and column position, and the line of
-input that failed.
+message will include the line and column position, and the line of input that
+failed at the current parse position, or a position earlier obtained using the
+C<pos> method.
 
 =cut
 
@@ -291,8 +307,14 @@ sub fail
 {
    my $self = shift;
    my ( $message ) = @_;
+   $self->fail_from( $self->pos, $message );
+}
 
-   die Parser::MGC::Failure->new( $message, $self, pos($self->{str}) );
+sub fail_from
+{
+   my $self = shift;
+   my ( $pos, $message ) = @_;
+   die Parser::MGC::Failure->new( $message, $self, $pos );
 }
 
 =head2 $eos = $parser->at_eos
@@ -831,6 +853,18 @@ sub token_float
    );
 }
 
+=head2 $number = $parser->token_number
+
+Expects to find a number expressed in either of the above forms.
+
+=cut
+
+sub token_number
+{
+   my $self = shift;
+   $self->any_of( \&token_float, \&token_int );
+}
+
 =head2 $str = $parser->token_string
 
 Expects to find a quoted string, and consumes it. The string should be quoted
diff --git a/t/04where.t b/t/04where.t
index a955bd2..1dec1fd 100644
--- a/t/04where.t
+++ b/t/04where.t
@@ -2,9 +2,10 @@
 
 use strict;
 
-use Test::More tests => 6;
+use Test::More tests => 12;
 
 my @positions;
+my @wheres;
 
 package TestParser;
 use base qw( Parser::MGC );
@@ -13,18 +14,27 @@ sub parse
 {
    my $self = shift;
 
-   main::is_deeply( [ $self->where ],
+   main::is( $self->pos,
       $positions[0],
+      '->pos before parsing' );
+   main::is_deeply( [ $self->where ],
+      $wheres[0],
       '->where before parsing' );
 
    $self->expect( "hello" );
-   main::is_deeply( [ $self->where ],
+   main::is( $self->pos,
       $positions[1],
+      '->pos during parsing' );
+   main::is_deeply( [ $self->where ],
+      $wheres[1],
       '->where during parsing' );
 
    $self->expect( qr/world/ );
-   main::is_deeply( [ $self->where ],
+   main::is( $self->pos,
       $positions[2],
+      '->pos after parsing' );
+   main::is_deeply( [ $self->where ],
+      $wheres[2],
       '->where after parsing' );
 
    return 1;
@@ -34,13 +44,15 @@ package main;
 
 my $parser = TestParser->new;
 
-@positions = (
+@positions = ( 0, 5, 11 );
+@wheres = (
    [ 1, 0, "hello world" ],
    [ 1, 5, "hello world" ],
    [ 1, 11, "hello world" ], );
 $parser->from_string( "hello world" );
 
-@positions = (
+@positions = ( 0, 5, 11 );
+@wheres = (
    [ 1, 0, "hello" ],
    [ 1, 5, "hello" ],
    [ 2, 5, "world" ], );
diff --git a/t/12token_number.t b/t/12token_number.t
new file mode 100644
index 0000000..0b150b1
--- /dev/null
+++ b/t/12token_number.t
@@ -0,0 +1,37 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 7;
+
+package TestParser;
+use base qw( Parser::MGC );
+
+sub parse
+{
+   my $self = shift;
+
+   return $self->token_number;
+}
+
+package main;
+
+my $parser = TestParser->new;
+
+# We're going to be testing floating point values.
+sub approx
+{
+   my ( $got, $exp, $name ) = @_;
+
+   ok( abs( $got - $exp ) < 1E-12, $name ) or
+      diag( "Expected approximately $exp, got $got" );
+}
+
+is( $parser->from_string( "123" ), 123, 'Decimal integer' );
+approx( $parser->from_string( "123.0" ), 123,    'Decimal integer' );
+approx( $parser->from_string( "0.0" ),     0,    'Zero' );
+approx( $parser->from_string( "12." ),    12,    'Trailing DP' );
+approx( $parser->from_string( ".34" ),     0.34, 'Leading DP' );
+approx( $parser->from_string( "8.9" ),     8.9,  'Infix DP' );
+
+ok( !eval { $parser->from_string( "hello" ) }, '"hello" fails' );
diff --git a/t/12token_string.t b/t/13token_string.t
similarity index 100%
rename from t/12token_string.t
rename to t/13token_string.t
diff --git a/t/13token_ident.t b/t/14token_ident.t
similarity index 100%
rename from t/13token_ident.t
rename to t/14token_ident.t
diff --git a/t/14token_kw.t b/t/15token_kw.t
similarity index 100%
rename from t/14token_kw.t
rename to t/15token_kw.t

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-perl/packages/libparser-mgc-perl.git

_______________________________________________
Pkg-perl-cvs-commits mailing list
Pkg-perl-cvs-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits

Reply via email to