Pegex-0.64000755000766000024 013157627333 11760 5ustar00ingystaff000000000000README100644000766000024 737013157627333 12730 0ustar00ingystaff000000000000Pegex-0.64NAME Pegex - Acmeist PEG Parser Framework VERSION This document describes Pegex version 0.64. SYNOPSIS use Pegex; my $result = pegex($grammar)->parse($input); or with options: use Pegex; use ReceiverClass; my $parser = pegex($grammar, 'ReceiverClass'); my $result = $parser->parse($input); or more explicitly: use Pegex::Parser; use Pegex::Grammar; my $pegex_grammar = Pegex::Grammar->new( text => $grammar, ); my $parser = Pegex::Parser->new( grammar => $pegex_grammar, ); my $result = $parser->parse($input); or customized explicitly: { package MyGrammar; use Pegex::Base; extends 'Pegex::Grammar'; has text => "your grammar definition text goes here"; has receiver => "MyReceiver"; } { package MyReceiver; use base 'Pegex::Receiver'; got_some_rule { ... } got_other_rule { ... } } use Pegex::Parser; my $parser = Pegex::Parser->new( grammar => MyGrammar->new, receiver => MyReceiver->new, ); $parser->parse($input); my $result = $parser->receiver->data; DESCRIPTION Pegex is an Acmeist parser framework. It allows you to easily create parsers that will work equivalently in lots of programming languages! The inspiration for Pegex comes from the parsing engine upon which the postmodern programming language Perl 6 is based on. Pegex brings this beauty to the other justmodern languages that have a normal regular expression engine available. Pegex gets it name by combining Parsing Expression Grammars (PEG), with Regular Expessions (Regex). That's actually what Pegex does. PEG is the cool new way to elegantly specify recursive descent grammars. The Perl 6 language is defined in terms of a self modifying PEG language called Perl 6 Rules. Regexes are familiar to programmers of most modern programming languages. Pegex defines a simple PEG syntax, where all the terminals are regexes. This means that Pegex can be quite fast and powerful. Pegex attempts to be the simplest way to define new (or old) Domain Specific Languages (DSLs) that need to be used in several programming languages and environments. Things like JSON, YAML, Markdown etc. It also great for writing parsers/compilers that only need to work in one language. USAGE The Pegex.pm module itself (this module) is just a trivial way to use the Pegex framework. It is only intended for the simplest of uses. This module exports a single function, pegex, which takes a Pegex grammar string as input. You may also pass a receiver class name after the grammar. my $parser = pegex($grammar, 'MyReceiver'); The pegex function returns a Pegex::Parser object, on which you would typically call the parse() method, which (on success) will return a data structure of the parsed data. See Pegex::API for more details. PEGEX DEBUGGING Pegex (Pegex::Parser) has many easy to use methods of debugging. See the "Debugging" section of Pegex::Parser for details. SEE ALSO * Pegex::Overview * Pegex::API * Pegex::Syntax * Pegex::Tutorial * Pegex::Resources * Pegex::Parser * http://github.com/ingydotnet/pegex-pm * irc://freenode.net#pegex AUTHOR Ingy döt Net COPYRIGHT AND LICENSE Copyright 2010-2017. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See http://www.perl.com/perl/misc/Artistic.html Changes100644000766000024 1261213157627333 13356 0ustar00ingystaff000000000000Pegex-0.640.64 Sun Sep 17 19:26:03 PDT 2017 - Applied 3 small PRs from @mohawk2++ (60,61,62) 0.63 Sat Jan 14 09:31:43 PST 2017 - Fixed colors on older perls. TINITA++ - Changed on/off to always/never. TINITA++ 0.62 Fri Jan 13 22:37:55 PST 2017 - Debug color and indent options added by TINITA++ - Recursion controls. Apply PR/46 by @pdl++ (refactored) - Support Perl regex look-behind assertions 0.61 Mon Jun 13 18:10:24 PDT 2016 - Performance improvements by @agentzh++ - See PR/52 0.60 Wed Jan 28 10:44:38 PST 2015 - Added EMPTY atom - Fix small bug in a helper function. Issue - Update docs and Meta for 2015 0.59 Sun Dec 28 14:25:13 PST 2014 - Release with new TestML-0.52 0.58 Fri Dec 12 11:10:16 PST 2014 - Fix test for windows (issue - Share Pegex grammar for Pegex 0.57 Mon Oct 6 14:30:28 CEST 2014 - Added 'rule' helper method to Pegex::Receiver - Refactored the calculator examples to be dry 0.56 Fri Oct 3 22:55:58 CEST 2014 - Upgrade Mo to 0.39 - Fix problems with % - Fix whitespace matching at start of regex 0.55 Sun Aug 24 10:03:26 PDT 2014 - Doc tweak 0.54 Sat Aug 16 14:14:34 PDT 2014 - Remove =travis section 0.53 Sat Aug 16 11:55:44 PDT 2014 - Meta 0.0.2 0.52 Sat Aug 16 02:33:53 PDT 2014 - Eliminate File::Basename from test/ 0.51 Fri Aug 15 20:26:26 PDT 2014 - Remove Pegex::Mo - Add t/000-compile-modules.t 0.50 Fri Aug 15 09:30:56 PDT 2014 - Fixed a Mo bug directly - Added regression test - Mo still needs fix - See https://github.com/ingydotnet/jsony-pm/issues/2 0.49 Tue Aug 12 11:01:28 PDT 2014 - Add `receiver` accessor back into parser - Other modules use it - Add test for it 0.48 Sun Aug 10 18:18:35 PDT 2014 - Refactor Pegex.pm to match CafeScript 0.47 Sat Aug 9 12:00:13 PDT 2014 - Refactor to match CafeScript - https://github.com/ingydotnet/pegex-cafe 0.46 Fri Aug 8 19:29:32 PDT 2014 - Fix swim errors 0.45 Mon Aug 4 00:17:27 PDT 2014 - Remove (c) from Copyright - Doc fixes 0.44 Tue Jul 29 16:35:34 PDT 2014 - Some Parser refactoring. - Add a new example parser called `self-parser.pl` - Get the devel tests working again 0.43 Wed Jul 23 14:21:29 PDT 2014 - Add inlining support for text to Pegex::Grammar - Add a line_column method to Pegex::Parser 0.42 Mon Jul 21 17:25:50 PDT 2014 - Fix copyright year stuff 0.41 Thu Jul 17 10:28:16 PDT 2014 - ZD put an incorrect dep on TestML. @rurban++ 0.40 Mon Jul 14 09:56:50 PDT 2014 - Fix Meta and add Contributing file 0.39 Tue Jul 1 10:05:51 PDT 2014 - Support a maxparse debugging option 0.38 Sun Jun 29 16:02:50 PDT 2014 - Fix issue#12. Make trace work on outermost rule. 0.37 Sat Jun 28 09:52:45 PDT 2014 - More doc change for Pegex::Module. ggl++ 0.36 Sat Jun 28 09:45:54 PDT 2014 - Doc change for Pegex::Module. ggl++ 0.35 Fri Jun 27 20:55:38 PDT 2014 - Kwim to Swim 0.34 Mon Jun 23 16:02:08 PDT 2014 - Fix for issue#13 0.33 Mon Jun 16 13:45:07 PDT 2014 - Change VERSION dist strategy. 0.32 Sat Jun 14 12:26:36 PDT 2014 - New badge syntax 0.31 Sat May 17 23:43:00 PDT 2014 - Add doc badges. - Switch to Zilla::Dist - Fix a bug in Pegex::Parser 0.30 Sat May 17 23:43:00 PDT 2014 - Major release. - New cleaner syntax. - Slight breakage of backwards compatability. - Grammar authors can get help on 0.25 Sat Feb 8 14:14:59 PST 2014 - Support 5.8.1+ 0.24 Thu Feb 6 22:56:23 PST 2014 - tweak some dzil settings 0.23 Thu Feb 6 17:16:39 PST 2014 - https://rt.cpan.org/Ticket/Display.html?id=82587 - Doc and example fixes - Add 2014 to all copyrights 0.22 Wed Feb 5 11:26:05 PST 2014 - Release under dzil (thanks frew++!!) - travis testing (frew++) 0.21 Thu Nov 8 10:47:42 PST 2012 - A massive refactoring release. - 8-10 times faster parsing speed! - Support a b | c precedence in Pegex grammars. - Complete documenatation. - Examples and Tutorials - New receivers, Pegex::Tree and Pegex::Tree::Wrap - API becomes more solidified. 0.20 Thu Aug 30 00:06:30 PDT 2012 - Refactored Pegex to make API less flexible but more sensible, explainable and maintainable. 0.19 Sat Nov 5 01:16:15 PDT 2011 - Fixed Test::Differences missing. 0.18 Fri Sep 30 00:44:35 CEST 2011 - Use Mo 0.25 - Support advanced quantifiers and %/%% - Rename classes - Make AST class use unwrap events and be much simpler. 0.17 Wed Sep 21 23:42:00 CEST 2011 - Complete refactoring of everything. - This hard fought gem was released from Liz++ and Wendy++'s TV room. 0.16 Fri Sep 9 14:51:38 CEST 2011 - Changed AST model to be faster and simpler. 0.15 Wed Sep 7 10:17:11 BST 2011 - With this release of Pegex, I do declare the true birthday of Acmeism. THis release was performed from the living room of Leon "Acme" Brocard. How fitting. His daughter Lara was present to witness her first ever CPAN release. 0.14 Sat Aug 20 18:19:20 CEST 2011 - Fix TestML dep with new version of Module::Package 0.13 Fri Aug 19 20:51:18 EEST 2011 - Use updated version of TestML with updated version of Pegex! - Switch Mouse back to Gloom 0.12 Sun Aug 14 17:27:13 EEST 2011 - Switch OO to Mouse 0.11 Fri Sep 10 10:41:30 PDT 2010 - Add manifest_skip and readme_from to Makefile.PL 0.10 Thu Sep 9 10:41:30 PDT 2010 - Changes supporting TestML 0.20 0.05 Sat Aug 14 17:11:17 PDT 2010 - Add REPOSITORY and COMMUNITY info to doc. 0.04 Sat Aug 14 17:11:17 PDT 2010 - Use new Gloom for base OO. 0.02 Tue Aug 10 01:15:58 PDT 2010 - Changed name from Parse::Pegex to Pegex. 0.01 Tue Aug 3 02:42:29 PDT 2010 - Initial version. t000755000766000024 013157627333 12144 5ustar00ingystaff000000000000Pegex-0.64api.t100644000766000024 77613157627333 13234 0ustar00ingystaff000000000000Pegex-0.64/tuse Test::More; use Pegex::Parser; use Pegex::Grammar; use Pegex::Receiver; use Pegex::Input; my $p = Pegex::Parser->new( grammar => Pegex::Grammar->new, receiver => Pegex::Receiver->new, input => Pegex::Input->new, debug => 1, ); ok $p->grammar, 'grammar accessor works'; ok $p->receiver, 'receiver accessor works'; ok $p->input, 'input accessor works'; ok $p->debug, 'debug accessor works'; eval { Pegex::Parser->new }; ok $@ =~ /grammar required/, 'grammar is required'; done_testing; LICENSE100644000766000024 4366013157627333 13077 0ustar00ingystaff000000000000Pegex-0.64This software is copyright (c) 2017 by Ingy döt Net. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2017 by Ingy döt Net. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 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 The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes 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 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 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 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 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 free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2017 by Ingy döt Net. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End safe.t100644000766000024 53013157627333 13365 0ustar00ingystaff000000000000Pegex-0.64/tuse Test::More; # 2015-02-03 Safe.pm fails to load on Travis + 5.14 BEGIN { if ($ENV{TRAVIS} eq 'true' and $ENV{TRAVIS_PERL_VERSION} eq '5.14') { plan skip_all => 'Travis/Safe/5.14'; } } use Safe; BEGIN { Safe->new } use Pegex; pegex('a: /a/')->parse('a'); pass 'GitHub ingydotnet/jsony-pm issue #2 fixed'; done_testing; MANIFEST100644000766000024 505613157627333 13200 0ustar00ingystaff000000000000Pegex-0.64# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.043. CONTRIBUTING Changes LICENSE MANIFEST META.json META.yml Makefile.PL README example/calculator/calculator1.pl example/calculator/calculator2.pl example/calculator/lib/Precedence.pm example/calculator/lib/Runner.pm example/calculator/tests example/calculator/tokenizer.pl example/self-parser.pl inc/Pegex/Base.pm inc/Pegex/Grammar.pm inc/Pegex/Input.pm inc/Pegex/Optimizer.pm inc/Pegex/Parser.pm inc/Pegex/Receiver.pm inc/Pegex/Tree.pm inc/TestML.pm inc/TestML/Base.pm inc/TestML/Bridge.pm inc/TestML/Compiler.pm inc/TestML/Compiler/Lite.pm inc/TestML/Compiler/Pegex.pm inc/TestML/Compiler/Pegex/AST.pm inc/TestML/Compiler/Pegex/Grammar.pm inc/TestML/Library/Debug.pm inc/TestML/Library/Standard.pm inc/TestML/Runtime.pm inc/TestML/Runtime/TAP.pm inc/TestML/Util.pm inc/Text/Diff.pm lib/Pegex.pm lib/Pegex.pod lib/Pegex/API.pod lib/Pegex/Base.pm lib/Pegex/Bootstrap.pm lib/Pegex/Bootstrap.pod lib/Pegex/Compiler.pm lib/Pegex/Compiler.pod lib/Pegex/Grammar.pm lib/Pegex/Grammar.pod lib/Pegex/Grammar/Atoms.pm lib/Pegex/Grammar/Atoms.pod lib/Pegex/Input.pm lib/Pegex/Input.pod lib/Pegex/Miscellany.pod lib/Pegex/Module.pm lib/Pegex/Module.pod lib/Pegex/Optimizer.pm lib/Pegex/Overview.pod lib/Pegex/Parser.pm lib/Pegex/Parser.pod lib/Pegex/Parser/Indent.pm lib/Pegex/Pegex/AST.pm lib/Pegex/Pegex/Grammar.pm lib/Pegex/Pegex/Grammar.pod lib/Pegex/Receiver.pm lib/Pegex/Receiver.pod lib/Pegex/Regex.pm lib/Pegex/Regex.pod lib/Pegex/Resources.pod lib/Pegex/Syntax.pod lib/Pegex/Tree.pm lib/Pegex/Tree.pod lib/Pegex/Tree/Wrap.pm lib/Pegex/Tree/Wrap.pod lib/Pegex/Tutorial.pod lib/Pegex/Tutorial/Calculator.pod lib/Pegex/Tutorial/JSON.pod share/pegex.pgx t/000-compile-modules.t t/TestAST.pm t/TestMLBridge.pm t/api.t t/author-pod-syntax.t t/export-api.t t/flatten.t t/function-rule.t t/grammar-api.t t/look-behind.t t/mice.pgx t/parse.t t/repeat.t t/safe.t t/sample.t t/testml-compiler-checks.t t/testml-compiler-equivalence.t t/testml-compiler.t t/testml-error.t t/testml-optimize.t t/testml-tree-pegex.t t/testml-tree.t t/testml.yaml t/testml/compiler-checks.tml t/testml/compiler-equivalence.tml t/testml/compiler.tml t/testml/error.tml t/testml/optimize.tml t/testml/tree-pegex.tml t/testml/tree.tml xt/TestDevelPegex.pm xt/compilers.t xt/grammars/Pg.pgx xt/grammars/drinkup.pgx xt/grammars/eyapp2pegex.pgx xt/grammars/json.pgx xt/grammars/kwim.pgx xt/grammars/pegex.pgx xt/grammars/pg-lexer.pgx xt/grammars/swim.pgx xt/grammars/testml.pgx xt/grammars/vic.pgx xt/grammars/yaml.pgx xt/speed-ast.t xt/speed.t xt/test-pegex-repos.t META.yml100644000766000024 130013157627333 13304 0ustar00ingystaff000000000000Pegex-0.64--- abstract: 'Acmeist PEG Parser Framework' author: - 'Ingy döt Net ' build_requires: YAML::XS: '0' configure_requires: ExtUtils::MakeMaker: '0' File::ShareDir::Install: '0.06' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.150005' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Pegex no_index: directory: - example - inc - t - xt requires: perl: v5.10.0 resources: bugtracker: https://github.com/ingydotnet/pegex-pm/issues homepage: https://github.com/ingydotnet/pegex-pm repository: https://github.com/ingydotnet/pegex-pm.git version: '0.64' parse.t100644000766000024 43713157627333 13567 0ustar00ingystaff000000000000Pegex-0.64/t# $Pegex::Parser::Debug = 1; my $t; use lib ($t = -e 't' ? 't' : 'test'); use Test::More tests => 1; use Pegex; use Pegex::Input; $grammar_file = "$t/mice.pgx"; eval { pegex( Pegex::Input->new(file => $grammar_file) )->parse("3 blind mice\n") }; $@ ? fail $@ : pass "! works"; META.json100644000766000024 255213157627333 13466 0ustar00ingystaff000000000000Pegex-0.64{ "abstract" : "Acmeist PEG Parser Framework", "author" : [ "Ingy döt Net " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.043, CPAN::Meta::Converter version 2.150005", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Pegex", "no_index" : { "directory" : [ "example", "inc", "t", "xt" ] }, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0", "File::ShareDir::Install" : "0.06" } }, "develop" : { "requires" : { "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "perl" : "v5.10.0" } }, "test" : { "requires" : { "YAML::XS" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/ingydotnet/pegex-pm/issues" }, "homepage" : "https://github.com/ingydotnet/pegex-pm", "repository" : { "type" : "git", "url" : "https://github.com/ingydotnet/pegex-pm.git", "web" : "https://github.com/ingydotnet/pegex-pm" } }, "version" : "0.64" } mice.pgx100644000766000024 13413157627333 13717 0ustar00ingystaff000000000000Pegex-0.64/tphrase: !one number - things EOL one: /1/ number: DIGIT things: / 'blind' SPACE 'mice' / repeat.t100644000766000024 33613157627333 13733 0ustar00ingystaff000000000000Pegex-0.64/tuse Test::More; use Pegex; my $parser = pegex('a: /*?(x+)*/'); is $parser->parse('xxxx')->{a}, 'xxxx', 'First parse works'; is $parser->parse('xxxx')->{a}, 'xxxx', 'Second parse works'; done_testing; sample.t100644000766000024 230513157627333 13752 0ustar00ingystaff000000000000Pegex-0.64/tuse Test::More; eval "use YAML::XS; 1" or plan skip_all => 'YAML::XS required'; plan tests => 1; my $grammar_text = <<'...'; contact: name_section phone_section address_section name_section: / 'Name' + / name EOL name: /(+)(+)/ phone_section: /Phone+/ phone_number: term address_section: /Address/ street_line city_line country_line? street_line: indent street EOL street: /*/ city_line: indent city EOL city: term country_line: indent country EOL country: term term: /( # NS is "non-space" * )/ indent: /{2}/ ... my $input = <<'...'; Name: Ingy Net Phone: 919-876-5432 Address: 1234 Main St Niceville OK ... my $want = <<'...'; ... use Pegex::Grammar; use Pegex::Receiver; use Pegex::Compiler; my $grammar = Pegex::Grammar->new( tree => Pegex::Compiler->new->compile($grammar_text)->tree, ); my $parser = Pegex::Parser->new( grammar => $grammar, receiver => Pegex::Receiver->new, debug => 1, ); my $ast1 = $parser->parse($input); pass 'parsed'; exit; my $got = YAML::XS::Dump($ast1); is $got, $want, 'It works'; xt000755000766000024 013157627333 12334 5ustar00ingystaff000000000000Pegex-0.64speed.t100644000766000024 71413157627333 13743 0ustar00ingystaff000000000000Pegex-0.64/xtuse strict; use warnings; use Test::More; use lib -e 'xt' ? 'xt' : 'test/devel'; use TestDevelPegex; for my $grammar (test_grammar_paths) { my $parser = pegex_parser; my $input = slurp($grammar); my $timer = [gettimeofday]; my $result = eval { $parser->parse($input) }; my $time = tv_interval($timer); if ($result) { pass "$grammar parses in $time seconds"; } else { fail "$grammar failed to parse $@"; } } flatten.t100644000766000024 100013157627333 14115 0ustar00ingystaff000000000000Pegex-0.64/tuse Test::More tests => 1; use Pegex; my $grammar = <<'...'; a: (((b)))+ b: (c | d) c: /(x)/ d: /y/ ... { package R; use base 'Pegex::Receiver'; sub got_a { my ($self, $got) = @_; $self->flatten($got); $got; } sub got_b { my ($self, $got) = @_; [$got]; } sub got_c { my ($self, $got) = @_; [$got]; } } my $parser = pegex($grammar, 'R'); my $got = $parser->parse('xxx'); is join('', @$got), 'xxx', 'Array was flattened'; Makefile.PL100644000766000024 231513157627333 14014 0ustar00ingystaff000000000000Pegex-0.64# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v5.043. use strict; use warnings; use 5.010000; use ExtUtils::MakeMaker; use File::ShareDir::Install; $File::ShareDir::Install::INCLUDE_DOTFILES = 1; $File::ShareDir::Install::INCLUDE_DOTDIRS = 1; install_share dist => "share"; my %WriteMakefileArgs = ( "ABSTRACT" => "Acmeist PEG Parser Framework", "AUTHOR" => "Ingy d\x{f6}t Net ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::ShareDir::Install" => "0.06" }, "DISTNAME" => "Pegex", "LICENSE" => "perl", "MIN_PERL_VERSION" => "5.010000", "NAME" => "Pegex", "PREREQ_PM" => {}, "TEST_REQUIRES" => { "YAML::XS" => 0 }, "VERSION" => "0.64", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "YAML::XS" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); { package MY; use File::ShareDir::Install qw(postamble); } CONTRIBUTING100644000766000024 234213157627333 13674 0ustar00ingystaff000000000000Pegex-0.64Contributing ============ The "Pegex" Project needs your help! Please consider being a contributor. This file contains instructions that will help you be an effective contributor to the Project. GitHub ------ The code for this Project is hosted at GitHub. The URL is: https://github.com/ingydotnet/pegex-pm You can get the code with this command: git clone https://github.com/ingydotnet/pegex-pm If you've found a bug or a missing feature that you would like the author to know about, report it here: https://github.com/ingydotnet/pegex-pm/issues or fix it and submit a pull request here: https://github.com/ingydotnet/pegex-pm/pulls See these links for help on interacting with GitHub: * https://help.github.com/ * https://help.github.com/articles/creating-a-pull-request Zilla::Dist ----------- This Project uses Zilla::Dist to prepare it for publishing to CPAN. Read: https://metacpan.org/pod/Zilla::Dist::Contributing for up-to-date instructions on what contributors like yourself need to know to use it. IRC --- Pegex has an IRC channel where you can find real people to help you: irc.freenode.net#pegex Join the channel. Join the team! Thanks in advance, # This file generated by Zilla-Dist-0.0.195 lib000755000766000024 013157627333 12447 5ustar00ingystaff000000000000Pegex-0.64Pegex.pm100644000766000024 136013157627333 14215 0ustar00ingystaff000000000000Pegex-0.64/libuse strict; use warnings; package Pegex; our $VERSION = '0.64'; use Pegex::Parser; use Exporter 'import'; our @EXPORT = 'pegex'; sub pegex { my ($grammar, $receiver) = @_; die "Argument 'grammar' required in function 'pegex'" unless $grammar; if (not ref $grammar or $grammar->isa('Pegex::Input')) { require Pegex::Grammar; $grammar = Pegex::Grammar->new(text => $grammar), } if (not defined $receiver) { require Pegex::Tree::Wrap; $receiver = Pegex::Tree::Wrap->new; } elsif (not ref $receiver) { eval "require $receiver; 1"; $receiver = $receiver->new; } return Pegex::Parser->new( grammar => $grammar, receiver => $receiver, ); } 1; TestAST.pm100644000766000024 22513157627333 14110 0ustar00ingystaff000000000000Pegex-0.64/tpackage TestAST; use Pegex::Base; extends 'Pegex::Tree'; sub got_zero { return 0 }; sub got_empty { return '' }; sub got_undef { return undef } 1; Pegex.pod100644000766000024 734213157627333 14371 0ustar00ingystaff000000000000Pegex-0.64/lib=pod =for comment DO NOT EDIT. This Pod was generated by Swim v0.1.45. See http://github.com/ingydotnet/swim-pm#readme =encoding utf8 =head1 NAME Pegex - Acmeist PEG Parser Framework =head1 VERSION This document describes L version B<0.64>. =head1 SYNOPSIS use Pegex; my $result = pegex($grammar)->parse($input); or with options: use Pegex; use ReceiverClass; my $parser = pegex($grammar, 'ReceiverClass'); my $result = $parser->parse($input); or more explicitly: use Pegex::Parser; use Pegex::Grammar; my $pegex_grammar = Pegex::Grammar->new( text => $grammar, ); my $parser = Pegex::Parser->new( grammar => $pegex_grammar, ); my $result = $parser->parse($input); or customized explicitly: { package MyGrammar; use Pegex::Base; extends 'Pegex::Grammar'; has text => "your grammar definition text goes here"; has receiver => "MyReceiver"; } { package MyReceiver; use base 'Pegex::Receiver'; got_some_rule { ... } got_other_rule { ... } } use Pegex::Parser; my $parser = Pegex::Parser->new( grammar => MyGrammar->new, receiver => MyReceiver->new, ); $parser->parse($input); my $result = $parser->receiver->data; =head1 DESCRIPTION Pegex is an Acmeist parser framework. It allows you to easily create parsers that will work equivalently in lots of programming languages! The inspiration for Pegex comes from the parsing engine upon which the postmodern programming language B is based on. Pegex brings this beauty to the other Imodern languages that have a normal regular expression engine available. Pegex gets it name by combining Parsing Expression Grammars (PEG), with Regular Expessions (Regex). That's actually what Pegex does. PEG is the cool new way to elegantly specify recursive descent grammars. The Perl 6 language is defined in terms of a self modifying PEG language called B. Regexes are familiar to programmers of most modern programming languages. Pegex defines a simple PEG syntax, where all the terminals are regexes. This means that Pegex can be quite fast and powerful. Pegex attempts to be the simplest way to define new (or old) Domain Specific Languages (DSLs) that need to be used in several programming languages and environments. Things like JSON, YAML, Markdown etc. It also great for writing parsers/compilers that only need to work in one language. =head1 USAGE The C module itself (this module) is just a trivial way to use the Pegex framework. It is only intended for the simplest of uses. This module exports a single function, C, which takes a Pegex grammar string as input. You may also pass a receiver class name after the grammar. my $parser = pegex($grammar, 'MyReceiver'); The C function returns a L object, on which you would typically call the C method, which (on success) will return a data structure of the parsed data. See L for more details. =head1 PEGEX DEBUGGING Pegex (Pegex::Parser) has many easy to use methods of debugging. See the "Debugging" section of L for details. =head1 SEE ALSO =over =item * L =item * L =item * L =item * L =item * L =item * L =item * L =item * L =back =head1 AUTHOR Ingy döt Net =head1 COPYRIGHT AND LICENSE Copyright 2010-2017. Ingy döt Net. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L =cut testml.yaml100644000766000024 67413157627333 14467 0ustar00ingystaff000000000000Pegex-0.64/tsource_testml_dir: ../ext/pegex-tml local_testml_dir: ./testml test_file_prefix: testml- test_file_template: | [% testml_setup_comment -%] use strict; use lib (-e 't' ? 't' : 'test'), 'inc'; use File::Spec; use TestML; use TestML::Compiler::Lite; use TestMLBridge; TestML->new( testml => File::Spec->catfile(qw{[% path.join(' ') %]}), bridge => 'TestMLBridge', compiler => 'TestML::Compiler::Lite', )->run; inc000755000766000024 013157627333 12452 5ustar00ingystaff000000000000Pegex-0.64TestML.pm100644000766000024 203713157627333 14322 0ustar00ingystaff000000000000Pegex-0.64/incpackage TestML; use TestML::Base; our $VERSION = '0.54'; has runtime => (); has compiler => (); has bridge => (); has library => (); has testml => (); sub run { my ($self) = @_; $self->set_default_classes; $self->runtime->new( compiler => $self->compiler, bridge => $self->bridge, library => $self->library, testml => $self->testml, )->run; } sub set_default_classes { my ($self) = @_; if (not $self->runtime) { require TestML::Runtime::TAP; $self->{runtime} = 'TestML::Runtime::TAP'; } if (not $self->compiler) { require TestML::Compiler::Pegex; $self->{compiler} = 'TestML::Compiler::Pegex'; } if (not $self->bridge) { require TestML::Bridge; $self->{bridge} = 'TestML::Bridge'; } if (not $self->library) { require TestML::Library::Standard; require TestML::Library::Debug; $self->{library} = [ 'TestML::Library::Standard', 'TestML::Library::Debug', ]; } } 1; export-api.t100644000766000024 140113157627333 14555 0ustar00ingystaff000000000000Pegex-0.64/t# BEGIN { $Pegex::Parser::Debug = 1 } use Test::More tests => 8; use Pegex; ok defined(&pegex), 'pegex is exported'; my $parser1 = pegex("foo: \n"); is ref($parser1), 'Pegex::Parser', 'pegex returns a Pegex::Parser object'; is $parser1->grammar->tree->{'+toprule'}, 'foo', 'pegex() contains a grammar with a compiled tree'; my $parser2 = pegex(<<'...'); number: /+/ ... eval { $parser2->parse('123'); pass '$parser2->parse worked'; }; fail $@ if $@; is ref $parser2, 'Pegex::Parser', 'grammar property is Pegex::Parser object'; my $tree2 = $parser2->grammar->tree; ok $tree2, 'Grammar object has tree'; ok ref($tree2), 'Grammar object is compiled to a tree'; is $tree2->{'+toprule'}, 'number', '_FIRST_RULE is set correctly'; compilers.t100644000766000024 121213157627333 14652 0ustar00ingystaff000000000000Pegex-0.64/xt# BEGIN { $TestML::Test::Differences = 1 } # BEGIN { $Pegex::Parser::Debug = 1 } # BEGIN { $Pegex::Bootstrap = 1 } use strict; use warnings; use Test::More; use lib -e 'xt' ? 'xt' : 'test/devel'; use TestDevelPegex; use Pegex::Bootstrap; use Pegex::Compiler; use YAML::XS; for my $grammar (test_grammar_paths) { my $expected = eval { Dump(Pegex::Bootstrap->new->parse(slurp($grammar))->tree); } or next; my $got = eval { Dump(Pegex::Bootstrap->new->parse(slurp($grammar))->tree); } or die "$grammar failed to compile: $@"; is $got, $expected, "Bootstrap compile matches normal compile for $grammar"; } speed-ast.t100644000766000024 72013157627333 14525 0ustar00ingystaff000000000000Pegex-0.64/xtuse strict; use warnings; use Test::More; use lib -e 'xt' ? 'xt' : 'test/devel'; use TestDevelPegex; for my $grammar (test_grammar_paths) { my $parser = pegex_parser_ast; my $input = slurp($grammar); my $timer = [gettimeofday]; my $result = eval { $parser->parse($input) }; my $time = tv_interval($timer); if ($result) { pass "$grammar parses in $time seconds"; } else { fail "$grammar failed to parse $@"; } } share000755000766000024 013157627333 13003 5ustar00ingystaff000000000000Pegex-0.64pegex.pgx100644000766000024 1242513157627333 15017 0ustar00ingystaff000000000000Pegex-0.64/share# This is the Pegex grammar for Pegex grammars! %grammar pegex %version 0.2.0 %include pegex-atoms grammar: meta-section rule-section ( doc-ending | ERROR-rule-definition ) meta-section: ( meta-definition | + | ERROR-meta-definition )* rule-section: ( rule-definition | + )* meta-definition: / '%' meta-name BLANK+ meta-value / rule-definition: rule-start rule-group ending rule-start: / ( rule-name ) BLANK* ':' -/ rule-group: any-group any-group: /- '|'? -/ all-group ( /- '|' -/ all-group )* all-group: rule-part (- rule-part)* rule-part: (rule-item)1-2 % /+ ( '%'{1,2} ) +/ rule-item: | bracketed-group | whitespace-token | rule-reference | quoted-regex | regular-expression | error-message rule-reference: / ( rule-modifier? ) # [=!.-+] (: # foo | ( rule-name ) | (: '<' ( rule-name ) '>' ) ) ( rule-quantifier? ) # [?*+] 2+ 2-3 (! BLANK* ':' ) # Avoid parsing 'foo:' / # as a rule reference. quoted-regex: / TICK ( [^ TICK ]* ) TICK / regular-expression: '/' whitespace-start? ( | whitespace-must | whitespace-maybe | quoted-regex | regex-rule-reference | + | regex-raw )* '/' whitespace-start: / ([ PLUS DASH]) (! [ DASH TILDE ]) / whitespace-must: /+ (: PLUS | DASH DASH ) (= [ SPACE SLASH CR NL ]) / whitespace-maybe: /- DASH (= [ SPACE SLASH CR NL ]) / regex-rule-reference: / (: + ( rule-name ) | (: '<' ( rule-name ) '>' ) ) (! BLANK* ':' ) / regex-raw: / ( '(?'? '<' | (?:[^ WS SLASH TICK LANGLE ])+ ) / bracketed-group: / ( group-modifier? ) '(' -/ rule-group /- ')' ( rule-quantifier? ) / whitespace-token: / ( (: PLUS | DASH | DASH DASH | TILDE | TILDE TILDE ) ) (= + )/ error-message: / '`' ( [^ '`' DOS ]* ) '`' / rule-modifier: / [ BANG EQUAL PLUS DASH DOT ] / group-modifier: / [ DASH DOT ] / rule-quantifier: / (: [ STAR PLUS QMARK ] | DIGIT+ (: DASH DIGIT+ | PLUS)? ) / meta-name: / ( 'grammar' | 'extends' | 'include' | 'version' ) / meta-value: / BLANK* ( [^ SEMI BREAK ]*? ) BLANK* ending / rule_name: / (: ALPHA ALNUM* (:[ DASH UNDER ] ALNUM+)* | DASH+ | UNDER+ ) (= [^ WORD DASH ]) / ending: / ~? (: BREAK - SEMI? - | comment - SEMI? - | SEMI - | EOS ) / ws: / (: WS | comment ) / comment: / '#' ANY* (: BREAK | EOS ) / ### # Pegex common error recognition and reporting: ### doc-ending: /- EOS / illegal-non-modifier-char: / [^ WORD LPAREN RPAREN LANGLE SLASH TILDE PIPE GRAVE WS ] / illegal-non-quantifier-char: / [^ WORD LPAREN RPAREN LANGLE SLASH TILDE PIPE GRAVE WS STAR PLUS QMARK BANG EQUAL PLUS DASH DOT COLON SEMI ] / ERROR-meta-definition: /(= PERCENT WORD+ )/ `Illegal meta rule` # Much of this is essentially a duplicate of the above rules, except with added # error checking ERROR-rule-definition: ERROR-rule-start ERROR-rule-group ( ending | `Rule ending syntax error` ) ERROR-rule-group: ERROR-any-group | ERROR-all-group ERROR-all-group: ERROR-rule-part+ % - ERROR-any-group: (ERROR-all-group)2+ % /- PIPE -/ ERROR-rule-part: (ERROR-rule-item)1-2 % /+ ( PERCENT{1,2} ) +/ ERROR-rule-start: / ( rule-name ) BLANK* COLON -/ | `Rule header syntax error` ERROR-rule-item: rule-item | ERROR-rule-reference | ERROR-regular-expression | ERROR-bracketed-group | ERROR-error-message # Errors - rule-reference ERROR-rule-reference: /(= rule-modifier? LANGLE rule-name (! RANGLE ) )/ `Missing > in rule reference` | /(= rule-modifier? rule-name RANGLE )/ `Missing < in rule reference` | /(= rule-modifier? (: rule-name | LANGLE rule-name RANGLE ) illegal-non-quantifier-char )/ `Illegal character in rule quantifier` | /(= rule-modifier? rule-name DASH )/ `Unprotected rule name with numeric quantifier; please use #-# syntax!` | !rule-modifier /(= illegal-non-modifier-char (: rule-name | LANGLE rule-name RANGLE ) rule-quantifier? # [?*+] 2+ 2-3 (! BLANK* COLON ) # Avoid parsing 'foo:' )/ # as a rule reference. `Illegal rule modifier (must be [=!.-+]?)` # Errors - regular-expression ERROR-regular-expression: /(= SLASH ( [^ SLASH ]* ) doc-ending )/ `Runaway regular expression; no ending slash at EOF` # Errors - bracketed-group ERROR-bracketed-group: /(! group-modifier) (= illegal-non-modifier-char LPAREN )/ `Illegal group rule modifier (can only use .)` | / ( group-modifier? ) LPAREN -/ rule-group ( =doc-ending `Runaway rule group; no ending parens at EOF` | / (= - RPAREN illegal-non-quantifier-char ) / `Illegal character in group rule quantifier` ) # Errors - error-message ERROR-error-message: /(= GRAVE [^ GRAVE DOS ]* [ DOS ] [^ GRAVE ]* GRAVE )/ `Multi-line error messages not allowed!` | /(= GRAVE [^ GRAVE ]* doc-ending )/ `Runaway error message; no ending grave at EOF` # Errors - separation ERROR-separation: /(= - PERCENT{3} )/ `Leading separator form (BOK) no longer supported` | /(= - PERCENT{1,2} [^ WS ] )/ `Illegal characters in separator indicator` # vim: set lisp: grammar-api.t100644000766000024 51313157627333 14645 0ustar00ingystaff000000000000Pegex-0.64/tuse Test::More tests => 1; package MyGrammar1; use Pegex::Base; extends 'Pegex::Grammar'; has start_rules => []; use constant text => <<'...'; foo: /xyz/ bar: /abc/ | baz: /def/ ... package main; my $g1 = MyGrammar1->new; is $g1->tree->{'+toprule'}, 'foo', 'MyGrammar1 compiled a tree from its text'; look-behind.t100644000766000024 36413157627333 14647 0ustar00ingystaff000000000000Pegex-0.64/tuse strict; use warnings; use Test::More; use Pegex; my $grammar = <<'...'; top: foo bar foo: 'foo' bar: /(<=oo)(bar)/ ... my $result = pegex($grammar)->parse("foobar"); is $result->{top}[0]{bar}, 'bar', 'Lookbehind works'; done_testing 1; testml-tree.t100644000766000024 61513157627333 14720 0ustar00ingystaff000000000000Pegex-0.64/t# DO NOT EDIT # # This file was generated by TestML::Setup (0.50) # # > perl -MTestML::Setup -e setup test/testml.yaml use strict; use lib (-e 't' ? 't' : 'test'), 'inc'; use File::Spec; use TestML; use TestML::Compiler::Lite; use TestMLBridge; TestML->new( testml => File::Spec->catfile(qw{testml tree.tml}), bridge => 'TestMLBridge', compiler => 'TestML::Compiler::Lite', )->run; testml-error.t100644000766000024 61613157627333 15113 0ustar00ingystaff000000000000Pegex-0.64/t# DO NOT EDIT # # This file was generated by TestML::Setup (0.50) # # > perl -MTestML::Setup -e setup test/testml.yaml use strict; use lib (-e 't' ? 't' : 'test'), 'inc'; use File::Spec; use TestML; use TestML::Compiler::Lite; use TestMLBridge; TestML->new( testml => File::Spec->catfile(qw{testml error.tml}), bridge => 'TestMLBridge', compiler => 'TestML::Compiler::Lite', )->run; Text000755000766000024 013157627333 13376 5ustar00ingystaff000000000000Pegex-0.64/incDiff.pm100644000766000024 5334313157627333 14774 0ustar00ingystaff000000000000Pegex-0.64/inc/Textpackage Text::Diff; use 5.006; use strict; use warnings; use Carp qw/ croak confess /; use Exporter (); use Algorithm::Diff (); our $VERSION = '1.44'; our @ISA = qw/ Exporter /; our @EXPORT = qw/ diff /; ## Hunks are made of ops. An op is the starting index for each ## sequence and the opcode: use constant A => 0; # Array index before match/discard use constant B => 1; use constant OPCODE => 2; # "-", " ", "+" use constant FLAG => 3; # What to display if not OPCODE "!" my %internal_styles = ( Unified => undef, Context => undef, OldStyle => undef, Table => undef, ## "internal", but in another module ); sub diff { my @seqs = ( shift, shift ); my $options = shift || {}; for my $i ( 0 .. 1 ) { my $seq = $seqs[$i]; my $type = ref $seq; while ( $type eq "CODE" ) { $seqs[$i] = $seq = $seq->( $options ); $type = ref $seq; } my $AorB = !$i ? "A" : "B"; if ( $type eq "ARRAY" ) { ## This is most efficient :) $options->{"OFFSET_$AorB"} = 0 unless defined $options->{"OFFSET_$AorB"}; } elsif ( $type eq "SCALAR" ) { $seqs[$i] = [split( /^/m, $$seq )]; $options->{"OFFSET_$AorB"} = 1 unless defined $options->{"OFFSET_$AorB"}; } elsif ( ! $type ) { $options->{"OFFSET_$AorB"} = 1 unless defined $options->{"OFFSET_$AorB"}; $options->{"FILENAME_$AorB"} = $seq unless defined $options->{"FILENAME_$AorB"}; $options->{"MTIME_$AorB"} = (stat($seq))[9] unless defined $options->{"MTIME_$AorB"}; local $/ = "\n"; open F, "<$seq" or croak "$!: $seq"; $seqs[$i] = []; close F; } elsif ( $type eq "GLOB" || UNIVERSAL::isa( $seq, "IO::Handle" ) ) { $options->{"OFFSET_$AorB"} = 1 unless defined $options->{"OFFSET_$AorB"}; local $/ = "\n"; $seqs[$i] = [<$seq>]; } else { confess "Can't handle input of type ", ref; } } ## Config vars my $output; my $output_handler = $options->{OUTPUT}; my $type = ref $output_handler ; if ( ! defined $output_handler ) { $output = ""; $output_handler = sub { $output .= shift }; } elsif ( $type eq "CODE" ) { ## No problems, mate. } elsif ( $type eq "SCALAR" ) { my $out_ref = $output_handler; $output_handler = sub { $$out_ref .= shift }; } elsif ( $type eq "ARRAY" ) { my $out_ref = $output_handler; $output_handler = sub { push @$out_ref, shift }; } elsif ( $type eq "GLOB" || UNIVERSAL::isa $output_handler, "IO::Handle" ) { my $output_handle = $output_handler; $output_handler = sub { print $output_handle shift }; } else { croak "Unrecognized output type: $type"; } my $style = $options->{STYLE}; $style = "Unified" unless defined $options->{STYLE}; $style = "Text::Diff::$style" if exists $internal_styles{$style}; if ( ! $style->can( "hunk" ) ) { eval "require $style; 1" or die $@; } $style = $style->new if ! ref $style && $style->can( "new" ); my $ctx_lines = $options->{CONTEXT}; $ctx_lines = 3 unless defined $ctx_lines; $ctx_lines = 0 if $style->isa( "Text::Diff::OldStyle" ); my @keygen_args = $options->{KEYGEN_ARGS} ? @{$options->{KEYGEN_ARGS}} : (); ## State vars my $diffs = 0; ## Number of discards this hunk my $ctx = 0; ## Number of " " (ctx_lines) ops pushed after last diff. my @ops; ## ops (" ", +, -) in this hunk my $hunks = 0; ## Number of hunks my $emit_ops = sub { $output_handler->( $style->file_header( @seqs, $options ) ) unless $hunks++; $output_handler->( $style->hunk_header( @seqs, @_, $options ) ); $output_handler->( $style->hunk ( @seqs, @_, $options ) ); $output_handler->( $style->hunk_footer( @seqs, @_, $options ) ); }; ## We keep 2*ctx_lines so that if a diff occurs ## at 2*ctx_lines we continue to grow the hunk instead ## of emitting diffs and context as we go. We ## need to know the total length of both of the two ## subsequences so the line count can be printed in the ## header. my $dis_a = sub {push @ops, [@_[0,1],"-"]; ++$diffs ; $ctx = 0 }; my $dis_b = sub {push @ops, [@_[0,1],"+"]; ++$diffs ; $ctx = 0 }; Algorithm::Diff::traverse_sequences( @seqs, { MATCH => sub { push @ops, [@_[0,1]," "]; if ( $diffs && ++$ctx > $ctx_lines * 2 ) { $emit_ops->( [ splice @ops, 0, $#ops - $ctx_lines ] ); $ctx = $diffs = 0; } ## throw away context lines that aren't needed any more shift @ops if ! $diffs && @ops > $ctx_lines; }, DISCARD_A => $dis_a, DISCARD_B => $dis_b, }, $options->{KEYGEN}, # pass in user arguments for key gen function @keygen_args, ); if ( $diffs ) { $#ops -= $ctx - $ctx_lines if $ctx > $ctx_lines; $emit_ops->( \@ops ); } $output_handler->( $style->file_footer( @seqs, $options ) ) if $hunks; return defined $output ? $output : $hunks; } sub _header { my ( $h ) = @_; my ( $p1, $fn1, $t1, $p2, $fn2, $t2 ) = @{$h}{ "FILENAME_PREFIX_A", "FILENAME_A", "MTIME_A", "FILENAME_PREFIX_B", "FILENAME_B", "MTIME_B" }; ## remember to change Text::Diff::Table if this logic is tweaked. return "" unless defined $fn1 && defined $fn2; return join( "", $p1, " ", $fn1, defined $t1 ? "\t" . localtime $t1 : (), "\n", $p2, " ", $fn2, defined $t2 ? "\t" . localtime $t2 : (), "\n", ); } ## _range encapsulates the building of, well, ranges. Turns out there are ## a few nuances. sub _range { my ( $ops, $a_or_b, $format ) = @_; my $start = $ops->[ 0]->[$a_or_b]; my $after = $ops->[-1]->[$a_or_b]; ## The sequence indexes in the lines are from *before* the OPCODE is ## executed, so we bump the last index up unless the OP indicates ## it didn't change. ++$after unless $ops->[-1]->[OPCODE] eq ( $a_or_b == A ? "+" : "-" ); ## convert from 0..n index to 1..(n+1) line number. The unless modifier ## handles diffs with no context, where only one file is affected. In this ## case $start == $after indicates an empty range, and the $start must ## not be incremented. my $empty_range = $start == $after; ++$start unless $empty_range; return $start == $after ? $format eq "unified" && $empty_range ? "$start,0" : $start : $format eq "unified" ? "$start,".($after-$start+1) : "$start,$after"; } sub _op_to_line { my ( $seqs, $op, $a_or_b, $op_prefixes ) = @_; my $opcode = $op->[OPCODE]; return () unless defined $op_prefixes->{$opcode}; my $op_sym = defined $op->[FLAG] ? $op->[FLAG] : $opcode; $op_sym = $op_prefixes->{$op_sym}; return () unless defined $op_sym; $a_or_b = $op->[OPCODE] ne "+" ? 0 : 1 unless defined $a_or_b; my @line = ( $op_sym, $seqs->[$a_or_b][$op->[$a_or_b]] ); unless ( $line[1] =~ /(?:\n|\r\n)$/ ) { $line[1] .= "\n\\ No newline at end of file\n"; } return @line; } SCOPE: { package Text::Diff::Base; sub new { my $proto = shift; return bless { @_ }, ref $proto || $proto; } sub file_header { return "" } sub hunk_header { return "" } sub hunk { return "" } sub hunk_footer { return "" } sub file_footer { return "" } } @Text::Diff::Unified::ISA = qw( Text::Diff::Base ); sub Text::Diff::Unified::file_header { shift; ## No instance data my $options = pop ; _header( { FILENAME_PREFIX_A => "---", FILENAME_PREFIX_B => "+++", %$options } ); } sub Text::Diff::Unified::hunk_header { shift; ## No instance data pop; ## Ignore options my $ops = pop; return join( "", "@@ -", _range( $ops, A, "unified" ), " +", _range( $ops, B, "unified" ), " @@\n", ); } sub Text::Diff::Unified::hunk { shift; ## No instance data pop; ## Ignore options my $ops = pop; my $prefixes = { "+" => "+", " " => " ", "-" => "-" }; return join "", map _op_to_line( \@_, $_, undef, $prefixes ), @$ops } @Text::Diff::Context::ISA = qw( Text::Diff::Base ); sub Text::Diff::Context::file_header { _header { FILENAME_PREFIX_A=>"***", FILENAME_PREFIX_B=>"---", %{$_[-1]} }; } sub Text::Diff::Context::hunk_header { return "***************\n"; } sub Text::Diff::Context::hunk { shift; ## No instance data pop; ## Ignore options my $ops = pop; ## Leave the sequences in @_[0,1] my $a_range = _range( $ops, A, "" ); my $b_range = _range( $ops, B, "" ); ## Sigh. Gotta make sure that differences that aren't adds/deletions ## get prefixed with "!", and that the old opcodes are removed. my $after; for ( my $start = 0; $start <= $#$ops ; $start = $after ) { ## Scan until next difference $after = $start + 1; my $opcode = $ops->[$start]->[OPCODE]; next if $opcode eq " "; my $bang_it; while ( $after <= $#$ops && $ops->[$after]->[OPCODE] ne " " ) { $bang_it ||= $ops->[$after]->[OPCODE] ne $opcode; ++$after; } if ( $bang_it ) { for my $i ( $start..($after-1) ) { $ops->[$i]->[FLAG] = "!"; } } } my $b_prefixes = { "+" => "+ ", " " => " ", "-" => undef, "!" => "! " }; my $a_prefixes = { "+" => undef, " " => " ", "-" => "- ", "!" => "! " }; return join( "", "*** ", $a_range, " ****\n", map( _op_to_line( \@_, $_, A, $a_prefixes ), @$ops ), "--- ", $b_range, " ----\n", map( _op_to_line( \@_, $_, B, $b_prefixes ), @$ops ), ); } @Text::Diff::OldStyle::ISA = qw( Text::Diff::Base ); sub _op { my $ops = shift; my $op = $ops->[0]->[OPCODE]; $op = "c" if grep $_->[OPCODE] ne $op, @$ops; $op = "a" if $op eq "+"; $op = "d" if $op eq "-"; return $op; } sub Text::Diff::OldStyle::hunk_header { shift; ## No instance data pop; ## ignore options my $ops = pop; my $op = _op $ops; return join "", _range( $ops, A, "" ), $op, _range( $ops, B, "" ), "\n"; } sub Text::Diff::OldStyle::hunk { shift; ## No instance data pop; ## ignore options my $ops = pop; ## Leave the sequences in @_[0,1] my $a_prefixes = { "+" => undef, " " => undef, "-" => "< " }; my $b_prefixes = { "+" => "> ", " " => undef, "-" => undef }; my $op = _op $ops; return join( "", map( _op_to_line( \@_, $_, A, $a_prefixes ), @$ops ), $op eq "c" ? "---\n" : (), map( _op_to_line( \@_, $_, B, $b_prefixes ), @$ops ), ); } 1; __END__ =head1 NAME Text::Diff - Perform diffs on files and record sets =head1 SYNOPSIS use Text::Diff; ## Mix and match filenames, strings, file handles, producer subs, ## or arrays of records; returns diff in a string. ## WARNING: can return B diffs for large files. my $diff = diff "file1.txt", "file2.txt", { STYLE => "Context" }; my $diff = diff \$string1, \$string2, \%options; my $diff = diff \*FH1, \*FH2; my $diff = diff \&reader1, \&reader2; my $diff = diff \@records1, \@records2; ## May also mix input types: my $diff = diff \@records1, "file_B.txt"; =head1 DESCRIPTION C provides a basic set of services akin to the GNU C utility. It is not anywhere near as feature complete as GNU C, but it is better integrated with Perl and available on all platforms. It is often faster than shelling out to a system's C executable for small files, and generally slower on larger files. Relies on L for, well, the algorithm. This may not produce the same exact diff as a system's local C executable, but it will be a valid diff and comprehensible by C. We haven't seen any differences between Algorithm::Diff's logic and GNU diff's, but we have not examined them to make sure they are indeed identical. B: If you don't want to import the C function, do one of the following: use Text::Diff (); require Text::Diff; That's a pretty rare occurence, so C is exported by default. If you pass a filename, but the file can't be read, then C will C. =head1 OPTIONS diff() takes two parameters from which to draw input and a set of options to control it's output. The options are: =over =item FILENAME_A, MTIME_A, FILENAME_B, MTIME_B The name of the file and the modification time "files" These are filled in automatically for each file when diff() is passed a filename, unless a defined value is passed in. If a filename is not passed in and FILENAME_A and FILENAME_B are not provided or C, the header will not be printed. Unused on C diffs. =item OFFSET_A, OFFSET_B The index of the first line / element. These default to 1 for all parameter types except ARRAY references, for which the default is 0. This is because ARRAY references are presumed to be data structures, while the others are line oriented text. =item STYLE "Unified", "Context", "OldStyle", or an object or class reference for a class providing C, C, C, C and C methods. The two footer() methods are provided for overloading only; none of the formats provide them. Defaults to "Unified" (unlike standard C, but Unified is what's most often used in submitting patches and is the most human readable of the three. If the package indicated by the STYLE has no hunk() method, c will load it automatically (lazy loading). Since all such packages should inherit from Text::Diff::Base, this should be marvy. Styles may be specified as class names (C