File Coverage

blib/lib/MarpaX/Demo/SampleScripts.pm
Criterion Covered Total %
statement 47 49 95.9
branch n/a
condition n/a
subroutine 16 17 94.1
pod 1 1 100.0
total 64 67 95.5


line stmt bran cond sub pod time code
1             package MarpaX::Demo::SampleScripts;
2              
3 1     1   548 use 5.010;
  1         2  
4 1     1   2410 use diagnostics;
  1         214099  
  1         11  
5 1     1   370 use strict;
  1         7  
  1         26  
6 1     1   998 use utf8;
  1         10  
  1         5  
7 1     1   26 use warnings;
  1         1  
  1         38  
8 1     1   5 use warnings qw(FATAL utf8); # Fatalize encoding glitches.
  1         1  
  1         43  
9 1     1   714 use open qw(:std :utf8); # Undeclared streams in UTF-8.
  1         1117  
  1         5  
10 1     1   14397 use charnames qw(:full :short); # Unneeded in v5.16.
  1         77642  
  1         9  
11              
12 1     1   1609 use Data::Dumper;
  1         23341  
  1         76  
13 1     1   732 use Data::Section;
  1         27429  
  1         7  
14              
15 1     1   917 use Marpa::R2;
  1         131542  
  1         60  
16 1     1   1231 use Marpa::R2::HTML;
  1         23204  
  1         51  
17              
18 1     1   842 use Moo;
  1         12781  
  1         6  
19              
20 1     1   2418 use POSIX;
  1         6439  
  1         7  
21              
22 1     1   3970 use Try::Tiny;
  1         2266  
  1         51  
23              
24 1     1   851 use Types::Standard qw/Any ArrayRef HashRef Int Str/;
  1         77331  
  1         11  
