pcre2el-1.12/0000755000175000017500000000000014473140155012627 5ustar dogslegdogslegpcre2el-1.12/.elpaignore0000644000175000017500000000002414473140155014751 0ustar dogslegdogsleg.travis.yml COPYING pcre2el-1.12/Makefile0000644000175000017500000000101214473140155014261 0ustar dogslegdogslegELPA_DEPENDENCIES=a.el ELPA_ARCHIVES=melpa gnu TEST_ERT_FILES="pcre2el-tests.el" LINT_CHECKDOC_FILES=$(wildcard *.el) LINT_PACKAGE_LINT_FILES=$(wildcard *.el) LINT_COMPILE_FILES=$(wildcard *.el) makel.mk: # Download makel @if [ -f ../makel/makel.mk ]; then \ ln -s ../makel/makel.mk .; \ else \ curl \ --fail --silent --show-error --insecure --location \ --retry 9 --retry-delay 9 \ -O https://gitlab.petton.fr/DamienCassou/makel/raw/v0.7.1/makel.mk; \ fi # Include makel.mk if present -include makel.mk pcre2el-1.12/.travis.yml0000644000175000017500000000170114473140155014737 0ustar dogslegdogsleglanguage: emacs env: - "EMACS=emacs25 CHECK_TARGET=test" - "EMACS=emacs25 CHECK_TARGET=test-interactive" - "EMACS=emacs-snapshot CHECK_TARGET=test" - "EMACS=emacs-snapshot CHECK_TARGET=test-interactive" matrix: allow_failures: - env: "EMACS=emacs-snapshot CHECK_TARGET=test" - env: "EMACS=emacs-snapshot CHECK_TARGET=test-interactive" install: - if [ "$EMACS" = "emacs25" ]; then sudo add-apt-repository -y ppa:cassou/emacs && sudo apt-get -qq update && sudo apt-get -qq -f install && sudo apt-get -qq install emacs25-nox; fi - if [ "$EMACS" = 'emacs-snapshot' ]; then sudo add-apt-repository -y ppa:ubuntu-elisp/ppa && sudo apt-get -qq update && sudo apt-get -qq -f install && sudo apt-get -qq install emacs-snapshot && sudo apt-get -qq install emacs-snapshot-el; fi script: - make $CHECK_TARGET EMACS=$EMACS notifications: email: false pcre2el-1.12/COPYING0000644000175000017500000010451514473140155013670 0ustar dogslegdogsleg GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), 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 prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey 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; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. 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. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 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. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS 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 the public, 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 state 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) 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 3 of the License, 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, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program 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, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . pcre2el-1.12/README.org0000644000175000017500000003745214473140155014310 0ustar dogslegdogsleg* pcre2el: convert between PCRE, Emacs and rx regexp syntax ** Overview =pcre2el= or =rxt= (RegeXp Translator or RegeXp Tools) is a utility for working with regular expressions in Emacs, based on a recursive-descent parser for regexp syntax. In addition to converting (a subset of) PCRE syntax into its Emacs equivalent, it can do the following: - convert Emacs syntax to PCRE - convert either syntax to =rx=, an S-expression based regexp syntax - untangle complex regexps by showing the parse tree in =rx= form and highlighting the corresponding chunks of code - show the complete list of strings (productions) matching a regexp, provided the list is finite - provide live font-locking of regexp syntax (so far only for Elisp buffers -- other modes on the TODO list) ** Usage Enable =rxt-mode= or its global equivalent =rxt-global-mode= to get the default key-bindings. There are three sets of commands: commands that take a PCRE regexp, commands which take an Emacs regexp, and commands that try to do the right thing based on the current mode. Currently, this means Emacs syntax in =emacs-lisp-mode= and =lisp-interaction-mode=, and PCRE syntax everywhere else. The default key bindings all begin with =C-c /= and have a mnemonic structure: =C-c / =, or just =C-c / = for the "do what I mean" commands. The complete list of key bindings is given here and explained in more detail below: - "Do-what-I-mean" commands: - =C-c / /= :: =rxt-explain= - =C-c / c= :: =rxt-convert-syntax= - =C-c / x= :: =rxt-convert-to-rx= - =C-c / ′= :: =rxt-convert-to-strings= - Commands that work on a PCRE regexp: - =C-c / p e= :: =rxt-pcre-to-elisp= - =C-c / %= :: =pcre-query-replace-regexp= - =C-c / p x= :: =rxt-pcre-to-rx= - =C-c / p s= :: =rxt-pcre-to-sre= - =C-c / p ′= :: =rxt-pcre-to-strings= - =C-c / p /= :: =rxt-explain-pcre= - Commands that work on an Emacs regexp: - =C-c / e /= :: =rxt-explain-elisp= - =C-c / e p= :: =rxt-elisp-to-pcre= - =C-c / e x= :: =rxt-elisp-to-rx= - =C-c / e s= :: =rxt-elisp-to-sre= - =C-c / e ′= :: =rxt-elisp-to-strings= - =C-c / e t= :: =rxt-toggle-elisp-rx= - =C-c / t= :: =rxt-toggle-elisp-rx= *** Interactive input and output When used interactively, the conversion commands can read a regexp either from the current buffer or from the minibuffer. The output is displayed in the minibuffer and copied to the kill-ring. - When called with a prefix argument (=C-u=), they read a regular expression from the minibuffer literally, without further processing -- meaning there's no need to double the backslashes if it's an Emacs regexp. This is the same way commands like =query-replace-regexp= read input. - When the region is active, they use they the region contents, again literally (without any translation of string syntax). - With neither a prefix arg nor an active region, the behavior depends on whether the command expects an Emacs regexp or a PCRE one. Commands that take an Emacs regexp behave like =C-x C-e=: they evaluate the sexp before point (which could be simply a string literal) and use its value. This is designed for use in Elisp buffers. As a special case, if point is *inside* a string, it's first moved to the string end, so in practice they should work as long as point is somewhere within the regexp literal. Commands that take a PCRE regexp try to read a Perl-style delimited regex literal *after* point in the current buffer, including its flags. For example, putting point before the =m= in the following example and doing =C-c / p e= (=rxt-pcre-to-elisp=) displays =\(?:bar\|foo\)=, correctly stripping out the whitespace and comment: : $x =~ m/ foo | (?# comment) bar /x The PCRE reader currently only works with =/ ... /= delimiters. It will ignore any preceding =m=, =s=, or =qr= operator, as well as the replacement part of an =s= construction. Readers for other PCRE-using languages are on the TODO list. The translation functions display their result in the minibuffer and copy it to the kill ring. When translating something into Elisp syntax, you might need to use the result either literally (e.g. for interactive input to a command like =query-replace-regexp=), or as a string to paste into Lisp code. To allow both uses, =rxt-pcre-to-elisp= copies both versions successively to the kill-ring. The literal regexp without string quoting is the top element of the kill-ring, while the Lisp string is the second-from-top. You can paste the literal regexp somewhere by doing =C-y=, or the Lisp string by =C-y M-y=. *** Syntax conversion commands =rxt-convert-syntax= (=C-c / c=) converts between Emacs and PCRE syntax, depending on the major mode in effect when called. Alternatively, you can specify the conversion direction explicitly by using either =rxt-pcre-to-elisp= (=C-c / p e=) or =rxt-elisp-to-pcre= (=C-c / e p=). Similarly, =rxt-convert-to-rx= (=C-c / x=) converts either kind of syntax to =rx= form, while =rxt-convert-pcre-to-rx= (=C-c / p x=) and =rxt-convert-elisp-to-rx= (=C-c / e x=) convert to =rx= from a specified source type. In Elisp buffers, you can use =rxt-toggle-elisp-rx= (=C-c / t= or =C-c / e t=) to switch the regexp at point back and forth between string and =rx= syntax. Point should either be within an =rx= or =rx-to-string= form or a string literal for this to work. *** PCRE mode (experimental) If you want to use emulated PCRE regexp syntax in all Emacs commands, try =pcre-mode=, which uses Emacs's advice system to make all commands that read regexps using the minibuffer use emulated PCRE syntax. It should also work with Isearch. This feature is still fairly experimental. It may fail to work or do the wrong thing with certain commands. Please report bugs. =pcre-query-replace-regexp= was originally defined to do query-replace using emulated PCRE regexps, and is now made somewhat obsolete by =pcre-mode=. It is bound to =C-c / %= by default, by analogy with =M-%=. Put the following in your =.emacs= if you want to use PCRE-style query replacement everywhere: : (global-set-key [(meta %)] 'pcre-query-replace-regexp) *** Explain regexps When syntax-highlighting isn't enough to untangle some gnarly regexp you find in the wild, try the 'explain' commands: =rxt-explain= (=C-c / /=), =rxt-explain-pcre= (=C-c / p=) and =rxt-explain-elisp= (=C-c / e=). These display the original regexp along with its pretty-printed =rx= equivalent in a new buffer. Moving point around either in the original regexp or the =rx= translation highlights corresponding pieces of syntax, which can aid in seeing things like the scope of quantifiers. I call them "explain" commands because the =rx= form is close to a plain syntax tree, and this plus the wordiness of the operators usually helps to clarify what is going on. People who dislike Lisp syntax might disagree with this assessment. *** Generate all matching strings (productions) Occasionally you come across a regexp which is designed to match a finite set of strings, e.g. a set of keywords, and it would be useful to recover the original set. (In Emacs you can generate such regexps using =regexp-opt=). The commands =rxt-convert-to-strings= (=C-c / ′=), =rxt-pcre-to-strings= (=C-c / p ′=) or =rxt-elisp-to-strings= (=C-c / e ′=) accomplish this by generating all the matching strings ("productions") of a regexp. (The productions are copied to the kill ring as a Lisp list). An example in Lisp code: : (regexp-opt '("cat" "caterpillar" "catatonic")) : ;; => "\\(?:cat\\(?:atonic\\|erpillar\\)?\\)" : (rxt-elisp-to-strings "\\(?:cat\\(?:atonic\\|erpillar\\)?\\)") : ;; => '("cat" "caterpillar" "catatonic") For obvious reasons, these commands only work with regexps that don't include any unbounded quantifiers like =+= or =*=. They also can't enumerate all the characters that match a named character class like =[[:alnum:]]=. In either case they will give a (hopefully meaningful) error message. Due to the nature of permutations, it's still possible for a finite regexp to generate a huge number of productions, which will eat memory and slow down your Emacs. Be ready with =C-g= if necessary. *** RE-Builder support The Emacs RE-Builder is a useful visual tool which allows using several different built-in syntaxes via =reb-change-syntax= (=C-c TAB=). It supports Elisp read and literal syntax and =rx=, but it can only convert from the symbolic forms to Elisp, not the other way. This package hacks the RE-Builder to also work with emulated PCRE syntax, and to convert transparently between Elisp, PCRE and rx syntaxes. PCRE mode reads a delimited Perl-like literal of the form =/ ... /=, and it should correctly support using the =x= and =s= flags. *** Use from Lisp Example of using the conversion functions: : (rxt-pcre-to-elisp "(abc|def)\\w+\\d+") : ;; => "\\(\\(?:abc\\|def\\)\\)[_[:alnum:]]+[[:digit:]]+" All the conversion functions take a single string argument, the regexp to translate: - =rxt-pcre-to-elisp= - =rxt-pcre-to-rx= - =rxt-pcre-to-sre= - =rxt-pcre-to-strings= - =rxt-elisp-to-pcre= - =rxt-elisp-to-rx= - =rxt-elisp-to-sre= - =rxt-elisp-to-strings= ** Bugs and Limitations *** Limitations on PCRE syntax PCRE has a complicated syntax and semantics, only some of which can be translated into Elisp. The following subset of PCRE should be correctly parsed and converted: - parenthesis grouping =( .. )=, including shy matches =(?: ... )= - backreferences (various syntaxes), but only up to 9 per expression - alternation =|= - greedy and non-greedy quantifiers =*=, =*?=, =+=, =+?=, =?= and =??= (all of which are the same in Elisp as in PCRE) - numerical quantifiers ={M,N}= - beginning/end of string =\A=, =\Z= - string quoting =\Q .. \E= - word boundaries =\b=, =\B= (these are the same in Elisp) - single character escapes =\a=, =\c=, =\e=, =\f=, =\n=, =\r=, =\t=, =\x=, and =\octal digits= (but see below about non-ASCII characters) - character classes =[...]= including Posix escapes - character classes =\d=, =\D=, =\h=, =\H=, =\s=, =\S=, =\v=, =\V= both within character class brackets and outside - word and non-word characters =\w= and =\W= (Emacs has the same syntax, but its meaning is different) - =s= (single line) and =x= (extended syntax) flags, in regexp literals, or set within the expression via =(?xs-xs)= or =(?xs-xs: .... )= syntax - comments =(?# ... )= Most of the more esoteric PCRE features can't really be supported by simple translation to Elisp regexps. These include the different lookaround assertions, conditionals, and the "backtracking control verbs" =(* ...)= . OTOH, there are a few other syntaxes which are currently unsupported and possibly could be: - =\L=, =\U=, =\l=, =\u= case modifiers - =\g{...}= backreferences *** Other limitations - The order of alternatives and characters in char classes sometimes gets shifted around, which is annoying. - Although the string parser tries to interpret PCRE's octal and hexadecimal escapes correctly, there are problems with matching 8-bit characters that I don't use enough to properly understand, e.g.: : (string-match-p (rxt-pcre-to-elisp "\\377") "\377") => nil A fix for this would be welcome. - Most of PCRE's rules for how =^=, =\A=, =$= and =\Z= interact with newlines are not implemented, since they seem less relevant to Emacs's buffer-oriented rather than line-oriented model. However, the different meanings of the =.= metacharacter *are* implemented (it matches newlines with the =/s= flag, but not otherwise). - Not currently namespace clean (both =rxt-= and a couple of =pcre-= functions). *** TODO: - Python-specific extensions to PCRE? - Language-specific stuff to enable regexp font-locking and explaining in different modes. Each language would need two functions, which could be kept in an alist: 1. A function to read PCRE regexps, taking the string syntax into account. E.g., Python has single-quoted, double-quoted and raw strings, each with different quoting rules. PHP has the kind of belt-and-suspenders solution you would expect: regexps are in strings, /and/ you have to include the =/ ... /= delimiters! Duh. 2. A function to copy faces back from the parsed string to the original buffer text. This has to recognize any escape sequences so they can be treated as a single character. ** Internal details Internally, =rxt= defines an abstract syntax tree data type for regular expressions, parsers for Elisp and PCRE syntax, and "unparsers" from to PCRE, rx, and SRE syntax. Converting from a parsed syntax tree to Elisp syntax is a two-step process: first convert to =rx= form, then let =rx-to-string= do the heavy lifting. See =rxt-parse-re=, =rxt-adt->pcre=, =rxt-adt->rx=, and =rxt-adt->sre=, and the section beginning "Regexp ADT" in pcre2el.el for details. This code is partially based on Olin Shivers' reference SRE implementation in scsh, although it is simplified in some respects and extended in others. See =scsh/re.scm=, =scsh/spencer.scm= and =scsh/posixstr.scm= in the =scsh= source tree for details. In particular, =pcre2el= steals the idea of an abstract data type for regular expressions and the general structure of the string regexp parser and unparser. The data types for character sets are extended in order to support symbolic translation between character set expressions without assuming a small (Latin1) character set. The string parser is also extended to parse a bigger variety of constructions, including POSIX character classes and various Emacs and Perl regexp assertions. Otherwise, only the bare minimum of scsh's abstract data type is implemented. ** Soapbox Emacs regexps have their annoyances, but it is worth getting used to them. The Emacs assertions for word boundaries, symbol boundaries, and syntax classes depending on the syntax of the mode in effect are especially useful. (PCRE has =\b= for word-boundary, but AFAIK it doesn't have separate assertions for beginning-of-word and end-of-word). Other things that might be done with huge regexps in other languages can be expressed more understandably in Elisp using combinations of `save-excursion' with the various searches (regexp, literal, skip-syntax-forward, sexp-movement functions, etc.). There's not much point in using =rxt-pcre-to-elisp= to use PCRE notation in a Lisp program you're going to maintain, since you still have to double all the backslashes. Better to just use the converted result (or better yet, the =rx= form). ** History and acknowledgments This was originally created out of an answer to a stackoverflow question: http://stackoverflow.com/questions/9118183/elisp-mechanism-for-converting-pcre-regexps-to-emacs-regexps Thanks to: - Wes Hardaker (hardaker) for the initial inspiration and subsequent hacking - priyadarshan for requesting RX/SRE support - Daniel Colascione (dcolascione) for a patch to support Emacs's explicitly-numbered match groups - Aaron Meurer (asmeurer) for requesting Isearch support - Philippe Vaucher (silex) for a patch to support =ibuffer-do-replace-regexp= in PCRE mode pcre2el-1.12/pcre2el-tests.el0000644000175000017500000135146314473140155015662 0ustar dogslegdogsleg;;; pcre2el.tests.el -- tests for pcre2el/rxt -*- lexical-binding: t; -*- ;;; The bulk of the tests for pcre->elisp conversion are adapted from ;;; part of the PCRE library's test suite. Therefore: ;; This file incorporates work covered by the following copyright and ;; permission notice: ;; ;; ;; PCRE LICENCE ;; ------------ ;; PCRE is a library of functions to support regular expressions whose syntax ;; and semantics are as close as possible to those of the Perl 5 language. ;; Release 8 of PCRE is distributed under the terms of the "BSD" licence, as ;; specified below. The documentation for PCRE, supplied in the "doc" ;; directory, is distributed under the same terms as the software itself. ;; The basic library functions are written in C and are freestanding. Also ;; included in the distribution is a set of C++ wrapper functions, and a ;; just-in-time compiler that can be used to optimize pattern matching. These ;; are both optional features that can be omitted when the library is built. ;; THE BASIC LIBRARY FUNCTIONS ;; --------------------------- ;; Written by: Philip Hazel ;; Email local part: ph10 ;; Email domain: cam.ac.uk ;; University of Cambridge Computing Service, ;; Cambridge, England. ;; Copyright (c) 1997-2012 University of Cambridge ;; All rights reserved. ;; PCRE JUST-IN-TIME COMPILATION SUPPORT ;; ------------------------------------- ;; Written by: Zoltan Herczeg ;; Email local part: hzmester ;; Emain domain: freemail.hu ;; Copyright(c) 2010-2012 Zoltan Herczeg ;; All rights reserved. ;; STACK-LESS JUST-IN-TIME COMPILER ;; -------------------------------- ;; Written by: Zoltan Herczeg ;; Email local part: hzmester ;; Emain domain: freemail.hu ;; Copyright(c) 2009-2012 Zoltan Herczeg ;; All rights reserved. ;; THE "BSD" LICENCE ;; ----------------- ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions are met: ;; * Redistributions of source code must retain the above copyright notice, ;; this list of conditions and the following disclaimer. ;; * Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; * Neither the name of the University of Cambridge nor the name of Google ;; Inc. nor the names of their contributors may be used to endorse or ;; promote products derived from this software without specific prior ;; written permission. ;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" ;; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN ;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ;; POSSIBILITY OF SUCH DAMAGE. ;;;; Code: (require 'pcre2el) (require 'ert) (require 'cl-lib) ;; Some older versions of ert lack `ert-skip'. (defun rxt-skip-test (message) (if (fboundp 'ert-skip) (ert-skip message) (message (concat "SKIPPING: " message)) (ert-pass))) ;;; Tests for source-location (ert-deftest rxt-location () (let ((dummy-1 (cl-gensym)) (dummy-2 (cl-gensym)) (location-1 (make-rxt-location :source "dummy 1" :start 2 :end 5)) (location-2 (make-rxt-location :source "dummy 2" :start 0 :end 4))) (setf (rxt-location dummy-1) location-1) (setf (rxt-location dummy-2) location-2) (should (eq (rxt-location dummy-1) location-1)) (should (eq (rxt-location dummy-2) location-2)))) (ert-deftest rxt-location-text () (let ((location-1 (make-rxt-location :source "dummy 1" :start 2 :end 5)) (location-2 (make-rxt-location :source "dummy 2" :start 0 :end 4))) (should (string= (rxt-location-text location-1) "mmy")) (should (string= (rxt-location-text location-2) "dumm")))) (ert-deftest rxt-with-source-location () "Test recording of source location information" (let ((string "dummy string") (dummy-1 (cl-gensym)) (dummy-2 (cl-gensym)) value-1 value-2) (let ((rxt-source-text-string string)) (with-temp-buffer (insert rxt-source-text-string) (goto-char (point-min)) (setq value-1 (rxt-with-source-location (goto-char (point-max)) dummy-1))) (with-temp-buffer (insert rxt-source-text-string) (goto-char (point-min)) (setq value-2 (rxt-with-source-location (forward-word) dummy-2)))) (should (eq value-1 dummy-1)) (should (eq value-2 dummy-2)) (let ((location (rxt-location value-1))) (should (not (null location))) (should (string= (rxt-location-source location) string)) (should (= 0 (rxt-location-start location))) (should (= (length string) (rxt-location-end location))) (should (string= string (rxt-location-text location)))) (let ((location (rxt-location value-2))) (should (not (null location))) (should (string= (rxt-location-source location) string)) (should (= 0 (rxt-location-start location))) (should (= 5 (rxt-location-end location))) (should (string= "dummy" (rxt-location-text location)))))) ;;; Syntax-tree tests (ert-deftest rxt-trivial-p () (should (rxt-trivial-p (rxt-empty-string)))) (ert-deftest rxt-string-concat () (let* ((source "dummy string") (string-1 (rxt-string "dummy ")) (string-2 (rxt-string "string"))) (should (equal (rxt-string source) (rxt-string-concat string-1 string-2))) (setf (rxt-location string-1) (make-rxt-location :source source :start 0 :end 6)) (setf (rxt-location string-2) (make-rxt-location :source source :start 6 :end 12)) (let ((result (rxt-string-concat string-1 string-2))) (should (equal (rxt-string source) result)) (let ((location (rxt-location result))) (should (not (null location))) (should (eq source (rxt-location-source location))) (should (= 0 (rxt-location-start location))) (should (= 12 (rxt-location-end location))))))) ;; Sequence constructor (ert-deftest rxt-seq-empty () (should (equal (rxt-empty-string) (rxt-seq)))) (ert-deftest rxt-seq-singleton () (let* ((string (rxt-string "sample string")) (sequence (rxt-seq string))) (should (equal string sequence)))) (ert-deftest rxt-seq-join-strings () ;; Strings with the same case-folding setting are folded together (let* ((string-1 (rxt-string "first")) (string-2 (rxt-string "second")) (string-3 (rxt-string "third")) (sequence (rxt-seq string-1 string-2 string-3))) (should (equal sequence (rxt-string (concat (rxt-string-chars string-1) (rxt-string-chars string-2) (rxt-string-chars string-3)))))) ;; Strings with different case-folding behaviours are not folded ;; together (let* ((string-1 (rxt-string "case-sensitive" nil)) (string-2 (rxt-string "case-insensitive" t)) (sequence (rxt-seq string-1 string-2))) (should (rxt-seq-p sequence)) (should (equal (rxt-seq-elts sequence) (list string-1 string-2))))) (ert-deftest rxt-seq-flatten-sequences () (let* ((sequence-1 (rxt-seq (rxt-bol) (rxt-string "word"))) (nested-sequence (rxt-seq sequence-1 (rxt-anything) (rxt-eol))) (flat-sequence (rxt-seq (rxt-bol) (rxt-string "word") (rxt-anything) (rxt-eol)))) (should (equal nested-sequence flat-sequence))) (let* ((sequence (rxt-seq (rxt-bol) (rxt-anything) (rxt-eol))) (nested-1 (rxt-seq sequence)) (nested-2 (rxt-seq nested-1))) (should (equal sequence nested-1)) (should (equal sequence nested-2)))) (ert-deftest rxt-seq-remove-empty () (let ((sequence-1 (rxt-seq (rxt-bow) (rxt-string "lorem ipsum") (rxt-anything) (rxt-eow))) (sequence-2 (rxt-seq (rxt-empty-string) (rxt-empty-string) (rxt-bow) (rxt-seq) (rxt-string "lorem ipsum") (rxt-seq) (rxt-empty-string) (rxt-anything) (rxt-empty-string) (rxt-eow)))) (should (equal sequence-1 sequence-2)))) ;;; Choice constructor (ert-deftest rxt-choice () ;; Singleton elements should be returned unchanged (let ((element (rxt-string "example"))) (should (equal (rxt-choice element) element))) ;; Nested choices should be flattened (should (equal (rxt-choice (rxt-choice (rxt-string "first") (rxt-string "second")) (rxt-string "third")) (rxt-choice (rxt-string "first") (rxt-string "second") (rxt-string "third")))) ;; Char sets with the same case-folding behaviour should be folded together (let* ((char-set-1 (make-rxt-char-set-union :chars '(?a ?q ?x))) (char-set-2 (make-rxt-char-set-union :chars '(?1 ?9 ?5))) (choice (rxt-choice char-set-1 char-set-2))) (should (rxt-char-set-union-p choice)) (should (rxt--char-set-equal choice (make-rxt-char-set-union :chars '(?a ?q ?x ?1 ?9 ?5))))) ;; Char-sets with different case-folding behaviour should NOT be ;; folded together (let* ((char-set-1 (make-rxt-char-set-union :chars '(?a ?b ?c) :case-fold nil)) (char-set-2 (make-rxt-char-set-union :chars '(?1 ?2 ?3) :case-fold t)) (choice (rxt-choice char-set-1 char-set-2))) (should (rxt-choice-p choice)))) ;;; Repeat ;; FIXME ;;; Character sets and case-folding (defun rxt--set-equal (a b) (null (cl-set-exclusive-or a b :test 'equal))) (defun rxt--char-set-equal (a b) (and (rxt--set-equal (rxt-char-set-union-chars a) (rxt-char-set-union-chars b)) (rxt--set-equal (rxt-char-set-union-ranges a) (rxt-char-set-union-ranges b)) (rxt--set-equal (rxt-char-set-union-classes a) (rxt-char-set-union-classes b)) (eq (rxt-char-set-union-case-fold a) (rxt-char-set-union-case-fold b)))) (ert-deftest rxt--all-char-set-union-chars () (should (rxt--set-equal (rxt--all-char-set-union-chars (make-rxt-char-set-union :chars '(?a ?x ?t))) '(?a ?x ?t))) (should (rxt--set-equal (rxt--all-char-set-union-chars (make-rxt-char-set-union :chars '(?a ?x ?t) :ranges '((?0 . ?3) (?d . ?f)))) '(?a ?x ?t ?0 ?1 ?2 ?3 ?d ?e ?f)))) (ert-deftest rxt--remove-redundant-chars () (should (rxt--set-equal (rxt--remove-redundant-chars '(?a ?q ?t ?\n) nil) '(?a ?q ?t ?\n))) (should (rxt--set-equal (rxt--remove-redundant-chars '(?a ?b ?c ?0 ?1 ?2) '(digit)) '(?a ?b ?c))) (should (rxt--set-equal (rxt--remove-redundant-chars '(?a ?b ?c ?0 ?1 ?2) '(letter)) '(?0 ?1 ?2))) (should (rxt--set-equal (rxt--remove-redundant-chars '(?a ?b ?c ?0 ?1 ?2) '(space)) '(?a ?b ?c ?0 ?1 ?2)))) (ert-deftest rxt--simplify-char-set () ;; [abcdq-z[:digit:]] is unchanged (let ((char-set (rxt--simplify-char-set (make-rxt-char-set-union :chars '(?a ?b ?c ?d) :ranges '((?q . ?z)) :classes '(digit) )))) (should (rxt--char-set-equal char-set (rxt--simplify-char-set char-set)))) ;; [abcd0-7[:alnum:]] => [[:alnum:]] (should (rxt--char-set-equal (rxt--simplify-char-set (make-rxt-char-set-union :chars '(?a ?b ?c ?d) :ranges '((?0 . ?7)) :classes '(alnum))) (make-rxt-char-set-union :classes '(alnum)))) ;; [abcda-z0-9] => [a-z0-9] (should (rxt--char-set-equal (rxt--simplify-char-set (make-rxt-char-set-union :chars '(?a ?b ?c ?d) :ranges '((?a . ?z) (?0 . ?9)))) (make-rxt-char-set-union :ranges '((?a . ?z) (?0 . ?9))))) ;; [g-za-f0-95-9] => [a-z0-9] (should (rxt--char-set-equal (rxt--simplify-char-set (make-rxt-char-set-union :ranges '((?g . ?z) (?a . ?f) (?0 . ?9) (?5 . ?9)))) (make-rxt-char-set-union :ranges '((?a . ?z) (?0 . ?9))))) ;; Two-character ranges are unchanged (let ((char-set (make-rxt-char-set-union :chars '(?a ?b ?8 ?9)))) (should (rxt--char-set-equal char-set (rxt--simplify-char-set char-set))))) (ert-deftest rxt--simplify-char-set-case-fold () ;; /[[:digit:][:space:]]/i => [[:digit:][:space:]] (let ((char-set (make-rxt-char-set-union :classes '(digit space)))) (should (rxt--char-set-equal char-set (rxt--simplify-char-set char-set t)))) ;; /[ad]/i => [ADad] (should (rxt--char-set-equal (rxt--simplify-char-set (make-rxt-char-set-union :chars '(?a ?d)) t) (make-rxt-char-set-union :chars '(?a ?d ?A ?D)))) ;; /[abcd]/i => [A-Da-d] (should (rxt--char-set-equal (rxt--simplify-char-set (make-rxt-char-set-union :chars '(?a ?b ?c ?d)) t) (make-rxt-char-set-union :ranges '((?a . ?d) (?A . ?D))))) ;; /[W-c]/i => [A-CW-ca-c] (should (rxt--char-set-equal (rxt--simplify-char-set (make-rxt-char-set-union :ranges '((?W . ?c))) t) (make-rxt-char-set-union :ranges '((?W . ?c) (?A . ?C) (?w . ?z)))))) (ert-deftest rxt--extract-ranges () (should (equal (rxt--extract-ranges '()) '())) (should (equal (rxt--extract-ranges '(1)) '((1 . 1)))) (should (equal (rxt--extract-ranges '(1 1)) '((1 . 1)))) (should (equal (rxt--extract-ranges '(1 1 1)) '((1 . 1)))) (should (equal (rxt--extract-ranges '(1 2)) '((1 . 2)))) (should (equal (rxt--extract-ranges '(1 2 3)) '((1 . 3)))) (should (equal (rxt--extract-ranges '(1 2 3 4)) '((1 . 4)))) (should (equal (rxt--extract-ranges '(1 2 3 4 5)) '((1 . 5)))) (should (equal (rxt--extract-ranges '(0 1)) '((0 . 1)))) (should (equal (rxt--extract-ranges '(0 0)) '((0 . 0)))) (should (equal (rxt--extract-ranges '(0 0 0)) '((0 . 0)))) (should (equal (rxt--extract-ranges '(-2 -1 0 1 2 3 4)) '((-2 . 4)))) (should (equal (rxt--extract-ranges '(0 3 4 5)) '((0 . 0) (3 . 5)))) (should (equal (rxt--extract-ranges '(0 0 0 3 3 4 5 0 3 4 5)) '((0 . 0) (3 . 5)))) (should (equal (rxt--extract-ranges '(10 9 8 7 6 5)) '((5 . 10))))) (ert-deftest rxt-char-set-union-case-fold-1 () (should (rxt--char-set-equal (rxt-char-set-union (make-rxt-char-set-union :chars '(?a) :case-fold t) (make-rxt-char-set-union :case-fold t)) (make-rxt-char-set-union :chars '(?a) :case-fold t))) (should (rxt--char-set-equal (rxt-char-set-union ?a (make-rxt-char-set-union :case-fold t)) (make-rxt-char-set-union :chars '(?a) :case-fold t))) (should (rxt--char-set-equal (rxt-char-set-union "a" (make-rxt-char-set-union :case-fold t)) (make-rxt-char-set-union :chars '(?a) :case-fold t))) (should (rxt--char-set-equal (rxt-char-set-union (make-rxt-char-set-union :case-fold t) (rxt-string "a")) (make-rxt-char-set-union :chars '(?a) :case-fold t)))) ;;; PCRE parsing tests (ert-deftest rxt-parse-pcre-simple-string () (let* ((string "simple string") (parse (rxt-parse-pcre string))) (should (equal (rxt-string string) parse)) (should (equal (rxt-source-text parse) string)))) (ert-deftest rxt-parse-pcre-quoted-string () (cl-flet ((pcre-quote (string) (concat "\\Q" string "\\E"))) (let* ((string "Simple string without metacharacters") (re (pcre-quote string)) (parse (rxt-parse-pcre re))) (should (equal (rxt-string string) parse)) (should (equal re (rxt-source-text parse)))) (let* ((string "String $ with (( ) regexp \\ special [a-z] characters") (re (pcre-quote string)) (parse (rxt-parse-pcre re))) (should (equal (rxt-string string) parse)) (should (equal re (rxt-source-text parse)))))) ;;; Simple pcre->elisp tests ;; Regexp quoting (ert-deftest rxt-pcre-special-chars () (let* ((string "String $ with (( ) regexp \\ special [a-z] characters") (re (pcre-to-elisp (concat "(\\Q" string "\\E)")))) (should (string-match re string)) (should (equal (match-string 1 string) string)) (should (equal (match-string 0 string) string)))) ;; Grouping, alternation (ert-deftest rxt-pcre-grouping () (let ((re (pcre-to-elisp "(foo|bar)"))) (should (string-match-p re "foo")) (should (string-match-p re "bar")))) ;; Grouping and character classes (ert-deftest rxt-pcre-char-classes () (let ((re (pcre-to-elisp "(\\D*):\\s*(\\d{3,5})$")) (string "Answer: 3501")) (should (string-match re string)) (should (equal (match-string 1 string) "Answer")) (should (equal (match-string 2 string) "3501")) (should (not (string-match re "bad: 23"))) (should (not (string-match re "also bad: 944732"))))) ;;;; Weird rules for \digits (ert-deftest rxt-pcre-digits () ;; \040 is another way of writing a space (should (string-match-p (pcre-to-elisp "\\040") " ")) ;; \40 is the same, provided there are fewer than 40 previous capturing subpatterns (should (string-match-p (pcre-to-elisp "\\40") " ")) ;; \7 is always a back reference (let ((re (pcre-to-elisp "(.)(.)(.)(.)(.)(.)(.)\\s*\\7"))) (should (string-match-p re "abcdefg g")) (should (not (string-match-p re "abcdefg\th")))) ;;\11 might be a back reference, or another way of writing a tab (should (string-match-p (pcre-to-elisp "\\11") "\t")) ;; Backreferences greater than 9 are unsupported in Emacs (should-error (pcre-to-elisp "(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\11")) ;; \011 is always a tab (should (string-match-p (pcre-to-elisp "\\011") "\t")) ;; \0113 is a tab followed by the character "3" (should (string-match-p (pcre-to-elisp "\\0113") "\t3")) ;; \113 might be a back reference, otherwise the character with octal ;; code 113 (should (string-match-p (pcre-to-elisp "\\113") (char-to-string #o113))) ;; \377 might be a back reference, otherwise the byte consisting ;; entirely of 1 bits (should (string-match-p (pcre-to-elisp "\\377") (char-to-string 255))) ;; \81 is either a back reference, or a binary zero followed by the ;; two characters "8" and "1" (should (string-match-p (pcre-to-elisp "\\81") (concat (char-to-string 0) "81")))) ;; Character classes with special characters (ert-deftest rxt-pcre-escapes-in-char-classes () (let ((re (pcre-to-elisp "^[\\d\\w]*$"))) (should (string-match-p re "012foo")) (should (not (string-match-p re "numbers 847 and 23 words")))) (let ((case-fold-search t)) (should (string-match-p (pcre-to-elisp "^[\\dA-Z]*$") "235711deadbeef")))) ;; Negated specials in character classes (ert-deftest rxt-pcre-negated-char-class-escapes () (let ((re (pcre-to-elisp "^[^\\d]*$"))) (should (string-match-p re "words without numbers")) (should-not (string-match-p re "words 2 and 4 numbers 8")))) ;; Hexadecimal and octal escapes (ert-deftest rxt-pcre-hex-octal () (should (string-match-p (pcre-to-elisp "\\xab") (char-to-string #xab))) (should (string-match-p (pcre-to-elisp "[\\xab]") (char-to-string #xab))) (should (string-match-p (pcre-to-elisp "\\x{237}") (char-to-string #x237))) (should (string-match-p (pcre-to-elisp "[\\x{237}]") (char-to-string #x237))) (should (string-match-p (pcre-to-elisp "[\\177]") (char-to-string #o177))) (should (string-match-p (pcre-to-elisp "[\\7]") (char-to-string 7)))) ;; Control characters (ert-deftest rxt-pcre-control-chars () (should (string-match-p (pcre-to-elisp "\\cx") (kbd "C-x"))) (should (string-match-p (pcre-to-elisp "\\cC\\cn") (kbd "C-c C-n")))) ;; Double negation (intersection) in character classes - fixme? (ert-deftest rxt-pcre-char-set-intersection () (should (string-match-p (pcre-to-elisp "^[^\\W]*$") "foo"))) (ert-deftest rxt-quote-pcre () (string= (rxt-quote-pcre ".*[]foo+") "\\.\\*\\[\\]foo\\+")) ;; String generation (ert-deftest rxt-string-generation () (let* ((strings '("caterpillar" "cat" "catatonic" "catamaran" "carthage" "calloo" "callay")) (regexp (regexp-opt strings)) (strings* (rxt-elisp-to-strings regexp))) (should (equal nil (cl-set-exclusive-or strings strings* :test #'string=))))) ;;;; Elisp -> PCRE translation (ert-deftest rxt-pcre-repetitions () "Check that repetition and grouping have correct precedence in PCREs." (should (equal (rxt-elisp-to-pcre (rx (repeat 3 5 "c"))) "c{3,5}")) (should (equal (rxt-elisp-to-pcre (rx (repeat 3 5 "string"))) "(?:string){3,5}")) (should (equal (rxt-elisp-to-pcre (rx (* "c"))) "c*")) (should (equal (rxt-elisp-to-pcre (rx (* "string"))) "(?:string)*"))) ;; Pretty-printing / explain tests (ert-deftest rxt--print () ;; Test that lists and dotted lists are printed correctly (cl-flet ((print-to-string (form) (with-temp-buffer (rxt-print form) (buffer-string)))) (should (string= (print-to-string '(normal list)) "(normal list)")) (should (string= (print-to-string '(short-list)) "(short-list)")) (should (string= (print-to-string '(dotted . pair)) "(dotted . pair)")) (should (string= (print-to-string '(longer dotted . list)) "(longer dotted . list)")) ;; Test correct printing of some `rx' forms (should (string= (print-to-string '(? (any digit))) "(? (any digit))")) (should (string= (print-to-string '(?? (any digit))) "(?? (any digit))")) (should (string= (print-to-string '(*? "some regexp")) "(*? \"some regexp\")")) (should (string= (print-to-string '(+? "some regexp")) "(+? \"some regexp\")")) (should (string= (print-to-string '(any ?a ?q ?z)) "(any ?a ?q ?z)")) (should (string= (print-to-string '(any (?a . ?z) (?0 . ?3))) "(any (?a . ?z) (?0 . ?3))")) (should (string= (print-to-string '(repeat 2 5 ?x)) "(repeat 2 5 ?x)")) (should (string= (print-to-string '(repeat 5 (any digit))) "(repeat 5 (any digit))")))) (ert-deftest rxt--propertize-whitespace () (let ((string (rxt--propertize-whitespace "\n\t\f\r"))) (should (equal (get-text-property 0 'display string) "\\n")) (should (equal (get-text-property 1 'display string) "\\t")) (should (equal (get-text-property 2 'display string) "\\f")) (should (equal (get-text-property 3 'display string) "\\r"))) (let ((string (rxt--propertize-whitespace "String\n\twith\n\tnewlines and tabs"))) (should (equal (get-text-property 6 'display string) "\\n")) (should (equal (get-text-property 7 'display string) "\\t")) (should (equal (get-text-property 12 'display string) "\\n")) (should (equal (get-text-property 13 'display string) "\\t")))) ;;;; Test PCRE reading (ert-deftest rxt-read-delimited-pcre () (cl-flet ((read-pcre-from-string (string) (with-temp-buffer (save-excursion (insert string)) (rxt-read-delimited-pcre)))) (should (string= (read-pcre-from-string "/[a-z]/") "[a-z]")) (should (string= (read-pcre-from-string " m/\\d+/") "\\d+")) (should (string= (read-pcre-from-string " qr/embedded\\/delimiters/") "embedded\\/delimiters")) (should (string= (read-pcre-from-string " s/several\\/embedded\\/delimiters/replacement/") "several\\/embedded\\/delimiters")) (should (string= (read-pcre-from-string " s/several\\/embedded\\/delimiters/replacement\\/with\\/delimiters/") "several\\/embedded\\/delimiters")) (let ((pcre (read-pcre-from-string "/regexp/"))) (should (string= pcre "regexp"))) (let ((pcre (read-pcre-from-string "m/regexp/s"))) (should (string= pcre "(?s)regexp"))) (let ((pcre (read-pcre-from-string "s/regexp/replacement/sx"))) (should (string= pcre "(?sx)regexp"))) (let ((pcre (read-pcre-from-string "s/regexp/embedded\\/delimiters/x"))) (should (string= pcre "(?x)regexp"))))) (ert-deftest rxt--read-pcre () (when noninteractive (rxt-skip-test "Skipping interacive-only test")) (let* ((unread-command-events (string-to-list "regexp text\C-ci\C-cs\C-j")) (result (rxt--read-pcre "Test: "))) (should (string= result "(?is)regexp text"))) (let* ((unread-command-events (string-to-list "\C-ciregexp text\C-ci\C-j")) (result (rxt--read-pcre "Test: "))) (should (string= result "regexp text")))) (ert-deftest rxt--toggle-flag-string () (cl-macrolet ((should-toggle (string flag result) `(should (string= (rxt--toggle-flag-string ,string ,flag) ,result)))) (should-toggle "foo" ?x "(?x)foo") (should-toggle "(?x)foo" ?x "foo") (should-toggle "(?xi)foo" ?x "(?i)foo") (should-toggle "(?xi)foo" ?i "(?x)foo") (should-toggle "(?xi)foo" ?s "(?isx)foo"))) (defmacro rxt-with-minor-mode (mode &rest body) (declare (indent 1)) (cl-assert (symbolp mode)) (let ((saved-mode (make-symbol (concat "saved-" (symbol-name mode))))) `(let ((,saved-mode ,mode)) (unwind-protect (progn (,mode +1) ,@body) (,mode (if ,saved-mode +1 0)))))) (defmacro rxt-with-minor-modes (modes &rest body) (declare (indent 1)) (cl-assert (listp modes)) (if (null modes) (macroexp-progn body) `(rxt-with-minor-modes ,(cdr modes) (rxt-with-minor-mode ,(car modes) ,@body)))) ;;; Test for repeated searching in evil-mode (issue #19) (ert-deftest rxt-pcre-mode-evil-search () (when noninteractive (rxt-skip-test "Skipping interactive test `pcre-mode-evil-search'")) (unless (require 'evil nil t) (rxt-skip-test "Skipping `pcre-mode-evil-search' since `evil-mode' is not installed")) (cl-flet ((process-input (&rest keys) (let ((unread-command-events (listify-key-sequence (apply #'vconcat `(,@keys ,(kbd "C-M-c")))))) (recursive-edit)))) (rxt-with-minor-modes (pcre-mode evil-mode) (save-window-excursion (with-temp-buffer (insert "\n\n(this) (that) (the other)") (goto-char (point-min)) (set-window-buffer (selected-window) (current-buffer)) (process-input "/\\(th" (kbd "RET")) (should (looking-at "(this)")) (process-input "n") (should (looking-at "(that)")) (process-input "n") (should (looking-at "(the other)")) (process-input "N") (should (looking-at "(that)")) (process-input "N") (should (looking-at "(this)"))))))) ;; The following tests are adapted from the first set of tests ;; ("testinput1") in the PCRE library's test suite: see ;; http://www.pcre.org/ and the copyright notice at the beginning of ;; this file. ;; Each test converts a particular PCRE regexp to its (supposed) Elisp ;; equivalent, then compares the set of matches for the Elisp regexp ;; against the set of matches generated by Perl for a number of ;; subject strings. (The set of Perl matches to compare with was ;; statically generated by a script adapted from the PCRE test script ;; to create this file, so the tests don't actually call out to Perl). ;; Many of the tests currently fail -- a bit under half of them. This ;; obviously is not very good, but many of the failing tests are ;; features of PCRE which are not easily supported in Emacs, like the ;; (* ...) backtracking control verbs. Other failing tests are bugs ;; that might be worth fixing, so these are a good place to look for ;; anyone interested in improving the pcre->elisp code. ;; The failing tests are marked with the `:expected-result :failed' ;; property in their definitions, so the tests as a whole are still ;; useful to guard against regressions. ;; (defun rxt-all-matches (regexp input) (if (string-match regexp input) (let* ((match-count (- (/ (length (match-data)) 2) 1))) (cl-loop for i from 0 to match-count collect (match-string i input))) nil)) (defmacro rxt-match-test (regexp input perl-matches) `(should (equal (rxt-all-matches ,regexp ,input) ,perl-matches))) (ert-deftest rxt-pcre-test-00002 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "the quick brown fox" ""))) (rxt-match-test regexp "the quick brown fox" '("the quick brown fox")) (rxt-match-test regexp "The quick brown FOX" 'nil) (rxt-match-test regexp "What do you know about the quick brown fox?" '("the quick brown fox")) (rxt-match-test regexp "What do you know about THE QUICK BROWN FOX?" 'nil))) (ert-deftest rxt-pcre-test-00003 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "The quick brown fox" "i"))) (rxt-match-test regexp "the quick brown fox" '("the quick brown fox")) (rxt-match-test regexp "The quick brown FOX" '("The quick brown FOX")) (rxt-match-test regexp "What do you know about the quick brown fox?" '("the quick brown fox")) (rxt-match-test regexp "What do you know about THE QUICK BROWN FOX?" '("THE QUICK BROWN FOX")))) (ert-deftest rxt-pcre-test-00004 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abcd\\t\\n\\r\\f\\a\\e\\071\\x3b\\$\\\\\\?caxyz" ""))) (rxt-match-test regexp "abcd \n \f9;$\\?caxyz" '("abcd \n \f9;$\\?caxyz")))) (ert-deftest rxt-pcre-test-00005 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz" ""))) (rxt-match-test regexp "abxyzpqrrrabbxyyyypqAzz" '("abxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "abxyzpqrrrabbxyyyypqAzz" '("abxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aabxyzpqrrrabbxyyyypqAzz" '("aabxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaabxyzpqrrrabbxyyyypqAzz" '("aaabxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaaabxyzpqrrrabbxyyyypqAzz" '("aaaabxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "abcxyzpqrrrabbxyyyypqAzz" '("abcxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aabcxyzpqrrrabbxyyyypqAzz" '("aabcxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypAzz" '("aaabcxyzpqrrrabbxyyyypAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypqAzz" '("aaabcxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypqqAzz" '("aaabcxyzpqrrrabbxyyyypqqAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypqqqAzz" '("aaabcxyzpqrrrabbxyyyypqqqAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypqqqqAzz" '("aaabcxyzpqrrrabbxyyyypqqqqAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypqqqqqAzz" '("aaabcxyzpqrrrabbxyyyypqqqqqAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypqqqqqqAzz" '("aaabcxyzpqrrrabbxyyyypqqqqqqAzz")) (rxt-match-test regexp "aaaabcxyzpqrrrabbxyyyypqAzz" '("aaaabcxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "abxyzzpqrrrabbxyyyypqAzz" '("abxyzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aabxyzzzpqrrrabbxyyyypqAzz" '("aabxyzzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaabxyzzzzpqrrrabbxyyyypqAzz" '("aaabxyzzzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaaabxyzzzzpqrrrabbxyyyypqAzz" '("aaaabxyzzzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "abcxyzzpqrrrabbxyyyypqAzz" '("abcxyzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aabcxyzzzpqrrrabbxyyyypqAzz" '("aabcxyzzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaabcxyzzzzpqrrrabbxyyyypqAzz" '("aaabcxyzzzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaaabcxyzzzzpqrrrabbxyyyypqAzz" '("aaaabcxyzzzzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "aaaabcxyzzzzpqrrrabbbxyyyypqAzz" '("aaaabcxyzzzzpqrrrabbbxyyyypqAzz")) (rxt-match-test regexp "aaaabcxyzzzzpqrrrabbbxyyyyypqAzz" '("aaaabcxyzzzzpqrrrabbbxyyyyypqAzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypABzz" '("aaabcxyzpqrrrabbxyyyypABzz")) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypABBzz" '("aaabcxyzpqrrrabbxyyyypABBzz")) (rxt-match-test regexp ">>>aaabxyzpqrrrabbxyyyypqAzz" '("aaabxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp ">aaaabxyzpqrrrabbxyyyypqAzz" '("aaaabxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp ">>>>abcxyzpqrrrabbxyyyypqAzz" '("abcxyzpqrrrabbxyyyypqAzz")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abxyzpqrrabbxyyyypqAzz" 'nil) (rxt-match-test regexp "abxyzpqrrrrabbxyyyypqAzz" 'nil) (rxt-match-test regexp "abxyzpqrrrabxyyyypqAzz" 'nil) (rxt-match-test regexp "aaaabcxyzzzzpqrrrabbbxyyyyyypqAzz" 'nil) (rxt-match-test regexp "aaaabcxyzzzzpqrrrabbbxyyypqAzz" 'nil) (rxt-match-test regexp "aaabcxyzpqrrrabbxyyyypqqqqqqqAzz" 'nil))) (ert-deftest rxt-pcre-test-00006 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(abc){1,2}zz" ""))) (rxt-match-test regexp "abczz" '("abczz" "abc")) (rxt-match-test regexp "abcabczz" '("abcabczz" "abc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "zz" 'nil) (rxt-match-test regexp "abcabcabczz" 'nil) (rxt-match-test regexp ">>abczz" 'nil))) (ert-deftest rxt-pcre-test-00007 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(b+?|a){1,2}?c" ""))) (rxt-match-test regexp "bc" '("bc" "b")) (rxt-match-test regexp "bbc" '("bbc" "b")) (rxt-match-test regexp "bbbc" '("bbbc" "bb")) (rxt-match-test regexp "bac" '("bac" "a")) (rxt-match-test regexp "bbac" '("bbac" "a")) (rxt-match-test regexp "aac" '("aac" "a")) (rxt-match-test regexp "abbbbbbbbbbbc" '("abbbbbbbbbbbc" "bbbbbbbbbbb")) (rxt-match-test regexp "bbbbbbbbbbbac" '("bbbbbbbbbbbac" "a")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aaac" 'nil) (rxt-match-test regexp "abbbbbbbbbbbac" 'nil))) (ert-deftest rxt-pcre-test-00008 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(b+|a){1,2}c" ""))) (rxt-match-test regexp "bc" '("bc" "b")) (rxt-match-test regexp "bbc" '("bbc" "bb")) (rxt-match-test regexp "bbbc" '("bbbc" "bbb")) (rxt-match-test regexp "bac" '("bac" "a")) (rxt-match-test regexp "bbac" '("bbac" "a")) (rxt-match-test regexp "aac" '("aac" "a")) (rxt-match-test regexp "abbbbbbbbbbbc" '("abbbbbbbbbbbc" "bbbbbbbbbbb")) (rxt-match-test regexp "bbbbbbbbbbbac" '("bbbbbbbbbbbac" "a")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aaac" 'nil) (rxt-match-test regexp "abbbbbbbbbbbac" 'nil))) (ert-deftest rxt-pcre-test-00009 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(b+|a){1,2}?bc" ""))) (rxt-match-test regexp "bbc" '("bbc" "b")))) (ert-deftest rxt-pcre-test-00010 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(b*|ba){1,2}?bc" ""))) (rxt-match-test regexp "babc" '("babc" "ba")) (rxt-match-test regexp "bbabc" '("bbabc" "ba")) (rxt-match-test regexp "bababc" '("bababc" "ba")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "bababbc" 'nil) (rxt-match-test regexp "babababc" 'nil))) (ert-deftest rxt-pcre-test-00011 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(ba|b*){1,2}?bc" ""))) (rxt-match-test regexp "babc" '("babc" "ba")) (rxt-match-test regexp "bbabc" '("bbabc" "ba")) (rxt-match-test regexp "bababc" '("bababc" "ba")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "bababbc" 'nil) (rxt-match-test regexp "babababc" 'nil))) (ert-deftest rxt-pcre-test-00012 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\ca\\cA\\c[\\c{\\c:" ""))) (rxt-match-test regexp ";z" '(";z")))) (ert-deftest rxt-pcre-test-00013 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[ab\\]cde]" ""))) (rxt-match-test regexp "athing" '("a")) (rxt-match-test regexp "bthing" '("b")) (rxt-match-test regexp "]thing" '("]")) (rxt-match-test regexp "cthing" '("c")) (rxt-match-test regexp "dthing" '("d")) (rxt-match-test regexp "ething" '("e")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "fthing" 'nil) (rxt-match-test regexp "[thing" 'nil) (rxt-match-test regexp "\\thing" 'nil))) (ert-deftest rxt-pcre-test-00014 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[]cde]" ""))) (rxt-match-test regexp "]thing" '("]")) (rxt-match-test regexp "cthing" '("c")) (rxt-match-test regexp "dthing" '("d")) (rxt-match-test regexp "ething" '("e")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "athing" 'nil) (rxt-match-test regexp "fthing" 'nil))) (ert-deftest rxt-pcre-test-00015 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[^ab\\]cde]" ""))) (rxt-match-test regexp "fthing" '("f")) (rxt-match-test regexp "[thing" '("[")) (rxt-match-test regexp "\\thing" '("\\")) (rxt-match-test regexp "*** Failers" '("*")) (rxt-match-test regexp "athing" 'nil) (rxt-match-test regexp "bthing" 'nil) (rxt-match-test regexp "]thing" 'nil) (rxt-match-test regexp "cthing" 'nil) (rxt-match-test regexp "dthing" 'nil) (rxt-match-test regexp "ething" 'nil))) (ert-deftest rxt-pcre-test-00016 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[^]cde]" ""))) (rxt-match-test regexp "athing" '("a")) (rxt-match-test regexp "fthing" '("f")) (rxt-match-test regexp "*** Failers" '("*")) (rxt-match-test regexp "]thing" 'nil) (rxt-match-test regexp "cthing" 'nil) (rxt-match-test regexp "dthing" 'nil) (rxt-match-test regexp "ething" 'nil))) (ert-deftest rxt-pcre-test-00017 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\\201" ""))) (rxt-match-test regexp "\201" '("\201")))) (ert-deftest rxt-pcre-test-00018 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\377" ""))) (rxt-match-test regexp "\377" '("\377")))) (ert-deftest rxt-pcre-test-00019 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[0-9]+$" ""))) (rxt-match-test regexp "0" '("0")) (rxt-match-test regexp "1" '("1")) (rxt-match-test regexp "2" '("2")) (rxt-match-test regexp "3" '("3")) (rxt-match-test regexp "4" '("4")) (rxt-match-test regexp "5" '("5")) (rxt-match-test regexp "6" '("6")) (rxt-match-test regexp "7" '("7")) (rxt-match-test regexp "8" '("8")) (rxt-match-test regexp "9" '("9")) (rxt-match-test regexp "10" '("10")) (rxt-match-test regexp "100" '("100")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abc" 'nil))) (ert-deftest rxt-pcre-test-00020 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*nter" ""))) (rxt-match-test regexp "enter" '("enter")) (rxt-match-test regexp "inter" '("inter")) (rxt-match-test regexp "uponter" '("uponter")))) (ert-deftest rxt-pcre-test-00021 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^xxx[0-9]+$" ""))) (rxt-match-test regexp "xxx0" '("xxx0")) (rxt-match-test regexp "xxx1234" '("xxx1234")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "xxx" 'nil))) (ert-deftest rxt-pcre-test-00022 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.+[0-9][0-9][0-9]$" ""))) (rxt-match-test regexp "x123" '("x123")) (rxt-match-test regexp "xx123" '("xx123")) (rxt-match-test regexp "123456" '("123456")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123" 'nil) (rxt-match-test regexp "x1234" '("x1234")))) (ert-deftest rxt-pcre-test-00023 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.+?[0-9][0-9][0-9]$" ""))) (rxt-match-test regexp "x123" '("x123")) (rxt-match-test regexp "xx123" '("xx123")) (rxt-match-test regexp "123456" '("123456")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123" 'nil) (rxt-match-test regexp "x1234" '("x1234")))) (ert-deftest rxt-pcre-test-00024 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^([^!]+)!(.+)=apquxz\\.ixr\\.zzz\\.ac\\.uk$" ""))) (rxt-match-test regexp "abc!pqr=apquxz.ixr.zzz.ac.uk" '("abc!pqr=apquxz.ixr.zzz.ac.uk" "abc" "pqr")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "!pqr=apquxz.ixr.zzz.ac.uk" 'nil) (rxt-match-test regexp "abc!=apquxz.ixr.zzz.ac.uk" 'nil) (rxt-match-test regexp "abc!pqr=apquxz:ixr.zzz.ac.uk" 'nil) (rxt-match-test regexp "abc!pqr=apquxz.ixr.zzz.ac.ukk" 'nil))) (ert-deftest rxt-pcre-test-00025 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ":" ""))) (rxt-match-test regexp "Well, we need a colon: somewhere" '(":")) (rxt-match-test regexp "*** Fail if we don't" 'nil))) (ert-deftest rxt-pcre-test-00026 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([\\da-f:]+)$" "i"))) (rxt-match-test regexp "0abc" '("0abc" "0abc")) (rxt-match-test regexp "abc" '("abc" "abc")) (rxt-match-test regexp "fed" '("fed" "fed")) (rxt-match-test regexp "E" '("E" "E")) (rxt-match-test regexp "::" '("::" "::")) (rxt-match-test regexp "5f03:12C0::932e" '("5f03:12C0::932e" "5f03:12C0::932e")) (rxt-match-test regexp "fed def" '("def" "def")) (rxt-match-test regexp "Any old stuff" '("ff" "ff")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "0zzz" 'nil) (rxt-match-test regexp "gzzz" 'nil) (rxt-match-test regexp "fed " 'nil) (rxt-match-test regexp "Any old rubbish" 'nil))) (ert-deftest rxt-pcre-test-00027 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$" ""))) (rxt-match-test regexp ".1.2.3" '(".1.2.3" "1" "2" "3")) (rxt-match-test regexp "A.12.123.0" '("A.12.123.0" "12" "123" "0")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp ".1.2.3333" 'nil) (rxt-match-test regexp "1.2.3" 'nil) (rxt-match-test regexp "1234.2.3" 'nil))) (ert-deftest rxt-pcre-test-00028 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(\\d+)\\s+IN\\s+SOA\\s+(\\S+)\\s+(\\S+)\\s*\\(\\s*$" ""))) (rxt-match-test regexp "1 IN SOA non-sp1 non-sp2(" '("1 IN SOA non-sp1 non-sp2(" "1" "non-sp1" "non-sp2")) (rxt-match-test regexp "1 IN SOA non-sp1 non-sp2 (" '("1 IN SOA non-sp1 non-sp2 (" "1" "non-sp1" "non-sp2")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "1IN SOA non-sp1 non-sp2(" 'nil))) (ert-deftest rxt-pcre-test-00029 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[a-zA-Z\\d][a-zA-Z\\d\\-]*(\\.[a-zA-Z\\d][a-zA-z\\d\\-]*)*\\.$" ""))) (rxt-match-test regexp "a." '("a.")) (rxt-match-test regexp "Z." '("Z.")) (rxt-match-test regexp "2." '("2.")) (rxt-match-test regexp "ab-c.pq-r." '("ab-c.pq-r." ".pq-r")) (rxt-match-test regexp "sxk.zzz.ac.uk." '("sxk.zzz.ac.uk." ".uk")) (rxt-match-test regexp "x-.y-." '("x-.y-." ".y-")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "-abc.peq." 'nil))) (ert-deftest rxt-pcre-test-00030 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\*\\.[a-z]([a-z\\-\\d]*[a-z\\d]+)?(\\.[a-z]([a-z\\-\\d]*[a-z\\d]+)?)*$" ""))) (rxt-match-test regexp "*.a" '("*.a")) (rxt-match-test regexp "*.b0-a" '("*.b0-a" "0-a")) (rxt-match-test regexp "*.c3-b.c" '("*.c3-b.c" "3-b" ".c")) (rxt-match-test regexp "*.c-a.b-c" '("*.c-a.b-c" "-a" ".b-c" "-c")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "*.0" 'nil) (rxt-match-test regexp "*.a-" 'nil) (rxt-match-test regexp "*.a-b.c-" 'nil) (rxt-match-test regexp "*.c-a.0-c" 'nil))) (ert-deftest rxt-pcre-test-00031 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=ab(de))(abd)(e)" ""))) (rxt-match-test regexp "abde" '("abde" "de" "abd" "e")))) (ert-deftest rxt-pcre-test-00032 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?!(ab)de|x)(abd)(f)" ""))) (rxt-match-test regexp "abdf" '("abdf" nil "abd" "f")))) (ert-deftest rxt-pcre-test-00033 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=(ab(cd)))(ab)" ""))) (rxt-match-test regexp "abcd" '("ab" "abcd" "cd" "ab")))) (ert-deftest rxt-pcre-test-00034 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[\\da-f](\\.[\\da-f])*$" "i"))) (rxt-match-test regexp "a.b.c.d" '("a.b.c.d" ".d")) (rxt-match-test regexp "A.B.C.D" '("A.B.C.D" ".D")) (rxt-match-test regexp "a.b.c.1.2.3.C" '("a.b.c.1.2.3.C" ".C")))) (ert-deftest rxt-pcre-test-00035 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\\".*\\\"\\s*(;.*)?$" ""))) (rxt-match-test regexp "\"1234\"" '("\"1234\"")) (rxt-match-test regexp "\"abcd\" ;" '("\"abcd\" ;" ";")) (rxt-match-test regexp "\"\" ; rhubarb" '("\"\" ; rhubarb" "; rhubarb")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "\"1234\" : things" 'nil))) (ert-deftest rxt-pcre-test-00036 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^$" ""))) (rxt-match-test regexp "" '("")) (rxt-match-test regexp "*** Failers" 'nil))) (ert-deftest rxt-pcre-test-00037 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp " ^ a (?# begins with a) b\\sc (?# then b c) $ (?# then end)" "x"))) (rxt-match-test regexp "ab c" '("ab c")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abc" 'nil) (rxt-match-test regexp "ab cde" 'nil))) (ert-deftest rxt-pcre-test-00038 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?x) ^ a (?# begins with a) b\\sc (?# then b c) $ (?# then end)" ""))) (rxt-match-test regexp "ab c" '("ab c")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abc" 'nil) (rxt-match-test regexp "ab cde" 'nil))) (ert-deftest rxt-pcre-test-00039 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^ a\\ b[c ]d $" "x"))) (rxt-match-test regexp "a bcd" '("a bcd")) (rxt-match-test regexp "a b d" '("a b d")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcd" 'nil) (rxt-match-test regexp "ab d" 'nil))) (ert-deftest rxt-pcre-test-00040 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a(b(c)))(d(e(f)))(h(i(j)))(k(l(m)))$" ""))) (rxt-match-test regexp "abcdefhijklm" '("abcdefhijklm" "abc" "bc" "c" "def" "ef" "f" "hij" "ij" "j" "klm" "lm" "m")))) (ert-deftest rxt-pcre-test-00041 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:a(b(c)))(?:d(e(f)))(?:h(i(j)))(?:k(l(m)))$" ""))) (rxt-match-test regexp "abcdefhijklm" '("abcdefhijklm" "bc" "c" "ef" "f" "ij" "j" "lm" "m")))) (ert-deftest rxt-pcre-test-00042 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[\\w][\\W][\\s][\\S][\\d][\\D][\\b][\\n][\\c]][\\022]" ""))) (rxt-match-test regexp "a+ Z0+\n" '("a+ Z0+\n")))) (ert-deftest rxt-pcre-test-00043 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[.^$|()*+?{,}]+" ""))) (rxt-match-test regexp ".^$(*+)|{?,?}" '(".^$(*+)|{?,?}")))) (ert-deftest rxt-pcre-test-00044 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^a*\\w" ""))) (rxt-match-test regexp "z" '("z")) (rxt-match-test regexp "az" '("az")) (rxt-match-test regexp "aaaz" '("aaaz")) (rxt-match-test regexp "a" '("a")) (rxt-match-test regexp "aa" '("aa")) (rxt-match-test regexp "aaaa" '("aaaa")) (rxt-match-test regexp "a+" '("a")) (rxt-match-test regexp "aa+" '("aa")))) (ert-deftest rxt-pcre-test-00045 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^a*?\\w" ""))) (rxt-match-test regexp "z" '("z")) (rxt-match-test regexp "az" '("a")) (rxt-match-test regexp "aaaz" '("a")) (rxt-match-test regexp "a" '("a")) (rxt-match-test regexp "aa" '("a")) (rxt-match-test regexp "aaaa" '("a")) (rxt-match-test regexp "a+" '("a")) (rxt-match-test regexp "aa+" '("a")))) (ert-deftest rxt-pcre-test-00046 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^a+\\w" ""))) (rxt-match-test regexp "az" '("az")) (rxt-match-test regexp "aaaz" '("aaaz")) (rxt-match-test regexp "aa" '("aa")) (rxt-match-test regexp "aaaa" '("aaaa")) (rxt-match-test regexp "aa+" '("aa")))) (ert-deftest rxt-pcre-test-00047 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^a+?\\w" ""))) (rxt-match-test regexp "az" '("az")) (rxt-match-test regexp "aaaz" '("aa")) (rxt-match-test regexp "aa" '("aa")) (rxt-match-test regexp "aaaa" '("aa")) (rxt-match-test regexp "aa+" '("aa")))) (ert-deftest rxt-pcre-test-00048 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\d{8}\\w{2,}" ""))) (rxt-match-test regexp "1234567890" '("1234567890")) (rxt-match-test regexp "12345678ab" '("12345678ab")) (rxt-match-test regexp "12345678__" '("12345678__")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "1234567" 'nil))) (ert-deftest rxt-pcre-test-00049 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[aeiou\\d]{4,5}$" ""))) (rxt-match-test regexp "uoie" '("uoie")) (rxt-match-test regexp "1234" '("1234")) (rxt-match-test regexp "12345" '("12345")) (rxt-match-test regexp "aaaaa" '("aaaaa")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123456" 'nil))) (ert-deftest rxt-pcre-test-00050 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[aeiou\\d]{4,5}?" ""))) (rxt-match-test regexp "uoie" '("uoie")) (rxt-match-test regexp "1234" '("1234")) (rxt-match-test regexp "12345" '("1234")) (rxt-match-test regexp "aaaaa" '("aaaa")) (rxt-match-test regexp "123456" '("1234")))) (ert-deftest rxt-pcre-test-00051 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A(abc|def)=(\\1){2,3}\\Z" ""))) (rxt-match-test regexp "abc=abcabc" '("abc=abcabc" "abc" "abc")) (rxt-match-test regexp "def=defdefdef" '("def=defdefdef" "def" "def")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abc=defdef" 'nil))) (ert-deftest rxt-pcre-test-00052 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)\\11*(\\3\\4)\\1(?#)2$" ""))) (rxt-match-test regexp "abcdefghijkcda2" '("abcdefghijkcda2" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "cd")) (rxt-match-test regexp "abcdefghijkkkkcda2" '("abcdefghijkkkkcda2" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "cd")))) (ert-deftest rxt-pcre-test-00053 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(cat(a(ract|tonic)|erpillar)) \\1()2(3)" ""))) (rxt-match-test regexp "cataract cataract23" '("cataract cataract23" "cataract" "aract" "ract" "" "3")) (rxt-match-test regexp "catatonic catatonic23" '("catatonic catatonic23" "catatonic" "atonic" "tonic" "" "3")) (rxt-match-test regexp "caterpillar caterpillar23" '("caterpillar caterpillar23" "caterpillar" "erpillar" nil "" "3")))) (ert-deftest rxt-pcre-test-00054 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^From +([^ ]+) +[a-zA-Z][a-zA-Z][a-zA-Z] +[a-zA-Z][a-zA-Z][a-zA-Z] +[0-9]?[0-9] +[0-9][0-9]:[0-9][0-9]" ""))) (rxt-match-test regexp "From abcd Mon Sep 01 12:33:02 1997" '("From abcd Mon Sep 01 12:33" "abcd")))) (ert-deftest rxt-pcre-test-00055 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^From\\s+\\S+\\s+([a-zA-Z]{3}\\s+){2}\\d{1,2}\\s+\\d\\d:\\d\\d" ""))) (rxt-match-test regexp "From abcd Mon Sep 01 12:33:02 1997" '("From abcd Mon Sep 01 12:33" "Sep ")) (rxt-match-test regexp "From abcd Mon Sep 1 12:33:02 1997" '("From abcd Mon Sep 1 12:33" "Sep ")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "From abcd Sep 01 12:33:02 1997" 'nil))) (ert-deftest rxt-pcre-test-00056 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^12.34" "s"))) (rxt-match-test regexp "12\n34" '("12\n34")) (rxt-match-test regexp "12 34" '("12 34")))) (ert-deftest rxt-pcre-test-00057 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\w+(?=\\t)" ""))) (rxt-match-test regexp "the quick brown fox" '("brown")))) (ert-deftest rxt-pcre-test-00058 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "foo(?!bar)(.*)" ""))) (rxt-match-test regexp "foobar is foolish see?" '("foolish see?" "lish see?")))) (ert-deftest rxt-pcre-test-00059 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(?!foo)...|^.{0,2})bar(.*)" ""))) (rxt-match-test regexp "foobar crowbar etc" '("rowbar etc" " etc")) (rxt-match-test regexp "barrel" '("barrel" "rel")) (rxt-match-test regexp "2barrel" '("2barrel" "rel")) (rxt-match-test regexp "A barrel" '("A barrel" "rel")))) (ert-deftest rxt-pcre-test-00060 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(\\D*)(?=\\d)(?!123)" ""))) (rxt-match-test regexp "abc456" '("abc" "abc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abc123" 'nil))) (ert-deftest rxt-pcre-test-00061 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^1234(?# test newlines\n inside)" ""))) (rxt-match-test regexp "1234" '("1234")))) (ert-deftest rxt-pcre-test-00062 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^1234 #comment in extended re\n " "x"))) (rxt-match-test regexp "1234" '("1234")))) (ert-deftest rxt-pcre-test-00063 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "#rhubarb\n abcd" "x"))) (rxt-match-test regexp "abcd" '("abcd")))) (ert-deftest rxt-pcre-test-00064 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^abcd#rhubarb" "x"))) (rxt-match-test regexp "abcd" '("abcd")))) (ert-deftest rxt-pcre-test-00065 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)\\1{2,3}(.)" ""))) (rxt-match-test regexp "aaab" '("aaab" "a" "b")) (rxt-match-test regexp "aaaab" '("aaaab" "a" "b")) (rxt-match-test regexp "aaaaab" '("aaaaa" "a" "a")) (rxt-match-test regexp "aaaaaab" '("aaaaa" "a" "a")))) (ert-deftest rxt-pcre-test-00066 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?!^)abc" ""))) (rxt-match-test regexp "the abc" '("abc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abc" 'nil))) (ert-deftest rxt-pcre-test-00067 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=^)abc" ""))) (rxt-match-test regexp "abc" '("abc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "the abc" 'nil))) (ert-deftest rxt-pcre-test-00068 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[ab]{1,3}(ab*|b)" ""))) (rxt-match-test regexp "aabbbbb" '("aabb" "b")))) (ert-deftest rxt-pcre-test-00069 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[ab]{1,3}?(ab*|b)" ""))) (rxt-match-test regexp "aabbbbb" '("aabbbbb" "abbbbb")))) (ert-deftest rxt-pcre-test-00070 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[ab]{1,3}?(ab*?|b)" ""))) (rxt-match-test regexp "aabbbbb" '("aa" "a")))) (ert-deftest rxt-pcre-test-00071 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[ab]{1,3}(ab*?|b)" ""))) (rxt-match-test regexp "aabbbbb" '("aabb" "b")))) (ert-deftest rxt-pcre-test-00072 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp " (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* # optional leading comment\n(?: (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\" (?: # opening quote...\n[^\\\\\\x80-\\xff\\n\\015\"] # Anything except backslash and quote\n| # or\n\\\\ [^\\x80-\\xff] # Escaped something (something != CR)\n)* \" # closing quote\n) # initial word\n(?: (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* \\. (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\" (?: # opening quote...\n[^\\\\\\x80-\\xff\\n\\015\"] # Anything except backslash and quote\n| # or\n\\\\ [^\\x80-\\xff] # Escaped something (something != CR)\n)* \" # closing quote\n) )* # further okay, if led by a period\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* @ (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # initial subdomain\n(?: #\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* \\. # if led by a period...\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # ...further okay\n)*\n# address\n| # or\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\" (?: # opening quote...\n[^\\\\\\x80-\\xff\\n\\015\"] # Anything except backslash and quote\n| # or\n\\\\ [^\\x80-\\xff] # Escaped something (something != CR)\n)* \" # closing quote\n) # one word, optionally followed by....\n(?:\n[^()<>@,;:\".\\\\\\[\\]\\x80-\\xff\\000-\\010\\012-\\037] | # atom and space parts, or...\n\\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) | # comments, or...\n\n\" (?: # opening quote...\n[^\\\\\\x80-\\xff\\n\\015\"] # Anything except backslash and quote\n| # or\n\\\\ [^\\x80-\\xff] # Escaped something (something != CR)\n)* \" # closing quote\n# quoted strings\n)*\n< (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* # leading <\n(?: @ (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # initial subdomain\n(?: #\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* \\. # if led by a period...\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # ...further okay\n)*\n\n(?: (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* , (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* @ (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # initial subdomain\n(?: #\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* \\. # if led by a period...\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # ...further okay\n)*\n)* # further okay, if led by comma\n: # closing colon\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* )? # optional route\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\" (?: # opening quote...\n[^\\\\\\x80-\\xff\\n\\015\"] # Anything except backslash and quote\n| # or\n\\\\ [^\\x80-\\xff] # Escaped something (something != CR)\n)* \" # closing quote\n) # initial word\n(?: (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* \\. (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\" (?: # opening quote...\n[^\\\\\\x80-\\xff\\n\\015\"] # Anything except backslash and quote\n| # or\n\\\\ [^\\x80-\\xff] # Escaped something (something != CR)\n)* \" # closing quote\n) )* # further okay, if led by a period\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* @ (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # initial subdomain\n(?: #\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* \\. # if led by a period...\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* (?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n| \\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n) # ...further okay\n)*\n# address spec\n(?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* > # trailing >\n# name and address\n) (?: [\\040\\t] | \\(\n(?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] | \\( (?: [^\\\\\\x80-\\xff\\n\\015()] | \\\\ [^\\x80-\\xff] )* \\) )*\n\\) )* # optional trailing comment\n" "x"))) (rxt-match-test regexp "Alan Other " '("Alan Other ")) (rxt-match-test regexp "" '("user@dom.ain")) (rxt-match-test regexp "user@dom.ain" '("user@dom.ain")) (rxt-match-test regexp "\"A. Other\" (a comment)" '("\"A. Other\" (a comment)")) (rxt-match-test regexp "A. Other (a comment)" '(" Other (a comment)")) (rxt-match-test regexp "\"/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/\"@x400-re.lay" '("\"/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/\"@x400-re.lay")) (rxt-match-test regexp "A missing angle @,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n# Atom\n| # or\n\" # \"\n[^\\\\\\x80-\\xff\\n\\015\"] * # normal\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015\"] * )* # ( special normal* )*\n\" # \"\n# Quoted string\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n\\.\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n# Atom\n| # or\n\" # \"\n[^\\\\\\x80-\\xff\\n\\015\"] * # normal\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015\"] * )* # ( special normal* )*\n\" # \"\n# Quoted string\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# additional words\n)*\n@\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n(?:\n\\.\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n)*\n# address\n| # or\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n# Atom\n| # or\n\" # \"\n[^\\\\\\x80-\\xff\\n\\015\"] * # normal\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015\"] * )* # ( special normal* )*\n\" # \"\n# Quoted string\n)\n# leading word\n[^()<>@,;:\".\\\\\\[\\]\\x80-\\xff\\000-\\010\\012-\\037] * # \"normal\" atoms and or spaces\n(?:\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n|\n\" # \"\n[^\\\\\\x80-\\xff\\n\\015\"] * # normal\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015\"] * )* # ( special normal* )*\n\" # \"\n) # \"special\" comment or quoted string\n[^()<>@,;:\".\\\\\\[\\]\\x80-\\xff\\000-\\010\\012-\\037] * # more \"normal\"\n)*\n<\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# <\n(?:\n@\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n(?:\n\\.\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n)*\n(?: ,\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n@\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n(?:\n\\.\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n)*\n)* # additional domains\n:\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n)? # optional route\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n# Atom\n| # or\n\" # \"\n[^\\\\\\x80-\\xff\\n\\015\"] * # normal\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015\"] * )* # ( special normal* )*\n\" # \"\n# Quoted string\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n\\.\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n# Atom\n| # or\n\" # \"\n[^\\\\\\x80-\\xff\\n\\015\"] * # normal\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015\"] * )* # ( special normal* )*\n\" # \"\n# Quoted string\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# additional words\n)*\n@\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n(?:\n\\.\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n(?:\n[^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]+ # some number of atom characters...\n(?![^(\\040)<>@,;:\".\\\\\\[\\]\\000-\\037\\x80-\\xff]) # ..not followed by something that could be part of an atom\n|\n\\[ # [\n(?: [^\\\\\\x80-\\xff\\n\\015\\[\\]] | \\\\ [^\\x80-\\xff] )* # stuff\n\\] # ]\n)\n[\\040\\t]* # Nab whitespace.\n(?:\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: # (\n(?: \\\\ [^\\x80-\\xff] |\n\\( # (\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n(?: \\\\ [^\\x80-\\xff] [^\\\\\\x80-\\xff\\n\\015()] * )* # (special normal*)*\n\\) # )\n) # special\n[^\\\\\\x80-\\xff\\n\\015()] * # normal*\n)* # )*\n\\) # )\n[\\040\\t]* )* # If comment found, allow more spaces.\n# optional trailing comments\n)*\n# address spec\n> # >\n# name and address\n)\n" "x"))) (rxt-match-test regexp "Alan Other " '("Alan Other ")) (rxt-match-test regexp "" '("user@dom.ain")) (rxt-match-test regexp "user@dom.ain" '("user@dom.ain")) (rxt-match-test regexp "\"A. Other\" (a comment)" '("\"A. Other\" ")) (rxt-match-test regexp "A. Other (a comment)" '(" Other ")) (rxt-match-test regexp "\"/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/\"@x400-re.lay" '("\"/s=user/ou=host/o=place/prmd=uu.yy/admd= /c=gb/\"@x400-re.lay")) (rxt-match-test regexp "A missing angle ?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377" '(" \n \f  !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377")))) (ert-deftest rxt-pcre-test-00145 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "P[^*]TAIRE[^*]{1,6}?LL" ""))) (rxt-match-test regexp "xxxxxxxxxxxPSTAIREISLLxxxxxxxxx" '("PSTAIREISLL")))) (ert-deftest rxt-pcre-test-00146 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "P[^*]TAIRE[^*]{1,}?LL" ""))) (rxt-match-test regexp "xxxxxxxxxxxPSTAIREISLLxxxxxxxxx" '("PSTAIREISLL")))) (ert-deftest rxt-pcre-test-00147 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(\\.\\d\\d[1-9]?)\\d+" ""))) (rxt-match-test regexp "1.230003938" '(".230003938" ".23")) (rxt-match-test regexp "1.875000282" '(".875000282" ".875")) (rxt-match-test regexp "1.235" '(".235" ".23")))) (ert-deftest rxt-pcre-test-00148 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(\\.\\d\\d((?=0)|\\d(?=\\d)))" ""))) (rxt-match-test regexp "1.230003938" '(".23" ".23" "")) (rxt-match-test regexp "1.875000282" '(".875" ".875" "5")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "1.235" 'nil))) (ert-deftest rxt-pcre-test-00149 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(?)b" ""))) (rxt-match-test regexp "ab" '("ab")))) (ert-deftest rxt-pcre-test-00150 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\b(foo)\\s+(\\w+)" "i"))) (rxt-match-test regexp "Food is on the foo table" '("foo table" "foo" "table")))) (ert-deftest rxt-pcre-test-00151 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "foo(.*)bar" ""))) (rxt-match-test regexp "The food is under the bar in the barn." '("food is under the bar in the bar" "d is under the bar in the ")))) (ert-deftest rxt-pcre-test-00152 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "foo(.*?)bar" ""))) (rxt-match-test regexp "The food is under the bar in the barn." '("food is under the bar" "d is under the ")))) (ert-deftest rxt-pcre-test-00153 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*)(\\d*)" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("I have 2 numbers: 53147" "I have 2 numbers: 53147" "")))) (ert-deftest rxt-pcre-test-00154 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*)(\\d+)" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("I have 2 numbers: 53147" "I have 2 numbers: 5314" "7")))) (ert-deftest rxt-pcre-test-00155 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*?)(\\d*)" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("" "" "")))) (ert-deftest rxt-pcre-test-00156 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*?)(\\d+)" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("I have 2" "I have " "2")))) (ert-deftest rxt-pcre-test-00157 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*)(\\d+)$" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("I have 2 numbers: 53147" "I have 2 numbers: 5314" "7")))) (ert-deftest rxt-pcre-test-00158 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*?)(\\d+)$" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("I have 2 numbers: 53147" "I have 2 numbers: " "53147")))) (ert-deftest rxt-pcre-test-00159 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*)\\b(\\d+)$" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("I have 2 numbers: 53147" "I have 2 numbers: " "53147")))) (ert-deftest rxt-pcre-test-00160 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*\\D)(\\d+)$" ""))) (rxt-match-test regexp "I have 2 numbers: 53147" '("I have 2 numbers: 53147" "I have 2 numbers: " "53147")))) (ert-deftest rxt-pcre-test-00161 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\D*(?!123)" ""))) (rxt-match-test regexp "ABC123" '("AB")))) (ert-deftest rxt-pcre-test-00162 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(\\D*)(?=\\d)(?!123)" ""))) (rxt-match-test regexp "ABC445" '("ABC" "ABC")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "ABC123" 'nil))) (ert-deftest rxt-pcre-test-00163 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[W-]46]" ""))) (rxt-match-test regexp "W46]789" '("W46]")) (rxt-match-test regexp "-46]789" '("-46]")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "Wall" 'nil) (rxt-match-test regexp "Zebra" 'nil) (rxt-match-test regexp "42" 'nil) (rxt-match-test regexp "[abcd]" 'nil) (rxt-match-test regexp "]abcd[" 'nil))) (ert-deftest rxt-pcre-test-00164 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[W-\\]46]" ""))) (rxt-match-test regexp "W46]789" '("W")) (rxt-match-test regexp "Wall" '("W")) (rxt-match-test regexp "Zebra" '("Z")) (rxt-match-test regexp "Xylophone" '("X")) (rxt-match-test regexp "42" '("4")) (rxt-match-test regexp "[abcd]" '("[")) (rxt-match-test regexp "]abcd[" '("]")) (rxt-match-test regexp "\\backslash" '("\\")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "-46]789" 'nil) (rxt-match-test regexp "well" 'nil))) (ert-deftest rxt-pcre-test-00165 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\d\\d\\/\\d\\d\\/\\d\\d\\d\\d" ""))) (rxt-match-test regexp "01/01/2000" '("01/01/2000")))) (ert-deftest rxt-pcre-test-00166 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "word (?:[a-zA-Z0-9]+ ){0,10}otherword" ""))) (rxt-match-test regexp "word cat dog elephant mussel cow horse canary baboon snake shark otherword" '("word cat dog elephant mussel cow horse canary baboon snake shark otherword")) (rxt-match-test regexp "word cat dog elephant mussel cow horse canary baboon snake shark" 'nil))) (ert-deftest rxt-pcre-test-00167 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "word (?:[a-zA-Z0-9]+ ){0,300}otherword" ""))) (rxt-match-test regexp "word cat dog elephant mussel cow horse canary baboon snake shark the quick brown fox and the lazy dog and several other words getting close to thirty by now I hope" 'nil))) (ert-deftest rxt-pcre-test-00168 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){0,0}" ""))) (rxt-match-test regexp "bcd" '("")) (rxt-match-test regexp "abc" '("")) (rxt-match-test regexp "aab" '("")))) (ert-deftest rxt-pcre-test-00169 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){0,1}" ""))) (rxt-match-test regexp "bcd" '("")) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("a" "a")))) (ert-deftest rxt-pcre-test-00170 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){0,2}" ""))) (rxt-match-test regexp "bcd" '("")) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("aa" "a")))) (ert-deftest rxt-pcre-test-00171 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){0,3}" ""))) (rxt-match-test regexp "bcd" '("")) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("aa" "a")) (rxt-match-test regexp "aaa" '("aaa" "a")))) (ert-deftest rxt-pcre-test-00172 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){0,}" ""))) (rxt-match-test regexp "bcd" '("")) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("aa" "a")) (rxt-match-test regexp "aaa" '("aaa" "a")) (rxt-match-test regexp "aaaaaaaa" '("aaaaaaaa" "a")))) (ert-deftest rxt-pcre-test-00173 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){1,1}" ""))) (rxt-match-test regexp "bcd" 'nil) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("a" "a")))) (ert-deftest rxt-pcre-test-00174 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){1,2}" ""))) (rxt-match-test regexp "bcd" 'nil) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("aa" "a")))) (ert-deftest rxt-pcre-test-00175 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){1,3}" ""))) (rxt-match-test regexp "bcd" 'nil) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("aa" "a")) (rxt-match-test regexp "aaa" '("aaa" "a")))) (ert-deftest rxt-pcre-test-00176 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){1,}" ""))) (rxt-match-test regexp "bcd" 'nil) (rxt-match-test regexp "abc" '("a" "a")) (rxt-match-test regexp "aab" '("aa" "a")) (rxt-match-test regexp "aaa" '("aaa" "a")) (rxt-match-test regexp "aaaaaaaa" '("aaaaaaaa" "a")))) (ert-deftest rxt-pcre-test-00177 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*\\.gif" ""))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("bib.gif")))) (ert-deftest rxt-pcre-test-00178 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".{0,}\\.gif" ""))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("bib.gif")))) (ert-deftest rxt-pcre-test-00179 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*\\.gif" "m"))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("bib.gif")))) (ert-deftest rxt-pcre-test-00180 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*\\.gif" "s"))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("borfle\nbib.gif")))) (ert-deftest rxt-pcre-test-00181 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*\\.gif" "ms"))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("borfle\nbib.gif")))) (ert-deftest rxt-pcre-test-00182 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" ""))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("no")))) (ert-deftest rxt-pcre-test-00183 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" "m"))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("borfle")))) (ert-deftest rxt-pcre-test-00184 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" "s"))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("borfle\nbib.gif\nno")))) (ert-deftest rxt-pcre-test-00185 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" "ms"))) (rxt-match-test regexp "borfle\nbib.gif\nno" '("borfle\nbib.gif\nno")))) (ert-deftest rxt-pcre-test-00186 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" ""))) (rxt-match-test regexp "borfle\nbib.gif\nno\n" '("no")))) (ert-deftest rxt-pcre-test-00187 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" "m"))) (rxt-match-test regexp "borfle\nbib.gif\nno\n" '("borfle")))) (ert-deftest rxt-pcre-test-00188 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" "s"))) (rxt-match-test regexp "borfle\nbib.gif\nno\n" '("borfle\nbib.gif\nno\n")))) (ert-deftest rxt-pcre-test-00189 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*$" "ms"))) (rxt-match-test regexp "borfle\nbib.gif\nno\n" '("borfle\nbib.gif\nno\n")))) (ert-deftest rxt-pcre-test-00190 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*X|^B)" ""))) (rxt-match-test regexp "abcde\n1234Xyz" '("1234X" "1234X")) (rxt-match-test regexp "BarFoo" '("B" "B")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcde\nBar" 'nil))) (ert-deftest rxt-pcre-test-00191 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*X|^B)" "m"))) (rxt-match-test regexp "abcde\n1234Xyz" '("1234X" "1234X")) (rxt-match-test regexp "BarFoo" '("B" "B")) (rxt-match-test regexp "abcde\nBar" '("B" "B")))) (ert-deftest rxt-pcre-test-00192 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*X|^B)" "s"))) (rxt-match-test regexp "abcde\n1234Xyz" '("abcde\n1234X" "abcde\n1234X")) (rxt-match-test regexp "BarFoo" '("B" "B")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcde\nBar" 'nil))) (ert-deftest rxt-pcre-test-00193 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*X|^B)" "ms"))) (rxt-match-test regexp "abcde\n1234Xyz" '("abcde\n1234X" "abcde\n1234X")) (rxt-match-test regexp "BarFoo" '("B" "B")) (rxt-match-test regexp "abcde\nBar" '("B" "B")))) (ert-deftest rxt-pcre-test-00194 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?s)(.*X|^B)" ""))) (rxt-match-test regexp "abcde\n1234Xyz" '("abcde\n1234X" "abcde\n1234X")) (rxt-match-test regexp "BarFoo" '("B" "B")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcde\nBar" 'nil))) (ert-deftest rxt-pcre-test-00195 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?s:.*X|^B)" ""))) (rxt-match-test regexp "abcde\n1234Xyz" '("abcde\n1234X")) (rxt-match-test regexp "BarFoo" '("B")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcde\nBar" 'nil))) (ert-deftest rxt-pcre-test-00196 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*B" ""))) (rxt-match-test regexp "**** Failers" 'nil) (rxt-match-test regexp "abc\nB" 'nil))) (ert-deftest rxt-pcre-test-00197 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?s)^.*B" ""))) (rxt-match-test regexp "abc\nB" '("abc\nB")))) (ert-deftest rxt-pcre-test-00198 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?m)^.*B" ""))) (rxt-match-test regexp "abc\nB" '("B")))) (ert-deftest rxt-pcre-test-00199 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?ms)^.*B" ""))) (rxt-match-test regexp "abc\nB" '("abc\nB")))) (ert-deftest rxt-pcre-test-00200 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?ms)^B" ""))) (rxt-match-test regexp "abc\nB" '("B")))) (ert-deftest rxt-pcre-test-00201 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?s)B$" ""))) (rxt-match-test regexp "B\n" '("B")))) (ert-deftest rxt-pcre-test-00202 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]" ""))) (rxt-match-test regexp "123456654321" '("123456654321")))) (ert-deftest rxt-pcre-test-00203 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d" ""))) (rxt-match-test regexp "123456654321" '("123456654321")))) (ert-deftest rxt-pcre-test-00204 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[\\d][\\d][\\d][\\d][\\d][\\d][\\d][\\d][\\d][\\d][\\d][\\d]" ""))) (rxt-match-test regexp "123456654321" '("123456654321")))) (ert-deftest rxt-pcre-test-00205 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[abc]{12}" ""))) (rxt-match-test regexp "abcabcabcabc" '("abcabcabcabc")))) (ert-deftest rxt-pcre-test-00206 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[a-c]{12}" ""))) (rxt-match-test regexp "abcabcabcabc" '("abcabcabcabc")))) (ert-deftest rxt-pcre-test-00207 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a|b|c){12}" ""))) (rxt-match-test regexp "abcabcabcabc" '("abcabcabcabc" "c")))) (ert-deftest rxt-pcre-test-00208 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[abcdefghijklmnopqrstuvwxy0123456789]" ""))) (rxt-match-test regexp "n" '("n")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "z" 'nil))) (ert-deftest rxt-pcre-test-00209 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abcde{0,0}" ""))) (rxt-match-test regexp "abcd" '("abcd")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abce" 'nil))) (ert-deftest rxt-pcre-test-00210 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "ab[cd]{0,0}e" ""))) (rxt-match-test regexp "abe" '("abe")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcde" 'nil))) (ert-deftest rxt-pcre-test-00211 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "ab(c){0,0}d" ""))) (rxt-match-test regexp "abd" '("abd")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcd" 'nil))) (ert-deftest rxt-pcre-test-00212 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(b*)" ""))) (rxt-match-test regexp "a" '("a" "")) (rxt-match-test regexp "ab" '("ab" "b")) (rxt-match-test regexp "abbbb" '("abbbb" "bbbb")) (rxt-match-test regexp "*** Failers" '("a" "")) (rxt-match-test regexp "bbbbb" 'nil))) (ert-deftest rxt-pcre-test-00213 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "ab\\d{0}e" ""))) (rxt-match-test regexp "abe" '("abe")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "ab1e" 'nil))) (ert-deftest rxt-pcre-test-00214 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\"([^\\\\\"]+|\\\\.)*\"" ""))) (rxt-match-test regexp "the \"quick\" brown fox" '("\"quick\"" "quick")) (rxt-match-test regexp "\"the \\\"quick\\\" brown fox\"" '("\"the \\\"quick\\\" brown fox\"" " brown fox")))) (ert-deftest rxt-pcre-test-00215 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp ".*?" "g"))) (rxt-match-test regexp "abc" '("" "a" "" "b" "" "c" "")))) (ert-deftest rxt-pcre-test-00216 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\b" "g"))) (rxt-match-test regexp "abc" '("" "")))) (ert-deftest rxt-pcre-test-00217 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\b" "g"))) (rxt-match-test regexp "abc" '("" "")))) (ert-deftest rxt-pcre-test-00218 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "" "g"))) (rxt-match-test regexp "abc" '("" "" "" "")))) (ert-deftest rxt-pcre-test-00219 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "]{0,})>]{0,})>([\\d]{0,}\\.)(.*)((
([\\w\\W\\s\\d][^<>]{0,})|[\\s]{0,}))<\\/a><\\/TD>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD><\\/TR>" "is"))) (rxt-match-test regexp "43.Word Processor
(N-1286)
Lega lstaff.comCA - Statewide" '("43.Word Processor
(N-1286)
Lega lstaff.comCA - Statewide" " BGCOLOR='#DBE9E9'" " align=left valign=top" "43." "Word Processor
(N-1286)" "" "" nil " align=left valign=top" "Lega lstaff.com" " align=left valign=top" "CA - Statewide")))) (ert-deftest rxt-pcre-test-00220 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a[^a]b" ""))) (rxt-match-test regexp "acb" '("acb")) (rxt-match-test regexp "a\nb" '("a\nb")))) (ert-deftest rxt-pcre-test-00221 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a.b" ""))) (rxt-match-test regexp "acb" '("acb")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "a\nb" 'nil))) (ert-deftest rxt-pcre-test-00222 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a[^a]b" "s"))) (rxt-match-test regexp "acb" '("acb")) (rxt-match-test regexp "a\nb" '("a\nb")))) (ert-deftest rxt-pcre-test-00223 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a.b" "s"))) (rxt-match-test regexp "acb" '("acb")) (rxt-match-test regexp "a\nb" '("a\nb")))) (ert-deftest rxt-pcre-test-00224 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(b+?|a){1,2}?c" ""))) (rxt-match-test regexp "bac" '("bac" "a")) (rxt-match-test regexp "bbac" '("bbac" "a")) (rxt-match-test regexp "bbbac" '("bbbac" "a")) (rxt-match-test regexp "bbbbac" '("bbbbac" "a")) (rxt-match-test regexp "bbbbbac" '("bbbbbac" "a")))) (ert-deftest rxt-pcre-test-00225 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(b+|a){1,2}?c" ""))) (rxt-match-test regexp "bac" '("bac" "a")) (rxt-match-test regexp "bbac" '("bbac" "a")) (rxt-match-test regexp "bbbac" '("bbbac" "a")) (rxt-match-test regexp "bbbbac" '("bbbbac" "a")) (rxt-match-test regexp "bbbbbac" '("bbbbbac" "a")))) (ert-deftest rxt-pcre-test-00226 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?!\\A)x" "m"))) (rxt-match-test regexp "x\nb\n" 'nil) (rxt-match-test regexp "ax\n" '("x")))) (ert-deftest rxt-pcre-test-00227 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\x0{ab}" ""))) (rxt-match-test regexp "{ab}" '("{ab}")))) (ert-deftest rxt-pcre-test-00228 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(A|B)*?CD" ""))) (rxt-match-test regexp "CD" '("CD")))) (ert-deftest rxt-pcre-test-00229 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(A|B)*CD" ""))) (rxt-match-test regexp "CD" '("CD")))) (ert-deftest rxt-pcre-test-00230 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(AB)*?\\1" ""))) (rxt-match-test regexp "ABABAB" '("ABAB" "AB")))) (ert-deftest rxt-pcre-test-00231 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(AB)*\\1" ""))) (rxt-match-test regexp "ABABAB" '("ABABAB" "AB")))) (ert-deftest rxt-pcre-test-00232 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?.*/)foo" ""))) (rxt-match-test regexp "/this/is/a/very/long/line/in/deed/with/very/many/slashes/in/it/you/see/" 'nil))) (ert-deftest rxt-pcre-test-00237 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>.*/)foo" ""))) (rxt-match-test regexp "/this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo" '("/this/is/a/very/long/line/in/deed/with/very/many/slashes/in/and/foo")))) (ert-deftest rxt-pcre-test-00238 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(\\.\\d\\d[1-9]?))\\d+" ""))) (rxt-match-test regexp "1.230003938" '(".230003938" ".23")) (rxt-match-test regexp "1.875000282" '(".875000282" ".875")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "1.235" 'nil))) (ert-deftest rxt-pcre-test-00239 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^((?>\\w+)|(?>\\s+))*$" ""))) (rxt-match-test regexp "now is the time for all good men to come to the aid of the party" '("now is the time for all good men to come to the aid of the party" "party")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "this is not a line with only words and spaces!" 'nil))) (ert-deftest rxt-pcre-test-00240 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(\\d+)(\\w)" ""))) (rxt-match-test regexp "12345a" '("12345a" "12345" "a")) (rxt-match-test regexp "12345+" '("12345" "1234" "5")))) (ert-deftest rxt-pcre-test-00241 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>\\d+))(\\w)" ""))) (rxt-match-test regexp "12345a" '("12345a" "12345" "a")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "12345+" 'nil))) (ert-deftest rxt-pcre-test-00242 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a+)b" ""))) (rxt-match-test regexp "aaab" '("aaab")))) (ert-deftest rxt-pcre-test-00243 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>a+)b)" ""))) (rxt-match-test regexp "aaab" '("aaab" "aaab")))) (ert-deftest rxt-pcre-test-00244 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(a+))b" ""))) (rxt-match-test regexp "aaab" '("aaab" "aaa")))) (ert-deftest rxt-pcre-test-00245 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>b)+" ""))) (rxt-match-test regexp "aaabbbccc" '("bbb")))) (ert-deftest rxt-pcre-test-00246 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a+|b+|c+)*c" ""))) (rxt-match-test regexp "aaabbbbccccd" '("aaabbbbc")))) (ert-deftest rxt-pcre-test-00247 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>[^()]+)|\\([^()]*\\))+" ""))) (rxt-match-test regexp "((abc(ade)ufh()()x" '("abc(ade)ufh()()x" "x")))) (ert-deftest rxt-pcre-test-00248 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\(((?>[^()]+)|\\([^()]+\\))+\\)" ""))) (rxt-match-test regexp "(abc)" '("(abc)" "abc")) (rxt-match-test regexp "(abc(def)xyz)" '("(abc(def)xyz)" "xyz")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 'nil))) (ert-deftest rxt-pcre-test-00249 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(?-i)b" "i"))) (rxt-match-test regexp "ab" '("ab")) (rxt-match-test regexp "Ab" '("Ab")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aB" 'nil) (rxt-match-test regexp "AB" 'nil))) (ert-deftest rxt-pcre-test-00250 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a (?x)b c)d e" ""))) (rxt-match-test regexp "a bcd e" '("a bcd e" "a bc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "a b cd e" 'nil) (rxt-match-test regexp "abcd e" 'nil) (rxt-match-test regexp "a bcde" 'nil))) (ert-deftest rxt-pcre-test-00251 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a b(?x)c d (?-x)e f)" ""))) (rxt-match-test regexp "a bcde f" '("a bcde f" "a bcde f")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcdef" 'nil))) (ert-deftest rxt-pcre-test-00252 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a(?i)b)c" ""))) (rxt-match-test regexp "abc" '("abc" "ab")) (rxt-match-test regexp "aBc" '("aBc" "aB")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abC" 'nil) (rxt-match-test regexp "aBC" 'nil) (rxt-match-test regexp "Abc" 'nil) (rxt-match-test regexp "ABc" 'nil) (rxt-match-test regexp "ABC" 'nil) (rxt-match-test regexp "AbC" 'nil))) (ert-deftest rxt-pcre-test-00253 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(?i:b)c" ""))) (rxt-match-test regexp "abc" '("abc")) (rxt-match-test regexp "aBc" '("aBc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "ABC" 'nil) (rxt-match-test regexp "abC" 'nil) (rxt-match-test regexp "aBC" 'nil))) (ert-deftest rxt-pcre-test-00254 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(?i:b)*c" ""))) (rxt-match-test regexp "aBc" '("aBc")) (rxt-match-test regexp "aBBc" '("aBBc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aBC" 'nil) (rxt-match-test regexp "aBBC" 'nil))) (ert-deftest rxt-pcre-test-00255 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(?=b(?i)c)\\w\\wd" ""))) (rxt-match-test regexp "abcd" '("abcd")) (rxt-match-test regexp "abCd" '("abCd")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aBCd" 'nil) (rxt-match-test regexp "abcD" 'nil))) (ert-deftest rxt-pcre-test-00256 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?s-i:more.*than).*million" "i"))) (rxt-match-test regexp "more than million" '("more than million")) (rxt-match-test regexp "more than MILLION" '("more than MILLION")) (rxt-match-test regexp "more \n than Million" '("more \n than Million")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "MORE THAN MILLION" 'nil) (rxt-match-test regexp "more \n than \n million" 'nil))) (ert-deftest rxt-pcre-test-00257 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(?s-i)more.*than).*million" "i"))) (rxt-match-test regexp "more than million" '("more than million")) (rxt-match-test regexp "more than MILLION" '("more than MILLION")) (rxt-match-test regexp "more \n than Million" '("more \n than Million")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "MORE THAN MILLION" 'nil) (rxt-match-test regexp "more \n than \n million" 'nil))) (ert-deftest rxt-pcre-test-00258 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a(?i)b+)+c" ""))) (rxt-match-test regexp "abc" '("abc")) (rxt-match-test regexp "aBbc" '("aBbc")) (rxt-match-test regexp "aBBc" '("aBBc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "Abc" 'nil) (rxt-match-test regexp "abAb" 'nil) (rxt-match-test regexp "abbC" 'nil))) (ert-deftest rxt-pcre-test-00259 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=a(?i)b)\\w\\wc" ""))) (rxt-match-test regexp "abc" '("abc")) (rxt-match-test regexp "aBc" '("aBc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "Ab" 'nil) (rxt-match-test regexp "abC" 'nil) (rxt-match-test regexp "aBC" 'nil))) (ert-deftest rxt-pcre-test-00260 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=a(?i)b)(\\w\\w)c" ""))) (rxt-match-test regexp "abxxc" '("xxc" "xx")) (rxt-match-test regexp "aBxxc" '("xxc" "xx")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "Abxxc" 'nil) (rxt-match-test regexp "ABxxc" 'nil) (rxt-match-test regexp "abxxC" 'nil))) (ert-deftest rxt-pcre-test-00261 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(a)|b)(?(1)A|B)" ""))) (rxt-match-test regexp "aA" '("aA" "a")) (rxt-match-test regexp "bB" '("bB")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aB" 'nil) (rxt-match-test regexp "bA" 'nil))) (ert-deftest rxt-pcre-test-00262 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)?(?(1)a|b)+$" ""))) (rxt-match-test regexp "aa" '("aa" "a")) (rxt-match-test regexp "b" '("b")) (rxt-match-test regexp "bb" '("bb")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "ab" 'nil))) (ert-deftest rxt-pcre-test-00263 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?(?=abc)\\w{3}:|\\d\\d)$" ""))) (rxt-match-test regexp "abc:" '("abc:")) (rxt-match-test regexp "12" '("12")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123" 'nil) (rxt-match-test regexp "xyz" 'nil))) (ert-deftest rxt-pcre-test-00264 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?(?!abc)\\d\\d|\\w{3}:)$" ""))) (rxt-match-test regexp "abc:" '("abc:")) (rxt-match-test regexp "12" '("12")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123" 'nil) (rxt-match-test regexp "xyz" 'nil))) (ert-deftest rxt-pcre-test-00265 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(?<=foo)bar|cat)" ""))) (rxt-match-test regexp "foobar" '("bar")) (rxt-match-test regexp "cat" '("cat")) (rxt-match-test regexp "fcat" '("cat")) (rxt-match-test regexp "focat" '("cat")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "foocat" 'nil))) (ert-deftest rxt-pcre-test-00266 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(?a*)*" ""))) (rxt-match-test regexp "a" '("a")) (rxt-match-test regexp "aa" '("aa")) (rxt-match-test regexp "aaaa" '("aaaa")))) (ert-deftest rxt-pcre-test-00273 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(abc|)+" ""))) (rxt-match-test regexp "abc" '("abc" "")) (rxt-match-test regexp "abcabc" '("abcabc" "")) (rxt-match-test regexp "abcabcabc" '("abcabcabc" "")) (rxt-match-test regexp "xyz" '("" "")))) (ert-deftest rxt-pcre-test-00274 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([a]*)*" ""))) (rxt-match-test regexp "a" '("a" "")) (rxt-match-test regexp "aaaaa" '("aaaaa" "")))) (ert-deftest rxt-pcre-test-00275 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([ab]*)*" ""))) (rxt-match-test regexp "a" '("a" "")) (rxt-match-test regexp "b" '("b" "")) (rxt-match-test regexp "ababab" '("ababab" "")) (rxt-match-test regexp "aaaabcde" '("aaaab" "")) (rxt-match-test regexp "bbbb" '("bbbb" "")))) (ert-deftest rxt-pcre-test-00276 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([^a]*)*" ""))) (rxt-match-test regexp "b" '("b" "")) (rxt-match-test regexp "bbbb" '("bbbb" "")) (rxt-match-test regexp "aaa" '("" "")))) (ert-deftest rxt-pcre-test-00277 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([^ab]*)*" ""))) (rxt-match-test regexp "cccc" '("cccc" "")) (rxt-match-test regexp "abab" '("" "")))) (ert-deftest rxt-pcre-test-00278 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([a]*?)*" ""))) (rxt-match-test regexp "a" '("" "")) (rxt-match-test regexp "aaaa" '("" "")))) (ert-deftest rxt-pcre-test-00279 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([ab]*?)*" ""))) (rxt-match-test regexp "a" '("" "")) (rxt-match-test regexp "b" '("" "")) (rxt-match-test regexp "abab" '("" "")) (rxt-match-test regexp "baba" '("" "")))) (ert-deftest rxt-pcre-test-00280 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([^a]*?)*" ""))) (rxt-match-test regexp "b" '("" "")) (rxt-match-test regexp "bbbb" '("" "")) (rxt-match-test regexp "aaa" '("" "")))) (ert-deftest rxt-pcre-test-00281 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([^ab]*?)*" ""))) (rxt-match-test regexp "c" '("" "")) (rxt-match-test regexp "cccc" '("" "")) (rxt-match-test regexp "baba" '("" "")))) (ert-deftest rxt-pcre-test-00282 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a*)*" ""))) (rxt-match-test regexp "a" '("a")) (rxt-match-test regexp "aaabcde" '("aaa")))) (ert-deftest rxt-pcre-test-00283 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>a*))*" ""))) (rxt-match-test regexp "aaaaa" '("aaaaa" "")) (rxt-match-test regexp "aabbaa" '("aa" "")))) (ert-deftest rxt-pcre-test-00284 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>a*?))*" ""))) (rxt-match-test regexp "aaaaa" '("" "")) (rxt-match-test regexp "aabbaa" '("" "")))) (ert-deftest rxt-pcre-test-00285 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(?=[^a-z]+[a-z]) \\d{2}-[a-z]{3}-\\d{2} | \\d{2}-\\d{2}-\\d{2} ) " "x"))) (rxt-match-test regexp "12-sep-98" '("12-sep-98")) (rxt-match-test regexp "12-09-98" '("12-09-98")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "sep-12-98" 'nil))) (ert-deftest rxt-pcre-test-00286 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=(foo))bar\\1" ""))) (rxt-match-test regexp "foobarfoo" '("barfoo" "foo")) (rxt-match-test regexp "foobarfootling" '("barfoo" "foo")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "foobar" 'nil) (rxt-match-test regexp "barfoo" 'nil))) (ert-deftest rxt-pcre-test-00287 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?i:saturday|sunday)" ""))) (rxt-match-test regexp "saturday" '("saturday")) (rxt-match-test regexp "sunday" '("sunday")) (rxt-match-test regexp "Saturday" '("Saturday")) (rxt-match-test regexp "Sunday" '("Sunday")) (rxt-match-test regexp "SATURDAY" '("SATURDAY")) (rxt-match-test regexp "SUNDAY" '("SUNDAY")) (rxt-match-test regexp "SunDay" '("SunDay")))) (ert-deftest rxt-pcre-test-00288 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a(?i)bc|BB)x" ""))) (rxt-match-test regexp "abcx" '("abcx" "abc")) (rxt-match-test regexp "aBCx" '("aBCx" "aBC")) (rxt-match-test regexp "bbx" '("bbx" "bb")) (rxt-match-test regexp "BBx" '("BBx" "BB")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcX" 'nil) (rxt-match-test regexp "aBCX" 'nil) (rxt-match-test regexp "bbX" 'nil) (rxt-match-test regexp "BBX" 'nil))) (ert-deftest rxt-pcre-test-00289 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^([ab](?i)[cd]|[ef])" ""))) (rxt-match-test regexp "ac" '("ac" "ac")) (rxt-match-test regexp "aC" '("aC" "aC")) (rxt-match-test regexp "bD" '("bD" "bD")) (rxt-match-test regexp "elephant" '("e" "e")) (rxt-match-test regexp "Europe" '("E" "E")) (rxt-match-test regexp "frog" '("f" "f")) (rxt-match-test regexp "France" '("F" "F")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "Africa" 'nil))) (ert-deftest rxt-pcre-test-00290 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(ab|a(?i)[b-c](?m-i)d|x(?i)y|z)" ""))) (rxt-match-test regexp "ab" '("ab" "ab")) (rxt-match-test regexp "aBd" '("aBd" "aBd")) (rxt-match-test regexp "xy" '("xy" "xy")) (rxt-match-test regexp "xY" '("xY" "xY")) (rxt-match-test regexp "zebra" '("z" "z")) (rxt-match-test regexp "Zambesi" '("Z" "Z")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aCD" 'nil) (rxt-match-test regexp "XY" 'nil))) (ert-deftest rxt-pcre-test-00291 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=foo\\n)^bar" "m"))) (rxt-match-test regexp "foo\nbar" '("bar")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "bar" 'nil) (rxt-match-test regexp "baz\nbar" 'nil))) (ert-deftest rxt-pcre-test-00292 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=(?]&" ""))) (rxt-match-test regexp "<&OUT" '("<&")))) (ert-deftest rxt-pcre-test-00531 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a\\1?){4}$" ""))) (rxt-match-test regexp "aaaaaaaaaa" '("aaaaaaaaaa" "aaaa")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "AB" 'nil) (rxt-match-test regexp "aaaaaaaaa" 'nil) (rxt-match-test regexp "aaaaaaaaaaa" 'nil))) (ert-deftest rxt-pcre-test-00532 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a(?(1)\\1)){4}$" ""))) (rxt-match-test regexp "aaaaaaaaaa" '("aaaaaaaaaa" "aaaa")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aaaaaaaaa" 'nil) (rxt-match-test regexp "aaaaaaaaaaa" 'nil))) (ert-deftest rxt-pcre-test-00533 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(f)(o)(o)|(b)(a)(r))*" ""))) (rxt-match-test regexp "foobar" '("foobar" "f" "o" "o" "b" "a" "r")))) (ert-deftest rxt-pcre-test-00534 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=a)b" ""))) (rxt-match-test regexp "ab" '("b")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "cb" 'nil) (rxt-match-test regexp "b" 'nil))) (ert-deftest rxt-pcre-test-00535 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?a+)ab" ""))))) (ert-deftest rxt-pcre-test-00626 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a+)b" ""))) (rxt-match-test regexp "aaab" '("aaab")))) (ert-deftest rxt-pcre-test-00627 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([[:]+)" ""))) (rxt-match-test regexp "a:[b]:" '(":[" ":[")))) (ert-deftest rxt-pcre-test-00628 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([[=]+)" ""))) (rxt-match-test regexp "a=[b]=" '("=[" "=[")))) (ert-deftest rxt-pcre-test-00629 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([[.]+)" ""))) (rxt-match-test regexp "a.[b]." '(".[" ".[")))) (ert-deftest rxt-pcre-test-00630 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>a+)b)" ""))) (rxt-match-test regexp "aaab" '("aaab" "aaab")))) (ert-deftest rxt-pcre-test-00631 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(a+))b" ""))) (rxt-match-test regexp "aaab" '("aaab" "aaa")))) (ert-deftest rxt-pcre-test-00632 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>[^()]+)|\\([^()]*\\))+" ""))) (rxt-match-test regexp "((abc(ade)ufh()()x" '("abc(ade)ufh()()x" "x")))) (ert-deftest rxt-pcre-test-00633 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a\\Z" ""))) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "aaab" 'nil) (rxt-match-test regexp "a\nb\n" 'nil))) (ert-deftest rxt-pcre-test-00634 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "b\\Z" ""))) (rxt-match-test regexp "a\nb\n" '("b")))) (ert-deftest rxt-pcre-test-00635 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "b\\z" ""))))) (ert-deftest rxt-pcre-test-00636 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "b\\Z" ""))) (rxt-match-test regexp "a\nb" '("b")))) (ert-deftest rxt-pcre-test-00637 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "b\\z" ""))) (rxt-match-test regexp "a\nb" '("b")) (rxt-match-test regexp "*** Failers" 'nil))) (ert-deftest rxt-pcre-test-00638 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?>(?(1)\\.|())[^\\W_](?>[a-z0-9-]*[^\\W_])?)+$" ""))) (rxt-match-test regexp "a" '("a" "")) (rxt-match-test regexp "abc" '("abc" "")) (rxt-match-test regexp "a-b" '("a-b" "")) (rxt-match-test regexp "0-9" '("0-9" "")) (rxt-match-test regexp "a.b" '("a.b" "")) (rxt-match-test regexp "5.6.7" '("5.6.7" "")) (rxt-match-test regexp "the.quick.brown.fox" '("the.quick.brown.fox" "")) (rxt-match-test regexp "a100.b200.300c" '("a100.b200.300c" "")) (rxt-match-test regexp "12-ab.1245" '("12-ab.1245" "")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "" 'nil) (rxt-match-test regexp ".a" 'nil) (rxt-match-test regexp "-a" 'nil) (rxt-match-test regexp "a-" 'nil) (rxt-match-test regexp "a." 'nil) (rxt-match-test regexp "a_b" 'nil) (rxt-match-test regexp "a.-" 'nil) (rxt-match-test regexp "a.." 'nil) (rxt-match-test regexp "ab..bc" 'nil) (rxt-match-test regexp "the.quick.brown.fox-" 'nil) (rxt-match-test regexp "the.quick.brown.fox." 'nil) (rxt-match-test regexp "the.quick.brown.fox_" 'nil) (rxt-match-test regexp "the.quick.brown.fox+" 'nil))) (ert-deftest rxt-pcre-test-00639 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>.*)(?<=(abcd|wxyz))" ""))) (rxt-match-test regexp "alphabetabcd" '("alphabetabcd" "abcd")) (rxt-match-test regexp "endingwxyz" '("endingwxyz" "wxyz")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "a rather long string that doesn't end with one of them" 'nil))) (ert-deftest rxt-pcre-test-00640 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "word (?>(?:(?!otherword)[a-zA-Z0-9]+ ){0,30})otherword" ""))) (rxt-match-test regexp "word cat dog elephant mussel cow horse canary baboon snake shark otherword" '("word cat dog elephant mussel cow horse canary baboon snake shark otherword")) (rxt-match-test regexp "word cat dog elephant mussel cow horse canary baboon snake shark" 'nil))) (ert-deftest rxt-pcre-test-00641 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "word (?>[a-zA-Z0-9]+ ){0,30}otherword" ""))) (rxt-match-test regexp "word cat dog elephant mussel cow horse canary baboon snake shark the quick brown fox and the lazy dog and several other words getting close to thirty by now I hope" 'nil))) (ert-deftest rxt-pcre-test-00642 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=\\d{3}(?!999))foo" ""))) (rxt-match-test regexp "999foo" '("foo")) (rxt-match-test regexp "123999foo" '("foo")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123abcfoo" 'nil))) (ert-deftest rxt-pcre-test-00643 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=(?!...999)\\d{3})foo" ""))) (rxt-match-test regexp "999foo" '("foo")) (rxt-match-test regexp "123999foo" '("foo")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123abcfoo" 'nil))) (ert-deftest rxt-pcre-test-00644 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=\\d{3}(?!999)...)foo" ""))) (rxt-match-test regexp "123abcfoo" '("foo")) (rxt-match-test regexp "123456foo" '("foo")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "123999foo" 'nil))) (ert-deftest rxt-pcre-test-00645 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=\\d{3}...)(?\\s*)=(?>\\s*) # find
Z)+|A)*" ""))) (rxt-match-test regexp "ZABCDEFG" '("ZA" "A")))) (ert-deftest rxt-pcre-test-00653 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>)+|A)*" ""))) (rxt-match-test regexp "ZABCDEFG" '("" "")))) (ert-deftest rxt-pcre-test-00654 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a*" "g"))) (rxt-match-test regexp "abbab" '("a" "" "" "a" "" "")))) (ert-deftest rxt-pcre-test-00655 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[a-\\d]" ""))) (rxt-match-test regexp "abcde" '("a")) (rxt-match-test regexp "-things" '("-")) (rxt-match-test regexp "0digit" '("0")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "bcdef" 'nil))) (ert-deftest rxt-pcre-test-00656 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[\\d-a]" ""))) (rxt-match-test regexp "abcde" '("a")) (rxt-match-test regexp "-things" '("-")) (rxt-match-test regexp "0digit" '("0")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "bcdef" 'nil))) (ert-deftest rxt-pcre-test-00657 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "[[:space:]]+" ""))) (rxt-match-test regexp "> \n\f <" '(" \n\f ")))) (ert-deftest rxt-pcre-test-00658 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "[[:blank:]]+" ""))) (rxt-match-test regexp "> \n\f <" '(" ")))) (ert-deftest rxt-pcre-test-00659 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "[\\s]+" ""))) (rxt-match-test regexp "> \n\f <" '(" \n\f ")))) (ert-deftest rxt-pcre-test-00660 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\s+" ""))) (rxt-match-test regexp "> \n\f <" '(" \n\f ")))) (ert-deftest rxt-pcre-test-00661 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a b" "x"))) (rxt-match-test regexp "ab" 'nil))) (ert-deftest rxt-pcre-test-00662 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?!\\A)x" "m"))) (rxt-match-test regexp "a\nxb\n" '("x")))) (ert-deftest rxt-pcre-test-00663 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?!^)x" "m"))) (rxt-match-test regexp "a\nxb\n" 'nil))) (ert-deftest rxt-pcre-test-00664 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc\\Qabc\\Eabc" ""))) (rxt-match-test regexp "abcabcabc" '("abcabcabc")))) (ert-deftest rxt-pcre-test-00665 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc\\Q(*+|\\Eabc" ""))) (rxt-match-test regexp "abc(*+|abc" '("abc(*+|abc")))) (ert-deftest rxt-pcre-test-00666 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp " abc\\Q abc\\Eabc" "x"))) (rxt-match-test regexp "abc abcabc" '("abc abcabc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcabcabc" 'nil))) (ert-deftest rxt-pcre-test-00667 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc#comment\n \\Q#not comment\n literal\\E" "x"))) (rxt-match-test regexp "abc#not comment\n literal" '("abc#not comment\n literal")))) (ert-deftest rxt-pcre-test-00668 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc#comment\n \\Q#not comment\n literal" "x"))) (rxt-match-test regexp "abc#not comment\n literal" '("abc#not comment\n literal")))) (ert-deftest rxt-pcre-test-00669 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc#comment\n \\Q#not comment\n literal\\E #more comment\n " "x"))) (rxt-match-test regexp "abc#not comment\n literal" '("abc#not comment\n literal")))) (ert-deftest rxt-pcre-test-00670 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc#comment\n \\Q#not comment\n literal\\E #more comment" "x"))) (rxt-match-test regexp "abc#not comment\n literal" '("abc#not comment\n literal")))) (ert-deftest rxt-pcre-test-00671 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\Qabc\\$xyz\\E" ""))) (rxt-match-test regexp "abc\\$xyz" '("abc\\$xyz")))) (ert-deftest rxt-pcre-test-00672 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\Qabc\\E\\$\\Qxyz\\E" ""))) (rxt-match-test regexp "abc$xyz" '("abc$xyz")))) (ert-deftest rxt-pcre-test-00673 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\Gabc" ""))) (rxt-match-test regexp "abc" '("abc")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "xyzabc" 'nil))) (ert-deftest rxt-pcre-test-00674 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\Gabc." "g"))) (rxt-match-test regexp "abc1abc2xyzabc3" '("abc1" "abc2")))) (ert-deftest rxt-pcre-test-00675 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc." "g"))) (rxt-match-test regexp "abc1abc2xyzabc3" '("abc1" "abc2" "abc3")))) (ert-deftest rxt-pcre-test-00676 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(?x: b c )d" ""))) (rxt-match-test regexp "XabcdY" '("abcd")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "Xa b c d Y" 'nil))) (ert-deftest rxt-pcre-test-00677 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?x)x y z | a b c)" ""))) (rxt-match-test regexp "XabcY" '("abc" "abc")) (rxt-match-test regexp "AxyzB" '("xyz" "xyz")))) (ert-deftest rxt-pcre-test-00678 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?i)AB(?-i)C" ""))) (rxt-match-test regexp "XabCY" '("abC")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "XabcY" 'nil))) (ert-deftest rxt-pcre-test-00679 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?i)AB(?-i)C|D)E" ""))) (rxt-match-test regexp "abCE" '("abCE" "abC")) (rxt-match-test regexp "DE" '("DE" "D")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "abcE" 'nil) (rxt-match-test regexp "abCe" 'nil) (rxt-match-test regexp "dE" 'nil) (rxt-match-test regexp "De" 'nil))) (ert-deftest rxt-pcre-test-00680 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*)\\d+\\1" ""))) (rxt-match-test regexp "abc123abc" '("abc123abc" "abc")) (rxt-match-test regexp "abc123bc" '("bc123bc" "bc")))) (ert-deftest rxt-pcre-test-00681 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(.*)\\d+\\1" "s"))) (rxt-match-test regexp "abc123abc" '("abc123abc" "abc")) (rxt-match-test regexp "abc123bc" '("bc123bc" "bc")))) (ert-deftest rxt-pcre-test-00682 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((.*))\\d+\\1" ""))) (rxt-match-test regexp "abc123abc" '("abc123abc" "abc" "abc")) (rxt-match-test regexp "abc123bc" '("bc123bc" "bc" "bc")))) (ert-deftest rxt-pcre-test-00683 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "-- This tests for an IPv6 address in the form where it can have up to --" ""))) (rxt-match-test regexp "/-- eight components, one and only one of which is empty. This must be --/" 'nil) (rxt-match-test regexp "/-- an internal component. --/" 'nil))) (ert-deftest rxt-pcre-test-00684 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?!:) # colon disallowed at start\n (?: # start of item\n (?: [0-9a-f]{1,4} | # 1-4 hex digits or\n (?(1)0 | () ) ) # if null previously matched, fail; else null\n : # followed by colon\n ){1,7} # end item; 1-7 of them required \n [0-9a-f]{1,4} $ # final hex number at end of string\n (?(1)|.) # check that there was an empty component\n " "xi"))) (rxt-match-test regexp "a123::a123" '("a123::a123" "")) (rxt-match-test regexp "a123:b342::abcd" '("a123:b342::abcd" "")) (rxt-match-test regexp "a123:b342::324e:abcd" '("a123:b342::324e:abcd" "")) (rxt-match-test regexp "a123:ddde:b342::324e:abcd" '("a123:ddde:b342::324e:abcd" "")) (rxt-match-test regexp "a123:ddde:b342::324e:dcba:abcd" '("a123:ddde:b342::324e:dcba:abcd" "")) (rxt-match-test regexp "a123:ddde:9999:b342::324e:dcba:abcd" '("a123:ddde:9999:b342::324e:dcba:abcd" "")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "1:2:3:4:5:6:7:8" 'nil) (rxt-match-test regexp "a123:bce:ddde:9999:b342::324e:dcba:abcd" 'nil) (rxt-match-test regexp "a123::9999:b342::324e:dcba:abcd" 'nil) (rxt-match-test regexp "abcde:2:3:4:5:6:7:8" 'nil) (rxt-match-test regexp "::1" 'nil) (rxt-match-test regexp "abcd:fee0:123::" 'nil) (rxt-match-test regexp ":1" 'nil) (rxt-match-test regexp "1:" 'nil))) (ert-deftest rxt-pcre-test-00685 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "[z\\Qa-d]\\E]" ""))) (rxt-match-test regexp "z" '("z")) (rxt-match-test regexp "a" '("a")) (rxt-match-test regexp "-" '("-")) (rxt-match-test regexp "d" '("d")) (rxt-match-test regexp "]" '("]")) (rxt-match-test regexp "*** Failers" '("a")) (rxt-match-test regexp "b" 'nil))) (ert-deftest rxt-pcre-test-00686 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "[\\z\\C]" ""))) (rxt-match-test regexp "z" '("z")) (rxt-match-test regexp "C" '("C")))) (ert-deftest rxt-pcre-test-00687 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\M" ""))) (rxt-match-test regexp "M" '("M")))) (ert-deftest rxt-pcre-test-00688 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a+)*b" ""))) (error "Skipping exponential blowup test %s" "(a+)*b"))) (ert-deftest rxt-pcre-test-00689 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?i)reg(?:ul(?:[a\344]|ae)r|ex)" ""))) (rxt-match-test regexp "REGular" '("REGular")) (rxt-match-test regexp "regulaer" '("regulaer")) (rxt-match-test regexp "Regex" '("Regex")) (rxt-match-test regexp "regul\344r" '("regul\344r")))) (ert-deftest rxt-pcre-test-00690 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\305\346\345\344[\340-\377\300-\337]+" ""))) (rxt-match-test regexp "\305\346\345\344\340" '("\305\346\345\344\340")) (rxt-match-test regexp "\305\346\345\344\377" '("\305\346\345\344\377")) (rxt-match-test regexp "\305\346\345\344\300" '("\305\346\345\344\300")) (rxt-match-test regexp "\305\346\345\344\337" '("\305\346\345\344\337")))) (ert-deftest rxt-pcre-test-00691 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=Z)X." ""))) (rxt-match-test regexp "\204XAZXB" '("XB")))) (ert-deftest rxt-pcre-test-00692 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "ab cd (?x) de fg" ""))) (rxt-match-test regexp "ab cd defg" '("ab cd defg")))) (ert-deftest rxt-pcre-test-00693 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "ab cd(?x) de fg" ""))) (rxt-match-test regexp "ab cddefg" '("ab cddefg")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "abcddefg" 'nil))) (ert-deftest rxt-pcre-test-00694 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?a|)*\\d" ""))) (rxt-match-test regexp "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 'nil) (rxt-match-test regexp "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4" '("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4")))) (ert-deftest rxt-pcre-test-00731 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:a|)*\\d" ""))) (rxt-match-test regexp "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 'nil) (rxt-match-test regexp "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4" '("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4")))) (ert-deftest rxt-pcre-test-00732 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\Z" "g"))) (rxt-match-test regexp "abc\n" '("" "")))) (ert-deftest rxt-pcre-test-00733 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?s)(?>.*)(?(a))b|(a)c" ""))) (rxt-match-test regexp "ac" '("ac" nil "a")))) (ert-deftest rxt-pcre-test-00768 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=(a))ab|(a)c" ""))) (rxt-match-test regexp "ac" '("ac" nil "a")))) (ert-deftest rxt-pcre-test-00769 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>(a))b|(a)c)" ""))) (rxt-match-test regexp "ac" '("ac" "ac" nil "a")))) (ert-deftest rxt-pcre-test-00770 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>(a))b|(a)c)++" ""))) (rxt-match-test regexp "ac" '("ac" "ac" nil "a")))) (ert-deftest rxt-pcre-test-00771 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(?>(a))b|(a)c)++" ""))) (rxt-match-test regexp "ac" '("ac" nil "a")))) (ert-deftest rxt-pcre-test-00772 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=(?>(a))b|(a)c)(..)" ""))) (rxt-match-test regexp "ac" '("ac" nil "a" "ac")))) (ert-deftest rxt-pcre-test-00773 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(?>(a))b|(a)c)" ""))) (rxt-match-test regexp "ac" '("ac" nil "a")))) (ert-deftest rxt-pcre-test-00774 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(?>([ab])))+a=" ""))) (rxt-match-test regexp "=ba=" '("ba=" "b")))) (ert-deftest rxt-pcre-test-00775 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>([ab]))+a=" ""))) (rxt-match-test regexp "=ba=" '("ba=" "b")))) (ert-deftest rxt-pcre-test-00776 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>(a+)b)+(aabab))" ""))) (rxt-match-test regexp "aaaabaaabaabab" '("aaaabaaabaabab" "aaaabaaabaabab" "aaa" "aabab")))) (ert-deftest rxt-pcre-test-00777 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a+|ab)+?c" ""))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00778 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a+|ab)+c" ""))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00779 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:a+|ab)+c" ""))) (rxt-match-test regexp "aabc" '("aabc")))) (ert-deftest rxt-pcre-test-00780 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(?=(a))a)" ""))) (rxt-match-test regexp "a" '("a" "a")))) (ert-deftest rxt-pcre-test-00781 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(?=(a))a)(b)" ""))) (rxt-match-test regexp "ab" '("ab" "a" "b")))) (ert-deftest rxt-pcre-test-00782 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:a|ab)++c" ""))) (rxt-match-test regexp "aaaabc" 'nil))) (ert-deftest rxt-pcre-test-00783 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?>a|ab)++c" ""))) (rxt-match-test regexp "aaaabc" 'nil))) (ert-deftest rxt-pcre-test-00784 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:a|ab)+c" ""))) (rxt-match-test regexp "aaaabc" '("aaaabc")))) (ert-deftest rxt-pcre-test-00785 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=abc){3}abc" ""))) (rxt-match-test regexp "abcabcabc" '("abc")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "xyz" 'nil))) (ert-deftest rxt-pcre-test-00786 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=abc)+abc" ""))) (rxt-match-test regexp "abcabcabc" '("abc")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "xyz" 'nil))) (ert-deftest rxt-pcre-test-00787 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=abc)++abc" ""))) (rxt-match-test regexp "abcabcabc" '("abc")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "xyz" 'nil))) (ert-deftest rxt-pcre-test-00788 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=abc){0}xyz" ""))) (rxt-match-test regexp "xyz" '("xyz")))) (ert-deftest rxt-pcre-test-00789 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=abc){1}xyz" ""))) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "xyz" 'nil))) (ert-deftest rxt-pcre-test-00790 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=(a))?." ""))) (rxt-match-test regexp "ab" '("a" "a")) (rxt-match-test regexp "bc" '("b")))) (ert-deftest rxt-pcre-test-00791 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=(a))??." ""))) (rxt-match-test regexp "ab" '("a")) (rxt-match-test regexp "bc" '("b")))) (ert-deftest rxt-pcre-test-00792 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=(a)){0}b(?1)" ""))) (rxt-match-test regexp "backgammon" '("ba")))) (ert-deftest rxt-pcre-test-00793 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=(?1))?[az]([abc])d" ""))) (rxt-match-test regexp "abd" '("abd" "b")) (rxt-match-test regexp "zcdxx" '("zcd" "c")))) (ert-deftest rxt-pcre-test-00794 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?!a){0}\\w+" ""))) (rxt-match-test regexp "aaaaa" '("aaaaa")))) (ert-deftest rxt-pcre-test-00795 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=(abc))?xyz" ""))) (rxt-match-test regexp "abcxyz" '("xyz" "abc")) (rxt-match-test regexp "pqrxyz" '("xyz")))) (ert-deftest rxt-pcre-test-00796 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[\\g]+" ""))) (rxt-match-test regexp "ggg<<>>" '("ggg<<>>")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "\\ga" 'nil))) (ert-deftest rxt-pcre-test-00797 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[\\ga]+" ""))) (rxt-match-test regexp "gggagagaxyz" '("gggagaga")))) (ert-deftest rxt-pcre-test-00798 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[:a[:digit:]]+" ""))) (rxt-match-test regexp "aaaa444:::Z" '("aaaa444:::")))) (ert-deftest rxt-pcre-test-00799 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^[:a[:digit:]:b]+" ""))) (rxt-match-test regexp "aaaa444:::bbbZ" '("aaaa444:::bbb")))) (ert-deftest rxt-pcre-test-00800 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "[:a]xxx[b:]" ""))) (rxt-match-test regexp ":xxx:" '(":xxx:")))) (ert-deftest rxt-pcre-test-00801 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=a{2})b" "i"))) (rxt-match-test regexp "xaabc" '("b")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "xabc" 'nil))) (ert-deftest rxt-pcre-test-00802 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?XNNNYZ" '("XNNNYZ")) (rxt-match-test regexp "> X NYQZ" '(" X NYQZ")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp ">XYZ" 'nil) (rxt-match-test regexp "> X NY Z" 'nil))) (ert-deftest rxt-pcre-test-00823 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\v*X\\v?Y\\v+Z\\V*\\x0a\\V+\\x0b\\V{2,3}\\x0c" ""))) (rxt-match-test regexp ">XY\nZ\nA NN\f" '("XY\nZ\nA NN\f")) (rxt-match-test regexp ">\n X\nY\n ZZZ\nAAA NNN\f" '("\n X\nY\n ZZZ\nAAA NNN\f")))) (ert-deftest rxt-pcre-test-00824 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(foo)\\Kbar" ""))) (rxt-match-test regexp "foobar" '("bar" "foo")))) (ert-deftest rxt-pcre-test-00825 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(foo)(\\Kbar|baz)" ""))) (rxt-match-test regexp "foobar" '("bar" "foo" "bar")) (rxt-match-test regexp "foobaz" '("foobaz" "foo" "baz")))) (ert-deftest rxt-pcre-test-00826 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(foo\\Kbar)baz" ""))) (rxt-match-test regexp "foobarbaz" '("barbaz" "foobar")))) (ert-deftest rxt-pcre-test-00827 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "abc\\K|def\\K" "g"))) (rxt-match-test regexp "Xabcdefghi" '("" "")))) (ert-deftest rxt-pcre-test-00828 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "ab\\Kc|de\\Kf" "g"))) (rxt-match-test regexp "Xabcdefghi" '("c" "f")))) (ert-deftest rxt-pcre-test-00829 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?=C)" "g"))) (rxt-match-test regexp "ABCDECBA" '("" "")))) (ert-deftest rxt-pcre-test-00830 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^abc\\K" ""))) (rxt-match-test regexp "abcdef" '("")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "defabcxyz" 'nil))) (ert-deftest rxt-pcre-test-00831 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a(b))\\1\\g1\\g{1}\\g-1\\g{-1}\\g{-02}Z" ""))) (rxt-match-test regexp "ababababbbabZXXXX" '("ababababbbabZ" "ab" "b")))) (ert-deftest rxt-pcre-test-00832 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?tom|bon)-\\g{A}" ""))) (rxt-match-test regexp "tom-tom" '("tom-tom" "tom")) (rxt-match-test regexp "bon-bon" '("bon-bon" "bon")))) (ert-deftest rxt-pcre-test-00833 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(^(a|b\\g{-1}))" ""))) (rxt-match-test regexp "bacxxx" 'nil))) (ert-deftest rxt-pcre-test-00834 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?|(abc)|(xyz))\\1" ""))) (rxt-match-test regexp "abcabc" '("abcabc" "abc")) (rxt-match-test regexp "xyzxyz" '("xyzxyz" "xyz")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "abcxyz" 'nil) (rxt-match-test regexp "xyzabc" 'nil))) (ert-deftest rxt-pcre-test-00835 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?|(abc)|(xyz))(?1)" ""))) (rxt-match-test regexp "abcabc" '("abcabc" "abc")) (rxt-match-test regexp "xyzabc" '("xyzabc" "xyz")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "xyzxyz" 'nil))) (ert-deftest rxt-pcre-test-00836 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^X(?5)(a)(?|(b)|(q))(c)(d)(Y)" ""))) (rxt-match-test regexp "XYabcdY" '("XYabcdY" "a" "b" "c" "d" "Y")))) (ert-deftest rxt-pcre-test-00837 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^X(?7)(a)(?|(b|(r)(s))|(q))(c)(d)(Y)" ""))) (rxt-match-test regexp "XYabcdY" '("XYabcdY" "a" "b" nil nil "c" "d" "Y")))) (ert-deftest rxt-pcre-test-00838 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^X(?7)(a)(?|(b|(?|(r)|(t))(s))|(q))(c)(d)(Y)" ""))) (rxt-match-test regexp "XYabcdY" '("XYabcdY" "a" "b" nil nil "c" "d" "Y")))) (ert-deftest rxt-pcre-test-00839 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?'abc'\\w+):\\k{2}" ""))) (rxt-match-test regexp "a:aaxyz" '("a:aa" "a")) (rxt-match-test regexp "ab:ababxyz" '("ab:abab" "ab")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "a:axyz" 'nil) (rxt-match-test regexp "ab:abxyz" 'nil))) (ert-deftest rxt-pcre-test-00840 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?'abc'\\w+):\\g{abc}{2}" ""))) (rxt-match-test regexp "a:aaxyz" '("a:aa" "a")) (rxt-match-test regexp "ab:ababxyz" '("ab:abab" "ab")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "a:axyz" 'nil) (rxt-match-test regexp "ab:abxyz" 'nil))) (ert-deftest rxt-pcre-test-00841 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?a)? (?()b|c) (?('ab')d|e)" "x"))) (rxt-match-test regexp "abd" '("abd" "a")) (rxt-match-test regexp "ce" '("ce")))) (ert-deftest rxt-pcre-test-00842 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a.)\\g-1Z" ""))) (rxt-match-test regexp "aXaXZ" '("aXaXZ" "aX")))) (ert-deftest rxt-pcre-test-00843 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a.)\\g{-1}Z" ""))) (rxt-match-test regexp "aXaXZ" '("aXaXZ" "aX")))) (ert-deftest rxt-pcre-test-00844 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?(DEFINE) (? a) (? b) ) (?&A) (?&B) " "x"))) (rxt-match-test regexp "abcd" '("ab")))) (ert-deftest rxt-pcre-test-00845 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(?&NAME_PAT))\\s+(?(?&ADDRESS_PAT))\n (?(DEFINE)\n (?[a-z]+)\n (?\\d+)\n )" "x"))) (rxt-match-test regexp "metcalfe 33" '("metcalfe 33" "metcalfe" "33")))) (ert-deftest rxt-pcre-test-00846 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(DEFINE)(?2[0-4]\\d|25[0-5]|1\\d\\d|[1-9]?\\d))\\b(?&byte)(\\.(?&byte)){3}" ""))) (rxt-match-test regexp "1.2.3.4" '("1.2.3.4" nil ".4")) (rxt-match-test regexp "131.111.10.206" '("131.111.10.206" nil ".206")) (rxt-match-test regexp "10.0.0.0" '("10.0.0.0" nil ".0")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "10.6" 'nil) (rxt-match-test regexp "455.3.4.5" 'nil))) (ert-deftest rxt-pcre-test-00847 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\b(?&byte)(\\.(?&byte)){3}(?(DEFINE)(?2[0-4]\\d|25[0-5]|1\\d\\d|[1-9]?\\d))" ""))) (rxt-match-test regexp "1.2.3.4" '("1.2.3.4" ".4")) (rxt-match-test regexp "131.111.10.206" '("131.111.10.206" ".206")) (rxt-match-test regexp "10.0.0.0" '("10.0.0.0" ".0")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "10.6" 'nil) (rxt-match-test regexp "455.3.4.5" 'nil))) (ert-deftest rxt-pcre-test-00848 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(\\w++|\\s++)*$" ""))) (error "Skipping exponential blowup test %s" "^(\\w++|\\s++)*$"))) (ert-deftest rxt-pcre-test-00849 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(\\d++)(\\w)" ""))) (rxt-match-test regexp "12345a" '("12345a" "12345" "a")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "12345+" 'nil))) (ert-deftest rxt-pcre-test-00850 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a++b" ""))) (rxt-match-test regexp "aaab" '("aaab")))) (ert-deftest rxt-pcre-test-00851 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a++b)" ""))) (rxt-match-test regexp "aaab" '("aaab" "aaab")))) (ert-deftest rxt-pcre-test-00852 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a++)b" ""))) (rxt-match-test regexp "aaab" '("aaab" "aaa")))) (ert-deftest rxt-pcre-test-00853 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "([^()]++|\\([^()]*\\))+" ""))) (rxt-match-test regexp "((abc(ade)ufh()()x" '("abc(ade)ufh()()x" "x")))) (ert-deftest rxt-pcre-test-00854 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\(([^()]++|\\([^()]+\\))+\\)" ""))) (rxt-match-test regexp "(abc)" '("(abc)" "abc")) (rxt-match-test regexp "(abc(def)xyz)" '("(abc(def)xyz)" "xyz")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "((()aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 'nil))) (ert-deftest rxt-pcre-test-00855 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^([^()]|\\((?1)*\\))*$" ""))) (rxt-match-test regexp "abc" '("abc" "c")) (rxt-match-test regexp "a(b)c" '("a(b)c" "c")) (rxt-match-test regexp "a(b(c))d" '("a(b(c))d" "d")) (rxt-match-test regexp "*** Failers)" 'nil) (rxt-match-test regexp "a(b(c)d" 'nil))) (ert-deftest rxt-pcre-test-00856 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^>abc>([^()]|\\((?1)*\\))*abc>123abc>123abc>1(2)3abc>1(2)3abc>(1(2)3)abc>(1(2)3)]*+) | (?2)) * >))" "x"))) (rxt-match-test regexp "<>" '("<>" "<>" "<>")) (rxt-match-test regexp "" '("" "" "")) (rxt-match-test regexp " hij>" '(" hij>" " hij>" " hij>")) (rxt-match-test regexp " hij>" '("" "" "")) (rxt-match-test regexp "def>" '("def>" "def>" "def>")) (rxt-match-test regexp "" '("<>" "<>" "<>")) (rxt-match-test regexp "*** Failers" 'nil) (rxt-match-test regexp "a)(?<=b(?&X))" ""))) (rxt-match-test regexp "baz" '("a" "a")))) (ert-deftest rxt-pcre-test-00875 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?|(abc)|(def))\\1" ""))) (rxt-match-test regexp "abcabc" '("abcabc" "abc")) (rxt-match-test regexp "defdef" '("defdef" "def")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "abcdef" 'nil) (rxt-match-test regexp "defabc" 'nil))) (ert-deftest rxt-pcre-test-00876 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?|(abc)|(def))(?1)" ""))) (rxt-match-test regexp "abcabc" '("abcabc" "abc")) (rxt-match-test regexp "defabc" '("defabc" "def")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "defdef" 'nil) (rxt-match-test regexp "abcdef" 'nil))) (ert-deftest rxt-pcre-test-00877 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:a(? (?')|(?\")) |b(? (?')|(?\")) ) (?('quote')[a-z]+|[0-9]+)" "x"))) (rxt-match-test regexp "a\"aaaaa" '("a\"aaaaa" "\"" nil "\"")) (rxt-match-test regexp "b\"aaaaa" '("b\"aaaaa" nil nil nil "\"" nil "\"")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "b\"11111" 'nil))) (ert-deftest rxt-pcre-test-00878 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(?1)|B)(A(*F)|C)" ""))) (rxt-match-test regexp "ABCD" '("BC" "C")) (rxt-match-test regexp "CCD" '("CC" "C")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "CAD" 'nil))) (ert-deftest rxt-pcre-test-00879 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:(?1)|B)(A(*F)|C)" ""))) (rxt-match-test regexp "CCD" '("CC" "C")) (rxt-match-test regexp "BCD" '("BC" "C")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "ABCD" 'nil) (rxt-match-test regexp "CAD" 'nil) (rxt-match-test regexp "BAD" 'nil))) (ert-deftest rxt-pcre-test-00880 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(?1)|B)(A(*ACCEPT)XX|C)D" ""))) (rxt-match-test regexp "AAD" '("AA" "A")) (rxt-match-test regexp "ACD" '("ACD" "C")) (rxt-match-test regexp "BAD" '("BA" "A")) (rxt-match-test regexp "BCD" '("BCD" "C")) (rxt-match-test regexp "BAX" '("BA" "A")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "ACX" 'nil) (rxt-match-test regexp "ABC" 'nil))) (ert-deftest rxt-pcre-test-00881 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(DEFINE)(A))B(?1)C" ""))) (rxt-match-test regexp "BAC" '("BAC")))) (ert-deftest rxt-pcre-test-00882 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(DEFINE)((A)\\2))B(?1)C" ""))) (rxt-match-test regexp "BAAC" '("BAAC")))) (ert-deftest rxt-pcre-test-00883 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(? \\( ( [^()]++ | (?&pn) )* \\) )" "x"))) (rxt-match-test regexp "(ab(cd)ef)" '("(ab(cd)ef)" "(ab(cd)ef)" "ef")))) (ert-deftest rxt-pcre-test-00884 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?!a(*SKIP)b)" ""))) (rxt-match-test regexp "ac" '("")))) (ert-deftest rxt-pcre-test-00885 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=a(*SKIP)b|ac)" ""))) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "ac" 'nil))) (ert-deftest rxt-pcre-test-00886 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=a(*THEN)b|ac)" ""))) (rxt-match-test regexp "ac" '("")))) (ert-deftest rxt-pcre-test-00887 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=a(*PRUNE)b)" ""))) (rxt-match-test regexp "ab" '("")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "ac" 'nil))) (ert-deftest rxt-pcre-test-00888 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=a(*ACCEPT)b)" ""))) (rxt-match-test regexp "ac" '("")))) (ert-deftest rxt-pcre-test-00889 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?(?!a(*SKIP)b))" ""))) (rxt-match-test regexp "ac" '("")))) (ert-deftest rxt-pcre-test-00890 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a\\Kb)" ""))) (rxt-match-test regexp "ab" '("b")))) (ert-deftest rxt-pcre-test-00891 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?>a\\Kb))" ""))) (rxt-match-test regexp "ab" '("b" "ab")))) (ert-deftest rxt-pcre-test-00892 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a\\Kb)" ""))) (rxt-match-test regexp "ab" '("b" "ab")))) (ert-deftest rxt-pcre-test-00893 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^a\\Kcz|ac" ""))) (rxt-match-test regexp "ac" '("ac")))) (ert-deftest rxt-pcre-test-00894 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a\\Kbz|ab)" ""))) (rxt-match-test regexp "ab" '("ab")))) (ert-deftest rxt-pcre-test-00895 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?&t)(?(DEFINE)(?a\\Kb))$" ""))) (rxt-match-test regexp "ab" '("b")))) (ert-deftest rxt-pcre-test-00896 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^([^()]|\\((?1)*\\))*$" ""))) (rxt-match-test regexp "a(b)c" '("a(b)c" "c")) (rxt-match-test regexp "a(b(c)d)e" '("a(b(c)d)e" "e")))) (ert-deftest rxt-pcre-test-00897 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?P(?P0)(?P>L1)|(?P>L2))" ""))) (rxt-match-test regexp "0" '("0" "0")) (rxt-match-test regexp "00" '("00" "00" "0")) (rxt-match-test regexp "0000" '("0000" "0000" "0")))) (ert-deftest rxt-pcre-test-00898 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?P(?P0)|(?P>L2)(?P>L1))" ""))) (rxt-match-test regexp "0" '("0" "0" "0")) (rxt-match-test regexp "00" '("0" "0" "0")) (rxt-match-test regexp "0000" '("0" "0" "0")))) (ert-deftest rxt-pcre-test-00899 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- This one does fail, as expected, in Perl. It needs the complex item at the\n end of the pattern. A single letter instead of (B|D) makes it not fail,\n which I think is a Perl bug. --- " ""))))) (ert-deftest rxt-pcre-test-00900 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "A(*COMMIT)(B|D)" ""))) (rxt-match-test regexp "ACABX" 'nil))) (ert-deftest rxt-pcre-test-00901 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Check the use of names for failure ---" ""))))) (ert-deftest rxt-pcre-test-00902 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(A(*PRUNE:A)B|C(*PRUNE:B)D)" ""))) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "AC" 'nil) (rxt-match-test regexp "CB" 'nil))) (ert-deftest rxt-pcre-test-00903 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Force no study, otherwise mark is not seen. The studied version is in\n test 2 because it isn't Perl-compatible. ---" ""))))) (ert-deftest rxt-pcre-test-00904 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(*MARK:A)(*SKIP:B)(C|X)" ""))) (rxt-match-test regexp "C" '("C" "C")) (rxt-match-test regexp "D" 'nil))) (ert-deftest rxt-pcre-test-00905 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(A(*THEN:A)B|C(*THEN:B)D)" ""))) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "CB" 'nil))) (ert-deftest rxt-pcre-test-00906 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:A(*THEN:A)B|C(*THEN:B)D)" ""))) (rxt-match-test regexp "CB" 'nil))) (ert-deftest rxt-pcre-test-00907 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?>A(*THEN:A)B|C(*THEN:B)D)" ""))) (rxt-match-test regexp "CB" 'nil))) (ert-deftest rxt-pcre-test-00908 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- This should succeed, as the skip causes bump to offset 1 (the mark). Note\nthat we have to have something complicated such as (B|Z) at the end because,\nfor Perl, a simple character somehow causes an unwanted optimization to mess\nwith the handling of backtracking verbs. ---" ""))))) (ert-deftest rxt-pcre-test-00909 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "A(*MARK:A)A+(*SKIP:A)(B|Z) | AC" "x"))) (rxt-match-test regexp "AAAC" '("AC")))) (ert-deftest rxt-pcre-test-00910 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Test skipping over a non-matching mark. ---" ""))))) (ert-deftest rxt-pcre-test-00911 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "A(*MARK:A)A+(*MARK:B)(*SKIP:A)(B|Z) | AC" "x"))) (rxt-match-test regexp "AAAC" '("AC")))) (ert-deftest rxt-pcre-test-00912 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Check shorthand for MARK ---" ""))))) (ert-deftest rxt-pcre-test-00913 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "A(*:A)A+(*SKIP:A)(B|Z) | AC" "x"))) (rxt-match-test regexp "AAAC" '("AC")))) (ert-deftest rxt-pcre-test-00914 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Don't loop! Force no study, otherwise mark is not seen. ---" ""))))) (ert-deftest rxt-pcre-test-00915 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(*:A)A+(*SKIP:A)(B|Z)" ""))) (rxt-match-test regexp "AAAC" 'nil))) (ert-deftest rxt-pcre-test-00916 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- This should succeed, as a non-existent skip name disables the skip ---" ""))))) (ert-deftest rxt-pcre-test-00917 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "A(*MARK:A)A+(*SKIP:B)(B|Z) | AC" "x"))) (rxt-match-test regexp "AAAC" '("AC")))) (ert-deftest rxt-pcre-test-00918 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "A(*MARK:A)A+(*SKIP:B)(B|Z) | AC(*:B)" "x"))) (rxt-match-test regexp "AAAC" '("AC")))) (ert-deftest rxt-pcre-test-00919 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- COMMIT at the start of a pattern should act like an anchor. Again, \nhowever, we need the complication for Perl. ---" ""))))) (ert-deftest rxt-pcre-test-00920 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(*COMMIT)(A|P)(B|P)(C|P)" ""))) (rxt-match-test regexp "ABCDEFG" '("ABC" "A" "B" "C")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "DEFGABC" 'nil))) (ert-deftest rxt-pcre-test-00921 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- COMMIT inside an atomic group can't stop backtracking over the group. ---" ""))))) (ert-deftest rxt-pcre-test-00922 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(\\w+)(?>b(*COMMIT))\\w{2}" ""))) (rxt-match-test regexp "abbb" '("abbb" "a")))) (ert-deftest rxt-pcre-test-00923 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(\\w+)b(*COMMIT)\\w{2}" ""))) (rxt-match-test regexp "abbb" 'nil))) (ert-deftest rxt-pcre-test-00924 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Check opening parens in comment when seeking forward reference. ---" ""))))) (ert-deftest rxt-pcre-test-00925 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?&t)(?#()(?(DEFINE)(?a))" ""))) (rxt-match-test regexp "bac" '("a")))) (ert-deftest rxt-pcre-test-00926 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- COMMIT should override THEN ---" ""))))) (ert-deftest rxt-pcre-test-00927 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(*COMMIT)(?>yes|no)(*THEN)(*F))?" ""))) (rxt-match-test regexp "yes" 'nil))) (ert-deftest rxt-pcre-test-00928 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(*COMMIT)(yes|no)(*THEN)(*F))?" ""))) (rxt-match-test regexp "yes" 'nil))) (ert-deftest rxt-pcre-test-00929 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "b?(*SKIP)c" ""))) (rxt-match-test regexp "bc" '("bc")) (rxt-match-test regexp "abc" '("bc")))) (ert-deftest rxt-pcre-test-00930 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(*SKIP)bc" ""))) (rxt-match-test regexp "a" 'nil))) (ert-deftest rxt-pcre-test-00931 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(*SKIP)b" ""))) (rxt-match-test regexp "a" 'nil))) (ert-deftest rxt-pcre-test-00932 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?P(?P=abn)xxx|)+" ""))) (rxt-match-test regexp "xxx" '("" "")))) (ert-deftest rxt-pcre-test-00933 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?i:([^b]))(?1)" ""))) (rxt-match-test regexp "aa" '("aa" "a")) (rxt-match-test regexp "aA" '("aA" "a")) (rxt-match-test regexp "** Failers" '("**" "*")) (rxt-match-test regexp "ab" 'nil) (rxt-match-test regexp "aB" 'nil) (rxt-match-test regexp "Ba" 'nil) (rxt-match-test regexp "ba" 'nil))) (ert-deftest rxt-pcre-test-00934 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?&t)*+(?(DEFINE)(?a))\\w$" ""))) (rxt-match-test regexp "aaaaaaX" '("aaaaaaX")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "aaaaaa" 'nil))) (ert-deftest rxt-pcre-test-00935 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?&t)*(?(DEFINE)(?a))\\w$" ""))) (rxt-match-test regexp "aaaaaaX" '("aaaaaaX")) (rxt-match-test regexp "aaaaaa" '("aaaaaa")))) (ert-deftest rxt-pcre-test-00936 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)*+(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aaaaX" "a" "X")) (rxt-match-test regexp "YZ" '("Y" nil "Y")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "aaaa" 'nil))) (ert-deftest rxt-pcre-test-00937 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:a)*+(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aaaaX" "X")) (rxt-match-test regexp "YZ" '("Y" "Y")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "aaaa" 'nil))) (ert-deftest rxt-pcre-test-00938 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)++(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aaaaX" "a" "X")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "aaaa" 'nil) (rxt-match-test regexp "YZ" 'nil))) (ert-deftest rxt-pcre-test-00939 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:a)++(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aaaaX" "X")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "aaaa" 'nil) (rxt-match-test regexp "YZ" 'nil))) (ert-deftest rxt-pcre-test-00940 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)?+(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aa" "a" "a")) (rxt-match-test regexp "YZ" '("Y" nil "Y")))) (ert-deftest rxt-pcre-test-00941 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:a)?+(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aa" "a")) (rxt-match-test regexp "YZ" '("Y" "Y")))) (ert-deftest rxt-pcre-test-00942 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a){2,}+(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aaaaX" "a" "X")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "aaa" 'nil) (rxt-match-test regexp "YZ" 'nil))) (ert-deftest rxt-pcre-test-00943 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?:a){2,}+(\\w)" ""))) (rxt-match-test regexp "aaaaX" '("aaaaX" "X")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "aaa" 'nil) (rxt-match-test regexp "YZ" 'nil))) (ert-deftest rxt-pcre-test-00944 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a|)*(?1)b" ""))) (rxt-match-test regexp "b" '("b" "")) (rxt-match-test regexp "ab" '("ab" "")) (rxt-match-test regexp "aab" '("aab" "")))) (ert-deftest rxt-pcre-test-00945 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a)++(?1)b" ""))) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "ab" 'nil) (rxt-match-test regexp "aab" 'nil))) (ert-deftest rxt-pcre-test-00946 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(a)*+(?1)b" ""))) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "ab" 'nil) (rxt-match-test regexp "aab" 'nil))) (ert-deftest rxt-pcre-test-00947 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?1)(?:(b)){0}" ""))) (rxt-match-test regexp "b" '("b")))) (ert-deftest rxt-pcre-test-00948 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(foo ( \\( ((?:(?> [^()]+ )|(?2))*) \\) ) )" "x"))) (rxt-match-test regexp "foo(bar(baz)+baz(bop))" '("foo(bar(baz)+baz(bop))" "foo(bar(baz)+baz(bop))" "(bar(baz)+baz(bop))" "bar(baz)+baz(bop)")))) (ert-deftest rxt-pcre-test-00949 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(A (A|B(*ACCEPT)|C) D)(E)" "x"))) (rxt-match-test regexp "AB" '("AB" "AB" "B")))) (ert-deftest rxt-pcre-test-00950 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(?:a|b(*THEN)c)" ""))) (rxt-match-test regexp "ba" '("ba")))) (ert-deftest rxt-pcre-test-00951 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(?:a|bc)" ""))) (rxt-match-test regexp "ba" '("ba")))) (ert-deftest rxt-pcre-test-00952 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(a|b(*THEN)c)" ""))) (rxt-match-test regexp "ba" '("ba" "a")))) (ert-deftest rxt-pcre-test-00953 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(a|bc)" ""))) (rxt-match-test regexp "ba" '("ba" "a")))) (ert-deftest rxt-pcre-test-00954 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(?:a|b(*THEN)c)++" ""))) (rxt-match-test regexp "ba" '("ba")))) (ert-deftest rxt-pcre-test-00955 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(?:a|bc)++" ""))) (rxt-match-test regexp "ba" '("ba")))) (ert-deftest rxt-pcre-test-00956 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(a|b(*THEN)c)++" ""))) (rxt-match-test regexp "ba" '("ba" "a")))) (ert-deftest rxt-pcre-test-00957 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(a|bc)++" ""))) (rxt-match-test regexp "ba" '("ba" "a")))) (ert-deftest rxt-pcre-test-00958 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(?:a|b(*THEN)c|d)" ""))) (rxt-match-test regexp "ba" '("ba")))) (ert-deftest rxt-pcre-test-00959 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "\\A.*?(?:a|bc|d)" ""))) (rxt-match-test regexp "ba" '("ba")))) (ert-deftest rxt-pcre-test-00960 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?:(b))++" ""))) (rxt-match-test regexp "beetle" '("b" "b")))) (ert-deftest rxt-pcre-test-00961 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(?=(a(*ACCEPT)z))a)" ""))) (rxt-match-test regexp "a" '("a" "a")))) (ert-deftest rxt-pcre-test-00962 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)(?1)+ab" ""))) (rxt-match-test regexp "aaaab" '("aaaab" "a")))) (ert-deftest rxt-pcre-test-00963 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(a)(?1)++ab" ""))) (rxt-match-test regexp "aaaab" 'nil))) (ert-deftest rxt-pcre-test-00964 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?=a(*:M))aZ" ""))) (rxt-match-test regexp "aZbc" '("aZ")))) (ert-deftest rxt-pcre-test-00965 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?!(*:M)b)aZ" ""))) (rxt-match-test regexp "aZbc" '("aZ")))) (ert-deftest rxt-pcre-test-00966 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(DEFINE)(a))?b(?1)" ""))) (rxt-match-test regexp "backgammon" '("ba")))) (ert-deftest rxt-pcre-test-00967 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\N+" ""))) (rxt-match-test regexp "abc\ndef" '("abc")))) (ert-deftest rxt-pcre-test-00968 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^\\N{1,}" ""))) (rxt-match-test regexp "abc\ndef" '("abc")))) (ert-deftest rxt-pcre-test-00969 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(R)a+|(?R)b)" ""))) (rxt-match-test regexp "aaaabcde" '("aaaab")))) (ert-deftest rxt-pcre-test-00970 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?(R)a+|((?R))b)" ""))) (rxt-match-test regexp "aaaabcde" '("aaaab" "aaaa")))) (ert-deftest rxt-pcre-test-00971 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?(R)a+|(?1)b))" ""))) (rxt-match-test regexp "aaaabcde" '("aaaab" "aaaab")))) (ert-deftest rxt-pcre-test-00972 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "((?(R1)a+|(?1)b))" ""))) (rxt-match-test regexp "aaaabcde" '("aaaab" "aaaab")))) (ert-deftest rxt-pcre-test-00973 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "a(*:any \nname)" ""))) (rxt-match-test regexp "abc" '("a")))) (ert-deftest rxt-pcre-test-00974 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(?&t)c|(?&t))(?(DEFINE)(?a|b(*PRUNE)c))" ""))) (rxt-match-test regexp "a" '("a")) (rxt-match-test regexp "ba" '("a")) (rxt-match-test regexp "bba" '("a")))) (ert-deftest rxt-pcre-test-00975 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Checking revised (*THEN) handling ---" ""))))) (ert-deftest rxt-pcre-test-00976 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Capture ---" ""))))) (ert-deftest rxt-pcre-test-00977 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (a(*THEN)b) c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00978 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (a(*THEN)b|(*F)) c" "x"))) (rxt-match-test regexp "aabc" '("aabc" "ab")))) (ert-deftest rxt-pcre-test-00979 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? ( (a(*THEN)b) | (*F) ) c" "x"))) (rxt-match-test regexp "aabc" '("aabc" "ab" "ab")))) (ert-deftest rxt-pcre-test-00980 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? ( (a(*THEN)b) ) c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00981 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Non-capture ---" ""))))) (ert-deftest rxt-pcre-test-00982 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?:a(*THEN)b) c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00983 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?:a(*THEN)b|(*F)) c" "x"))) (rxt-match-test regexp "aabc" '("aabc")))) (ert-deftest rxt-pcre-test-00984 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?: (?:a(*THEN)b) | (*F) ) c" "x"))) (rxt-match-test regexp "aabc" '("aabc")))) (ert-deftest rxt-pcre-test-00985 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?: (?:a(*THEN)b) ) c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00986 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Atomic ---" ""))))) (ert-deftest rxt-pcre-test-00987 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?>a(*THEN)b) c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00988 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?>a(*THEN)b|(*F)) c" "x"))) (rxt-match-test regexp "aabc" '("aabc")))) (ert-deftest rxt-pcre-test-00989 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?> (?>a(*THEN)b) | (*F) ) c" "x"))) (rxt-match-test regexp "aabc" '("aabc")))) (ert-deftest rxt-pcre-test-00990 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?> (?>a(*THEN)b) ) c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00991 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Possessive capture ---" ""))))) (ert-deftest rxt-pcre-test-00992 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (a(*THEN)b)++ c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00993 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (a(*THEN)b|(*F))++ c" "x"))) (rxt-match-test regexp "aabc" '("aabc" "ab")))) (ert-deftest rxt-pcre-test-00994 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? ( (a(*THEN)b)++ | (*F) )++ c" "x"))) (rxt-match-test regexp "aabc" '("aabc" "ab" "ab")))) (ert-deftest rxt-pcre-test-00995 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? ( (a(*THEN)b)++ )++ c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00996 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Possessive non-capture ---" ""))))) (ert-deftest rxt-pcre-test-00997 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?:a(*THEN)b)++ c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-00998 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?:a(*THEN)b|(*F))++ c" "x"))) (rxt-match-test regexp "aabc" '("aabc")))) (ert-deftest rxt-pcre-test-00999 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?: (?:a(*THEN)b)++ | (*F) )++ c" "x"))) (rxt-match-test regexp "aabc" '("aabc")))) (ert-deftest rxt-pcre-test-01000 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*? (?: (?:a(*THEN)b)++ )++ c" "x"))) (rxt-match-test regexp "aabc" 'nil))) (ert-deftest rxt-pcre-test-01001 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Condition assertion ---" ""))))) (ert-deftest rxt-pcre-test-01002 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^(?(?=a(*THEN)b)ab|ac)" ""))) (rxt-match-test regexp "ac" '("ac")))) (ert-deftest rxt-pcre-test-01003 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Condition ---" ""))))) (ert-deftest rxt-pcre-test-01004 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*?(?(?=a)a|b(*THEN)c)" ""))) (rxt-match-test regexp "ba" 'nil))) (ert-deftest rxt-pcre-test-01005 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*?(?:(?(?=a)a|b(*THEN)c)|d)" ""))) (rxt-match-test regexp "ba" '("ba")))) (ert-deftest rxt-pcre-test-01006 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*?(?(?=a)a(*THEN)b|c)" ""))) (rxt-match-test regexp "ac" 'nil))) (ert-deftest rxt-pcre-test-01007 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "--- Assertion ---" ""))))) (ert-deftest rxt-pcre-test-01008 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "^.*(?=a(*THEN)b)" ""))) (rxt-match-test regexp "aabc" '("a")))) (ert-deftest rxt-pcre-test-01009 nil (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "------------------------------" ""))))) (ert-deftest rxt-pcre-test-01010 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>a(*:m))" "imsx"))) (rxt-match-test regexp "a" '("a")))) (ert-deftest rxt-pcre-test-01011 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?>(a)(*:m))" "imsx"))) (rxt-match-test regexp "a" '("a" "a")))) (ert-deftest rxt-pcre-test-01012 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=a(*ACCEPT)b)c" ""))) (rxt-match-test regexp "xacd" '("c")))) (ert-deftest rxt-pcre-test-01013 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=(a(*ACCEPT)b))c" ""))) (rxt-match-test regexp "xacd" '("c" "a")))) (ert-deftest rxt-pcre-test-01014 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(?<=(a(*COMMIT)b))c" ""))) (rxt-match-test regexp "xabcd" '("c" "ab")) (rxt-match-test regexp "** Failers" 'nil) (rxt-match-test regexp "xacd" 'nil))) (ert-deftest rxt-pcre-test-01015 nil :expected-result :failed (let* ((case-fold-search nil) (regexp (rxt-pcre-to-elisp "(? ;; Author: joddie ;; Hacked additionally by: opensource at hardakers dot net ;; Created: 14 Feb 2012 ;; Updated: 13 December 2015 ;; Version: 1.11 ;; Url: https://github.com/joddie/pcre2el ;; Package-Requires: ((emacs "25.1")) ;; This file is NOT part of GNU Emacs. ;; 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 3 of the ;; License, 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, see `http://www.gnu.org/licenses/'. ;; This file incorporates work covered by the following copyright and ;; permission notice: ;; ;; Copyright (c) 1993-2002 Richard Kelsey and Jonathan Rees ;; Copyright (c) 1994-2002 by Olin Shivers and Brian D. Carlstrom. ;; Copyright (c) 1999-2002 by Martin Gasbichler. ;; Copyright (c) 2001-2002 by Michael Sperber. ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: 1. Redistributions of source code must retain the above ;; copyright notice, this list of conditions and the following ;; disclaimer. 2. Redistributions in binary form must reproduce the ;; above copyright notice, this list of conditions and the following ;; disclaimer in the documentation and/or other materials provided ;; with the distribution. 3. The name of the authors may not be used ;; to endorse or promote products derived from this software without ;; specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY ;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS ;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; Commentary: ;; 1 Overview ;; ========== ;; `pcre2el' or `rxt' (RegeXp Translator or RegeXp Tools) is a utility ;; for working with regular expressions in Emacs, based on a ;; recursive-descent parser for regexp syntax. In addition to converting ;; (a subset of) PCRE syntax into its Emacs equivalent, it can do the ;; following: ;; - convert Emacs syntax to PCRE ;; - convert either syntax to `rx', an S-expression based regexp syntax ;; - untangle complex regexps by showing the parse tree in `rx' form and ;; highlighting the corresponding chunks of code ;; - show the complete list of strings (productions) matching a regexp, ;; provided the list is finite ;; - provide live font-locking of regexp syntax (so far only for Elisp ;; buffers -- other modes on the TODO list) ;; 2 Usage ;; ======= ;; Enable `rxt-mode' or its global equivalent `rxt-global-mode' to get ;; the default key-bindings. There are three sets of commands: commands ;; that take a PCRE regexp, commands which take an Emacs regexp, and ;; commands that try to do the right thing based on the current ;; mode. Currently, this means Emacs syntax in `emacs-lisp-mode' and ;; `lisp-interaction-mode', and PCRE syntax everywhere else. ;; The default key bindings all begin with `C-c /' and have a mnemonic ;; structure: `C-c / ', or just `C-c / ' for the ;; "do what I mean" commands. The complete list of key bindings is given ;; here and explained in more detail below: ;; - "Do-what-I-mean" commands: ;; `C-c / /': `rxt-explain' ;; `C-c / c': `rxt-convert-syntax' ;; `C-c / x': `rxt-convert-to-rx' ;; `C-c / '': `rxt-convert-to-strings' ;; - Commands that work on a PCRE regexp: ;; `C-c / p e': `rxt-pcre-to-elisp' ;; `C-c / %': `pcre-query-replace-regexp' ;; `C-c / p x': `rxt-pcre-to-rx' ;; `C-c / p '': `rxt-pcre-to-strings' ;; `C-c / p /': `rxt-explain-pcre' ;; - Commands that work on an Emacs regexp: ;; `C-c / e /': `rxt-explain-elisp' ;; `C-c / e p': `rxt-elisp-to-pcre' ;; `C-c / e x': `rxt-elisp-to-rx' ;; `C-c / e '': `rxt-elisp-to-strings' ;; `C-c / e t': `rxt-toggle-elisp-rx' ;; `C-c / t': `rxt-toggle-elisp-rx' ;; 2.1 Interactive input and output ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; When used interactively, the conversion commands can read a regexp ;; either from the current buffer or from the minibuffer. The output is ;; displayed in the minibuffer and copied to the kill-ring. ;; - When called with a prefix argument (`C-u'), they read a regular ;; expression from the minibuffer literally, without further processing ;; -- meaning there's no need to double the backslashes if it's an ;; Emacs regexp. This is the same way commands like ;; `query-replace-regexp' read input. ;; - When the region is active, they use they the region contents, again ;; literally (without any translation of string syntax). ;; - With neither a prefix arg nor an active region, the behavior depends ;; on whether the command expects an Emacs regexp or a PCRE one. ;; Commands that take an Emacs regexp behave like `C-x C-e': they ;; evaluate the sexp before point (which could be simply a string ;; literal) and use its value. This is designed for use in Elisp ;; buffers. As a special case, if point is *inside* a string, it's ;; first moved to the string end, so in practice they should work as ;; long as point is somewhere within the regexp literal. ;; Commands that take a PCRE regexp try to read a Perl-style delimited ;; regex literal *after* point in the current buffer, including its ;; flags. For example, putting point before the `m' in the following ;; example and doing `C-c / p e' (`rxt-pcre-to-elisp') displays ;; `\(?:bar\|foo\)', correctly stripping out the whitespace and ;; comment: ;; ,---- ;; | $x =~ m/ foo | (?# comment) bar /x ;; `---- ;; The PCRE reader currently only works with `/ ... /' delimiters. It ;; will ignore any preceding `m', `s', or `qr' operator, as well as the ;; replacement part of an `s' construction. ;; Readers for other PCRE-using languages are on the TODO list. ;; The translation functions display their result in the minibuffer and ;; copy it to the kill ring. When translating something into Elisp ;; syntax, you might need to use the result either literally (e.g. for ;; interactive input to a command like `query-replace-regexp'), or as a ;; string to paste into Lisp code. To allow both uses, ;; `rxt-pcre-to-elisp' copies both versions successively to the ;; kill-ring. The literal regexp without string quoting is the top ;; element of the kill-ring, while the Lisp string is the ;; second-from-top. You can paste the literal regexp somewhere by doing ;; `C-y', or the Lisp string by `C-y M-y'. ;; 2.2 Syntax conversion commands ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; `rxt-convert-syntax' (`C-c / c') converts between Emacs and PCRE ;; syntax, depending on the major mode in effect when called. ;; Alternatively, you can specify the conversion direction explicitly by ;; using either `rxt-pcre-to-elisp' (`C-c / p e') or `rxt-elisp-to-pcre' ;; (`C-c / e p'). ;; Similarly, `rxt-convert-to-rx' (`C-c / x') converts either kind of ;; syntax to `rx' form, while `rxt-convert-pcre-to-rx' (`C-c / p x') and ;; `rxt-convert-elisp-to-rx' (`C-c / e x') convert to `rx' from a ;; specified source type. ;; In Elisp buffers, you can use `rxt-toggle-elisp-rx' (`C-c / t' or `C-c ;; / e t') to switch the regexp at point back and forth between string ;; and `rx' syntax. Point should either be within an `rx' or ;; `rx-to-string' form or a string literal for this to work. ;; 2.3 PCRE mode (experimental) ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; If you want to use emulated PCRE regexp syntax in all Emacs commands, ;; try `pcre-mode', which uses Emacs's advice system to make all commands ;; that read regexps using the minibuffer use emulated PCRE syntax. It ;; should also work with Isearch. ;; This feature is still fairly experimental. It may fail to work or do ;; the wrong thing with certain commands. Please report bugs. ;; `pcre-query-replace-regexp' was originally defined to do query-replace ;; using emulated PCRE regexps, and is now made somewhat obsolete by ;; `pcre-mode'. It is bound to `C-c / %' by default, by analogy with ;; `M-%'. Put the following in your `.emacs' if you want to use ;; PCRE-style query replacement everywhere: ;; ,---- ;; | (global-set-key [(meta %)] 'pcre-query-replace-regexp) ;; `---- ;; 2.5 Explain regexps ;; ~~~~~~~~~~~~~~~~~~~ ;; When syntax-highlighting isn't enough to untangle some gnarly regexp ;; you find in the wild, try the 'explain' commands: `rxt-explain' (`C-c ;; / /'), `rxt-explain-pcre' (`C-c / p') and `rxt-explain-elisp' (`C-c / ;; e'). These display the original regexp along with its pretty-printed ;; `rx' equivalent in a new buffer. Moving point around either in the ;; original regexp or the `rx' translation highlights corresponding ;; pieces of syntax, which can aid in seeing things like the scope of ;; quantifiers. ;; I call them "explain" commands because the `rx' form is close to a ;; plain syntax tree, and this plus the wordiness of the operators ;; usually helps to clarify what is going on. People who dislike Lisp ;; syntax might disagree with this assessment. ;; 2.6 Generate all matching strings (productions) ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; Occasionally you come across a regexp which is designed to match a ;; finite set of strings, e.g. a set of keywords, and it would be useful ;; to recover the original set. (In Emacs you can generate such regexps ;; using `regexp-opt'). The commands `rxt-convert-to-strings' (`C-c / ;; ′'), `rxt-pcre-to-strings' (`C-c / p ′') or `rxt-elisp-to-strings' ;; (`C-c / e ′') accomplish this by generating all the matching strings ;; ("productions") of a regexp. (The productions are copied to the kill ;; ring as a Lisp list). ;; An example in Lisp code: ;; ,---- ;; | (regexp-opt '("cat" "caterpillar" "catatonic")) ;; | ;; => "\\(?:cat\\(?:atonic\\|erpillar\\)?\\)" ;; | (rxt-elisp-to-strings "\\(?:cat\\(?:atonic\\|erpillar\\)?\\)") ;; | ;; => '("cat" "caterpillar" "catatonic") ;; `---- ;; For obvious reasons, these commands only work with regexps that don't ;; include any unbounded quantifiers like `+' or `*'. They also can't ;; enumerate all the characters that match a named character class like ;; `[[:alnum:]]'. In either case they will give a (hopefully meaningful) ;; error message. Due to the nature of permutations, it's still possible ;; for a finite regexp to generate a huge number of productions, which ;; will eat memory and slow down your Emacs. Be ready with `C-g' if ;; necessary. ;; 2.7 RE-Builder support ;; ~~~~~~~~~~~~~~~~~~~~~~ ;; The Emacs RE-Builder is a useful visual tool which allows using ;; several different built-in syntaxes via `reb-change-syntax' (`C-c ;; TAB'). It supports Elisp read and literal syntax and `rx', but it can ;; only convert from the symbolic forms to Elisp, not the other way. This ;; package hacks the RE-Builder to also work with emulated PCRE syntax, ;; and to convert transparently between Elisp, PCRE and rx syntaxes. PCRE ;; mode reads a delimited Perl-like literal of the form `/ ... /', and it ;; should correctly support using the `x' and `s' flags. ;; 2.8 Use from Lisp ;; ~~~~~~~~~~~~~~~~~ ;; Example of using the conversion functions: ;; ,---- ;; | (rxt-pcre-to-elisp "(abc|def)\\w+\\d+") ;; | ;; => "\\(\\(?:abc\\|def\\)\\)[_[:alnum:]]+[[:digit:]]+" ;; `---- ;; All the conversion functions take a single string argument, the regexp ;; to translate: ;; - `rxt-pcre-to-elisp' ;; - `rxt-pcre-to-rx' ;; - `rxt-pcre-to-strings' ;; - `rxt-elisp-to-pcre' ;; - `rxt-elisp-to-rx' ;; - `rxt-elisp-to-strings' ;; 3 Bugs and Limitations ;; ====================== ;; 3.1 Limitations on PCRE syntax ;; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;; PCRE has a complicated syntax and semantics, only some of which can be ;; translated into Elisp. The following subset of PCRE should be ;; correctly parsed and converted: ;; - parenthesis grouping `( .. )', including shy matches `(?: ... )' ;; - backreferences (various syntaxes), but only up to 9 per expression ;; - alternation `|' ;; - greedy and non-greedy quantifiers `*', `*?', `+', `+?', `?' and `??' ;; (all of which are the same in Elisp as in PCRE) ;; - numerical quantifiers `{M,N}' ;; - beginning/end of string `\A', `\Z' ;; - string quoting `\Q .. \E' ;; - word boundaries `\b', `\B' (these are the same in Elisp) ;; - single character escapes `\a', `\c', `\e', `\f', `\n', `\r', `\t', ;; `\x', and `\octal digits' (but see below about non-ASCII characters) ;; - character classes `[...]' including Posix escapes ;; - character classes `\d', `\D', `\h', `\H', `\s', `\S', `\v', `\V' ;; both within character class brackets and outside ;; - word and non-word characters `\w' and `\W' (Emacs has the same ;; syntax, but its meaning is different) ;; - `s' (single line) and `x' (extended syntax) flags, in regexp ;; literals, or set within the expression via `(?xs-xs)' or `(?xs-xs: ;; .... )' syntax ;; - comments `(?# ... )' ;; Most of the more esoteric PCRE features can't really be supported by ;; simple translation to Elisp regexps. These include the different ;; lookaround assertions, conditionals, and the "backtracking control ;; verbs" `(* ...)' . OTOH, there are a few other syntaxes which are ;; currently unsupported and possibly could be: ;; - `\L', `\U', `\l', `\u' case modifiers ;; - `\g{...}' backreferences ;; 3.2 Other limitations ;; ~~~~~~~~~~~~~~~~~~~~~ ;; - The order of alternatives and characters in char classes sometimes ;; gets shifted around, which is annoying. ;; - Although the string parser tries to interpret PCRE's octal and ;; hexadecimal escapes correctly, there are problems with matching ;; 8-bit characters that I don't use enough to properly understand, ;; e.g.: ;; ,---- ;; | (string-match-p (rxt-pcre-to-elisp "\\377") "\377") => nil ;; `---- ;; A fix for this would be welcome. ;; - Most of PCRE's rules for how `^', `\A', `$' and `\Z' interact with ;; newlines are not implemented, since they seem less relevant to ;; Emacs's buffer-oriented rather than line-oriented model. However, ;; the different meanings of the `.' metacharacter *are* implemented ;; (it matches newlines with the `/s' flag, but not otherwise). ;; - Not currently namespace clean (both `rxt-' and a couple of `pcre-' ;; functions). ;; 3.3 TODO: ;; ~~~~~~~~~ ;; - Python-specific extensions to PCRE? ;; - Language-specific stuff to enable regexp font-locking and explaining ;; in different modes. Each language would need two functions, which ;; could be kept in an alist: ;; 1. A function to read PCRE regexps, taking the string syntax into ;; account. E.g., Python has single-quoted, double-quoted and raw ;; strings, each with different quoting rules. PHP has the kind of ;; belt-and-suspenders solution you would expect: regexps are in ;; strings, /and/ you have to include the `/ ... /' delimiters! ;; Duh. ;; 2. A function to copy faces back from the parsed string to the ;; original buffer text. This has to recognize any escape sequences ;; so they can be treated as a single character. ;; 4 Internal details ;; ================== ;; `rxt' defines an internal syntax tree representation of regular ;; expressions, parsers for Elisp and PCRE syntax, and 'unparsers' ;; to convert the internal representation to PCRE or `rx' syntax. ;; Converting from the internal representation to Emacs syntax is ;; done by converting to `rx' form and passing it to `rx-to-string'. ;; See `rxt-parse-re', `rxt-adt->pcre', and `rxt-adt->rx' for ;; details. ;; This code is partially based on Olin Shivers' reference SRE ;; implementation in scsh, although it is simplified in some respects and ;; extended in others. See `scsh/re.scm', `scsh/spencer.scm' and ;; `scsh/posixstr.scm' in the `scsh' source tree for details. In ;; particular, `pcre2el' steals the idea of an abstract data type for ;; regular expressions and the general structure of the string regexp ;; parser and unparser. The data types for character sets are extended in ;; order to support symbolic translation between character set ;; expressions without assuming a small (Latin1) character set. The ;; string parser is also extended to parse a bigger variety of ;; constructions, including POSIX character classes and various Emacs and ;; Perl regexp assertions. Otherwise, only the bare minimum of scsh's ;; abstract data type is implemented. ;; 5 Soapbox ;; ========= ;; Emacs regexps have their annoyances, but it is worth getting used to ;; them. The Emacs assertions for word boundaries, symbol boundaries, and ;; syntax classes depending on the syntax of the mode in effect are ;; especially useful. (PCRE has `\b' for word-boundary, but AFAIK it ;; doesn't have separate assertions for beginning-of-word and ;; end-of-word). Other things that might be done with huge regexps in ;; other languages can be expressed more understandably in Elisp using ;; combinations of `save-excursion' with the various searches (regexp, ;; literal, skip-syntax-forward, sexp-movement functions, etc.). ;; There's not much point in using `rxt-pcre-to-elisp' to use PCRE ;; notation in a Lisp program you're going to maintain, since you still ;; have to double all the backslashes. Better to just use the converted ;; result (or better yet, the `rx' form). ;; 6 History and acknowledgments ;; ============================= ;; This was originally created out of an answer to a stackoverflow ;; question: ;; [http://stackoverflow.com/questions/9118183/elisp-mechanism-for-converting-pcre-regexps-to-emacs-regexps] ;; Thanks to: ;; - Wes Hardaker (hardaker) for the initial inspiration and subsequent ;; hacking ;; - priyadarshan for requesting RX support ;; - Daniel Colascione (dcolascione) for a patch to support Emacs's ;; explicitly-numbered match groups ;; - Aaron Meurer (asmeurer) for requesting Isearch support ;; - Philippe Vaucher (silex) for a patch to support `ibuffer-do-replace-regexp' ;; in PCRE mode ;;; Code: (require 'cl-lib) (require 'rx) (require 're-builder) (require 'advice) (require 'ring) (require 'pcase) ;;; Customization group (defgroup rxt nil "Regex syntax converter and utilities." :version 1.2 :group 'tools :group 'lisp :link '(emacs-commentary-link :tag "commentary" "pcre2el.el") :link '(emacs-library-link :tag "lisp file" "pcre2el.el") :link '(url-link :tag "web page" "https://github.com/joddie/pcre2el")) (defface rxt-highlight-face '((((min-colors 16581375) (background light)) :background "#eee8d5") (((min-colors 16581375) (background dark)) :background "#222222")) "Face for highlighting corresponding regex syntax in `rxt-explain' buffers." :group 'rxt) (defcustom rxt-verbose-rx-translation nil "Non-nil if `rxt-pcre-to-rx' and `rxt-elisp-to-rx' should use verbose `rx' primitives. Verbose primitives are things like `line-start' instead of `bol', etc." :group 'rxt :type 'boolean) (defcustom rxt-explain-verbosely t "Non-nil if `rxt-explain-elisp' and `rxt-explain-pcre' should use verbose `rx' primitives. This overrides the value of `rxt-verbose-rx-translation' for these commands only." :group 'rxt :type 'boolean) ;;;; Macros and functions for writing interactive input and output ;; Macros for handling return values. If called interactively, ;; display the value in the echo area and copy it to the kill ring, ;; otherwise just return the value. PCREs are copied as unquoted ;; strings for yanking into Perl, JS, etc. `rx' forms and other sexps ;; are copied as `read'-able literals for yanking into Elisp buffers. ;; Emacs regexps are copied twice: once as an unquoted value for ;; interactive use, and once as a readable string literal for yanking ;; into Elisp buffers. (defmacro rxt-return-pcre (expr) (let ((value (make-symbol "value"))) `(let ((,value ,expr)) (when (called-interactively-p 'any) (rxt--kill-pcre ,value)) ,value))) (defmacro rxt-return-sexp (expr) (let ((value (make-symbol "value"))) `(let ((,value ,expr)) (when (called-interactively-p 'any) (rxt--kill-sexp ,value)) ,value))) (defmacro rxt-return-emacs-regexp (expr) (let ((value (make-symbol "value"))) `(let ((,value ,expr)) (when (called-interactively-p 'any) (rxt--kill-emacs-regexp ,value)) ,value))) (defun rxt--kill-sexp (value) (let ((lisp-literal (prin1-to-string value))) (message "%s" lisp-literal) (kill-new lisp-literal))) (defun rxt--kill-pcre (value) (message "%s" value) (kill-new value)) (defun rxt--kill-emacs-regexp (value) (let ((lisp-literal (prin1-to-string value))) (message "%s" value) (kill-new lisp-literal) (kill-new value))) ;; Read an Elisp regexp interactively. ;; ;; Three possibilities: ;; ;; 1) With a prefix arg, reads literally from the minibuffer, w/o ;; using string syntax -- just like query-replace-regexp, etc. ;; ;; 2) If the region is active, use the text of the region literally ;; (again w/o string syntax) ;; ;; 3) Otherwise, eval the sexp before point (which might be a string ;; literal or an expression) and use its value. Falls back to method ;; (1) if this fails to produce a string value. ;; (cl-defun rxt-interactive/elisp (&optional (prompt "Emacs regexp: ")) (list (cond (current-prefix-arg (read-string prompt)) ((use-region-p) (buffer-substring-no-properties (region-beginning) (region-end))) (t (condition-case nil (save-excursion (while (nth 3 (syntax-ppss)) (forward-char)) (let ((re (eval (elisp--preceding-sexp)))) (if (stringp re) re (read-string prompt)))) (error (read-string prompt))))))) ;; Read a PCRE regexp interactively. ;; ;; Three possibilities: As above, except that without prefix arg or ;; active region, tries to read a delimited regexp literal like /.../, ;; m/.../, or qr/.../ following point in the current buffer. Falls ;; back to reading from minibuffer if that fails. ;; ;; Returns the regexp, with flags as text properties. ;; ;; TODO: Different delimiters (cl-defun rxt-interactive/pcre (&optional (prompt "PCRE regexp: ")) (list (cond (current-prefix-arg (rxt--read-pcre prompt)) ((use-region-p) (buffer-substring-no-properties (region-beginning) (region-end))) (t (condition-case nil (rxt-read-delimited-pcre) (error ; Fall back to reading from minibuffer (rxt--read-pcre prompt))))) nil)) (define-minor-mode rxt--read-pcre-mode "Minor-mode with key-bindings for toggling PCRE flags. You should not normally call this directly. It will be enabled in minibuffers for `read-regexp' and in the `re-builder' buffer when `pcre-mode' is active. These bindings will also be added to `isearch-mode-map' in `pcre-mode'." :initial-value nil :lighter nil :keymap `((,(kbd "C-c s") . ,#'rxt--toggle-s-mode) (,(kbd "C-c x") . ,#'rxt--toggle-x-mode) (,(kbd "C-c i") . ,#'rxt--toggle-i-mode))) (defun rxt--read-pcre (prompt) "Read a PCRE regexp for translation, together with option flags. The `s', `x', and `i' flags can be toggled using the following commands: \\ \\[rxt--toggle-s-mode] : toggle `s' (single-line) mode \\[rxt--toggle-x-mode] : toggle `x' (extended) mode \\[rxt--toggle-i-mode] : toggle `i' (case-insensitive) mode In single-line mode, `.' will also match newlines. In extended mode, whitespace is ignored. Case-insensitive mode emulates matching without case, independently of Emacs's builtin `case-fold-search' setting. Note that this does not apply to backreferences." (minibuffer-with-setup-hook #'rxt--read-pcre-mode (read-from-minibuffer prompt))) (defun rxt--toggle-s-mode () "Toggle emulated PCRE single-line (s) flag." (interactive) (rxt--toggle-flag ?s)) (defun rxt--toggle-x-mode () "Toggle emulated PCRE extended (x) flag." (interactive) (rxt--toggle-flag ?x)) (defun rxt--toggle-i-mode () "Toggle emulated PCRE case-insensitive (i) flag." (interactive) (rxt--toggle-flag ?i)) (defun rxt--toggle-flag (char) "Toggle CHAR, a PCRE flag." (cond ((derived-mode-p 'reb-mode) ; RE-Builder (rxt--toggle-flag-re-builder char)) ((minibufferp) (rxt--toggle-flag-minibuffer char)) (isearch-mode (rxt--toggle-flag-isearch char)) (t (error "Not in minibuffer, RE-Builder or isearch mode.")))) (defun rxt--toggle-flag-re-builder (char) (save-excursion (goto-char (point-max)) (search-backward "/") (forward-char) (when (looking-at (rx (* (any ?i ?s ?x)))) (let ((inhibit-modification-hooks t)) (replace-match (rxt--xor-flags (match-string 0) char) t t)))) (reb-do-update)) (defun rxt--toggle-flag-minibuffer (char) (setf (buffer-substring (minibuffer-prompt-end) (point-max)) (rxt--toggle-flag-string (minibuffer-contents) char)) (when (and (= (point) (minibuffer-prompt-end)) (looking-at (rx "(?" (group (+ (any ?i ?s ?x))) ")"))) (forward-sexp))) (defun rxt--toggle-flag-isearch (char) (when isearch-regexp (setq isearch-string (rxt--toggle-flag-string isearch-string char)) (setq isearch-message (mapconcat #'isearch-text-char-description isearch-string "")) (isearch-search-and-update))) (defun rxt--toggle-flag-string (string char) (if (string-match (rx string-start "(?" (group (+ (any ?i ?s ?x))) ")") string) (let ((flags (rxt--xor-flags (match-string 1 string) char))) (if (string= flags "") (replace-match "" t t string) (replace-match flags t t string 1))) (format "(?%c)%s" char string))) (defun rxt--xor-flags (flags char) (concat (sort (cl-set-exclusive-or (string-to-list flags) (list char)) #'<))) ;;;; Minor mode for using emulated PCRE syntax (defvar pcre-old-isearch-search-fun-function nil "Original value of `isearch-search-fun-function' before entering `pcre-mode.' This function is wrapped by `pcre-isearch-search-fun-function' and restored on exit from `pcre-mode'.") (make-variable-buffer-local 'pcre-old-isearch-search-fun-function) (defvar pcre-old-isearch-key-bindings nil "Alist of key-bindings to restore in `isearch-mode-map' on exiting `pcre-mode'.") ;;;###autoload (define-minor-mode pcre-mode "Use emulated PCRE syntax for regexps wherever possible. Advises the `interactive' specs of `read-regexp' and the following other functions so that they read PCRE syntax and translate to its Emacs equivalent: - `align-regexp' - `find-tag-regexp' - `sort-regexp-fields' - `isearch-message-prefix' - `ibuffer-do-replace-regexp' Also alters the behavior of `isearch-mode' when searching by regexp." :init-value nil :lighter " PCRE" :keymap nil :global t (if pcre-mode ;; Enabling (progn ;; Enable advice (ad-enable-regexp "pcre-mode") ;; Set up isearch hooks (add-hook 'isearch-mode-hook #'pcre-isearch-mode-hook) (add-hook 'isearch-mode-end-hook #'pcre-isearch-mode-end-hook) ;; Add the keybindings of `rxt--read-pcre-mode-map' to ;; `isearch-mode-map' (so that they do not cause an exit from ;; `isearch-mode'), and save any existing bindings for those ;; keys to restore on exit from `pcre-mode'. (setq pcre-old-isearch-key-bindings (cl-loop for key being the key-seqs of rxt--read-pcre-mode-map for def = (lookup-key isearch-mode-map key) collect (cons (copy-sequence key) (if (numberp def) nil def)))) (cl-loop for key being the key-seqs of rxt--read-pcre-mode-map using (key-bindings def) do (define-key isearch-mode-map key def))) ;; Disable advice (ad-disable-regexp "pcre-mode") ;; Remove from isearch hooks (remove-hook 'isearch-mode-hook #'pcre-isearch-mode-hook) (remove-hook 'isearch-mode-end-hook #'pcre-isearch-mode-end-hook) ;; Restore key-bindings (cl-loop for (key . def) in pcre-old-isearch-key-bindings do (define-key isearch-mode-map key def))) ;; "Activating" advice re-computes the function definitions, which ;; is necessary whether enabling or disabling (ad-activate-regexp "pcre-mode")) ;;; Cache of PCRE -> Elisp translations (defvar pcre-mode-cache-size 100 "Number of PCRE-to-Emacs translations to keep in the `pcre-mode' cache.") (defvar pcre-mode-cache (make-hash-table :test 'equal) "Cache of PCRE-to-Emacs translations used in `pcre-mode'. Keys are PCRE regexps, values are their Emacs equivalents.") (defvar pcre-mode-reverse-cache (make-hash-table :test 'equal) "Cache of original PCREs translated to Emacs syntax in `pcre-mode'. Keys are translated Emacs regexps, values are their original PCRE form. This is used to display the original PCRE regexp in place of its translated form.") (defvar pcre-cache-ring (make-ring pcre-mode-cache-size) "Ring of PCRE-to-Emacs translations used in `pcre-mode'. When the ring fills up, the oldest element is removed and the corresponding entries are deleted from the hash tables `pcre-mode-cache' and `pcre-mode-reverse-cache'.") (defun pcre-to-elisp/cached (pcre) "Translate PCRE to Emacs syntax, caching both forms." (or (gethash pcre pcre-mode-cache) (let ((elisp (rxt-pcre-to-elisp pcre))) (pcre-set-cache pcre elisp) elisp))) (defun pcre-set-cache (pcre-regexp emacs-regexp) "Add a PCRE-to-Emacs translation to the `pcre-mode' cache." (when (and (not (zerop (length pcre-regexp))) (not (zerop (length emacs-regexp))) (not (gethash pcre-regexp pcre-mode-cache))) (if (= (ring-length pcre-cache-ring) (ring-size pcre-cache-ring)) (let* ((old-item (ring-remove pcre-cache-ring)) (old-pcre (car old-item)) (old-emacs (cdr old-item))) (remhash old-pcre pcre-mode-cache) (remhash old-emacs pcre-mode-reverse-cache)) (puthash pcre-regexp emacs-regexp pcre-mode-cache) (puthash emacs-regexp pcre-regexp pcre-mode-reverse-cache) (ring-insert pcre-cache-ring (cons pcre-regexp emacs-regexp))))) ;;; Isearch advice (defun pcre-isearch-mode-hook () (when (not (eq isearch-search-fun-function #'isearch-search-fun-default)) (message "Warning: pcre-mode overriding existing isearch function `%s'" isearch-search-fun-function)) ;; Prevent an infinite loop, if a previous isearch in pcre-mode ;; exited without restoring the original search function for some ;; reason (unless (eq isearch-search-fun-function #'pcre-isearch-search-fun-function) (setq pcre-old-isearch-search-fun-function isearch-search-fun-function)) (set (make-local-variable 'isearch-search-fun-function) #'pcre-isearch-search-fun-function)) (defun pcre-isearch-mode-end-hook () (setq isearch-search-fun-function pcre-old-isearch-search-fun-function)) (defun pcre-isearch-search-fun-function () "Enable isearching using emulated PCRE syntax. This is set as the value of `isearch-search-fun-function' when `pcre-mode' is enabled. Returns a function which searches using emulated PCRE regexps when `isearch-regexp' is true." (lambda (string bound noerror) (let ((real-search-function (funcall (or pcre-old-isearch-search-fun-function 'isearch-search-fun-default)))) (if (not isearch-regexp) (funcall real-search-function string bound noerror) ;; Raise an error if the regexp ends in an incomplete escape ;; sequence (= odd number of backslashes). ;; TODO: Perhaps this should really be handled in rxt-pcre-to-elisp? (if (isearch-backslash string) (rxt-error "Trailing backslash")) (funcall real-search-function (pcre-to-elisp/cached string) bound noerror))))) (defadvice isearch-message-prefix (after pcre-mode disable) "Add \"PCRE\" to the Isearch message when searching by regexp in `pcre-mode'." (when (and isearch-regexp ;; Prevent an inaccurate message if our callback was ;; removed somehow (eq isearch-search-fun-function #'pcre-isearch-search-fun-function)) (let ((message ad-return-value)) ;; Some hackery to give replacement the same fontification as ;; the original (when (let ((case-fold-search t)) (string-match "regexp" message)) (let* ((match (match-string 0 message)) (properties (text-properties-at 0 match)) (replacement (apply #'propertize "PCRE regexp" properties)) (new-message (replace-match replacement t t message))) (setq ad-return-value new-message)))))) (defadvice isearch-fallback (before pcre-mode (want-backslash &optional allow-invalid to-barrier) disable) "Hack to fall back correctly in `pcre-mode'. " ;; A dirty hack to the internals of isearch. Falling back to a ;; previous match position is necessary when the (Emacs) regexp ends ;; in "*", "?", "\{" or "\|": this is handled in ;; `isearch-process-search-char' by calling `isearch-fallback' with ;; `t' for the value of the first parameter, `want-backslash', in ;; the last two cases. With PCRE regexps, falling back should take ;; place on "*", "?", "{" or "|", with no backslashes required. ;; This advice handles the last two cases by unconditionally setting ;; `want-backslash' to nil. (ad-set-arg 0 nil)) (defadvice isearch-edit-string (around pcre-mode disable) "Add PCRE mode-toggling keys to Isearch minibuffer in regexp mode." (if isearch-regexp (minibuffer-with-setup-hook #'rxt--read-pcre-mode ad-do-it) ad-do-it)) ;;; evil-mode advice (defadvice evil-search-function (around pcre-mode (forward regexp-p wrap) disable) (if (and regexp-p (not isearch-mode)) (let ((real-search-function ad-do-it)) (setq ad-return-value (pcre-decorate-search-function real-search-function))) ad-do-it)) (eval-after-load 'evil '(when pcre-mode (ad-enable-advice 'evil-search-function 'around 'pcre-mode) (ad-activate 'evil-search-function))) (defun pcre-decorate-search-function (real-search-function) (lambda (string &optional bound noerror count) (funcall real-search-function (pcre-to-elisp/cached string) bound noerror count))) ;;; Other hooks and defadvices ;;;###autoload (defun pcre-query-replace-regexp () "Perform `query-replace-regexp' using PCRE syntax. Consider using `pcre-mode' instead of this function." (interactive) (let ((old-pcre-mode pcre-mode)) (unwind-protect (progn (pcre-mode +1) (call-interactively #'query-replace-regexp)) (pcre-mode (if old-pcre-mode 1 0))))) (defadvice add-to-history (before pcre-mode (history-var newelt &optional maxelt keep-all) disable) "Add the original PCRE to query-replace history in `pcre-mode'." (when (eq history-var query-replace-from-history-variable) (let ((original (gethash newelt pcre-mode-reverse-cache))) (when original (ad-set-arg 1 original))))) (defadvice query-replace-descr (before pcre-mode (from) disable) "Use the original PCRE in Isearch prompts in `pcre-mode'." (let ((original (gethash from pcre-mode-reverse-cache))) (when original (ad-set-arg 0 original)))) ;;; The `interactive' specs of the following functions are lifted ;;; wholesale from the original built-ins, which see. (defadvice read-regexp (around pcre-mode first (prompt &optional defaults history) disable) "Read regexp using PCRE syntax and convert to Elisp equivalent." (ad-set-arg 0 (concat "[PCRE] " prompt)) (minibuffer-with-setup-hook #'rxt--read-pcre-mode ad-do-it) (setq ad-return-value (pcre-to-elisp/cached ad-return-value))) (defadvice align-regexp (before pcre-mode first (beg end regexp &optional group spacing repeat) disable) "Read regexp using PCRE syntax and convert to Elisp equivalent." (interactive (append (list (region-beginning) (region-end)) (if current-prefix-arg (list (rxt-pcre-to-elisp (read-string "Complex align using PCRE regexp: " "(\\s*)")) (string-to-number (read-string "Parenthesis group to modify (justify if negative): " "1")) (string-to-number (read-string "Amount of spacing (or column if negative): " (number-to-string align-default-spacing))) (y-or-n-p "Repeat throughout line? ")) (list (concat "\\(\\s-*\\)" (rxt-pcre-to-elisp (read-string "Align PCRE regexp: "))) 1 align-default-spacing nil))))) (defadvice ibuffer-do-replace-regexp (before pcre-mode first (from-str to-str) disable) "Read regexp using PCRE syntax and convert to Elisp equivalent." (interactive (let* ((from-str (read-from-minibuffer "[PCRE] Replace regexp: ")) (to-str (read-from-minibuffer (concat "[PCRE] Replace " from-str " with: ")))) (list (rxt-pcre-to-elisp from-str) to-str)))) (defadvice find-tag-regexp (before pcre-mode first (regexp &optional next-p other-window) disable) "Read regexp using PCRE syntax and convert to Elisp equivalent. Perform `find-tag-regexp' using emulated PCRE regexp syntax." (interactive (let ((args (find-tag-interactive "[PCRE] Find tag regexp: " t))) (list (rxt-pcre-to-elisp (nth 0 args)) (nth 1 args) (nth 2 args))))) (defadvice sort-regexp-fields (before pcre-mode first (reverse record-regexp key-regexp beg end) disable) "Read regexp using PCRE syntax and convert to Elisp equivalent." (interactive "P\nsPCRE regexp specifying records to sort: \n\ sPCRE regexp specifying key within record: \nr") (ad-set-arg 1 (rxt-pcre-to-elisp (ad-get-arg 1))) (ad-set-arg 2 (rxt-pcre-to-elisp (ad-get-arg 2)))) ;;; Commands that take Emacs-style regexps as input ;;;###autoload (defun rxt-elisp-to-pcre (regexp) "Translate REGEXP, a regexp in Emacs Lisp syntax, to Perl-compatible syntax. Interactively, reads the regexp in one of three ways. With a prefix arg, reads from minibuffer without string escaping, like `query-replace-regexp'. Without a prefix arg, uses the text of the region if it is active. Otherwise, uses the result of evaluating the sexp before point (which might be a string regexp literal or an expression that produces a string). Displays the translated PCRE regexp in the echo area and copies it to the kill ring. Emacs regexp features such as syntax classes which cannot be translated to PCRE will cause an error." (interactive (rxt-interactive/elisp)) (rxt-return-pcre (rxt-adt->pcre (rxt-parse-elisp regexp)))) ;;;###autoload (defun rxt-elisp-to-rx (regexp) "Translate REGEXP, a regexp in Emacs Lisp syntax, to `rx' syntax. See `rxt-elisp-to-pcre' for a description of the interactive behavior and `rx' for documentation of the S-expression based regexp syntax." (interactive (rxt-interactive/elisp)) (rxt-return-sexp (rxt-adt->rx (rxt-parse-elisp regexp)))) ;;;###autoload (defun rxt-elisp-to-strings (regexp) "Return a list of all strings matched by REGEXP, an Emacs Lisp regexp. See `rxt-elisp-to-pcre' for a description of the interactive behavior. This is useful primarily for getting back the original list of strings from a regexp generated by `regexp-opt', but it will work with any regexp without unbounded quantifiers (*, +, {2, } and so on). Throws an error if REGEXP contains any infinite quantifiers." (interactive (rxt-interactive/elisp)) (rxt-return-sexp (rxt-adt->strings (rxt-parse-elisp regexp)))) ;;;###autoload (defun rxt-toggle-elisp-rx () "Toggle the regexp near point between Elisp string and rx syntax." (interactive) ;; First, position point before the regex form near point (either ;; a string literal or a list beginning `rx' or `rx-to-string'). (let* ((context (syntax-ppss)) (string-start (nth 8 context))) (cond (string-start (goto-char string-start)) ((looking-back "\"" nil t) (backward-sexp)) ((looking-at "\"") nil) (t ;; Search backwards, leaving point in place on error (goto-char (save-excursion (skip-syntax-forward "-") (while (not (looking-at (rx "(" (or "rx" "rx-to-string") symbol-end))) (backward-up-list)) (point)))))) ;; Read and replace the regex following point (let* ((regex (read (current-buffer))) (print-escape-newlines t)) (save-excursion (if (listp regex) ;; Replace rx form with string value (prin1 (eval regex) (current-buffer)) ;; Pretty-print rx form (save-restriction (let* ((start (point)) (rx--syntax-codes (rxt-elisp-to-rx regex)) (rx--form (pcase rx--syntax-codes (`(seq . ,rest) `(rx . ,rest)) (form `(rx ,form))))) (rxt-print rx--form) (narrow-to-region start (point))) (pp-buffer) ;; remove the extra newline that pp-buffer inserts (goto-char (point-max)) (delete-region (point) (save-excursion (skip-chars-backward " \t\n") (point)))))) (kill-sexp -1) (indent-pp-sexp))) ;;; Commands that translate PCRE to other formats ;;;###autoload (defun rxt-pcre-to-elisp (pcre &optional flags) "Translate PCRE, a regexp in Perl-compatible syntax, to Emacs Lisp. Interactively, uses the contents of the region if it is active, otherwise reads from the minibuffer. Prints the Emacs translation in the echo area and copies it to the kill ring. PCRE regexp features that cannot be translated into Emacs syntax will cause an error. See the commentary section of pcre2el.el for more details." (interactive (rxt-interactive/pcre)) (rxt-return-emacs-regexp (rx-to-string (rxt-pcre-to-rx (rxt--add-flags pcre flags)) t))) ;;;###autoload (defalias 'pcre-to-elisp 'rxt-pcre-to-elisp) ;;;###autoload (defun rxt-pcre-to-rx (pcre &optional flags) "Translate PCRE, a regexp in Perl-compatible syntax, to `rx' syntax. See `rxt-pcre-to-elisp' for a description of the interactive behavior." (interactive (rxt-interactive/pcre)) (rxt-return-sexp (rxt-adt->rx (rxt-parse-pcre (rxt--add-flags pcre flags))))) ;;;###autoload (defun rxt-pcre-to-strings (pcre &optional flags) "Return a list of all strings matched by PCRE, a Perl-compatible regexp. See `rxt-elisp-to-pcre' for a description of the interactive behavior and `rxt-elisp-to-strings' for why this might be useful. Throws an error if PCRE contains any infinite quantifiers." (interactive (rxt-interactive/pcre)) (rxt-return-sexp (rxt-adt->strings (rxt-parse-pcre (rxt--add-flags pcre flags))))) (defun rxt--add-flags (pcre flags) "Prepend FLAGS to PCRE." (if (not (zerop (length flags))) (concat "(?" flags ")" pcre) pcre)) ;;; Regexp explaining functions to display pretty-printed rx syntax ;; When the `rxt-explain' flag is non-nil, `rxt-adt->rx' records ;; location information for each element of the generated `rx' form, ;; allowing highlighting corresponding pieces of syntax at point. (defvar rxt-explain nil) (defvar rxt-highlight-overlays nil "List of active location-highlighting overlays in rxt-help-mode buffer.") ;;;###autoload (defun rxt-explain-elisp (regexp) "Insert the pretty-printed `rx' syntax for REGEXP in a new buffer. REGEXP is a regular expression in Emacs Lisp syntax. See `rxt-elisp-to-pcre' for a description of how REGEXP is read interactively." (interactive (rxt-interactive/elisp)) (let ((rxt-explain t) (rxt-verbose-rx-translation rxt-explain-verbosely)) (rxt-pp-rx regexp (rxt-elisp-to-rx regexp)))) ;;;###autoload (defun rxt-explain-pcre (regexp &optional flags) "Insert the pretty-printed `rx' syntax for REGEXP in a new buffer. REGEXP is a regular expression in PCRE syntax. See `rxt-pcre-to-elisp' for a description of how REGEXP is read interactively." (interactive (rxt-interactive/pcre)) (let ((rxt-explain t) (rxt-verbose-rx-translation rxt-explain-verbosely)) (rxt-pp-rx regexp (rxt-pcre-to-rx regexp flags)))) ;;;###autoload (defun rxt-quote-pcre (text) "Return a PCRE regexp which matches TEXT literally. Any PCRE metacharacters in TEXT will be quoted with a backslash." (rxt-adt->pcre (rxt-string text))) ;;;; Commands that depend on the major mode in effect ;; Macro: interactively call one of two functions depending on the ;; major mode (defmacro rxt-mode-dispatch (elisp-function pcre-function) `(if (memq major-mode '(emacs-lisp-mode lisp-interaction-mode)) (call-interactively #',elisp-function) (call-interactively #',pcre-function))) ;;;###autoload (defun rxt-explain () "Pop up a buffer with pretty-printed `rx' syntax for the regex at point. Chooses regex syntax to read based on current major mode, calling `rxt-explain-elisp' if buffer is in `emacs-lisp-mode' or `lisp-interaction-mode', or `rxt-explain-pcre' otherwise." (interactive) (rxt-mode-dispatch rxt-explain-elisp rxt-explain-pcre)) ;;;###autoload (defun rxt-convert-syntax () "Convert regex at point to other kind of syntax, depending on major mode. For buffers in `emacs-lisp-mode' or `lisp-interaction-mode', calls `rxt-elisp-to-pcre' to convert to PCRE syntax. Otherwise, calls `rxt-pcre-to-elisp' to convert to Emacs syntax. The converted syntax is displayed in the echo area and copied to the kill ring; see the two functions named above for details." (interactive) (rxt-mode-dispatch rxt-elisp-to-pcre rxt-pcre-to-elisp)) ;;;###autoload (defun rxt-convert-to-rx () "Convert regex at point to RX syntax. Chooses Emacs or PCRE syntax by major mode." (interactive) (rxt-mode-dispatch rxt-elisp-to-rx rxt-pcre-to-rx)) ;;;###autoload (defun rxt-convert-to-strings () "Convert regex at point to RX syntax. Chooses Emacs or PCRE syntax by major mode." (interactive) (rxt-mode-dispatch rxt-elisp-to-strings rxt-pcre-to-strings)) ;;; Minor mode and keybindings (defvar rxt-mode-map (let ((map (make-sparse-keymap))) ;; Generic (define-key map (kbd "C-c / /") 'rxt-explain) (define-key map (kbd "C-c / c") 'rxt-convert-syntax) (define-key map (kbd "C-c / x") 'rxt-convert-to-rx) (define-key map (kbd "C-c / '") 'rxt-convert-to-strings) ;; From PCRE (define-key map (kbd "C-c / p /") 'rxt-explain-pcre) (define-key map (kbd "C-c / p e") 'rxt-pcre-to-elisp) (define-key map (kbd "C-c / p x") 'rxt-pcre-to-rx) (define-key map (kbd "C-c / p '") 'rxt-pcre-to-strings) ;; From Elisp (define-key map (kbd "C-c / e /") 'rxt-explain-elisp) (define-key map (kbd "C-c / e p") 'rxt-elisp-to-pcre) (define-key map (kbd "C-c / e x") 'rxt-elisp-to-rx) (define-key map (kbd "C-c / e '") 'rxt-elisp-to-strings) (define-key map (kbd "C-c / e t") 'rxt-toggle-elisp-rx) (define-key map (kbd "C-c / t") 'rxt-toggle-elisp-rx) ;; Search (define-key map (kbd "C-c / %") 'pcre-query-replace-regexp) map) "Keymap for `rxt-mode'.") ;;;###autoload (define-minor-mode rxt-mode "Regex translation utilities." :init-value nil :lighter nil :keymap rxt-mode-map) ;;;###autoload (defun turn-on-rxt-mode () "Turn on `rxt-mode' in the current buffer." (interactive) (rxt-mode 1)) ;;;###autoload (define-globalized-minor-mode rxt-global-mode rxt-mode turn-on-rxt-mode) ;;;; Syntax explanations ;; Major mode for displaying pretty-printed S-exp syntax (define-derived-mode rxt-help-mode emacs-lisp-mode "Regexp Explain" (setq buffer-read-only t) (add-hook 'post-command-hook 'rxt-highlight-text nil t) (rxt-highlight-text)) ;; Hack: stop paredit-mode interfering with `rxt-print' (eval-when-compile (declare-function paredit-mode "paredit.el")) (add-hook 'rxt-help-mode-hook (lambda () (if (and (boundp 'paredit-mode) paredit-mode) (paredit-mode 0)))) (define-key rxt-help-mode-map "q" 'quit-window) (define-key rxt-help-mode-map "z" 'kill-this-buffer) (define-key rxt-help-mode-map "n" 'next-line) (define-key rxt-help-mode-map "p" 'previous-line) (define-key rxt-help-mode-map "f" 'forward-list) (define-key rxt-help-mode-map "b" 'backward-list) (define-key rxt-help-mode-map "u" 'backward-up-list) (define-key rxt-help-mode-map "d" 'down-list) (defvar rxt--print-with-overlays nil) (defvar rxt--print-depth 0) (defconst rxt--print-char-alist '((?\a . "\\a") (?\b . "\\b") (?\t . "\\t") (?\n . "\\n") (?\v . "\\v") (?\f . "\\f") (?\r . "\\r") (?\e . "\\e") (?\s . "\\s") (?\\ . "\\\\") (?\d . "\\d")) "Alist of characters to print using an escape sequence in Elisp source. See (info \"(elisp) Basic Char Syntax\").") (defconst rxt--whitespace-display-regexp (rx-to-string `(any ,@(mapcar #'car rxt--print-char-alist)))) (defconst rxt--print-special-chars '(?\( ?\) ?\\ ?\| ?\; ?\' ?\` ?\" ?\# ?\. ?\,) "Characters which require a preceding backslash in Elisp source. See (info \"(elisp) Basic Char Syntax\").") (defun rxt-pp-rx (regexp rx) "Display string regexp REGEXP with its `rx' form RX in an `rxt-help-mode' buffer." (with-current-buffer (get-buffer-create "* Regexp Explain *") (let ((print-escape-newlines t) (inhibit-read-only t)) (erase-buffer) (rxt-help-mode) (insert (rxt--propertize-whitespace regexp)) (newline 2) (save-excursion (let ((sexp-begin (point)) (rxt--print-with-overlays t)) (rxt-print rx) (narrow-to-region sexp-begin (point)) (pp-buffer) (widen))) (rxt-highlight-text)) (pop-to-buffer (current-buffer)))) (cl-defun rxt-print (rx) "Insert RX, an `rx' form, into the current buffer, optionally adding overlays. Similar to `print' or `prin1', but ensures that `rx' forms are printed readably, using character or integer syntax depending on context. If `rxt--print-with-overlays' is non-nil, also creates overlays linking elements of RX to their corresponding locations in the source string (see `rxt-explain-elisp', `rxt-explain-pcre' and `rxt--make-help-overlays')." (let ((start (point))) (cl-typecase rx (cons (pcase rx (`(,(and (or `repeat `**) head) ,(and (pred integerp) from) ,(and (pred integerp) to) . ,rest) (insert (format "(%s %d %d" head from to)) (rxt--print-list-tail rest)) (`(,(and (or `repeat `= `>=) head) ,(and (pred integerp) n) . ,rest) (insert (format "(%s %d" head n)) (rxt--print-list-tail rest)) (_ (rxt--print-list-tail rx t)))) (symbol (cl-case rx ;; `print' escapes the ? characters in the rx operators *? ;; and +?, but this looks bad and is not strictly necessary: ;; (eq (read "*?") (read "*\\?")) => t ;; (eq (read "+?") (read "+\\?")) => t ((*? +?) (insert (symbol-name rx))) (t (prin1 rx (current-buffer))))) (string (insert (rxt--propertize-whitespace (prin1-to-string rx)))) (character (cond ((eq ? rx) (insert "?")) ((memq rx rxt--print-special-chars) (insert "?\\" rx)) ((assq rx rxt--print-char-alist) (insert "?" (assoc-default rx rxt--print-char-alist))) (t (insert "?" (char-to-string rx))))) (t (prin1 rx (current-buffer)))) (when rxt--print-with-overlays (rxt--make-help-overlays rx start (point))))) (defun rxt--print-list-tail (tail &optional open-paren) (let ((rxt--print-depth (1+ rxt--print-depth))) (let ((done nil)) (while (not done) (cl-typecase tail (null (insert ")") (setq done t)) (cons (if open-paren (progn (insert "(") (setq open-paren nil)) (insert " ")) (rxt-print (car tail)) (setq tail (cdr tail))) (t (insert " . ") (rxt-print tail) (insert ")") (setq done t))))))) (defun rxt--make-help-overlays (rx start end) (let ((location (rxt-location rx))) (when (and location (rxt-location-start location) (rxt-location-end location)) (let* ((sexp-begin (copy-marker start t)) (sexp-end (copy-marker end)) (sexp-bounds (list sexp-begin sexp-end)) (source-begin (1+ (rxt-location-start location))) (source-end (1+ (rxt-location-end location))) (source-bounds (list source-begin source-end)) (bounds (list source-bounds sexp-bounds)) (sexp-ol (make-overlay sexp-begin sexp-end (current-buffer) t nil)) (source-ol (make-overlay source-begin source-end (current-buffer) t nil))) (dolist (ol (list sexp-ol source-ol)) (overlay-put ol 'priority rxt--print-depth) (overlay-put ol 'rxt-bounds bounds)))))) (defun rxt--propertize-whitespace (string) (let ((string (copy-sequence string)) (start 0)) (while (string-match rxt--whitespace-display-regexp string start) (put-text-property (match-beginning 0) (match-end 0) 'display (assoc-default (string-to-char (match-string 0 string)) rxt--print-char-alist) string) (setq start (match-end 0))) string)) (defun rxt-highlight-text () "Highlight the regex syntax at point and its corresponding RX/string form." (let ((all-bounds (get-char-property (point) 'rxt-bounds))) (mapc #'delete-overlay rxt-highlight-overlays) (setq rxt-highlight-overlays nil) (dolist (bounds all-bounds) (cl-destructuring-bind (begin end) bounds (let ((overlay (make-overlay begin end))) (push overlay rxt-highlight-overlays) (overlay-put overlay 'face 'rxt-highlight-face)))))) ;;;; Error handling (if (fboundp 'define-error) (define-error 'rxt-invalid-regexp "Invalid regexp" 'invalid-regexp) (put 'rxt-invalid-regexp 'error-conditions '(rxt-invalid-regexp invalid-regexp error)) (put 'rxt-invalid-regexp 'error-message "Invalid regexp")) (defun rxt-error (&rest format-args) (signal 'rxt-invalid-regexp (list (apply #'format format-args)))) ;;;; Regexp syntax tree data type ;; Base class from which other elements of the syntax-tree inherit (cl-defstruct rxt-syntax-tree) ;; Struct representing the original source location (cl-defstruct rxt-location source ; Either a string or a buffer start end ; Offsets, 0- or 1-indexed as appropriate ) (defun rxt-location-text (location) (if (not (rxt-location-p location)) nil (let ((start (rxt-location-start location)) (end (rxt-location-end location)) (source (rxt-location-source location))) (cond ((buffer-live-p source) (with-current-buffer source (buffer-substring-no-properties start end))) ((stringp source) (substring source start end)) (t nil))))) ;; Hash table mapping from syntax-tree elements to source locations. (defvar rxt-location-map (make-hash-table :weakness 'key)) (defun rxt-location (object) (gethash object rxt-location-map)) (gv-define-setter rxt-location (value object) `(puthash ,object ,value rxt-location-map)) (defun rxt-source-text (object) (rxt-location-text (rxt-location object))) (defun rxt-to-string (tree) "Return a readable representation of TREE, a regex syntax-tree object." (or (rxt-source-text tree) (let ((print-level 1)) (prin1-to-string tree)))) (defalias 'rxt-syntax-tree-readable 'rxt-to-string) ;; FIXME (defvar rxt-pcre-case-fold nil) ;; Literal string (cl-defstruct (rxt-string (:constructor rxt-string (chars &optional case-fold)) (:include rxt-syntax-tree)) chars (case-fold rxt-pcre-case-fold)) (defun rxt-empty-string () (rxt-string "")) (defun rxt-trivial-p (re) (and (rxt-string-p re) (equal (rxt-string-chars re) ""))) ;;; Other primitives (cl-defstruct (rxt-primitive (:constructor rxt-primitive (pcre rx)) (:include rxt-syntax-tree)) pcre rx) (defun rxt-bos () (rxt-primitive "\\A" 'bos)) (defun rxt-eos () (rxt-primitive "\\Z" 'eos)) (defun rxt-bol () (rxt-primitive "^" 'bol)) (defun rxt-eol () (rxt-primitive "$" 'eol)) ;; FIXME (defun rxt-anything () (rxt-primitive "." 'anything)) (defun rxt-nonl () (rxt-primitive "." 'nonl)) (defun rxt-word-boundary () (rxt-primitive "\\b" 'word-boundary)) (defun rxt-not-word-boundary () (rxt-primitive "\\B" 'not-word-boundary)) (defun rxt-wordchar () (rxt-primitive "\\w" 'wordchar)) (defun rxt-not-wordchar () (rxt-primitive "\\W" 'not-wordchar)) (defun rxt-symbol-start () (rxt-primitive nil 'symbol-start)) (defun rxt-symbol-end () (rxt-primitive nil 'symbol-end)) (defun rxt-bow () (rxt-primitive nil 'bow)) (defun rxt-eow () (rxt-primitive nil 'eow)) ;;; Sequence (cl-defstruct (rxt-seq (:constructor make-rxt-seq (elts)) (:include rxt-syntax-tree)) elts) ;; Slightly smart sequence constructor: ;; - Flattens nested sequences ;; - Drops trivial "" elements ;; - Empty sequence => "" ;; - Singleton sequence is reduced to its one element. (defun rxt-seq (&rest res) ; Flatten nested seqs & drop ""'s. (let ((res (rxt-seq-flatten res))) (if (consp res) (if (consp (cdr res)) (make-rxt-seq res) ; General case (car res)) ; Singleton sequence (rxt-empty-string)))) ; Empty seq -- "" (defun rxt-seq-flatten (res) (if (consp res) (let ((re (car res)) (tail (rxt-seq-flatten (cdr res)))) (cond ((rxt-seq-p re) ; Flatten nested seqs (append (rxt-seq-flatten (rxt-seq-elts re)) tail)) ((rxt-trivial-p re) tail) ; Drop trivial elts ((and (rxt-string-p re) ; Flatten strings (consp tail) (rxt-string-p (car tail))) (cons (rxt-string-concat re (car tail)) (cdr tail))) (t (cons re tail)))) '())) (defun rxt-string-concat (str1 str2) (if (not (eq (rxt-string-case-fold str1) (rxt-string-case-fold str2))) (make-rxt-seq (list str1 str2)) (let ((result (rxt-string (concat (rxt-string-chars str1) (rxt-string-chars str2)) (rxt-string-case-fold str1))) (first (rxt-location str1)) (last (rxt-location str2))) (when (and first last) (setf (rxt-location result) (make-rxt-location :source (rxt-location-source first) :start (rxt-location-start first) :end (rxt-location-end last)))) result))) ;;; Choice (alternation/union) (cl-defstruct (rxt-choice (:constructor make-rxt-choice (elts)) (:include rxt-syntax-tree)) elts) ;;; The empty choice represents a regexp that never matches in any context (defvar rxt-empty (make-rxt-choice nil)) (defun rxt-empty-p (re) (or (and (rxt-choice-p re) (null (rxt-choice-elts re))) (rxt-empty-char-set-p re))) (defun rxt-choice (&rest alternatives) "Construct the alternation (union) of several regexps. ALTERNATIVES should be a list of `rxt-syntax-tree' objects. The return value is an `rxt-choice' object representing a regexp which matches any one of ALTERNATIVES, but simplified in the following ways: - If ALTERNATIVES contains only one element, it is returned unchanged. - All existing `rxt-choice' elements in ALTERNATIVES are replaced by a flat list of their subexpressions: symbolically, a|(b|(c|d)) is replaced by a|b|c|d - All character sets and single-character strings in ALTERNATIVES are combined together into one or two character sets, respecting case-folding behaviour." (cl-destructuring-bind (other-elements char-set case-fold-char-set) (rxt--simplify-alternatives alternatives) (let ((simplified-alternatives (append (if (not (rxt-empty-p char-set)) (list char-set) '()) (if (not (rxt-empty-p case-fold-char-set)) (list case-fold-char-set) '()) other-elements))) (pcase simplified-alternatives (`() rxt-empty) (`(,element) element) (_ (make-rxt-choice simplified-alternatives)))))) (defun rxt--simplify-alternatives (alternatives) "Simplify a set of regexp alternatives. ALTERNATIVES should be a list of `rxt-syntax-tree' objects to be combined into an `rxt-choice' structure. The result is a three-element list (OTHER-ELEMENTS CHAR-SET CASE-FOLDED-CHAR-SET): - CHAR-SET is an `rxt-char-set-union' containing the union of all case-sensitive character sets and single-character strings in RES. - CASE-FOLDED-CHAR-SET is similar but combines all the case-insensitive character sets and single-character strings. - OTHER-ELEMENTS is a list of all other elements, with all `rxt-choice' structures replaced by a flat list of their component subexpressions." (if (null alternatives) (list '() (make-rxt-char-set-union :case-fold nil) (make-rxt-char-set-union :case-fold t)) (let* ((re (car alternatives))) (cl-destructuring-bind (tail char-set case-fold-char-set) (rxt--simplify-alternatives (cdr alternatives)) (cond ((rxt-choice-p re) ; Flatten nested choices (list (append (rxt-choice-elts re) tail) char-set case-fold-char-set)) ((rxt-empty-p re) ; Drop empty re's. (list tail char-set case-fold-char-set)) ((rxt-char-set-union-p re) ; Fold char sets together (if (rxt-char-set-union-case-fold re) (list tail char-set (rxt-char-set-union case-fold-char-set re)) (list tail (rxt-char-set-union char-set re) case-fold-char-set))) ((and (rxt-string-p re) ; Same for 1-char strings (= 1 (length (rxt-string-chars re)))) (if (rxt-string-case-fold re) (list tail char-set (rxt-char-set-union case-fold-char-set re)) (list tail (rxt-char-set-union char-set re) case-fold-char-set))) (t ; Otherwise. (list (cons re tail) char-set case-fold-char-set))))))) ;;; Repetition (cl-defstruct (rxt-repeat (:include rxt-syntax-tree)) from to body greedy) (cl-defun rxt-repeat (from to body &optional (greedy t)) (if (equal to 0) (rxt-empty-string) (make-rxt-repeat :from from :to to :body body :greedy greedy))) ;;; Submatch (cl-defstruct (rxt-submatch (:constructor rxt-submatch (body)) (:include rxt-syntax-tree)) body) ;;; Numbered submatch (Emacs only) (cl-defstruct (rxt-submatch-numbered (:constructor rxt-submatch-numbered (n body)) (:include rxt-syntax-tree)) n body) ;;; Backreference (cl-defstruct (rxt-backref (:constructor rxt-backref (n)) (:include rxt-syntax-tree)) n) ;;; Syntax classes (Emacs only) (cl-defstruct (rxt-syntax-class (:include rxt-syntax-tree)) symbol) (defun rxt-syntax-class (symbol) (if (assoc symbol rx--syntax-codes) (make-rxt-syntax-class :symbol symbol) (rxt-error "Invalid syntax class symbol `%s'" symbol))) ;;; Character categories (Emacs only) (cl-defstruct (rxt-char-category (:include rxt-syntax-tree)) symbol) (defun rxt-char-category (symbol) (if (assoc symbol rx--categories) (make-rxt-char-category :symbol symbol) (rxt-error "Invalid character category symbol `%s'" symbol))) ;;; Char sets ;; ::= ;; | ;; | (cl-defstruct (rxt-char-set (:include rxt-syntax-tree))) ;; An rxt-char-set-union represents the union of any number of ;; characters, character ranges, and POSIX character classes: anything ;; that can be represented in string notation as a class [ ... ] ;; without the negation operator. (cl-defstruct (rxt-char-set-union (:include rxt-char-set)) chars ; list of single characters ranges ; list of ranges (from . to) classes ; list of character classes (case-fold rxt-pcre-case-fold)) ;; Test for empty character set (defun rxt-empty-char-set-p (cset) (and (rxt-char-set-union-p cset) (null (rxt-char-set-union-chars cset)) (null (rxt-char-set-union-ranges cset)) (null (rxt-char-set-union-classes cset)))) ;; Simple union constructor (defun rxt-char-set-union (&rest items) "Construct an regexp character set representing the union of ITEMS. Each element of ITEMS may be either: a character; a single-character string; a single-character `rxt-string' object; a cons, (FROM . TO) representing a range of characters; a symbol, representing a named character class; or an `rxt-char-set-union' object. All `rxt-char-set-union' objects in ITEMS must have the same `case-fold' property." (let ((chars '()) (ranges '()) (classes '()) (case-fold 'undetermined)) (dolist (item items) (cl-etypecase item (character (push item chars)) (string (cl-assert (= 1 (length item))) (push (string-to-char item) chars)) (rxt-string (cl-assert (= 1 (length (rxt-string-chars item)))) (push (string-to-char (rxt-string-chars item)) chars)) (cons ; range (from . to) (cl-check-type (car item) character) (cl-check-type (cdr item) character) (push item ranges)) (symbol ; named character class (push item classes)) (rxt-char-set-union (if (eq case-fold 'undetermined) (setq case-fold (rxt-char-set-union-case-fold item)) (unless (eq case-fold (rxt-char-set-union-case-fold item)) (error "Cannot construct union of char-sets with unlike case-fold setting: %S" item))) (setq chars (nconc chars (rxt-char-set-union-chars item))) (setq ranges (nconc ranges (rxt-char-set-union-ranges item))) (setq classes (nconc classes (rxt-char-set-union-classes item)))))) (make-rxt-char-set-union :chars chars :ranges ranges :classes classes :case-fold (if (eq case-fold 'undetermined) rxt-pcre-case-fold case-fold)))) (defun rxt--all-char-set-union-chars (char-set) "Return a list of all characters in CHAR-SET." (cl-assert (rxt-char-set-union-p char-set)) (append (rxt-char-set-union-chars char-set) (cl-loop for (start . end) in (rxt-char-set-union-ranges char-set) nconc (cl-loop for char from start to end collect char)))) (defun rxt--simplify-char-set (char-set &optional case-fold-p) "Return a minimal char-set to match the same characters as CHAR-SET. With optional argument CASE-FOLD-P, return a char-set which emulates case-folding behaviour by including both uppercase and lowercase versions of all characters in CHAR-SET." (cl-assert (rxt-char-set-union-p char-set)) (let* ((classes (rxt-char-set-union-classes char-set)) (all-chars (if case-fold-p (cl-loop for char in (rxt--all-char-set-union-chars char-set) nconc (list (upcase char) (downcase char))) (rxt--all-char-set-union-chars char-set))) (all-ranges (rxt--extract-ranges (rxt--remove-redundant-chars all-chars classes)))) (let ((singletons nil) (ranges nil)) (cl-loop for (start . end) in all-ranges do (cond ((= start end) (push start singletons)) ((= (1+ start) end) (push start singletons) (push end singletons)) (t (push (cons start end) ranges)))) (make-rxt-char-set-union :chars (nreverse singletons) :ranges (nreverse ranges) :classes classes :case-fold (if case-fold-p nil (rxt-char-set-union-case-fold char-set)))))) (defun rxt--remove-redundant-chars (chars classes) "Remove all characters which match a character class in CLASSES from CHARS." (if (null classes) chars (string-to-list (replace-regexp-in-string (rx-to-string `(any ,@classes)) "" (apply #'string chars))))) (defun rxt--extract-ranges (chars) "Return a list of all contiguous ranges in CHARS. CHARS should be a list of characters (integers). The return value is a list of conses (START . END) representing ranges, such that the union of all the ranges represents the same of characters as CHARS. Example: (rxt--extract-ranges (list ?a ?b ?c ?q ?x ?y ?z)) => ((?a . ?c) (?q . ?q) (?x . ?z))" (let ((array (apply #'vector (cl-remove-duplicates (sort (copy-sequence chars) #'<))))) (cl-labels ((recur (start end) (if (< end start) nil (let ((min (aref array start)) (max (aref array end))) (if (= (- max min) (- end start)) (list (cons min max)) (let* ((split-point (/ (+ start end) 2)) (left (recur start split-point)) (right (recur (1+ split-point) end))) (pcre2el-merge left right)))))) (pcre2el-merge (left right) (cond ((null left) right) ((null right) left) (t (let ((last-left (car (last left))) (first-right (car right))) (if (= (1+ (cdr last-left)) (car first-right)) (append (cl-subseq left 0 -1) (list (cons (car last-left) (cdr first-right))) (cl-subseq right 1)) (append left right))))))) (recur 0 (1- (length array)))))) ;;; Set complement of character set, syntax class, or character ;;; category ;; In general, all character sets that can be represented in string ;; notation as [^ ... ] (but see `rxt-char-set-intersection', below), plus ;; Emacs' \Sx and \Cx constructions. (cl-defstruct (rxt-char-set-negation (:include rxt-char-set)) elt) (defun rxt-negate (char-set) "Construct the logical complement (negation) of CHAR-SET. CHAR-SET may be any of the following types: `rxt-char-set-union', `rxt-syntax-class', `rxt-char-category', or `rxt-char-set-negation'." (cl-etypecase char-set ((or rxt-char-set-union rxt-syntax-class rxt-char-category) (make-rxt-char-set-negation :elt char-set)) (rxt-char-set-negation (rxt-char-set-negation-elt char-set)))) ;;; Intersections of char sets ;; These are difficult to represent in general, but can be constructed ;; in Perl using double negation; for example: [^\Wabc] means the set ;; complement of [abc] with respect to the universe of "word ;; characters": (& (~ (~ word)) (~ ("abc"))) == (& word (~ ("abc"))) ;; == (- word ("abc")) (cl-defstruct (rxt-char-set-intersection (:include rxt-char-set)) elts) ;; Intersection constructor (defun rxt-char-set-intersection (&rest charsets) (let ((elts '()) (cmpl (make-rxt-char-set-union))) (dolist (cset (rxt-int-flatten charsets)) (cond ((rxt-char-set-negation-p cset) ;; Fold negated charsets together: ~A & ~B = ~(A|B) (setq cmpl (rxt-char-set-union cmpl (rxt-char-set-negation-elt cset)))) ((rxt-char-set-union-p cset) (push cset elts)) (t (rxt-error "Can't take intersection of non-character-set %S" cset)))) (if (null elts) (rxt-negate cmpl) (unless (rxt-empty-char-set-p cmpl) (push (rxt-negate cmpl) elts)) (if (null (cdr elts)) (car elts) ; singleton case (make-rxt-char-set-intersection :elts elts))))) ;; Constructor helper: flatten nested intersections (defun rxt-int-flatten (csets) (if (consp csets) (let ((cset (car csets)) (tail (rxt-int-flatten (cdr csets)))) (if (rxt-char-set-intersection-p cset) (append (rxt-int-flatten (rxt-char-set-intersection-elts cset)) tail) (cons cset tail))) '())) ;;;; Macros for building the parser (defmacro rxt-token-case (&rest cases) "Consume a token at point and evaluate corresponding forms. CASES is a list of `cond'-like clauses, (REGEXP BODY ...) where the REGEXPs define possible tokens which may appear at point. The CASES are considered in order. For each case, if the text at point matches REGEXP, then point is moved to the end of the matched token, the corresponding BODY is evaluated and their value returned. The matched token is available within the BODY forms as (match-string 0). There can be a default case where REGEXP is `t', which evaluates the corresponding FORMS but does not move point. Returns `nil' if none of the CASES matches." (declare (debug (&rest (sexp &rest form)))) `(cond ,@(cl-loop for (token . action) in cases collect (if (eq token t) `(t ,@action) `((looking-at ,token) (goto-char (match-end 0)) ,@action))))) (defmacro rxt-with-source-location (&rest body) "Evaluate BODY and record source location information on its value. BODY may evaluate to any kind of object, but its value should generally not be `eq' to any other object." (declare (debug (&rest form))) (let ((begin (make-symbol "begin")) (value (make-symbol "value"))) `(let ((,begin (point)) (,value ,(macroexp-progn body))) (setf (rxt-location ,value) (make-rxt-location :source rxt-source-text-string :start (1- ,begin) :end (1- (point)))) ,value))) ;; Read PCRE + flags (defun rxt-read-delimited-pcre () "Read a Perl-style delimited regexp and flags from the current buffer. Point should be before the regexp literal before calling this. Currently only regexps delimited by / ... / are supported. A preceding \"m\", \"qr\" or \"s\" will be ignored, as will the replacement string in an s/.../.../ construction. Returns two strings: the regexp and the flags." (save-excursion (skip-syntax-forward "-") ;; Skip m, qr, s (let ((is-subst (rxt-token-case ("s" t) ((rx (or "m" "qr")) nil)))) (when (not (looking-at "/")) (error "Only Perl regexps delimited by slashes are supported")) (let ((beg (match-end 0)) (delim (rx (not (any "\\")) (group "/")))) (search-forward-regexp delim) (let ((end (match-beginning 1))) (when is-subst (search-forward-regexp delim)) (let ((pcre (buffer-substring-no-properties beg end))) (rxt-token-case ("[gimosx]*" (rxt--add-flags pcre (match-string-no-properties 0)))))))))) ;;;; Elisp and PCRE string notation parser ;;; Parser constants (defconst rxt-pcre-char-set-alist `((?w . ; "word" characters (?_ alnum)) (?d . ; digits (digit)) (?h . ; horizontal whitespace (#x0009 #x0020 #x00A0 #x1680 #x180E #x2000 #x2001 #x2002 #x2003 #x2004 #x2005 #x2006 #x2007 #x2008 #x2009 #x200A #x202F #x205F #x3000)) (?s . ; whitespace (9 10 12 13 32)) (?v . ; vertical whitespace (#x000A #x000B #x000C #x000D #x0085 #x2028 #x2029)))) (defconst rxt-pcre-named-classes-regexp (rx "[:" (submatch (or "alnum" "alpha" "ascii" "blank" "cntrl" "digit" "graph" "lower" "print" "punct" "space" "upper" "word" "xdigit")) ":]")) (defconst rxt-elisp-named-classes-regexp (rx "[:" (submatch (or "alnum" "alpha" "ascii" "blank" "cntrl" "digit" "graph" "lower" "print" "punct" "space" "upper" "word" "xdigit" "unibyte" "nonascii" "multibyte")) ":]")) ;;; The following dynamically bound variables control the operation of ;;; the parser (see `rxt-parse-re'.) (defvar rxt-parse-pcre nil "t if the rxt string parser is parsing PCRE syntax, nil for Elisp syntax. This should only be let-bound internally, never set otherwise.") (defvar rxt-pcre-extended-mode nil "t if the rxt string parser is emulating PCRE's \"extended\" mode. In extended mode (indicated by /x in Perl/PCRE), whitespace outside of character classes and \\Q...\\E quoting is ignored, and a `#' character introduces a comment that extends to the end of line.") (defvar rxt-pcre-s-mode nil "t if the rxt string parser is emulating PCRE's single-line \"/s\" mode. When /s is used, PCRE's \".\" matches newline characters, which otherwise it would not match.") (defvar rxt-pcre-case-fold nil "non-nil to emulate PCRE's case-insensitive \"/i\" mode in translated regexps.") (defvar rxt-branch-end-regexp nil) (defvar rxt-choice-regexp nil) (defvar rxt-brace-begin-regexp nil) (defvar rxt-m-to-n-brace-regexp nil) (defvar rxt-m-to-?-brace-regexp nil) (defvar rxt-m-brace-regexp nil) (defvar rxt-named-classes-regexp nil) (defvar rxt-subgroup-count nil) (defvar rxt-source-text-string nil) (defun rxt-parse-pcre (re) (rxt-parse-re re t)) (defun rxt-parse-elisp (re) (rxt-parse-re re nil)) (defun rxt-parse-re (re pcre-p) (let* ((rxt-parse-pcre pcre-p) (rxt-pcre-extended-mode nil) (rxt-pcre-s-mode nil) (rxt-pcre-case-fold nil) ;; Bind regexps to match syntax that differs between PCRE and ;; Elisp only in the addition of a backslash "\" (escape (if pcre-p "" "\\")) (rxt-choice-regexp (rx-to-string `(seq ,escape "|"))) (rxt-branch-end-regexp (rx-to-string `(or buffer-end (seq ,escape (or "|" ")"))))) (rxt-brace-begin-regexp (rx-to-string `(seq ,escape "{"))) (rxt-m-to-n-brace-regexp (rx-to-string `(seq (submatch (* (any "0-9"))) "," (submatch (+ (any "0-9"))) ,escape "}"))) (rxt-m-to-?-brace-regexp (rx-to-string `(seq (submatch (+ (any "0-9"))) "," ,escape "}"))) (rxt-m-brace-regexp (rx-to-string `(seq (submatch (+ (any "0-9"))) ,escape "}"))) ;; Named character classes [: ... :] differ slightly (rxt-named-classes-regexp (if pcre-p rxt-pcre-named-classes-regexp rxt-elisp-named-classes-regexp)) (rxt-subgroup-count 0) (case-fold-search nil)) (with-temp-buffer (insert re) (goto-char (point-min)) (let ((rxt-source-text-string re)) (rxt-parse-exp))))) ;; Parse a complete regex: a number of branches separated by | or ;; \|, as determined by `rxt-branch-end-regexp'. (defun rxt-parse-exp () ;; These variables are let-bound here because in PCRE mode they may ;; be set internally by (?x) or (?s) constructions, whose scope ;; lasts until the end of a sub-expression (rxt-with-source-location (let ((rxt-pcre-extended-mode rxt-pcre-extended-mode) (rxt-pcre-s-mode rxt-pcre-s-mode) (rxt-pcre-case-fold rxt-pcre-case-fold)) (if (eobp) (rxt-seq) (let ((branches '())) (cl-block nil (while t (let ((branch (rxt-parse-branch))) (push branch branches) (rxt-token-case (rxt-choice-regexp nil) (t (cl-return (apply #'rxt-choice (reverse branches))))))))))))) ;; Skip over whitespace and comments in PCRE extended mode (defun rxt-extended-skip () (when rxt-pcre-extended-mode (skip-syntax-forward "-") (while (looking-at "#") (beginning-of-line 2) (skip-syntax-forward "-")))) ;; Parse a regexp "branch": a sequence of pieces (defun rxt-parse-branch () (rxt-extended-skip) (rxt-with-source-location (let ((pieces '()) (branch-start-p t)) (while (not (looking-at rxt-branch-end-regexp)) (push (rxt-parse-piece branch-start-p) pieces) (setq branch-start-p nil)) (apply #'rxt-seq (reverse pieces))))) ;; Parse a regexp "piece": an atom (`rxt-parse-atom') plus any ;; following quantifiers (defun rxt-parse-piece (&optional branch-begin) (rxt-extended-skip) (rxt-with-source-location (let ((atom (rxt-parse-atom branch-begin))) (rxt-parse-quantifiers atom)))) ;; Parse any and all quantifiers after ATOM and return the quantified ;; regexp, or ATOM unchanged if no quantifiers (defun rxt-parse-quantifiers (atom) (catch 'done (while (not (eobp)) (let ((atom1 (rxt-parse-quantifier atom))) (if (eq atom1 atom) (throw 'done t) (setq atom atom1))))) atom) ;; Possibly parse a single quantifier after ATOM and return the ;; quantified atom, or ATOM if no quantifier (defun rxt-parse-quantifier (atom) (rxt-extended-skip) (rxt-token-case ((rx "*?") (rxt-repeat 0 nil atom nil)) ((rx "*") (rxt-repeat 0 nil atom t)) ((rx "+?") (rxt-repeat 1 nil atom nil)) ((rx "+") (rxt-repeat 1 nil atom t)) ((rx "??") (rxt-repeat 0 1 atom nil)) ((rx "?") (rxt-repeat 0 1 atom t)) ;; Brace expression "{M,N}", "{M,}", "{M}" (rxt-brace-begin-regexp (cl-destructuring-bind (from to) (rxt-parse-braces) (rxt-repeat from to atom))) ;; No quantifiers found (t atom))) ;; Parse a regexp atom, i.e. an element that binds to any following ;; quantifiers. This includes characters, character classes, ;; parenthesized groups, assertions, etc. (defun rxt-parse-atom (&optional branch-begin) (if (eobp) (rxt-error "Unexpected end of regular expression") (if rxt-parse-pcre (rxt-parse-atom/pcre) (rxt-parse-atom/el branch-begin)))) (defun rxt-parse-atom/common () (rxt-token-case ((rx "[") (rxt-parse-char-class)) ((rx "\\b") (rxt-word-boundary)) ((rx "\\B") (rxt-not-word-boundary)))) (defun rxt-parse-atom/el (branch-begin) (rxt-with-source-location (or (rxt-parse-atom/common) (rxt-token-case ;; "." wildcard ((rx ".") (rxt-nonl)) ;; "^" and "$" are metacharacters only at beginning or end of a ;; branch in Elisp; elsewhere they are literals ((rx "^") (if branch-begin (rxt-bol) (rxt-string "^"))) ((rx "$") (if (looking-at rxt-branch-end-regexp) (rxt-eol) (rxt-string "$"))) ;; Beginning & end of string, word, symbol ((rx "\\`") (rxt-bos)) ((rx "\\'") (rxt-eos)) ((rx "\\<") (rxt-bow)) ((rx "\\>") (rxt-eow)) ((rx "\\_<") (rxt-symbol-start)) ((rx "\\_>") (rxt-symbol-end)) ;; Subgroup ((rx "\\(") (rxt-parse-subgroup/el)) ;; Word/non-word characters (meaning depending on syntax table) ((rx "\\w") (rxt-wordchar)) ((rx "\\W") (rxt-not-wordchar)) ;; Other syntax categories ((rx "\\" (submatch (any ?S ?s)) (submatch nonl)) (let ((negated (string= (match-string 1) "S")) (syntax (car (rassoc (string-to-char (match-string 2)) rx--syntax-codes)))) (if syntax (let ((re (rxt-syntax-class syntax))) (if negated (rxt-negate re) re)) (rxt-error "Invalid syntax class `\\%s'" (match-string 0))))) ;; Character categories ((rx "\\" (submatch (any ?C ?c)) (submatch nonl)) (let ((negated (string= (match-string 1) "C")) (category (car (rassoc (string-to-char (match-string 2)) rx--categories)))) (if category (let ((re (rxt-char-category category))) (if negated (rxt-negate re) re)) (rxt-error "Invalid character category `%s'" (match-string 0))))) ;; Backreference ((rx (seq "\\" (submatch (any "1-9")))) (rxt-backref (string-to-number (match-string 1)))) ;; Other escaped characters ((rx (seq "\\" (submatch nonl))) (rxt-string (match-string 1))) ;; Normal characters ((rx (or "\n" nonl)) (rxt-string (match-string 0))))))) (defun rxt-parse-atom/pcre () (rxt-extended-skip) (rxt-with-source-location (or ;; Is it an atom that's the same in Elisp? (rxt-parse-atom/common) ;; Is it common to PCRE regex and character class syntax? (let ((char (rxt-parse-escapes/pcre))) (and char (rxt-string (char-to-string char)))) ;; Otherwise: (rxt-token-case ;; "." wildcard ((rx ".") (if rxt-pcre-s-mode (rxt-anything) (rxt-nonl))) ;; Beginning & end of string/line ((rx "^") (rxt-bol)) ((rx "$") (rxt-eol)) ((rx "\\A") (rxt-bos)) ((rx "\\Z") (rxt-eos)) ;; Subgroup ((rx "(") (rxt-parse-subgroup/pcre)) ;; Metacharacter quoting ((rx "\\Q") ;; It would seem simple to take all the characters between \Q ;; and \E and make an rxt-string, but \Q...\E isn't an atom: ;; any quantifiers afterward should bind only to the last ;; character, not the whole string. (let ((begin (point))) (search-forward "\\E" nil t) (let* ((end (match-beginning 0)) (str (buffer-substring-no-properties begin (1- end))) (char (char-to-string (char-before end)))) (rxt-seq (rxt-string str) (rxt-parse-quantifiers (rxt-string char)))))) ;; Pre-defined character sets ((rx "\\" (submatch (any "d" "D" "h" "H" "s" "S" "v" "V" "w" "W"))) (rxt--pcre-char-set (string-to-char (match-string 1)))) ;; \ + digits: backreference or octal char? ((rx "\\" (submatch (+ (any "0-9")))) (let* ((digits (match-string 1)) (dec (string-to-number digits))) ;; from "man pcrepattern": If the number is less than 10, or if ;; there have been at least that many previous capturing left ;; parentheses in the expression, the entire sequence is taken ;; as a back reference. (if (and (> dec 0) (or (< dec 10) (>= rxt-subgroup-count dec))) (progn (when rxt-pcre-case-fold (display-warning 'rxt "Backreferences with case-folding are handled poorly")) (rxt-backref dec)) ;; from "man pcrepattern": if the decimal number is greater ;; than 9 and there have not been that many capturing ;; subpatterns, PCRE re-reads up to three octal digits ;; following the backslash, and uses them to generate a data ;; character. Any subsequent digits stand for themselves. (goto-char (match-beginning 1)) (re-search-forward (rx (** 0 3 (any "0-7")))) (rxt-string (char-to-string (string-to-number (match-string 0) 8)))))) ;; Other escaped characters ((rx "\\" (submatch nonl)) (rxt-string (match-string 1))) ;; Everything else ((rx (or (any "\n") nonl)) (rxt-string (match-string 0))))))) (defun rxt-parse-escapes/pcre () "Consume a one-char PCRE escape at point and return its codepoint equivalent. Handles only those character escapes which have the same meaning in character classes as outside them." (rxt-token-case ((rx "\\a") #x07) ; bell ((rx "\\e") #x1b) ; escape ((rx "\\f") #x0c) ; formfeed ((rx "\\n") #x0a) ; linefeed ((rx "\\r") #x0d) ; carriage return ((rx "\\t") #x09) ; tab ;; Control character ((rx "\\c" (submatch nonl)) ;; from `man pcrepattern': ;; The precise effect of \cx is as follows: if x is a lower case ;; letter, it is converted to upper case. Then bit 6 of the ;; character (hex 40) is inverted. (logxor (string-to-char (upcase (match-string 1))) #x40)) ;; Hex escapes ((rx "\\x" (submatch (** 1 2 (any "0-9" "A-Z" "a-z")))) (string-to-number (match-string 1) 16)) ((rx "\\x{" (submatch (* (any "0-9" "A-Z" "a-z"))) "}") (string-to-number (match-string 1) 16)))) (defun rxt-parse-subgroup/pcre () (catch 'return (let ((shy nil) (extended-mode rxt-pcre-extended-mode) (single-line-mode rxt-pcre-s-mode) (case-fold rxt-pcre-case-fold)) (rxt-extended-skip) ;; Check for special (? ..) and (* ...) syntax (rxt-token-case ((rx "?") ; (? (rxt-token-case ((rx ")") ; Empty group (?) (throw 'return (rxt-empty-string))) (":" (setq shy t)) ; Shy group (?: ("#" ; Comment (?# (search-forward ")") (throw 'return (rxt-empty-string))) ((rx (or ; Flags (?isx-isx (seq (group (* (any "gimosx"))) "-" (group (+ (any "gimosx")))) (seq (group (+ (any "gimosx")))))) (let ((token (match-string 0)) (on (or (match-string 1) (match-string 3))) (off (or (match-string 2) ""))) (if (cl-find ?x on) (setq extended-mode t)) (if (cl-find ?s on) (setq single-line-mode t)) (if (cl-find ?i on) (setq case-fold t)) (if (cl-find ?x off) (setq extended-mode nil)) (if (cl-find ?s off) (setq single-line-mode nil)) (if (cl-find ?i off) (setq case-fold nil)) (when (string-match-p "[gmo]" token) (display-warning 'rxt (format "Unhandled PCRE flags in (?%s" token)))) (rxt-token-case (":" (setq shy t)) ; Shy group with flags (?isx-isx: ... (")" ; Set flags (?isx-isx) ;; Set flags for the remainder of the current subexpression (setq rxt-pcre-extended-mode extended-mode rxt-pcre-s-mode single-line-mode rxt-pcre-case-fold case-fold) (throw 'return (rxt-empty-string))))) ;; Other constructions like (?=, (?!, etc. are not recognised (t (rxt-error "Unrecognized PCRE extended construction `(?%c'" (char-after))))) ;; No special (* ...) verbs are recognised ((rx "*") (let ((begin (point))) (search-forward ")" nil 'go-to-end) (rxt-error "Unrecognized PCRE extended construction `(*%s'" (buffer-substring begin (point)))))) ;; Parse the remainder of the subgroup (unless shy (cl-incf rxt-subgroup-count)) (let* ((rxt-pcre-extended-mode extended-mode) (rxt-pcre-s-mode single-line-mode) (rxt-pcre-case-fold case-fold) (rx (rxt-parse-exp))) (rxt-extended-skip) (rxt-token-case (")" (if shy rx (rxt-submatch rx))) (t (rxt-error "Subexpression missing close paren"))))))) (defun rxt-parse-subgroup/el () (let ((kind (rxt-token-case ((rx "?:") (cl-incf rxt-subgroup-count) 'shy) ((rx "?" (group (+ (in "0-9"))) ":") (let ((n (string-to-number (match-string 1)))) (when (< rxt-subgroup-count n) (setf rxt-subgroup-count n)) n)) ((rx "?") ; Reserved (rxt-error "Unknown match group sequence"))))) (let ((rx (rxt-parse-exp))) (rxt-token-case ((rx "\\)") (cond ((eq kind 'shy) rx) ((numberp kind) (rxt-submatch-numbered kind rx)) (t (rxt-submatch rx)))) (t (rxt-error "Subexpression missing close paren")))))) (defun rxt-parse-braces () (rxt-token-case (rxt-m-to-n-brace-regexp (list (string-to-number (match-string 1)) (string-to-number (match-string 2)))) (rxt-m-to-?-brace-regexp (list (string-to-number (match-string 1)) nil)) (rxt-m-brace-regexp (let ((a (string-to-number (match-string 1)))) (list a a))) (t (let ((begin (point))) (search-forward "}" nil 'go-to-end) (rxt-error "Bad brace expression {%s" (buffer-substring-no-properties begin (point))))))) ;; Parse a character set range [...] (defun rxt-parse-char-class () (when (eobp) (rxt-error "Missing close right bracket in regexp")) (rxt-with-source-location (let* ((negated (rxt-token-case ((rx "^") t) (t nil))) (begin (point)) (result (if negated (rxt-negate (rxt-char-set-union)) (rxt-char-set-union))) (transformer (if negated #'rxt-negate #'identity)) (builder (if negated #'rxt-char-set-intersection #'rxt-choice))) (catch 'done (while t (when (eobp) (rxt-error "Missing close right bracket in regexp")) (if (and (looking-at (rx "]")) (not (= (point) begin))) (throw 'done result) (let ((piece (funcall transformer (rxt-parse-char-class-piece)))) (setq result (funcall builder result piece)))))) (forward-char) ; Skip over closing "]" result))) ;; Parse a single character, a character range, or a posix class ;; within a character set context. Returns an `rxt-char-set'. (defun rxt-parse-char-class-piece () (let ((atom (rxt-parse-char-class-atom))) (cl-typecase atom (rxt-char-set ; return unchanged atom) (integer ; character: check for range (let ((range-end (rxt-maybe-parse-range-end))) (if range-end (rxt-char-set-union (cons atom range-end)) (rxt-char-set-union atom)))) (t ; transform into character set (rxt-char-set-union atom))))) ;; Parse a single character or named class within a charset. ;; ;; Returns an integer (a character), a symbol (representing a named ;; character class) or an `rxt-char-set' (for pre-defined character ;; classes like \d, \W, etc.) (defun rxt-parse-char-class-atom () (or ;; First, check for PCRE-specific backslash sequences (and rxt-parse-pcre (rxt-parse-char-class-atom/pcre)) ;; Char-class syntax (rxt-token-case ;; Named classes [:alnum:], ... (rxt-named-classes-regexp (intern (match-string 1))) ;; Error on unknown posix-class-like syntax ((rx "[:" (* (any "a-z")) ":]") (rxt-error "Unknown posix character class `%s'" (match-string 0))) ;; Error on [= ... ]= collation syntax ((rx "[" (submatch (any "." "=")) (* (any "a-z")) (backref 1) "]") (rxt-error "Unsupported collation syntax `%s'" (match-string 0))) ;; Other characters stand for themselves ((rx (or "\n" nonl)) (string-to-char (match-string 0)))))) ;; Parse backslash escapes inside PCRE character classes (defun rxt-parse-char-class-atom/pcre () (or (rxt-parse-escapes/pcre) (rxt-token-case ;; Backslash + digits => octal char ((rx "\\" (submatch (** 1 3 (any "0-7")))) (string-to-number (match-string 1) 8)) ;; Pre-defined character sets ((rx "\\" (submatch (any "d" "D" "h" "H" "s" "S" "v" "V" "w" "W"))) (rxt--pcre-char-set (string-to-char (match-string 1)))) ;; "\b" inside character classes is a backspace ((rx "\\b") ?\C-h) ;; Ignore other escapes ((rx "\\" (submatch nonl)) (string-to-char (match-string 1)))))) ;; Look for a range tail (the "-z" in "a-z") after parsing a single ;; character within in a character set. Returns either a character ;; representing the range end, or nil. (defun rxt-maybe-parse-range-end () (let ((range-end nil) (end-position nil)) (when (looking-at (rx "-" (not (any "]")))) (save-excursion (forward-char) (setq range-end (rxt-parse-char-class-atom) end-position (point)))) (if (characterp range-end) ;; This is a range: move point after it and return the ending character (progn (goto-char end-position) range-end) ;; Not a range. nil))) ;; Return the pre-defined PCRE char-set associated with CHAR: i.e. \d ;; is digits, \D non-digits, \s space characters, etc. (defun rxt--pcre-char-set (char) (let* ((base-char (downcase char)) (negated (/= char base-char)) (elements (assoc-default base-char rxt-pcre-char-set-alist)) (base-char-set (apply #'rxt-char-set-union elements))) (if negated (rxt-negate base-char-set) base-char-set))) ;;;; Unparser to `rx' syntax (defconst rxt-rx-verbose-equivalents '((bol . line-start) (eol . line-end) (nonl . not-newline) (bos . string-start) (eos . string-end) (bow . word-start) (eow . word-end) (seq . sequence)) "Alist of verbose equivalents for short `rx' primitives.") (defun rxt-rx-symbol (sym) (if rxt-verbose-rx-translation (or (assoc-default sym rxt-rx-verbose-equivalents) sym) sym)) (defun rxt-adt->rx (re) (let ((rx (cl-typecase re (rxt-primitive (rxt-rx-symbol (rxt-primitive-rx re))) (rxt-string (if (or (not (rxt-string-case-fold re)) (string= "" (rxt-string-chars re))) (rxt-string-chars re) `(seq ,@(cl-loop for char across (rxt-string-chars re) collect `(any ,(upcase char) ,(downcase char)))))) (rxt-seq `(seq ,@(mapcar #'rxt-adt->rx (rxt-seq-elts re)))) (rxt-choice `(or ,@(mapcar #'rxt-adt->rx (rxt-choice-elts re)))) (rxt-submatch (if (rxt-seq-p (rxt-submatch-body re)) `(submatch ,@(mapcar #'rxt-adt->rx (rxt-seq-elts (rxt-submatch-body re)))) `(submatch ,(rxt-adt->rx (rxt-submatch-body re))))) (rxt-submatch-numbered (if (rxt-seq-p (rxt-submatch-numbered-p re)) `(,(rxt-rx-symbol 'submatch-n) ,(rxt-submatch-numbered-n re) ,@(mapcar #'rxt-adt->rx (rxt-seq-elts (rxt-submatch-numbered-body re)))) `(,(rxt-rx-symbol 'submatch-n) ,(rxt-submatch-numbered-n re) ,(rxt-adt->rx (rxt-submatch-numbered-body re))))) (rxt-backref (let ((n (rxt-backref-n re))) (if (<= n 9) `(backref ,(rxt-backref-n re)) (rxt-error "Too many backreferences (%s)" n)))) (rxt-syntax-class `(syntax ,(rxt-syntax-class-symbol re))) (rxt-char-category `(category ,(rxt-char-category-symbol re))) (rxt-repeat (let ((from (rxt-repeat-from re)) (to (rxt-repeat-to re)) (greedy (rxt-repeat-greedy re)) (body (rxt-adt->rx (rxt-repeat-body re)))) (if rxt-verbose-rx-translation (let ((rx (cond ((and (zerop from) (null to)) `(zero-or-more ,body)) ((and (equal from 1) (null to)) `(one-or-more ,body)) ((and (zerop from) (equal to 1)) `(zero-or-one ,body)) ((null to) `(>= ,from ,body)) ((equal from to) `(repeat ,from ,body)) (t `(** ,from ,to ,body))))) (if greedy (if rxt-explain rx ; Readable but not strictly accurate. Fixme? `(maximal-match ,rx)) `(minimal-match ,rx))) (cond ((and (zerop from) (null to)) `(,(if greedy '* '*?) ,body)) ((and (equal from 1) (null to)) `(,(if greedy '+ '+?) ,body)) ((and (zerop from) (equal to 1)) `(,(if greedy '\? ??) ,body)) ((null to) `(>= ,from ,body)) ((equal from to) `(= ,from ,body)) (t `(** ,from ,to ,body)))))) (rxt-char-set-union (let* ((case-fold (rxt-char-set-union-case-fold re)) (re (rxt--simplify-char-set re case-fold)) (chars (rxt-char-set-union-chars re)) (ranges (rxt-char-set-union-ranges re)) (classes (rxt-char-set-union-classes re)) (case-fold (rxt-char-set-union-case-fold re))) ;; Do not let the byte compiler optimize this variable out. (ignore case-fold) (if (and (null chars) (null ranges) (= 1 (length classes))) (car classes) `(any ,@chars ,@ranges ,@classes)))) (rxt-char-set-negation `(not ,(rxt-adt->rx (rxt-char-set-negation-elt re)))) (t (rxt-error "No RX translation of `%s'" (rxt-to-string re)))))) ;; Store source information on each fragment of the generated RX ;; sexp for rxt-explain mode (when rxt-explain ;; Use gensyms to store unique source information for multiple ;; occurrences of primitives like `bol' (when (symbolp rx) (setq rx (make-symbol (symbol-name rx)))) (setf (rxt-location rx) (rxt-location re))) rx)) ;;;; 'Unparser' to PCRE notation ;;; Based on scsh/posixstr.scm in scsh ;; To ensure that the operator precedence in the generated regexp does ;; what we want, we need to keep track of what kind of production is ;; returned from each step. Therefore these functions return a string ;; and a numeric "level" which lets the function using the generated ;; regexp know whether it has to be parenthesized: ;; ;; 0: an already parenthesized expression ;; ;; 1: a "piece" binds to any succeeding quantifiers ;; ;; 2: a "branch", or concatenation of pieces, needs parenthesizing to ;; bind to quantifiers ;; ;; 3: a "top", or alternation of branches, needs parenthesizing to ;; bind to quantifiers or to concatenation ;; ;; This idea is stolen straight out of the scsh implementation. (defun rxt-adt->pcre (re) (cl-destructuring-bind (s _) (rxt-adt->pcre/lev re) s)) (defun rxt-adt->pcre/lev (re) (cl-typecase re (rxt-primitive (let ((s (rxt-primitive-pcre re))) (if s (list s 1) (rxt-error "No PCRE translation of `%s'" (rxt-to-string re))))) (rxt-string (rxt-string->pcre re)) (rxt-seq (rxt-seq->pcre re)) (rxt-choice (rxt-choice->pcre re)) (rxt-submatch (rxt-submatch->pcre re)) (rxt-backref (list (format "\\%d" (rxt-backref-n re)) 1)) (rxt-repeat (rxt-repeat->pcre re)) ((or rxt-char-set-union rxt-char-set-negation) (rxt-char-set->pcre re)) ;; FIXME ;; ((rxt-char-set-intersection re) (rxt-char-set-intersection->pcre re)) (t (rxt-error "No PCRE translation of `%s'" (rxt-to-string re))))) (defconst rxt-pcre-metachars (rx (any "\\^.$|()[]*+?{}"))) (defconst rxt-pcre-charset-metachars (rx (any "]" "[" "\\" "^" "-"))) (defun rxt-string->pcre (re) (let ((chars (rxt-string-chars re))) (list (replace-regexp-in-string rxt-pcre-metachars "\\\\\\&" chars) ;; A one-character string is a 'piece' (it binds to a following ;; quantifier). A longer string is a 'branch' (it has to be ;; enclosed in parentheses to bind to a following quantifier). (if (> (length chars) 1) 2 1)))) (defun rxt-seq->pcre (re) (let ((elts (rxt-seq-elts re))) (if (null elts) "" (rxt-seq-elts->pcre elts)))) (defun rxt-seq-elts->pcre (elts) (cl-destructuring-bind (s lev) (rxt-adt->pcre/lev (car elts)) (if (null (cdr elts)) (list s lev) (cl-destructuring-bind (s1 lev1) (rxt-seq-elts->pcre (cdr elts)) (list (concat (rxt-paren-if-necessary s lev) (rxt-paren-if-necessary s1 lev1)) 2))))) (defun rxt-paren-if-necessary (s lev) (if (< lev 3) s (concat "(?:" s ")"))) (defun rxt-choice->pcre (re) (let ((elts (rxt-choice-elts re))) (if (null elts) nil (rxt-choice-elts->pcre elts)))) (defun rxt-choice-elts->pcre (elts) (cl-destructuring-bind (s lev) (rxt-adt->pcre/lev (car elts)) (if (null (cdr elts)) (list s lev) (cl-destructuring-bind (s1 _lev1) (rxt-choice-elts->pcre (cdr elts)) (list (concat s "|" s1) 3))))) (defun rxt-submatch->pcre (re) (cl-destructuring-bind (s _lev) (rxt-adt->pcre/lev (rxt-submatch-body re)) (list (concat "(" s ")") 0))) (defun rxt-repeat->pcre (re) (let ((from (rxt-repeat-from re)) (to (rxt-repeat-to re)) (body (rxt-repeat-body re)) (greedy (rxt-repeat-greedy re))) (cl-destructuring-bind (s lev) (rxt-adt->pcre/lev body) (cond ((and to (= from 1) (= to 1)) (list s lev)) ((and to (= from 0) (= to 0)) (list "" 2)) (t (when (> lev 1) ; parenthesize non-atoms (setq s (concat "(?:" s ")") lev 0)) (list (if to (cond ((and (= from 0) (= to 1)) (concat s (if greedy "?" "??"))) ((= from to) (concat s "{" (number-to-string to) "}")) (t (concat s "{" (number-to-string from) "," (number-to-string to) "}"))) (cond ((= from 0) (concat s (if greedy "*" "*?"))) ((= from 1) (concat s (if greedy "+" "+?"))) (t (concat s "{" (number-to-string from) ",}")))) 1)))))) (defun rxt-char-set->pcre (re) (cond ((rxt-char-set-union-p re) (list (concat "[" (rxt-char-set->pcre/chars re) "]") 1)) ((rxt-char-set-negation-p re) (let ((elt (rxt-char-set-negation-elt re))) (if (rxt-char-set-union-p elt) (list (concat "[^" (rxt-char-set->pcre/chars elt) "]") 1) (rxt-error "No PCRE translation of `%s'" (rxt-to-string elt))))) (t (rxt-error "Non-char-set in rxt-char-set->pcre: %s" re)))) ;; Fortunately, easier in PCRE than in POSIX! (defun rxt-char-set->pcre/chars (re) (cl-flet ((escape (char) (let ((s (char-to-string char))) (cond ((string-match rxt-pcre-charset-metachars s) (concat "\\" s)) ((and (not (string= s " ")) (string-match "[^[:graph:]]" s)) (format "\\x{%x}" char)) (t s))))) (let ((chars (rxt-char-set-union-chars re)) (ranges (rxt-char-set-union-ranges re)) (classes (rxt-char-set-union-classes re))) (concat (mapconcat #'escape chars "") (mapconcat #'(lambda (rg) (format "%s-%s" (escape (car rg)) (escape (cdr rg)))) ranges "") (mapconcat #'(lambda (class) (format "[:%s:]" class)) classes ""))))) ;;;; Generate all productions of a finite regexp (defun rxt-adt->strings (re) (cl-typecase re (rxt-primitive (list "")) (rxt-string (list (rxt-string-chars re))) (rxt-seq (rxt-seq-elts->strings (rxt-seq-elts re))) (rxt-choice (rxt-choice-elts->strings (rxt-choice-elts re))) (rxt-submatch (rxt-adt->strings (rxt-submatch-body re))) (rxt-submatch-numbered (rxt-adt->strings (rxt-submatch-numbered-body re))) (rxt-repeat (rxt-repeat->strings re)) (rxt-char-set-union (rxt-char-set->strings re)) (t (error "Can't generate productions of %s" (rxt-syntax-tree-readable re))))) (defun rxt-concat-product (heads tails) (cl-mapcan (lambda (hs) (mapcar (lambda (ts) (concat hs ts)) tails)) heads)) (defun rxt-seq-elts->strings (elts) (if (null elts) '("") (let ((heads (rxt-adt->strings (car elts))) (tails (rxt-seq-elts->strings (cdr elts)))) (rxt-concat-product heads tails)))) (defun rxt-choice-elts->strings (elts) (if (null elts) '() (append (rxt-adt->strings (car elts)) (rxt-choice-elts->strings (cdr elts))))) (defun rxt-repeat->strings (re) (let ((from (rxt-repeat-from re)) (to (rxt-repeat-to re))) (if (not to) (error "Can't generate all productions of unbounded repeat \"%s\"" (rxt-syntax-tree-readable re)) (let ((strings (rxt-adt->strings (rxt-repeat-body re)))) (rxt-repeat-n-m->strings from to strings))))) (defun rxt-repeat-n-m->strings (from to strings) (cond ((zerop to) '("")) ((= to from) (rxt-repeat-n->strings from strings)) (t ; to > from (let* ((strs-n (rxt-repeat-n->strings from strings)) (accum (cl-copy-list strs-n))) (dotimes (_i (- to from)) (setq strs-n (rxt-concat-product strs-n strings)) (setq accum (nconc accum strs-n))) accum)))) (defun rxt-repeat-n->strings (n strings) ;; n > 1 (cond ((zerop n) '("")) ((= n 1) strings) (t (rxt-concat-product (rxt-repeat-n->strings (- n 1) strings) strings)))) (defun rxt-char-set->strings (re) (if (rxt-char-set-union-classes re) (error "Can't generate all productions of named character classes in \"%s\"" (rxt-syntax-tree-readable re)) (let ((chars (mapcar #'char-to-string (rxt-char-set-union-chars re)))) (dolist (range (rxt-char-set-union-ranges re)) (let ((end (cdr range))) (cl-do ((i (car range) (+ i 1))) ((> i end)) (push (char-to-string i) chars)))) chars))) ;;;; RE-Builder hacks (defadvice reb-update-modestring (after rxt () activate compile) "This function is hacked for emulated PCRE syntax and regexp conversion." (setq reb-mode-string (concat (format " (%s)" reb-re-syntax) reb-mode-string)) (force-mode-line-update)) (defadvice reb-change-syntax (around rxt (&optional syntax) activate compile) "This function is hacked for emulated PCRE syntax and regexp conversion." (interactive (list (intern (completing-read (format "Select syntax (%s): " reb-re-syntax) '(read string pcre sregex rx) nil t "" nil (symbol-name reb-re-syntax))))) (unless (memq syntax '(read string pcre lisp-re sregex rx)) (error "Invalid syntax: %s" syntax)) (let ((re-builder-buffer (get-buffer reb-buffer))) (setq reb-re-syntax syntax) (when re-builder-buffer (with-current-buffer reb-target-buffer (cl-case syntax (rx (let ((rx (rxt-elisp-to-rx reb-regexp))) (setq reb-regexp-src (with-temp-buffer (insert "\n" "'") (rxt-print rx) (buffer-string))))) (pcre (setq reb-regexp-src (rxt-elisp-to-pcre reb-regexp))))) (with-current-buffer re-builder-buffer ;; Hack: prevent reb-auto-update from clobbering the ;; reb-regexp-src we just set (let ((inhibit-modification-hooks t)) (reb-initialize-buffer)) ;; Enable flag-toggling bindings for PCRE syntax (rxt--re-builder-switch-pcre-mode))))) (defadvice reb-read-regexp (around rxt () activate compile) "This function is hacked for emulated PCRE syntax and regexp conversion." (if (eq reb-re-syntax 'pcre) (setq ad-return-value (save-excursion (goto-char (point-min)) (rxt-read-delimited-pcre))) ad-do-it)) (defadvice reb-insert-regexp (around rxt () activate compile) "This function is hacked for emulated PCRE syntax and regexp conversion." (if (eq reb-re-syntax 'pcre) (let ((src (if (fboundp #'reb-target-value) (reb-target-value 'reb-regexp-src) (reb-target-binding reb-regexp-src)))) (if src (insert "\n/" (replace-regexp-in-string "/" "\\/" src t t) "/") (insert "\n//"))) ad-do-it)) (defadvice reb-cook-regexp (around rxt (re) activate compile) "This function is hacked for emulated PCRE syntax and regexp conversion." (if (eq reb-re-syntax 'pcre) (setq ad-return-value (rxt-pcre-to-elisp re)) ad-do-it)) (defadvice reb-update-regexp (around rxt () activate compile) "This function is hacked for emulated PCRE syntax and regexp conversion." (setq ad-return-value (let* ((re-src (reb-read-regexp)) (re (reb-cook-regexp re-src))) (with-current-buffer reb-target-buffer (let ((oldre reb-regexp)) (prog1 (not (string= oldre re)) (setq reb-regexp re) ;; Update the source re if format requires translation (when (or (reb-lisp-syntax-p) (eq reb-re-syntax 'pcre)) (setq reb-regexp-src re-src)))))))) (defun rxt--re-builder-switch-pcre-mode () (rxt--read-pcre-mode (if (eq reb-re-syntax 'pcre) 1 0))) (add-hook 'reb-mode-hook #'rxt--re-builder-switch-pcre-mode) (provide 'rxt) (provide 'pcre2el) ;;; pcre2el.el ends here