| 1 | package MarpaX::Demo::SampleScripts; | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use diagnostics; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use utf8; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use warnings qw(FATAL utf8); # Fatalize encoding glitches. |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 1 | ▶ | use open qw(:std :utf8); # Undeclared streams in UTF-8. |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use charnames qw(:full :short); # Unneeded in v5.16. |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 1 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use Data::Section; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 1 | ▶ | use Marpa::R2; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 1 | ▶ | use Marpa::R2::HTML; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 19 | |||
| 20 | 1 | ▶ | use POSIX; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | |||
| 22 | 1 | ▶ | use Try::Tiny; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | |||
| 24 | 1 | ▶ | use Types::Standard qw/Any ArrayRef HashRef Int Str/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | |||
| 26 | 1 | our $VERSION = '1.04'; | |
| 27 | |||
| 28 | # ------------------------------------------------ | ||
| 29 | |||
| 30 | sub run | ||
| 31 | 0 | ▶ | { |
|
Subroutine
run: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 32 | 0 | 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 | 1; | |
| 43 | |||
| 44 | =pod | ||
| 45 | |||
| 46 | =head1 NAME | ||
| 47 | |||
| 48 | C<MarpaX::Demo::SampleScripts> - A collection of scripts using Marpa::R2 | ||
| 49 | |||
| 50 | =head1 Synopsis | ||
| 51 | |||
| 52 | See scripts/*.pl. | ||
| 53 | |||
| 54 | =head1 Description | ||
| 55 | |||
| 56 | C<MarpaX::Demo::SampleScripts> 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<MarpaX::Demo::SampleScripts> as you would for any C<Perl> 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<new()> is called as C<< my($parser) = MarpaX::Demo::SampleScripts -> new(k1 => v1, k2 => v2, ...) >>. | ||
| 90 | |||
| 91 | It returns a new object of type C<MarpaX::Demo::SampleScripts>. | ||
| 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<unique> 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<Velocity|http://velocity.apache.org/engine/releases/velocity-1.4/specification-bnf.html> 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<Marpa::R2> | ||
| 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<HTML::WikiConverter>, 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<Module::Metadata::Changes>. | ||
| 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<https://rt.cpan.org/Public/Dist/Display.html?Name=MarpaX::Demo::SampleScripts>. | ||
| 271 | |||
| 272 | =head1 Author | ||
| 273 | |||
| 274 | L<MarpaX::Demo::SampleScripts> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2014. | ||
| 275 | |||
| 276 | Marpa's homepage: <http://savage.net.au/Marpa.html>. | ||
| 277 | |||
| 278 | My homepage: L<http://savage.net.au/>. | ||
| 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 | ||