25              
26             our $VERSION = '1.04';
27              
28             # ------------------------------------------------
29              
30             sub run
31             {
32 0     0 1   my($self) = @_;
33              
34             # Return 0 for success and 1 for failure.
35              
36 0           return 0;
37              
38             } # End of run.
39              
40             # ------------------------------------------------
41              
42             1;
43              
44             =pod
45              
46             =head1 NAME
47              
48             C - A collection of scripts using Marpa::R2
49              
50             =head1 Synopsis
51              
52             See scripts/*.pl.
53              
54             =head1 Description
55              
56             C demonstrates various grammars and various ways to write and test
57             scripts.
58              
59             The whole point of this module is in scripts/*.pl.
60              
61             =head1 Installation
62              
63             Install C as you would for any C module:
64              
65             Run:
66              
67             cpanm MarpaX::Demo::SampleScripts
68              
69             or run:
70              
71             sudo cpan MarpaX::Demo::SampleScripts
72              
73             or unpack the distro, and then either:
74              
75             perl Build.PL
76             ./Build
77             ./Build test
78             sudo ./Build install
79              
80             or:
81              
82             perl Makefile.PL
83             make (or dmake or nmake)
84             make test
85             make install
86              
87             =head1 Constructor and Initialization
88              
89             C is called as C<< my($parser) = MarpaX::Demo::SampleScripts -> new(k1 => v1, k2 => v2, ...) >>.
90              
91             It returns a new object of type C.
92              
93             Key-value pairs accepted in the parameter list:
94              
95             =over 4
96              
97             (None).
98              
99             =back
100              
101             =head1 Methods
102              
103             =head2 run()
104              
105             This method does nothing, and return 0 for success.
106              
107             =head1 Files Shipped with this Module
108              
109             Many of these scripts are gists, i.e. from https://gist.github.com/. You can always go there are
110             search for some I text within the script, to see if there are other versions, or commentary
111             available.
112              
113             =head2 Runnable Scripts
114              
115             All these scripts are in the scripts/ directory.
116              
117             =over 4
118              
119             =item o ambiguous.grammar.03.pl
120              
121             A grammar for the
122             L language.
123              
124             =item o grammar.inspector.01.pl
125              
126             Display Marpa's view of the structure of a grammar.
127              
128             =item o html.02.pl
129              
130             Process defective HTML.
131              
132             =item o match.parentheses.01.pl
133              
134             Match nested parantheses, i.e. the '(' and ')' pair.
135              
136             =item o match.parentheses.02.pl
137              
138             This sophisticated example checks files for matching brackets: (){}[].
139              
140             Or, it can be run (self-tested) with the '--test' option'.
141              
142             The new rejection events are used, along with the Ruby Slippers, meaning it requires L
143             V 2.098000.
144              
145             This program uses the method of adding known tokens (my $suffix = '(){}[]';) to the end of the input
146             string so Marpa can be told to search just that part of the string when the logic dictates that a
147             Ruby Slippers token (bracket) is to be passed to Marpa to satisfy the grammar. It's put at the end
148             so that it does not interfere with line and column counts in the original input string.
149              
150             =item o parmaterized.grammar.01.pl
151              
152             Handle parts of the grammar as strings, and interpolate various things into those strings, before
153             using them to build the final grammar.
154              
155             =item o quoted.strings.01.pl
156              
157             =over 4
158              
159             =item o Handle events
160              
161             =item o Handle utf8 input
162              
163             =item o Handle doublequoted strings
164              
165             =item o Handle single-quoted strings
166              
167             =back
168              
169             =item o quoted.strings.02.pl
170              
171             Handle nested, double-quoted, strings.
172              
173             =item o quoted.strings.03.pl
174              
175             Handle strings quoted with various characters, and with escaped characters in there too.
176              
177             =item o quoted.strings.04.pl
178              
179             Uses a grammar with pauses to handle various types of quoted strings, with manual scanning.
180              
181             See quoted.strings.05.pl for getting Marpa to handling the scanning of HTML.
182              
183             =item o quoted.strings.05.pl
184              
185             Handles HTML.
186              
187             =over 4
188              
189             =item o Handle strings containing escaped characters
190              
191             =item o Handle events
192              
193             =item o Handle unquoted strings
194              
195             =item o Handle doublequoted strings
196              
197             =item o Handle single-quoted strings
198              
199             =back
200              
201             =item o use.utf8.01.pl
202              
203             =over 4
204              
205             =item o Handle events
206              
207             =item o Handle utf8 input
208              
209             =item o Handle unquoted strings
210              
211             =item o Handle doublequoted strings
212              
213             =item o Handle single-quoted strings
214              
215             =back
216              
217             =back
218              
219             =head2 Un-runnable Scripts
220              
221             All these scripts are in the examples/ directory.
222              
223             =over 4
224              
225             =item o action.parse.pl
226              
227             Show how, during an action sub, another parse can be done using the output of the parse which
228             triggered the action. The inner parse uses the same grammar as the outer parse.
229              
230             =item o ambiguous.grammar.01.pl
231              
232             Contains both ambiguous and un-ambiguous grammars.
233              
234             Uses MarpaX::ASF::PFG, which is not on MetaCPAN.
235              
236             =item o heredoc.pl
237              
238             Parse multiple heredocs.
239              
240             =item o html.01.pl
241              
242             Processes HTML.
243              
244             Uses L, which won't install without patches, and which the author apparently
245             refuses to fix.
246              
247             =item o match.keywords.pl
248              
249              
250             =back
251              
252             =head1 FAQ
253              
254             =head2 Do any scripts handle HTML?
255              
256             Yes. See scripts/quoted.strings.05.pl.
257              
258             =head1 Machine-Readable Change Log
259              
260             The file Changes was converted into Changelog.ini by L.
261              
262             =head1 Version Numbers
263              
264             Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
265              
266             =head1 Support
267              
268             Email the author, or log a bug on RT:
269              
270             L.
271              
272             =head1 Author
273              
274             L was written by Ron Savage Iron@savage.net.auE> in 2014.
275              
276             Marpa's homepage: .
277              
278             My homepage: L.
279              
280             =head1 Copyright
281              
282             Australian copyright (c) 2014, Ron Savage.
283              
284             All Programs of mine are 'OSI Certified Open Source Software';
285             you can redistribute them and/or modify them under the terms of
286             The Artistic License 2.0, a copy of which is available at:
287             http://www.opensource.org/licenses/index.html
288              
289             =cut