Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added an example

* Parse numbers and whitespace
  • Loading branch information...
commit f1c697b54922ac836e5f717081069b6ee7ffaa8d 1 parent b4ddc12
@pstuifzand authored
Showing with 26 additions and 0 deletions.
  1. +25 −0 examples/ex1.pl
  2. +1 −0  examples/ex1.txt
View
25 examples/ex1.pl
@@ -0,0 +1,25 @@
+use strict;
+use 5.14.1;
+
+use Data::Dumper;
+use IO::String;
+
+use MarpaX::Parser::Loader 'load_parser';
+
+my $grammar_fh = IO::String->new(<<'INPUT');
+NUMBER = /(\d+)/
+SPACE = /[ \t\r\n]/
+
+Parser ::= Numbers+ {{ shift; return \@_; }}
+Numbers ::= NUMBER WS {{ shift; return $_[0]; }}
+WS ::= SPACE+
+WS ::= Null
+INPUT
+
+$grammar_fh->setpos(0);
+
+my $parser = load_parser($grammar_fh);
+
+open my $fh, '<', 'examples/ex1.txt' or die "Can't open file";
+print Dumper($parser->parse($fh));
+
View
1  examples/ex1.txt
@@ -0,0 +1 @@
+100 4 59 2 0 9 9 999 9
Please sign in to comment.
Something went wrong with that request. Please try again.