diff --git a/comby-kernel.opam b/comby-kernel.opam index 9db7cc55..2e1cabf4 100644 --- a/comby-kernel.opam +++ b/comby-kernel.opam @@ -21,8 +21,6 @@ depends: [ "dune" {>= "2.8.0"} "ocaml" {>= "4.08.1"} "core_kernel" - "mparser" {>= "1.3"} - "mparser-pcre" "ppx_deriving" "ppx_deriving_yojson" {>= "3.6.0"} "yojson" {>= "1.6.0" < "2.0.0"} diff --git a/comby.opam b/comby.opam index 011de663..b0248358 100644 --- a/comby.opam +++ b/comby.opam @@ -32,12 +32,11 @@ depends: [ "comby-kernel" {= version} "comby-semantic" {= version} "core" + "cstruct-lwt" "hack_parallel" {arch != "arm32" & arch != "arm64"} "lwt" "lwt_react" "lwt_ssl" - "mparser" {>= "1.3"} - "mparser-pcre" "parany" {>= "12.0.3"} "patience_diff" {>= "v0.14" & < "v0.15"} "ppx_deriving" @@ -45,8 +44,8 @@ depends: [ "yojson" {>= "1.6.0" < "2.0.0"} "pcre" "shell" - "tar" - "tar-unix" + "tar" {< "3.0.0"} + "tar-unix" {< "3.0.0"} "toml" {>= "6.0.0"} "bisect_ppx" {with-test & dev & >= "2.5.0"} ] diff --git a/docs/third-party-licenses/ALL.txt b/docs/third-party-licenses/ALL.txt index f8257375..98ba94d2 100644 --- a/docs/third-party-licenses/ALL.txt +++ b/docs/third-party-licenses/ALL.txt @@ -1265,544 +1265,6 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -LICENSE FOR mparser: - -This library is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License (LGPL) as -published by the Free Software Foundation; either version 2.1 of the -License (see below), or (at your option) any later version. - -As a special exception to the GNU Lesser General Public License, you -may link, statically or dynamically, a "work that uses the Library" -with a publicly distributed version of the Library to produce an -executable file containing portions of the Library, and distribute -that executable file under terms of your choice, without any of the -additional requirements listed in clause 6 of the GNU Lesser General -Public License. By "a publicly distributed version of the Library", we -mean either the unmodified Library as distributed, or a modified -version of the Library that is distributed under the conditions -defined in clause 2 of the GNU Lesser General Public License. This -exception does not however invalidate any other reasons why the -executable file might be covered by the GNU Lesser General Public -License. - -This library 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. - -====================================================================== - - - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -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 this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -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 -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser 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 Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "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 -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY 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 -LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - -====================================================================== - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms -of the ordinary General Public License). - - To apply these terms, attach the following notices to the library. -It is safest to attach them to the start of each source file to most -effectively convey the exclusion of warranty; and each file should -have at least the "copyright" line and a pointer to where the full -notice is found. - - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library 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 - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or -your school, if any, to sign a "copyright disclaimer" for the library, -if necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James - Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - LICENSE FOR ocaml-ci-scripts: ## ISC License diff --git a/docs/third-party-licenses/pull-and-update-release-scripts.sh b/docs/third-party-licenses/pull-and-update-release-scripts.sh index 463664c7..4d165946 100755 --- a/docs/third-party-licenses/pull-and-update-release-scripts.sh +++ b/docs/third-party-licenses/pull-and-update-release-scripts.sh @@ -1,6 +1,6 @@ #!/bin/bash -LIBS="ppx_deriving_yojson core ppxlib ppx_deriving hack_parallel opium pcre-ocaml ocaml-tls camlzip bisect_ppx mparser ocaml-ci-scripts patdiff lwt toml" +LIBS="ppx_deriving_yojson core ppxlib ppx_deriving hack_parallel opium pcre-ocaml ocaml-tls camlzip bisect_ppx ocaml-ci-scripts patdiff lwt toml" rm ALL.txt 2> /dev/null for l in $LIBS; do rm -rf $l; done @@ -49,10 +49,6 @@ wget -P camlzip https://raw.githubusercontent.com/xavierleroy/camlzip/master/LIC mkdir bisect_ppx && \ wget -P bisect_ppx https://raw.githubusercontent.com/aantron/bisect_ppx/master/LICENSE.md -# LGPL -mkdir mparser && \ -wget -P mparser https://raw.githubusercontent.com/comby-tools/mparser/master/LICENSE.txt - # ISC mkdir ocaml-ci-scripts && \ wget -P ocaml-ci-scripts https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/LICENSE.md diff --git a/lib/app/configuration/command_configuration.ml b/lib/app/configuration/command_configuration.ml index 8b09a4b3..d2f7ef9b 100644 --- a/lib/app/configuration/command_configuration.ml +++ b/lib/app/configuration/command_configuration.ml @@ -219,7 +219,6 @@ type user_input_options = ; override_matcher : string option ; regex_pattern : bool ; ripgrep_args : string option - ; omega : bool } type compute_mode = @@ -628,24 +627,14 @@ let extension file_filters = | _, Some extension -> "." ^ extension | extension, None -> "." ^ extension) -let of_extension - (module Engine : Matchers.Engine.S) - (module External : Matchers.External.S) - file_filters - = +let of_extension (module External : Matchers.External.S) file_filters = let external_handler = External.handler in let extension = extension file_filters in - match Engine.select_with_extension extension ~external_handler with + match Matchers.select_with_extension extension ~external_handler with | Some matcher -> matcher, Some extension, None - | None -> (module Engine.Generic), Some extension, None + | None -> (module Matchers.Generic), Some extension, None -let select_matcher custom_metasyntax custom_matcher override_matcher file_filters omega = - let (module Engine : Matchers.Engine.S) = - if omega then - (module Matchers.Omega) - else - (module Matchers.Alpha) - in +let select_matcher custom_metasyntax custom_matcher override_matcher file_filters = let module External = struct let handler = External_semantic.lsif_hover end @@ -656,15 +645,15 @@ let select_matcher custom_metasyntax custom_matcher override_matcher file_filter (* custom matcher, optional custom metasyntax *) let metasyntax = parse_metasyntax custom_metasyntax in let syntax = syntax custom_matcher in - if debug then Format.printf "Engine.create@."; - Engine.create ~metasyntax syntax, None, Some metasyntax + if debug then Format.printf "Matchers.create@."; + Matchers.create ~metasyntax syntax, None, Some metasyntax | _, Some language, custom_metasyntax -> (* forced language, optional custom metasyntax *) let metasyntax = parse_metasyntax custom_metasyntax in let (module Metasyntax) = Matchers.Metasyntax.create metasyntax in let (module Language) = force_language language in if debug then Format.printf "Engine.Make@."; - ( (module Engine.Make (Language) (Metasyntax) (External) : Matchers.Matcher.S) + ( (module Matchers.Make (Language) (Metasyntax) (External) : Matchers.Matcher.S) , None , Some metasyntax ) | _, _, Some custom_metasyntax -> @@ -673,13 +662,13 @@ let select_matcher custom_metasyntax custom_matcher override_matcher file_filter let (module Metasyntax) = Matchers.Metasyntax.create metasyntax in let (module Language) = force_language (extension file_filters) in if debug then Format.printf "Engine.Make2@."; - ( (module Engine.Make (Language) (Metasyntax) (External) : Matchers.Matcher.S) + ( (module Matchers.Make (Language) (Metasyntax) (External) : Matchers.Matcher.S) , None , Some metasyntax ) | _, _, None -> (* infer language from file filters, use default metasyntax *) - if debug then Format.printf "Engine.Infer@."; - of_extension (module Engine) (module External) file_filters + if debug then Format.printf "Matchers.Infer@."; + of_extension (module External) file_filters let regex_of_specifications specifications = Format.sprintf "(%s)" @@ -722,7 +711,6 @@ let create ; override_matcher ; regex_pattern ; ripgrep_args - ; omega } ; run_options ; output_options = @@ -831,7 +819,7 @@ let create Printer.Rewrite.print replacement_output source_path replacements result source_content in let ((module M) as matcher), _, metasyntax = - select_matcher custom_metasyntax custom_matcher override_matcher file_filters omega + select_matcher custom_metasyntax custom_matcher override_matcher file_filters in return { matcher diff --git a/lib/app/configuration/command_configuration.mli b/lib/app/configuration/command_configuration.mli index 09c9bc43..a7936159 100644 --- a/lib/app/configuration/command_configuration.mli +++ b/lib/app/configuration/command_configuration.mli @@ -60,7 +60,6 @@ type user_input_options = ; override_matcher : string option ; regex_pattern : bool ; ripgrep_args : string option - ; omega : bool } type compute_mode = diff --git a/lib/app/configuration/dune b/lib/app/configuration/dune index 9e849a08..a9d0bbf2 100644 --- a/lib/app/configuration/dune +++ b/lib/app/configuration/dune @@ -11,6 +11,7 @@ comby.patdiff comby.camlzip core + pcre yojson ppx_deriving_yojson toml diff --git a/lib/app/pipeline/dune b/lib/app/pipeline/dune index bd4646d3..24892fe2 100644 --- a/lib/app/pipeline/dune +++ b/lib/app/pipeline/dune @@ -13,6 +13,7 @@ comby.camlzip core core.uuid + cstruct-lwt yojson ppx_deriving_yojson parany diff --git a/lib/kernel/comby_kernel.ml b/lib/kernel/comby_kernel.ml index 23a8e845..737aa5c0 100644 --- a/lib/kernel/comby_kernel.ml +++ b/lib/kernel/comby_kernel.ml @@ -7,7 +7,6 @@ module Replacement = Replacement type replacement = Replacement.result module Matchers = struct - module Engine = Matchers.Engine module Language = Matchers.Language module Matcher = Matchers.Matcher module Configuration = Matchers.Configuration @@ -20,11 +19,10 @@ module Matchers = struct type metasyntax = Matchers.Metasyntax.t module External = Matchers.External - module Alpha = Matchers.Alpha - module Omega = Matchers.Omega module Languages = Matchers.Languages module Template = Matchers.Template module Ast = Matchers.Ast + include Matchers.Matcher_engine module Rule = struct include Matchers.Rule diff --git a/lib/kernel/comby_kernel.mli b/lib/kernel/comby_kernel.mli index 76f6874b..3e68ee00 100644 --- a/lib/kernel/comby_kernel.mli +++ b/lib/kernel/comby_kernel.mli @@ -661,106 +661,94 @@ module Matchers : sig val select_with_extension : string -> (module Language.S) option end - module Engine : sig - module type S = sig - module Make (_ : Language.S) (_ : Metasyntax.S) (_ : External.S) : Matcher.S - - (** {4 Supported Matchers} *) - module Text : Matcher.S - - module Paren : Matcher.S - module Dyck : Matcher.S - module JSON : Matcher.S - module JSONC : Matcher.S - module GraphQL : Matcher.S - module Dhall : Matcher.S - module Latex : Matcher.S - module Assembly : Matcher.S - module Clojure : Matcher.S - module Lisp : Matcher.S - module Generic : Matcher.S - module Bash : Matcher.S - module Ruby : Matcher.S - module Elixir : Matcher.S - module Python : Matcher.S - module Html : Matcher.S - module Xml : Matcher.S - module SQL : Matcher.S - module Erlang : Matcher.S - module C : Matcher.S - module Csharp : Matcher.S - module Java : Matcher.S - module CSS : Matcher.S - module Kotlin : Matcher.S - module Scala : Matcher.S - module Nim : Matcher.S - module Matlab : Matcher.S - module Dart : Matcher.S - module Php : Matcher.S - module Go : Matcher.S - module Javascript : Matcher.S - module Jsx : Matcher.S - module Typescript : Matcher.S - module Tsx : Matcher.S - module Swift : Matcher.S - module Rust : Matcher.S - module R : Matcher.S - module OCaml : Matcher.S - module Reason : Matcher.S - module Fsharp : Matcher.S - module Pascal : Matcher.S - module Julia : Matcher.S - module Fortran : Matcher.S - module Haskell : Matcher.S - module HCL : Matcher.S - module Elm : Matcher.S - module Zig : Matcher.S - module Coq : Matcher.S - module Move : Matcher.S - module Solidity : Matcher.S - module C_nested_comments : Matcher.S - - (** [all] returns all default matchers. *) - val all : (module Matcher.S) list - - (** [select_with_extension metasyntax external file_extension] is a - convenience function that returns a matcher associated with a - [file_extension]. E.g., use ".c" to get the C matcher. For a full list - of extensions associated with matchers, run comby -list. If - [metasyntax] is specified, the matcher will use a custom metasyntax - definition instead of the default. An experimental [external] callback - is a general callback for handling external properties in the rewrite - template. *) - val select_with_extension - : ?metasyntax:Metasyntax.t - -> ?external_handler:External.t - -> string - -> (module Matcher.S) option - - (** [create metasyntax external syntax] creates a matcher for a language - defined by [syntax]. If [metasyntax] is specified, the matcher will use - a custom metasyntax definition instead of the default. An experimental - [external] callback is a general callback for handling external - properties in the rewrite template. *) - val create - : ?metasyntax:metasyntax - -> ?external_handler:External.t - -> Language.Syntax.t - -> (module Matcher.S) - end - end - - (** {3 Alpha Matcher} - - Alpha is the match engine that defines default matchers for languages. - *) - module Alpha : Engine.S - - (** {3 Omega Matcher} - - Alternative, partial, experimental match engine. - *) - module Omega : Engine.S + (** {3 Matchers} + + Default matchers for each supported language, plus helpers to construct + matchers from a file extension or a custom language syntax. *) + module Make (_ : Language.S) (_ : Metasyntax.S) (_ : External.S) : Matcher.S + + (** {4 Supported Matchers} *) + module Text : Matcher.S + + module Paren : Matcher.S + module Dyck : Matcher.S + module JSON : Matcher.S + module JSONC : Matcher.S + module GraphQL : Matcher.S + module Dhall : Matcher.S + module Latex : Matcher.S + module Assembly : Matcher.S + module Clojure : Matcher.S + module Lisp : Matcher.S + module Generic : Matcher.S + module Bash : Matcher.S + module Ruby : Matcher.S + module Elixir : Matcher.S + module Python : Matcher.S + module Html : Matcher.S + module Xml : Matcher.S + module SQL : Matcher.S + module Erlang : Matcher.S + module C : Matcher.S + module Csharp : Matcher.S + module Java : Matcher.S + module CSS : Matcher.S + module Kotlin : Matcher.S + module Scala : Matcher.S + module Nim : Matcher.S + module Matlab : Matcher.S + module Dart : Matcher.S + module Php : Matcher.S + module Go : Matcher.S + module Javascript : Matcher.S + module Jsx : Matcher.S + module Typescript : Matcher.S + module Tsx : Matcher.S + module Swift : Matcher.S + module Rust : Matcher.S + module R : Matcher.S + module OCaml : Matcher.S + module Reason : Matcher.S + module Fsharp : Matcher.S + module Pascal : Matcher.S + module Julia : Matcher.S + module Fortran : Matcher.S + module Haskell : Matcher.S + module HCL : Matcher.S + module Elm : Matcher.S + module Zig : Matcher.S + module Coq : Matcher.S + module Move : Matcher.S + module Solidity : Matcher.S + module C_nested_comments : Matcher.S + + (** [all] returns all default matchers. *) + val all : (module Matcher.S) list + + (** [select_with_extension metasyntax external file_extension] is a + convenience function that returns a matcher associated with a + [file_extension]. E.g., use ".c" to get the C matcher. For a full list + of extensions associated with matchers, run comby -list. If + [metasyntax] is specified, the matcher will use a custom metasyntax + definition instead of the default. An experimental [external] callback + is a general callback for handling external properties in the rewrite + template. *) + val select_with_extension + : ?metasyntax:Metasyntax.t + -> ?external_handler:External.t + -> string + -> (module Matcher.S) option + + (** [create metasyntax external syntax] creates a matcher for a language + defined by [syntax]. If [metasyntax] is specified, the matcher will use + a custom metasyntax definition instead of the default. An experimental + [external] callback is a general callback for handling external + properties in the rewrite template. *) + val create + : ?metasyntax:metasyntax + -> ?external_handler:External.t + -> Language.Syntax.t + -> (module Matcher.S) (** {3 Rewrite} diff --git a/lib/kernel/match/match_context.ml b/lib/kernel/match/match_context.ml index 5b1c0af1..6dfb5db7 100644 --- a/lib/kernel/match/match_context.ml +++ b/lib/kernel/match/match_context.ml @@ -35,13 +35,13 @@ let update_match f m = { m with range; environment } let convert_offset ~fast ~source match_ = + let index = + if fast then + Offset.index ~source + else + Offset.empty + in let f offset = - let index = - if fast then - Offset.index ~source - else - Offset.empty - in if fast then Offset.convert_fast ~offset index else diff --git a/lib/kernel/matchers/alpha.ml b/lib/kernel/matchers/alpha.ml deleted file mode 100644 index d2321b08..00000000 --- a/lib/kernel/matchers/alpha.ml +++ /dev/null @@ -1,1146 +0,0 @@ -open Core_kernel -open MParser -open MParser_PCRE -open Configuration -open Match -open Range -open Location -module R = MakeRegexp (Regexp) - -let configuration_ref = ref (Configuration.create ()) -let weaken_delimiter_hole_matching = false - -let debug = - match Sys.getenv "DEBUG_COMBY" with - | exception Not_found -> false - | _ -> true - -let debug_hole = - match Sys.getenv "DEBUG_COMBY_HOLE" with - | exception Not_found -> false - | _ -> true - -let debug_position = - match Sys.getenv "DEBUG_COMBY_POS" with - | exception Not_found -> false - | _ -> true - -let f _ = return Types.Unit - -let extract_matched_text source { offset = match_start; _ } { offset = match_end; _ } = - String.slice source match_start match_end - -let is_not p s = - if is_ok (p s) then - Empty_failed (unknown_error s) - else ( - match read_char s with - | Some c -> Consumed_ok (c, advance_state s 1, No_error) - | None -> Empty_failed (unknown_error s)) - -type 'a literal_parser_callback = - contents:string -> left_delimiter:string -> right_delimiter:string -> 'a - -type 'a nested_delimiter_callback = left_delimiter:string -> right_delimiter:string -> 'a - -module Make (Lang : Types.Language.S) (Meta : Types.Metasyntax.S) (Ext : Types.External.S) = struct - module rec Matcher : Types.Matcher.S = struct - module Syntax = Lang.Syntax - include Lang.Info - - let wildcard = "_" - - let create v = - Types.Ast.Template [ Hole { variable = v; pattern = v; offset = 0; kind = Value } ] - - let implicit_equals_satisfied environment identifier range matched = - if debug then Format.printf "Looking up %s@." identifier; - match Environment.lookup environment identifier with - | None -> Some (Environment.add ~range environment identifier (String.concat matched)) - | Some _ when String.(identifier = wildcard) -> Some environment - | Some existing_value when String.(existing_value = String.concat matched) -> - let identifier' = Format.sprintf "%s_equal_%s" identifier (!configuration_ref.fresh ()) in - let environment' = Environment.add ~range environment identifier' (String.concat matched) in - Some environment' - | _ -> None - - let escapable_string_literal_parser (f : 'a literal_parser_callback) = - (match Syntax.escapable_string_literals with - | None -> [] - | Some { delimiters; escape_character } -> - List.map delimiters ~f:(fun delimiter -> - let module M = - Parsers.String_literals.Alpha.Escapable.Make (struct - let delimiter = delimiter - let escape = escape_character - end) - in - M.base_string_literal - >>= fun contents -> - return (f ~contents ~left_delimiter:delimiter ~right_delimiter:delimiter))) - |> choice - - let raw_string_literal_parser (f : 'a literal_parser_callback) = - List.map Syntax.raw_string_literals ~f:(fun (left_delimiter, right_delimiter) -> - let module M = - Parsers.String_literals.Alpha.Raw.Make (struct - let left_delimiter = left_delimiter - let right_delimiter = right_delimiter - end) - in - M.base_string_literal - >>= fun contents -> return (f ~contents ~left_delimiter ~right_delimiter)) - |> choice - - let comment_parser = - match Syntax.comments with - | [] -> MParser.zero - | syntax -> - List.map syntax ~f:(function - | Multiline (left, right) -> - let module M = - Parsers.Comments.Alpha.Multiline.Make (struct - let left = left - let right = right - end) - in - M.comment - | Nested_multiline (left, right) -> - let module M = - Parsers.Comments.Alpha.Nested_multiline.Make (struct - let left = left - let right = right - end) - in - M.comment - | Until_newline start -> - let module M = - Parsers.Comments.Alpha.Until_newline.Make (struct - let start = start - end) - in - M.comment) - |> choice - - let escapable_literal_grammar ~right_delimiter = - match Syntax.escapable_string_literals with - | None -> zero - | Some { escape_character; _ } -> - string (Format.sprintf "%c%s" escape_character right_delimiter) - <|> string (Format.sprintf "%c%c" escape_character escape_character) - <|> (is_not (string right_delimiter) |>> String.of_char) - - let raw_literal_grammar ~right_delimiter = is_not (string right_delimiter) |>> String.of_char - - (* Does not take into account code comments. *) - let generate_pure_spaces_parser () = spaces1 >>= fun result -> f result - - (* Takes into account code comments. *) - let generate_spaces_parser () = - many1 @@ choice [ skip comment_parser; spaces1 ] >>= fun _ -> f Types.Unit - - let sequence_chain (plist : ('c, Match.t) parser sexp_list) : ('c, Match.t) parser = - List.fold plist ~init:(return Types.Unit) ~f:( >> ) - - let with_debug_matcher s tag = - if debug then ( - match tag with - | `Position tag -> - if debug_position then ( - let prev = prev_char s in - let curr = read_char s in - let next = next_char s in - let print_if = function - | Some s -> s - | None -> '?' - in - Format.printf "Position Tag: %s@." tag; - Format.printf - "H_prev: %c H_curr: %c H_next: %c@." - (print_if prev) - (print_if curr) - (print_if next)) - | `Delimited delimited -> Format.printf "%s%!" delimited - | `Delimited_suffix suffix -> Format.printf "%s%!" suffix - | `Checkpoint (label, s) -> Format.printf "Point(%s):%s" label s - | _ -> assert false) - - let is_alphanum delim = Pcre.(pmatch ~rex:(regexp "^[[:alnum:]]+$") delim) - let whitespace : (string, Match.t) parser = many1 space |>> String.of_char_list - let not_alphanum = many1 (is_not alphanum) |>> String.of_char_list - - let reserved_alphanum_delimiter_must_satisfy = - Syntax.user_defined_delimiters - |> List.filter_map ~f:(fun (from, until) -> - if not (is_alphanum from) then - Some [ from; until ] - else - None) - |> List.concat - |> List.map ~f:string - |> List.map ~f:attempt - - let nested_delimiters_parser (f : 'a nested_delimiter_callback) = - (* All alphanum delimiter fixups happen in the generated parser, not here. *) - let between p from until s = - (string from - >>= fun from -> - if debug then with_debug_matcher s (`Delimited from); - p - >>= fun p_result -> - string until - >>= fun until -> - if debug then with_debug_matcher s (`Delimited until); - return p_result) - s - in - Syntax.user_defined_delimiters - |> List.map ~f:(fun (left_delimiter, right_delimiter) -> - between (f ~left_delimiter ~right_delimiter) left_delimiter right_delimiter) - |> choice - (* Backtrack on failure, specifically for alphanum. *) - |> attempt - - (** Generates a word that is NOT OK with having alphanum chars before or after - it. This disables substring parsing. *) - let generate_word chars : ('c, _) parser = - fun s -> - let prev = prev_char s in - (match prev with - | Some prev when is_alphanum (Char.to_string prev) -> fail "unsat" - | _ -> - string (String.of_char_list chars) - >>= fun result -> - (* there has to be at least one "not alphanum" after this parser for it to succeed, or eof. *) - look_ahead (skip (many1 (is_not alphanum)) <|> eof) >>= fun _ -> f result) - s - - let generate_string_token_parser str : ('c, _) parser = - many comment_parser >> string str >>= fun result -> f result - - let identifier () = choice @@ List.map ~f:char (String.to_list Meta.identifier) - let optional_identifier () = many (identifier ()) |>> String.of_char_list - let identifier () = many1 (identifier ()) |>> String.of_char_list - let hole_body () = identifier () - - let regex_body separator suffix () = - let rec expr s = - (choice - [ (char '[' - >> many1 expr - << char ']' - |>> fun char_class -> Format.sprintf "[%s]" @@ String.concat char_class) - ; (char '\\' >> any_char |>> fun c -> Format.sprintf "\\%c" c) - ; is_not (string suffix) |>> Char.to_string - ]) - s - in - let regex_identifier () = - optional_identifier () - >>= fun v -> - char separator - >> many1 expr - >>= fun e -> return (Format.sprintf "%s%c%s" v separator (String.concat e)) - in - regex_identifier () - >>= fun identifier -> - if debug then Format.printf "Regex accepts %s@." identifier; - return identifier - - let p = function - | Some delim -> skip (string delim) - | None -> return () - - let hole_parsers = - List.fold ~init:[] Meta.syntax ~f:(fun acc -> function - | Hole (sort, Delimited (left, right)) -> (sort, p left >> hole_body () << p right) :: acc - | Hole (sort, Reserved_identifiers l) -> (sort, choice (List.map ~f:string l)) :: acc - | Regex (left, separator, right) -> - (Regex, p (Some left) >> regex_body separator right () << p (Some right)) :: acc) - - let reserved_holes = List.map hole_parsers ~f:(fun (_, parser) -> parser >>= fun _ -> return "") - - let reserved_parsers () = - (* Alphanum blocks *) - let required_from_suffix = not_alphanum in - let required_until_suffix = not_alphanum in - let handle_alphanum_delimiters_reserved_trigger from until = - let from_parser s = - (match prev_char s with - | Some prev when is_alphanum (Char.to_string prev) -> fail "unsat" - | _ -> - string from >>= fun from -> look_ahead required_from_suffix >>= fun _ -> return from) - s - in - let until_parser s = - (string until - >>= fun until -> - eof - <|> look_ahead (skip required_until_suffix) - >>= fun _ -> - (* if current char/next_char is alphanum, make unsat. *) - let prev = prev_char s in - if debug then with_debug_matcher s (`Position "reserved_delimiter_until"); - match prev with - | Some prev when is_alphanum (Char.to_string prev) -> fail "unsat" - | _ -> return until) - s - in - [ from_parser; until_parser ] - in - (* Isomorphic to Omega *) - let user_defined_reserved_delimiters = - List.concat_map Syntax.user_defined_delimiters ~f:(fun (from, until) -> - if is_alphanum from && is_alphanum until then - handle_alphanum_delimiters_reserved_trigger from until - else - [ string from; string until ]) - in - let user_defined_reserved_escapable_strings = - match Syntax.escapable_string_literals with - | Some { delimiters; _ } -> - List.concat_map delimiters ~f:(fun delimiter -> [ string delimiter ]) - | None -> [] - in - let user_defined_reserved_raw_strings = - List.concat_map Syntax.raw_string_literals ~f:(fun (from, until) -> - [ string from; string until ]) - in - let user_defined_reserved_comments = - List.concat_map Syntax.comments ~f:(function - | Multiline (left, right) -> [ string left; string right ] - | Nested_multiline (left, right) -> [ string left; string right ] - | Until_newline start -> [ string start ]) - in - [ user_defined_reserved_delimiters - ; reserved_holes - ; user_defined_reserved_escapable_strings - ; user_defined_reserved_raw_strings - ; user_defined_reserved_comments - (* only needed once it's significant for matching and not treated like spaces*) - ] - |> List.concat - |> List.map ~f:skip - (* Attempt the reserved: otherwise, if a parser partially succeeds, - it won't detect that single or greedy is reserved. *) - |> List.map ~f:attempt - |> choice - - let until_of_from from = - Syntax.user_defined_delimiters - |> List.find_map ~f:(fun (from', until) -> - if String.equal from from' then Some until else None) - |> function - | Some until -> until - | None -> assert false - - let record_matches identifier p : ('c, Match.t) parser = - get_pos - >>= fun (pre_index, pre_line, pre_column) -> - p - >>= fun matched -> - get_pos - >>= fun (post_index, post_line, post_column) -> - let post_index, post_line, post_column = - if String.(concat matched = "") then - pre_index, pre_line, pre_column - else - post_index, post_line, post_column - in - get_user_state - >>= fun { environment; _ } -> - let pre_location : Location.t = - Location.{ offset = pre_index; line = pre_line; column = pre_column } - in - let post_location : Location.t = - Location.{ offset = post_index; line = post_line; column = post_column } - in - let range = { match_start = pre_location; match_end = post_location } in - match implicit_equals_satisfied environment identifier range matched with - | None -> fail "don't record, unsat" - | Some environment -> - update_user_state (fun result -> - if debug then ( - Format.printf "Updating user state:@."; - Format.printf "%s |-> %s@." identifier (String.concat matched); - Format.printf - "ID %s: %d:%d:%d - %d:%d:%d@." - identifier - pre_index - pre_line - pre_column - post_index - post_line - post_column); - { result with environment }) - >>= fun () -> f matched - - let alphanum_delimiter_must_satisfy = - many1 (is_not (skip (choice reserved_alphanum_delimiter_must_satisfy) <|> skip alphanum)) - |>> String.of_char_list - - let generate_delimited_hole_parser - ?priority_left_delimiter:left_delimiter - ?priority_right_delimiter:right_delimiter - = - let delimiters = - if weaken_delimiter_hole_matching then ( - match left_delimiter, right_delimiter with - | Some left_delimiter, Some right_delimiter -> [ left_delimiter, right_delimiter ] - | _ -> Syntax.user_defined_delimiters) - else - Syntax.user_defined_delimiters - in - let reserved = - List.concat_map delimiters ~f:(fun (from, until) -> [ string from; string until ]) - |> List.map ~f:attempt - |> choice - in - let other = is_not reserved |>> String.of_char in - (* A parser that understands the hole matching cut off points happen at - delimiters. *) - let rec nested_grammar s = - (comment_parser - <|> raw_string_literal_parser (fun ~contents ~left_delimiter:_ ~right_delimiter:_ -> - contents) - <|> escapable_string_literal_parser (fun ~contents ~left_delimiter:_ ~right_delimiter:_ -> - contents) - <|> (many1 space |>> String.of_char_list) - <|> attempt @@ delims_over_holes - (* Only consume if not reserved. If it is reserved, we want to trigger the 'many' - in (many nested_grammar) to continue. *) - <|> other) - s - and delims_over_holes s = - let between_nested_delims p = - let capture_delimiter_result p ~from = - let until = until_of_from from in - between (string from) (string until) p - >>= fun result -> return (String.concat @@ [ from ] @ result @ [ until ]) - in - delimiters - |> List.map ~f:(fun pair -> capture_delimiter_result p ~from:(fst pair)) - |> choice - in - (between_nested_delims (many nested_grammar)) s - in - delims_over_holes - - let generate_everything_hole_parser - ?priority_left_delimiter:left_delimiter - ?priority_right_delimiter:right_delimiter - ?at_depth - = - let with_debug_hole tag = - match tag with - | `Spaces chars -> - if debug_hole then Format.printf ""; - return (String.of_char_list chars) - | `Delimited delimited -> - if debug_hole then Format.printf "%s" delimited; - return delimited - | `Character c -> - if debug_hole then Format.printf "%c" c; - return (String.of_char c) - | `Body body -> - let body = String.concat body in - if debug_hole then Format.printf "%s" body; - return body - | `Checkpoint (label, s) -> - if debug_hole then Format.printf "Point(%s):%s" label s; - return s - | _ -> assert false - in - let delimiters = - if weaken_delimiter_hole_matching then ( - match left_delimiter, right_delimiter with - | Some left_delimiter, Some right_delimiter -> [ left_delimiter, right_delimiter ] - | _ -> Syntax.user_defined_delimiters) - else - Syntax.user_defined_delimiters - in - let handle_alphanum_delimiters from until p = - (* mandatory_prefix: needs to be not alphanum AND not non-alphanum delim. - If it is a paren, we need to fail and get out of this alphanum block - parser (how did we end up in here? because we said that we'd accept - anything as prefix to 'def', including '(', and so '(' is not handled - as a delim.) *) - let mandatory_prefix = alphanum_delimiter_must_satisfy in - (* mandatory_suffix: be more strict with suffix of opening delimiter: don't - use 'any non-alphanum', but instead use whitespace. This since 'def;' - is undesirable, and 'def.foo' may be intentional. But 'end.' or 'end;' - probably still refer to a closing delim. *) - let mandatory_suffix = choice reserved_alphanum_delimiter_must_satisfy <|> whitespace in - let satisfy_opening_delimiter prev = - (match prev with - | Some prev when is_alphanum (Char.to_string prev) -> fail "unsat" - (* Try parse whitespace, and we want to capture its length, in case - this is a space between, like 'def def end end'. But in the case - where there's no space, it means we have just entered the beginning - of the hole which may start with the 'd' of 'def', but since we - already know that the previous char is not alphanum in this branch - (so it is a delimiter or whitespace) it is OK to continue: in this - case, return "". *) - | _ -> mandatory_prefix <|> return "") - >>= fun prefix -> - string from - >>= fun open_delimiter -> - with_debug_hole - (`Checkpoint ("open_delimiter_
" ^ prefix ^ "
_sat_for", open_delimiter)) - >>= fun _ -> - (* Use look_ahead to ensure that there is, e.g., whitespace after this - possible delimiter, but without consuming input. Whitespace needs to - not be consumed so that we can detect subsequent delimiters. *) - look_ahead mandatory_suffix - >>= fun suffix -> - with_debug_hole - (`Checkpoint ("open_delimiter_" ^ suffix ^ "_sat_for", open_delimiter)) - >>= fun _ -> return (prefix, open_delimiter) - in - let satisfy_closing_delimiter = - string until - >>= fun close_delimiter -> - look_ahead @@ mandatory_suffix - >>= fun suffix -> - with_debug_hole - (`Checkpoint ("close_delimiter_" ^ suffix ^ "_sat_for", close_delimiter)) - >>= fun _ -> return close_delimiter - in - (fun s -> - let prev = prev_char s in - (satisfy_opening_delimiter prev - >>= fun (prefix, open_delimiter) -> - p - >>= fun in_between -> - with_debug_hole (`Body in_between) - >>= fun in_between -> - satisfy_closing_delimiter - >>= fun close_delimiter -> - return ((prefix ^ open_delimiter) ^ in_between ^ close_delimiter)) - s) - (* Use attempt so that, e.g., 'struct' is tried after 'begin' delimiters under choice. *) - |> attempt - in - let handle_alphanum_delimiters_reserved_trigger from until = - (* If it's alphanum, only consider it reserved if there is, say, whitespace after and so - handle alternatively. Otherwise, return empty to indicate 'this sequence of characters - is not reserved'. *) - let reserved = - Syntax.user_defined_delimiters - |> List.filter_map ~f:(fun (from, _) -> - if not (is_alphanum from) then - Some from - else - None) - |> List.map ~f:string - |> List.map ~f:attempt - in - let required_delimiter_terminal = - many1 (is_not (skip (choice reserved) <|> skip alphanum)) |>> String.of_char_list - in - List.map [ from; until ] ~f:(fun delimiter s -> - let prev = prev_char s in - (match prev with - | Some prev when is_alphanum (Char.to_string prev) -> - (* If prev is alphanum, this can't possibly be a reserved delimiter. Just continue. *) - fail "unsat" - | _ -> string delimiter >>= fun _ -> look_ahead required_delimiter_terminal) - s) - in - (* The cases for which we need to stop parsing just characters - and consider delimiters. *) - let reserved = - List.concat_map delimiters ~f:(fun (from, until) -> - if is_alphanum from then - handle_alphanum_delimiters_reserved_trigger from until - else - [ string from; string until ]) - |> List.map ~f:attempt - |> choice - in - (* A parser that understands the hole matching cut off points happen at - delimiters. *) - let rec nested_grammar s = - (comment_parser - <|> raw_string_literal_parser (fun ~contents ~left_delimiter:_ ~right_delimiter:_ -> - contents) - <|> escapable_string_literal_parser (fun ~contents ~left_delimiter:_ ~right_delimiter:_ -> - contents) - <|> (many1 (if Option.equal Int.equal (Some 0) at_depth then blank else space) - >>= fun r -> with_debug_hole (`Spaces r)) - <|> (attempt @@ delims_over_holes >>= fun r -> with_debug_hole (`Delimited r)) - (* Only consume if not reserved. If it is reserved, we want to trigger the 'many' - in (many nested_grammar) to continue. *) - <|> (is_not (reserved <|> (space |>> Char.to_string)) - >>= fun r -> with_debug_hole (`Character r))) - s - and delims_over_holes s = - let between_nested_delims p = - let capture_delimiter_result p ~from = - let until = until_of_from from in - if is_alphanum from then - handle_alphanum_delimiters from until p - else - between (string from) (string until) p - >>= fun result -> return (String.concat @@ [ from ] @ result @ [ until ]) - in - delimiters - |> List.map ~f:(fun pair -> capture_delimiter_result p ~from:(fst pair)) - |> choice - in - (between_nested_delims (many nested_grammar)) s - in - nested_grammar - - let coalesce_whitespace prefix_parser suffix_parser = - let is_whitespace p = - match - ( parse_string p " " (Match.create ()) - , (* suffix parser could be a hole. It needs to fail on - parsing something like "X" to be a whitespace parser *) - parse_string p "X" (Match.create ()) ) - with - | Success _, Failed _ -> true - | _ -> false - in - let pre = is_whitespace prefix_parser in - if debug then Format.printf "Pre: %b@." pre; - let suf = is_whitespace suffix_parser in - if debug then Format.printf "Suf: %b@." suf; - pre && suf - - let prefix_parser p_list i = - match List.nth (List.rev p_list) (i + 1) with - | Some p -> p - | None -> - if debug then Format.printf "Prefix parser unsat@."; - fail "unsat" - - let turn_holes_into_matchers_for_this_level - ?left_delimiter - ?right_delimiter - (p_list : (Types.production, Match.t) parser list) - : (Types.production, Match.t) parser list - = - List.fold (List.rev p_list) ~init:[] ~f:(fun acc p -> - match parse_string p "_signal_hole" (Match.create ()) with - | Failed _ -> p :: acc - | Success (Types.Hole { sort; identifier; dimension; at_depth }) -> - (match sort with - | Regex -> - let separator = - List.find_map_exn Meta.syntax ~f:(function - | Hole _ -> None - | Regex (_, separator, _) -> Some separator) - in - let identifier, pattern = String.lsplit2_exn identifier ~on:separator in - (* FIXME parse *) - let identifier = if String.(identifier = "") then wildcard else identifier in - if debug then Format.printf "Regex: Id: %s Pat: %s@." identifier pattern; - let compiled_regexp = R.make_regexp pattern in - let regexp_parser = R.regexp compiled_regexp in - let base_parser = [ regexp_parser ] in - let base_parser = - (* adds begin line parser if the pattern has ^ anchor *) - if String.is_prefix pattern ~prefix:"^" then ( - let p = R.make_regexp (String.drop_prefix pattern 1) |> R.regexp in - (char '\n' >>= fun _ -> p) :: base_parser) - else - base_parser - in - let base_parser = - (* adds end line parser if the pattern has $ anchor *) - if String.is_suffix pattern ~suffix:"$" then ( - let p = R.make_regexp (String.drop_suffix pattern 1) |> R.regexp in - (p << (skip @@ char '\n' <|> eof)) :: base_parser) - else - base_parser - in - let hole_semantics = - choice base_parser - >>= fun result -> - if debug then Format.printf "Regex success: %s@." result; - return [ result ] - in - record_matches identifier hole_semantics :: acc - | Alphanum -> - let allowed = choice [ alphanum; char '_' ] |>> String.of_char in - let hole_semantics = many1 allowed in - record_matches identifier hole_semantics :: acc - | Non_space -> - let allowed = - [ skip space; reserved_parsers () ] |> choice |> is_not |>> Char.to_string - in - let rest = - match acc with - | [] -> eof >>= fun () -> f [ "" ] - | _ -> sequence_chain acc - in - let hole_semantics = many1 (not_followed_by rest "" >> allowed) in - record_matches identifier hole_semantics :: acc - | Line -> - let allowed = - many (is_not (char '\n')) |>> fun x -> [ String.of_char_list x ^ "\n" ] - in - let hole_semantics = allowed << char '\n' in - record_matches identifier hole_semantics :: acc - | Blank -> - let allowed = blank |>> String.of_char in - let hole_semantics = many1 allowed in - record_matches identifier hole_semantics :: acc - | Expression -> - let non_space = - [ skip space; reserved_parsers () ] |> choice |> is_not |>> Char.to_string - in - let delimited = - generate_delimited_hole_parser - ?priority_left_delimiter:left_delimiter - ?priority_right_delimiter:right_delimiter - in - let matcher = - choice - [ raw_string_literal_parser (fun ~contents ~left_delimiter:_ ~right_delimiter:_ -> - contents) - ; escapable_string_literal_parser - (fun ~contents ~left_delimiter:_ ~right_delimiter:_ -> contents) - ; non_space - ; delimited - ] - in - let rest = - match acc with - | [] -> eof >>= fun () -> f [ "" ] - | _ -> sequence_chain acc - in - let hole_semantics = many1 (not_followed_by rest "" >> matcher) in - record_matches identifier hole_semantics :: acc - | Everything -> - let matcher = - match dimension with - | Code -> - generate_everything_hole_parser - ?priority_left_delimiter:left_delimiter - ?priority_right_delimiter:right_delimiter - ?at_depth - | Escapable_string_literal -> - let right_delimiter = Option.value_exn right_delimiter in - escapable_literal_grammar ~right_delimiter - | Raw_string_literal -> - let right_delimiter = Option.value_exn right_delimiter in - raw_literal_grammar ~right_delimiter - | Comment -> failwith "Unimplemented" - in - let rest = - match acc with - | [] -> eof >>= fun () -> f [ "" ] - | _ -> sequence_chain acc - in - (* Continue until rest, but don't consume rest. acc will - propagate the rest that needs to be consumed. *) - let hole_semantics = many (not_followed_by rest "" >> matcher) in - record_matches identifier hole_semantics :: acc) - | Success Unit -> acc (* for comment *) - | Success _ -> failwith "Hole expected") - - let hole_parser ?at_depth sort dimension = - let open Types.Hole in - let hole_parser = - let open Polymorphic_compare in - List.fold ~init:[] hole_parsers ~f:(fun acc (sort', parser) -> - if sort' = sort then parser :: acc else acc) - in - let skip_signal hole = skip (string "_signal_hole") |>> fun () -> Types.Hole hole in - let at_depth = - if !configuration_ref.match_newline_toplevel then - None - else ( - (* Match newlines at toplevel if for languages that are likely to match - around context-sensitive tags *) - match Lang.Info.name with - | "HTML" | "XML" | "Text" | "LaTeX" -> None - | _ -> at_depth) - in - match hole_parser with - | [] -> fail "none" (* not defined *) - | l -> - choice l - |>> (function - | identifier -> skip_signal { sort; identifier; dimension; at_depth }) - - let generate_hole_for_literal dimension ~contents ~left_delimiter ~right_delimiter s = - let holes = - choice @@ List.map hole_parsers ~f:(fun (kind, _) -> attempt (hole_parser kind dimension)) - in - let reserved_holes = reserved_holes |> List.map ~f:skip |> List.map ~f:attempt |> choice in - let p = - many - @@ choice - [ holes - ; spaces1 |>> generate_pure_spaces_parser - ; many1 (is_not (choice [ reserved_holes; skip space ])) - |>> String.of_char_list - |>> generate_string_token_parser - ] - in - match parse_string p contents (Match.create ()) with - | Success p -> - (match dimension with - | Escapable_string_literal | Raw_string_literal -> - (turn_holes_into_matchers_for_this_level ~left_delimiter ~right_delimiter p - |> sequence_chain) - s - | _ -> assert false) - | Failed (_msg, _) -> failwith "literal parser did not succeed" - - let depth = ref (-1) - - let rec generate_parsers s = - depth := !depth + 1; - many (common s) - - and common _s = - let holes at_depth = - hole_parsers |> List.map ~f:(fun (sort, _) -> attempt (hole_parser sort Code ~at_depth)) - in - choice - [ (choice (holes !depth) - >>= fun result -> - if debug then Format.printf "Depth hole %d@." !depth; - return result) - (* String literals are handled specially because match semantics change inside string delimiters. *) - ; raw_string_literal_parser (generate_hole_for_literal Raw_string_literal) - ; escapable_string_literal_parser (generate_hole_for_literal Escapable_string_literal) - (* Nested delimiters are handled specially for nestedness. *) - ; (nested_delimiters_parser generate_outer_delimiter_parsers - >>= fun result -> - depth := !depth - 1; - return result) - (* Skip comments in the template, just succeed. If desired, could return the comment string. *) - ; (many1 (skip comment_parser <|> spaces1) |>> fun _ -> generate_spaces_parser ()) - (* Optional: parse identifiers and disallow substring matching *) - ; (if !configuration_ref.disable_substring_matching then - many1 (alphanum <|> char '_') |>> generate_word - else - zero (* Everything else. *)) - ; many1 @@ is_not @@ choice [ reserved_parsers (); skip space ] - |>> (fun cl -> - if debug then Format.printf "%s" @@ String.of_char_list cl; - String.of_char_list cl) - |>> generate_string_token_parser - ] - - and generate_outer_delimiter_parsers ~left_delimiter ~right_delimiter s = - let before s = - (if debug_hole then with_debug_matcher s (`Position "generate_outer_delimiter"); - let p = - if is_alphanum left_delimiter then ( - (* This logic is needed for cases where we say 'def :[1] end' in the template, - and don't match partially on, say, 'adef body endq' in the underlying generated - parser. *) - let prev = prev_char s in - match prev with - | Some prev when is_alphanum (Char.to_string prev) -> fail "unsat" - | _ -> string left_delimiter) - else - string left_delimiter - in - p >>= fun _ -> f [ left_delimiter ]) - s - in - let after = - let p = - if is_alphanum right_delimiter then - (* This handles the case for something like 'def body endly'. *) - string right_delimiter - >>= fun delim -> look_ahead @@ (eof <|> skip not_alphanum) >>= fun _ -> return delim - else - string right_delimiter - in - p >>= fun _ -> f [ right_delimiter ] - in - (generate_parsers s - >>= fun p_list -> - turn_holes_into_matchers_for_this_level - ~left_delimiter - ~right_delimiter - ([ before ] @ p_list @ [ after ]) - |> sequence_chain - |> return) - s - - let general_parser_generator s = - let outer_p = - generate_parsers s - >>= fun p_list -> - (* EOF of template is here. *) - eof - >> - (* Result is unit so ignore. *) - (* Customize the inner parser. *) - let inner_p = - let matcher : ('a, Match.t) parser = - turn_holes_into_matchers_for_this_level p_list |> sequence_chain - in - let matcher : ('a, Match.t) parser = - let with_positions (matcher : ('a, Match.t) parser) : ('a, Match.t) parser = - get_pos - >>= fun (pre_offset, pre_line, pre_column) -> - matcher - >>= fun _last_production -> - get_pos - >>= fun (post_offset, post_line, post_column) -> - let match_start = { offset = pre_offset; line = pre_line; column = pre_column } in - let match_end = { offset = post_offset; line = post_line; column = post_column } in - let range = { match_start; match_end } in - update_user_state (fun result -> { result with range }) >> return Types.Unit - in - with_positions matcher - in - match !configuration_ref.match_kind with - | Exact -> matcher << eof - | Fuzzy -> - many - (not_followed_by matcher "" - >> ((* Respect grammar but ignore contents up to a match. *) - skip comment_parser - <|> skip - (raw_string_literal_parser - (fun ~contents:_ ~left_delimiter:_ ~right_delimiter:_ -> ())) - <|> skip - (escapable_string_literal_parser - (fun ~contents:_ ~left_delimiter:_ ~right_delimiter:_ -> ())) - <|> skip any_char)) - >> matcher - in - return inner_p - in - outer_p s - - let to_template template : ('a, Match.t) MParser.t Or_error.t = - (* Use a match type for state so we can reuse parsers for inner and outer. *) - match parse_string general_parser_generator template (Match.create ()) with - | Success p -> Ok p - | Failed (msg, _) -> Or_error.error_string msg - - (** shift: start the scan in the source at an offset *) - let first' shift p source : Match.t Or_error.t = - if debug then Format.printf "First for shift %d@." shift; - let set_start_pos p s = p (advance_state s shift) in - let p = set_start_pos p in - match parse_string (pair p get_user_state) source (Match.create ()) with - | Success (_, result) -> - if String.is_empty source then - (* If source is empty and p succeeds, it's the trivial case. We set - the result manually. *) - Ok - { result with - range = - { match_start = { offset = 0; line = 1; column = 1 } - ; match_end = { offset = 0; line = 1; column = 1 } - } - } - else - Ok result - | Failed (msg, _) -> Or_error.error_string msg - - let first ?configuration ?shift ?filepath template source = - let open Or_error in - let (_ : string option) = filepath in - configuration_ref := Option.value configuration ~default:!configuration_ref; - to_template template - >>= fun p -> - let shift = - match shift with - | Some s -> s - | None -> 0 - in - first' shift p source - - let all - ?configuration - ?filepath - ?(rule = [ Types.Ast.True ]) - ~template - ~source:original_source - () - : Match.t list - = - let (_ : string option) = filepath in - let Rule.{ nested; _ } = Rule.options rule in - let template, rule = Preprocess.map_aliases (module Meta) (module Ext) template (Some rule) in - let rule = Option.value_exn rule in - (* OK in this case *) - let rec aux_all ?configuration ?(nested = false) ~template ~source:original_source () = - let open Or_error in - depth := -1; - configuration_ref := Option.value configuration ~default:!configuration_ref; - let make_result = function - | Ok ok -> ok - | Error _ -> [] - in - make_result - @@ (to_template template - >>= fun p -> - let p = - if String.is_empty template then - MParser.(eof >> return Types.Unit) - else - p - in - let rec aux acc shift = - match first' shift p original_source with - | Ok ({ range = { match_start; match_end; _ }; environment; _ } as result) -> - if debug then Format.printf "Ok first'"; - let shift = match_end.offset in - let shift, matched = - if match_start.offset = match_end.offset then - ( match_start.offset + 1 - , "" (* advance one if the matched content is the empty string *) ) - else - shift, extract_matched_text original_source match_start match_end - in - if debug then Format.printf "Extracted matched: %s@." matched; - let result = { result with matched } in - let result = - if debug then Format.printf "Rule: %s@." (Sexp.to_string @@ Rule.sexp_of_t rule); - (* FIXME we should not have to convert here. Pass module, but after fixing this functor's signature. *) - let metasyntax = - Metasyntax. - { syntax = Meta.syntax; identifier = Meta.identifier; aliases = Meta.aliases } - in - let external_handler = Ext.handler in - let sat, env = - Program.apply - ~metasyntax - ~external_handler - ~substitute_in_place:!configuration_ref.substitute_in_place - ?filepath - rule - environment - in - if debug && Option.is_some env then - Format.printf - "Got back: %b %S" - sat - (Match.Environment.to_string @@ Option.value_exn env); - let new_env = if sat then env else None in - match new_env with - | None -> None - | Some env -> Some { result with environment = env } - in - if shift >= String.length original_source then ( - match result with - | Some result -> result :: acc - | None -> acc) - else ( - match result with - | Some result -> aux (result :: acc) shift - | None -> aux acc shift) - | Error _ -> acc - in - let matches = aux [] 0 |> List.rev in - if nested then - return (compute_nested_matches ?configuration ~nested template matches @ matches) - else - return matches) - and compute_nested_matches ?configuration ?nested template matches = - let rec aux acc matches = - match (matches : Match.t list) with - | [] -> acc - | { environment; _ } :: rest -> - List.fold ~init:acc (Environment.vars environment) ~f:(fun acc v -> - let source_opt = Environment.lookup environment v in - match source_opt with - | Some source -> - let nested_matches = - match first ?configuration template source with - | Ok { matched; _ } when String.(matched <> source) -> - if String.(matched = "") && String.length source > 1 then ( - let matches = aux_all ?configuration ?nested ~template ~source () in - let { match_start = ms; _ } = - Option.value_exn (Environment.lookup_range environment v) - in - List.map matches ~f:(fun m -> - (*Format.eprintf "Doing %S. Parent matched is %S. Start is %d@." m.matched matched ms.offset;*) - let environment = - List.fold - (Environment.vars m.environment) - ~init:m.environment - ~f:(fun env var -> - let open Option in - let updated : environment option = - Environment.lookup_range env var - >>| fun r -> - let range = - { match_start = - { r.match_start with - offset = ms.offset + r.match_start.offset - 1 - } - ; match_end = - { r.match_end with offset = ms.offset + r.match_end.offset - 1 } - } - in - Environment.update_range env var range - in - match updated with - | None -> env - | Some env -> env) - in - let range = - { match_start = - { m.range.match_start with - offset = ms.offset + m.range.match_start.offset - 1 - } - ; match_end = - { m.range.match_end with - offset = ms.offset + m.range.match_end.offset - 1 - } - } - in - { m with range; environment })) - else - [] - | _ -> [] - in - acc @ nested_matches - | _ -> acc) - @ aux acc rest - in - aux [] matches - in - if nested then (* Use sort on offset for a top-down ordering. *) - aux_all ?configuration ~nested ~template ~source:original_source () - |> List.sort ~compare:(fun left right -> - left.range.match_start.offset - right.range.match_start.offset) - else - (* Don't change list order for non-nested matches--it's backwards and matters for rewriting. *) - aux_all ?configuration ~nested ~template ~source:original_source () - - let set_rewrite_template _ = () (* Unused in alpha matcher *) - end - - and Program : sig - val apply - : ?substitute_in_place:bool - -> ?metasyntax:Types.Metasyntax.t - -> ?external_handler:Types.External.t - -> ?filepath:string - -> Rule.t - -> Match.environment - -> Evaluate.result - end = struct - let apply ?substitute_in_place ?metasyntax ?external_handler ?filepath rule env = - let Rule.{ nested; _ } = Rule.options rule in - let subrule = if nested then [ Types.Ast.True; Option "nested" ] else [ Types.Ast.True ] in - Evaluate.apply - ?substitute_in_place - ?metasyntax - ?external_handler - ?filepath - ~match_all:(Matcher.all ~rule:subrule) - rule - env - end - - include Matcher -end diff --git a/lib/kernel/matchers/alpha.mli b/lib/kernel/matchers/alpha.mli deleted file mode 100644 index 6be01201..00000000 --- a/lib/kernel/matchers/alpha.mli +++ /dev/null @@ -1,2 +0,0 @@ -open Types -module Make (_ : Language.S) (_ : Metasyntax.S) (_ : External.S) : Matcher.S diff --git a/lib/kernel/matchers/dune b/lib/kernel/matchers/dune index 4625458f..2f157fe3 100644 --- a/lib/kernel/matchers/dune +++ b/lib/kernel/matchers/dune @@ -11,8 +11,7 @@ comby-kernel.match comby-kernel.vangstrom core_kernel - mparser - mparser-pcre + pcre re yojson ppx_deriving_yojson)) diff --git a/lib/kernel/matchers/engine.ml b/lib/kernel/matchers/engine.ml deleted file mode 100644 index aa425fc3..00000000 --- a/lib/kernel/matchers/engine.ml +++ /dev/null @@ -1,164 +0,0 @@ -open Core_kernel -open Languages - -module Make - (Make : functor - (_ : Types.Language.S) - (_ : Types.Metasyntax.S) - (_ : Types.External.S) - -> Types.Matcher.S) : Types.Engine.S = struct - module Make = Make - - let create - ?(metasyntax = Metasyntax.default_metasyntax) - ?(external_handler = External.default_external) - Types.Language.Syntax. - { user_defined_delimiters; escapable_string_literals; raw_string_literals; comments } - = - let module Info = struct - let name = "User_defined_language" - let extensions = [] - end - in - let module Syntax = struct - let user_defined_delimiters = user_defined_delimiters - let escapable_string_literals = escapable_string_literals - let raw_string_literals = raw_string_literals - let comments = comments - end - in - let module User_language = struct - module Info = Info - module Syntax = Syntax - end - in - let (module Metasyntax : Metasyntax.S) = Metasyntax.(create metasyntax) in - let module External = struct - let handler = external_handler - end - in - (module Make (User_language) (Metasyntax) (External) : Types.Matcher.S) - - module Text = Make (Text) (Metasyntax.Default) (External.Default) - module Paren = Make (Paren) (Metasyntax.Default) (External.Default) - module Dyck = Make (Dyck) (Metasyntax.Default) (External.Default) - module JSON = Make (JSON) (Metasyntax.Default) (External.Default) - module JSONC = Make (JSONC) (Metasyntax.Default) (External.Default) - module GraphQL = Make (GraphQL) (Metasyntax.Default) (External.Default) - module Dhall = Make (Dhall) (Metasyntax.Default) (External.Default) - module Latex = Make (Latex) (Metasyntax.Default) (External.Default) - module Assembly = Make (Assembly) (Metasyntax.Default) (External.Default) - module Clojure = Make (Clojure) (Metasyntax.Default) (External.Default) - module Lisp = Make (Lisp) (Metasyntax.Default) (External.Default) - module Generic = Make (Generic) (Metasyntax.Default) (External.Default) - module Bash = Make (Bash) (Metasyntax.Default) (External.Default) - module Ruby = Make (Ruby) (Metasyntax.Default) (External.Default) - module Elixir = Make (Elixir) (Metasyntax.Default) (External.Default) - module Python = Make (Python) (Metasyntax.Default) (External.Default) - module Html = Make (Html) (Metasyntax.Default) (External.Default) - module Xml = Make (Xml) (Metasyntax.Default) (External.Default) - module SQL = Make (SQL) (Metasyntax.Default) (External.Default) - module Erlang = Make (Erlang) (Metasyntax.Default) (External.Default) - module C = Make (C) (Metasyntax.Default) (External.Default) - module Csharp = Make (Csharp) (Metasyntax.Default) (External.Default) - module Java = Make (Java) (Metasyntax.Default) (External.Default) - module CSS = Make (CSS) (Metasyntax.Default) (External.Default) - module Kotlin = Make (Kotlin) (Metasyntax.Default) (External.Default) - module Scala = Make (Scala) (Metasyntax.Default) (External.Default) - module Nim = Make (Nim) (Metasyntax.Default) (External.Default) - module Matlab = Make (Matlab) (Metasyntax.Default) (External.Default) - module Dart = Make (Dart) (Metasyntax.Default) (External.Default) - module Php = Make (Php) (Metasyntax.Default) (External.Default) - module Go = Make (Go) (Metasyntax.Default) (External.Default) - module Javascript = Make (Javascript) (Metasyntax.Default) (External.Default) - module Jsx = Make (Jsx) (Metasyntax.Default) (External.Default) - module Typescript = Make (Typescript) (Metasyntax.Default) (External.Default) - module Tsx = Make (Tsx) (Metasyntax.Default) (External.Default) - module Swift = Make (Swift) (Metasyntax.Default) (External.Default) - module Rust = Make (Rust) (Metasyntax.Default) (External.Default) - module R = Make (R) (Metasyntax.Default) (External.Default) - module OCaml = Make (OCaml) (Metasyntax.Default) (External.Default) - module Reason = Make (Reason) (Metasyntax.Default) (External.Default) - module Fsharp = Make (Fsharp) (Metasyntax.Default) (External.Default) - module Pascal = Make (Pascal) (Metasyntax.Default) (External.Default) - module Julia = Make (Julia) (Metasyntax.Default) (External.Default) - module Fortran = Make (Fortran) (Metasyntax.Default) (External.Default) - module Haskell = Make (Haskell) (Metasyntax.Default) (External.Default) - module HCL = Make (HCL) (Metasyntax.Default) (External.Default) - module Elm = Make (Elm) (Metasyntax.Default) (External.Default) - module Zig = Make (Zig) (Metasyntax.Default) (External.Default) - module Coq = Make (Coq) (Metasyntax.Default) (External.Default) - module Move = Make (Move) (Metasyntax.Default) (External.Default) - module Solidity = Make (Solidity) (Metasyntax.Default) (External.Default) - module C_nested_comments = Make (C_nested_comments) (Metasyntax.Default) (External.Default) - - let all : (module Types.Matcher.S) list = - [ (module Assembly) - ; (module Bash) - ; (module C) - ; (module Csharp) - ; (module CSS) - ; (module Dart) - ; (module Dyck) - ; (module Clojure) - ; (module Coq) - ; (module Elm) - ; (module Erlang) - ; (module Elixir) - ; (module Fortran) - ; (module Fsharp) - ; (module Go) - ; (module Html) - ; (module Haskell) - ; (module HCL) - ; (module Java) - ; (module Javascript) - ; (module Jsx) - ; (module JSON) - ; (module JSONC) - ; (module GraphQL) - ; (module Dhall) - ; (module Julia) - ; (module Kotlin) - ; (module Latex) - ; (module Lisp) - ; (module Move) - ; (module Nim) - ; (module Matlab) - ; (module OCaml) - ; (module Paren) - ; (module Pascal) - ; (module Php) - ; (module Python) - ; (module Reason) - ; (module R) - ; (module Ruby) - ; (module Rust) - ; (module Scala) - ; (module Solidity) - ; (module SQL) - ; (module Swift) - ; (module Text) - ; (module Typescript) - ; (module Tsx) - ; (module Xml) - ; (module Zig) - ; (module Generic) - ] - - let select_with_extension - ?(metasyntax = Metasyntax.default_metasyntax) - ?(external_handler = External.default_external) - extension - : (module Types.Matcher.S) option - = - let open Option in - Languages.select_with_extension extension - >>| fun (module Language : Types.Language.S) -> - let (module Metasyntax) = Metasyntax.(create metasyntax) in - let module External = struct - let handler = external_handler - end - in - (module Make (Language) (Metasyntax) (External) : Types.Matcher.S) -end diff --git a/lib/kernel/matchers/engine.mli b/lib/kernel/matchers/engine.mli deleted file mode 100644 index b0d4eeea..00000000 --- a/lib/kernel/matchers/engine.mli +++ /dev/null @@ -1,4 +0,0 @@ -open Types - -module Make (_ : functor (_ : Language.S) (_ : Metasyntax.S) (_ : External.S) -> Matcher.S) : - Engine.S diff --git a/lib/kernel/matchers/omega.ml b/lib/kernel/matchers/matcher_engine.ml similarity index 77% rename from lib/kernel/matchers/omega.ml rename to lib/kernel/matchers/matcher_engine.ml index c286781f..28dff323 100644 --- a/lib/kernel/matchers/omega.ml +++ b/lib/kernel/matchers/matcher_engine.ml @@ -117,7 +117,6 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. implicit_equals_match_satisfied := false; return (Unit, acc) (* don't record, unsat *) | Some environment -> - let environment = Environment.add ~range environment identifier content in current_environment_ref := environment; return (Unit, acc)) | _ -> return (Unit, acc) @@ -223,6 +222,16 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. in M.comment + let nested_multiline left right = + let open Parsers.Comments.Omega.Nested_multiline in + let module M = + Make (struct + let left = left + let right = right + end) + in + M.comment + let comment_parser = match Language.Syntax.comments with | [] -> zero @@ -231,8 +240,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. List.map syntax ~f:(function | Multiline (left, right) -> multiline left right | Until_newline start -> until_newline start - | Nested_multiline (_, _) -> zero) - (* FIXME: unimplemented nested multiline comments *) + | Nested_multiline (left, right) -> nested_multiline left right) in choice parsers @@ -319,6 +327,58 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. |> List.concat |> choice + let is_word_char = function + | 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_' -> true + | _ -> false + + let is_word_token str = (not (String.is_empty str)) && String.for_all str ~f:is_word_char + + let is_reserved_word_delimiter str = + is_word_token str + && + List.exists Language.Syntax.user_defined_delimiters ~f:(fun (left, right) -> + String.equal str left || String.equal str right) + + let word_boundary_before = + pos + >>= fun offset -> + if offset = 0 || offset > String.length !source_ref then + return () + else if is_word_char (String.get !source_ref (offset - 1)) then + fail "substring prefix" + else + return () + + let word_boundary_after = + pos + >>= fun offset -> + if offset >= String.length !source_ref then + return () + else if is_word_char (String.get !source_ref offset) then + fail "substring suffix" + else + return () + + let reserved_delimiter_token ?(check_boundaries = true) str = + if check_boundaries && is_reserved_word_delimiter str then + word_boundary_before *> string str <* word_boundary_after + else + string str + + let substring_checked_token str = + let token = string str in + if not !configuration_ref.disable_substring_matching then + token + else ( + let starts_with_word = + (not (String.is_empty str)) && is_word_char (String.get str 0) + in + let ends_with_word = + (not (String.is_empty str)) && is_word_char (String.get str (String.length str - 1)) + in + let token = if starts_with_word then word_boundary_before *> token else token in + if ends_with_word then token <* word_boundary_after else token) + let generate_single_hole_parser () = alphanum <|> char '_' >>| String.of_char let delimiters left right = @@ -329,7 +389,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. let between_nested_delims p delimiters = let between_nested_delims p from = let until = until_of_from from in - between (string from) (string until) p + between (reserved_delimiter_token from) (reserved_delimiter_token until) p >>| fun result -> String.concat @@ [ from ] @ result @ [ until ] in delimiters |> List.map ~f:fst |> List.map ~f:(between_nested_delims p) |> choice @@ -337,12 +397,25 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. let generate_everything_hole_parser ?priority_left_delimiter:left ?priority_right_delimiter:right + ?at_depth () = let delimiters = delimiters left right in - let reserved = List.concat_map delimiters ~f:(fun (from, until) -> [ from; until ]) in + let reserved = + List.concat_map delimiters ~f:(fun (from, until) -> + [ reserved_delimiter_token from; reserved_delimiter_token until ]) + in + let whitespace = + if Option.equal Int.equal (Some 0) at_depth then + many1 blank >>| String.of_char_list + else + spaces1 + in + let reserved_or_space = + choice [ Omega_parser_helper.skip (choice reserved); Omega_parser_helper.skip space1 ] + in let other = - not_followed_by (choice @@ List.map reserved ~f:string) *> any_char >>| String.of_char + not_followed_by reserved_or_space *> any_char >>| String.of_char in fix (fun grammar -> let delims_over_holes = between_nested_delims (many grammar) delimiters in @@ -352,7 +425,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. contents) ; escapable_string_literal_parser (fun ~contents ~left_delimiter:_ ~right_delimiter:_ -> contents) - ; spaces1 + ; whitespace ; delims_over_holes ; other ]) @@ -403,7 +476,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. | Error s -> if debug then Format.printf "Composing p with terminating parser, error %s@." s; p :: acc - | Ok (Hole { sort; identifier; dimension; _ }, user_state) -> + | Ok (Hole { sort; identifier; dimension; at_depth }, user_state) -> (match sort with | Regex -> let separator = @@ -466,7 +539,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. add_match user_state identifier hole_semantics :: acc | Line -> let allowed = - many (not_followed_by (string "\n" <|> string "\r\n") *> any_char) + many (not_followed_by (char '\n') *> any_char) >>| fun x -> [ String.of_char_list x ^ "\n" ] in let hole_semantics = allowed <* char '\n' >>| String.concat in @@ -513,6 +586,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. generate_everything_hole_parser ?priority_left_delimiter:left_delimiter ?priority_right_delimiter:right_delimiter + ?at_depth () | Escapable_string_literal -> let right_delimiter = Option.value_exn right_delimiter in @@ -539,7 +613,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. (* XXX change ignore to unit once everything works. right now it's the string that was parsed by spaces1 *) let generate_spaces_parser _ignored = - (* XXX still some parts ignored in the choice case in Alpha *) + (* XXX still some parts ignored in the choice case *) if debug then Format.printf "Template_spaces(%s)@." _ignored; many1 @@ choice [ comment_parser; spaces1 ] >>= fun result -> r acc (Template_string (String.concat result)) @@ -548,9 +622,16 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. let generate_string_token_parser str = if debug then Format.printf "Template_string(%s)@." str; many comment_parser - >>= fun s1 -> string str >>= fun result -> r acc (Template_string (String.concat s1 ^ result)) + >>= fun s1 -> + let token = + if is_reserved_word_delimiter str then + reserved_delimiter_token str + else + substring_checked_token str + in + token >>= fun result -> r acc (Template_string (String.concat s1 ^ result)) - let hole_parser sort dimension : (production * 'a) t t = + let hole_parser ?at_depth sort dimension : (production * 'a) t t = let hole_parser = (* This must be fold, can't be find *) let open Polymorphic_compare in @@ -565,7 +646,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. | l -> choice l >>| (function - | identifier -> skip_signal { sort; identifier; dimension; at_depth = None }) + | identifier -> skip_signal { sort; identifier; dimension; at_depth }) let generate_hole_for_literal dimension ~contents ~left_delimiter ~right_delimiter () = let literal_holes = @@ -630,8 +711,16 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. >>| generate_string_token_parser in let code_holes = + let at_depth = + if !configuration_ref.match_newline_toplevel then + None + else ( + match Language.Info.name with + | "HTML" | "XML" | "Text" | "LaTeX" -> None + | _ -> Some 0) + in Template.Matching.hole_parsers - |> List.map ~f:(fun (sort, _) -> hole_parser sort Code) + |> List.map ~f:(fun (sort, _) -> hole_parser ?at_depth sort Code) |> choice in let strict = Option.(value ~default:false (rule >>| Rule.is_strict)) in @@ -643,15 +732,19 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. @@ List.map Language.Syntax.user_defined_delimiters ~f:(fun (left_delimiter, right_delimiter) -> - string left_delimiter *> generator - <* string right_delimiter + reserved_delimiter_token ~check_boundaries:false left_delimiter *> generator + <* reserved_delimiter_token ~check_boundaries:false right_delimiter >>= fun (g : (production * 'a) t list) -> if debug then Format.printf "G size: %d; delim %s@." (List.length g) left_delimiter; return @@ sequence_chain' - @@ [ (string left_delimiter >>= fun result -> r acc (Template_string result)) ] + @@ [ (reserved_delimiter_token left_delimiter + >>= fun result -> r acc (Template_string result)) + ] @ (if strict then g else loose_whitespace g) - @ [ (string right_delimiter >>= fun result -> r acc (Template_string result)) ]) + @ [ (reserved_delimiter_token right_delimiter + >>= fun result -> r acc (Template_string result)) + ]) in many @@ choice @@ -722,8 +815,8 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. in (if String.length value = 0 then advance 1 - else - return ()) + else + return ()) >>= fun () -> if debug then Format.printf "Calculated end_pos %d@." end_pos; if !implicit_equals_match_satisfied then record_match_context start_pos end_pos rule; @@ -736,8 +829,7 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. let prefix = prefix >>= fun s -> r acc (String s) in let first_match_attempt = choice [ match_one; prefix ] in (* consumes a character in prefix if no match *) - let matches = many first_match_attempt *> end_of_input in - matches >>= fun _result -> r acc Unit) + skip_many first_match_attempt *> end_of_input >>= fun () -> r acc Unit) let to_template template rule = match parse_string ~consume:All (general_parser_generator rule) template with @@ -920,3 +1012,158 @@ module Make (Language : Types.Language.S) (Meta : Metasyntax.S) (Ext : External. include Matcher end + +open Languages + +let create + ?(metasyntax = Metasyntax.default_metasyntax) + ?(external_handler = External.default_external) + Types.Language.Syntax. + { user_defined_delimiters; escapable_string_literals; raw_string_literals; comments } + = + let module Info = struct + let name = "User_defined_language" + let extensions = [] + end + in + let module Syntax = struct + let user_defined_delimiters = user_defined_delimiters + let escapable_string_literals = escapable_string_literals + let raw_string_literals = raw_string_literals + let comments = comments + end + in + let module User_language = struct + module Info = Info + module Syntax = Syntax + end + in + let (module Metasyntax : Metasyntax.S) = Metasyntax.(create metasyntax) in + let module External = struct + let handler = external_handler + end + in + (module Make (User_language) (Metasyntax) (External) : Types.Matcher.S) + +module Text = Make (Text) (Metasyntax.Default) (External.Default) +module Paren = Make (Paren) (Metasyntax.Default) (External.Default) +module Dyck = Make (Dyck) (Metasyntax.Default) (External.Default) +module JSON = Make (JSON) (Metasyntax.Default) (External.Default) +module JSONC = Make (JSONC) (Metasyntax.Default) (External.Default) +module GraphQL = Make (GraphQL) (Metasyntax.Default) (External.Default) +module Dhall = Make (Dhall) (Metasyntax.Default) (External.Default) +module Latex = Make (Latex) (Metasyntax.Default) (External.Default) +module Assembly = Make (Assembly) (Metasyntax.Default) (External.Default) +module Clojure = Make (Clojure) (Metasyntax.Default) (External.Default) +module Lisp = Make (Lisp) (Metasyntax.Default) (External.Default) +module Generic = Make (Generic) (Metasyntax.Default) (External.Default) +module Bash = Make (Bash) (Metasyntax.Default) (External.Default) +module Ruby = Make (Ruby) (Metasyntax.Default) (External.Default) +module Elixir = Make (Elixir) (Metasyntax.Default) (External.Default) +module Python = Make (Python) (Metasyntax.Default) (External.Default) +module Html = Make (Html) (Metasyntax.Default) (External.Default) +module Xml = Make (Xml) (Metasyntax.Default) (External.Default) +module SQL = Make (SQL) (Metasyntax.Default) (External.Default) +module Erlang = Make (Erlang) (Metasyntax.Default) (External.Default) +module C = Make (C) (Metasyntax.Default) (External.Default) +module Csharp = Make (Csharp) (Metasyntax.Default) (External.Default) +module Java = Make (Java) (Metasyntax.Default) (External.Default) +module CSS = Make (CSS) (Metasyntax.Default) (External.Default) +module Kotlin = Make (Kotlin) (Metasyntax.Default) (External.Default) +module Scala = Make (Scala) (Metasyntax.Default) (External.Default) +module Nim = Make (Nim) (Metasyntax.Default) (External.Default) +module Matlab = Make (Matlab) (Metasyntax.Default) (External.Default) +module Dart = Make (Dart) (Metasyntax.Default) (External.Default) +module Php = Make (Php) (Metasyntax.Default) (External.Default) +module Go = Make (Go) (Metasyntax.Default) (External.Default) +module Javascript = Make (Javascript) (Metasyntax.Default) (External.Default) +module Jsx = Make (Jsx) (Metasyntax.Default) (External.Default) +module Typescript = Make (Typescript) (Metasyntax.Default) (External.Default) +module Tsx = Make (Tsx) (Metasyntax.Default) (External.Default) +module Swift = Make (Swift) (Metasyntax.Default) (External.Default) +module Rust = Make (Rust) (Metasyntax.Default) (External.Default) +module R = Make (R) (Metasyntax.Default) (External.Default) +module OCaml = Make (OCaml) (Metasyntax.Default) (External.Default) +module Reason = Make (Reason) (Metasyntax.Default) (External.Default) +module Fsharp = Make (Fsharp) (Metasyntax.Default) (External.Default) +module Pascal = Make (Pascal) (Metasyntax.Default) (External.Default) +module Julia = Make (Julia) (Metasyntax.Default) (External.Default) +module Fortran = Make (Fortran) (Metasyntax.Default) (External.Default) +module Haskell = Make (Haskell) (Metasyntax.Default) (External.Default) +module HCL = Make (HCL) (Metasyntax.Default) (External.Default) +module Elm = Make (Elm) (Metasyntax.Default) (External.Default) +module Zig = Make (Zig) (Metasyntax.Default) (External.Default) +module Coq = Make (Coq) (Metasyntax.Default) (External.Default) +module Move = Make (Move) (Metasyntax.Default) (External.Default) +module Solidity = Make (Solidity) (Metasyntax.Default) (External.Default) +module C_nested_comments = Make (C_nested_comments) (Metasyntax.Default) (External.Default) + +let all : (module Types.Matcher.S) list = + [ (module Assembly) + ; (module Bash) + ; (module C) + ; (module Csharp) + ; (module CSS) + ; (module Dart) + ; (module Dyck) + ; (module Clojure) + ; (module Coq) + ; (module Elm) + ; (module Erlang) + ; (module Elixir) + ; (module Fortran) + ; (module Fsharp) + ; (module Go) + ; (module Html) + ; (module Haskell) + ; (module HCL) + ; (module Java) + ; (module Javascript) + ; (module Jsx) + ; (module JSON) + ; (module JSONC) + ; (module GraphQL) + ; (module Dhall) + ; (module Julia) + ; (module Kotlin) + ; (module Latex) + ; (module Lisp) + ; (module Move) + ; (module Nim) + ; (module Matlab) + ; (module OCaml) + ; (module Paren) + ; (module Pascal) + ; (module Php) + ; (module Python) + ; (module Reason) + ; (module R) + ; (module Ruby) + ; (module Rust) + ; (module Scala) + ; (module Solidity) + ; (module SQL) + ; (module Swift) + ; (module Text) + ; (module Typescript) + ; (module Tsx) + ; (module Xml) + ; (module Zig) + ; (module Generic) + ] + +let select_with_extension + ?(metasyntax = Metasyntax.default_metasyntax) + ?(external_handler = External.default_external) + extension + : (module Types.Matcher.S) option + = + let open Option in + Languages.select_with_extension extension + >>| fun (module Language : Types.Language.S) -> + let (module Metasyntax) = Metasyntax.(create metasyntax) in + let module External = struct + let handler = external_handler + end + in + (module Make (Language) (Metasyntax) (External) : Types.Matcher.S) diff --git a/lib/kernel/matchers/matcher_engine.mli b/lib/kernel/matchers/matcher_engine.mli new file mode 100644 index 00000000..44f94f41 --- /dev/null +++ b/lib/kernel/matchers/matcher_engine.mli @@ -0,0 +1,69 @@ +open Types + +module Make (_ : Language.S) (_ : Metasyntax.S) (_ : External.S) : Matcher.S +module Text : Matcher.S +module Paren : Matcher.S +module Dyck : Matcher.S +module JSON : Matcher.S +module JSONC : Matcher.S +module GraphQL : Matcher.S +module Dhall : Matcher.S +module Latex : Matcher.S +module Assembly : Matcher.S +module Clojure : Matcher.S +module Lisp : Matcher.S +module Generic : Matcher.S +module Bash : Matcher.S +module Ruby : Matcher.S +module Elixir : Matcher.S +module Python : Matcher.S +module Html : Matcher.S +module Xml : Matcher.S +module SQL : Matcher.S +module Erlang : Matcher.S +module C : Matcher.S +module Csharp : Matcher.S +module Java : Matcher.S +module CSS : Matcher.S +module Kotlin : Matcher.S +module Scala : Matcher.S +module Nim : Matcher.S +module Matlab : Matcher.S +module Dart : Matcher.S +module Php : Matcher.S +module Go : Matcher.S +module Javascript : Matcher.S +module Jsx : Matcher.S +module Typescript : Matcher.S +module Tsx : Matcher.S +module Swift : Matcher.S +module Rust : Matcher.S +module R : Matcher.S +module OCaml : Matcher.S +module Reason : Matcher.S +module Fsharp : Matcher.S +module Pascal : Matcher.S +module Julia : Matcher.S +module Fortran : Matcher.S +module Haskell : Matcher.S +module HCL : Matcher.S +module Elm : Matcher.S +module Zig : Matcher.S +module Coq : Matcher.S +module Move : Matcher.S +module Solidity : Matcher.S +module C_nested_comments : Matcher.S + +val all : (module Matcher.S) list + +val select_with_extension + : ?metasyntax:Metasyntax.t + -> ?external_handler:External.t + -> string + -> (module Matcher.S) option + +val create + : ?metasyntax:Metasyntax.t + -> ?external_handler:External.t + -> Language.Syntax.t + -> (module Matcher.S) diff --git a/lib/kernel/matchers/matchers.ml b/lib/kernel/matchers/matchers.ml index af71a0d9..a35125e3 100644 --- a/lib/kernel/matchers/matchers.ml +++ b/lib/kernel/matchers/matchers.ml @@ -10,9 +10,8 @@ module Ast = struct end module Evaluate = Evaluate -module Alpha = Engine.Make (Alpha.Make) -module Omega = Engine.Make (Omega.Make) -module Engine = Types.Engine +module Matcher_engine = Matcher_engine +include Matcher_engine module Matcher = Types.Matcher module Hole = Types.Hole module Language = Types.Language diff --git a/lib/kernel/matchers/matchers.mli b/lib/kernel/matchers/matchers.mli index cc9aeb69..3d1cde6a 100644 --- a/lib/kernel/matchers/matchers.mli +++ b/lib/kernel/matchers/matchers.mli @@ -7,9 +7,8 @@ module Rule = Rule (* Only need to expose Types.Ast. module type of to export sexp. *) module Ast : module type of Types.Ast module Evaluate = Evaluate -module Alpha : Types.Engine.S -module Omega : Types.Engine.S -module Engine = Types.Engine +module Matcher_engine : module type of Matcher_engine +include module type of Matcher_engine module Matcher = Types.Matcher module Hole = Types.Hole module Language = Types.Language diff --git a/lib/kernel/matchers/omega.mli b/lib/kernel/matchers/omega.mli deleted file mode 100644 index 6be01201..00000000 --- a/lib/kernel/matchers/omega.mli +++ /dev/null @@ -1,2 +0,0 @@ -open Types -module Make (_ : Language.S) (_ : Metasyntax.S) (_ : External.S) : Matcher.S diff --git a/lib/kernel/matchers/regexp.ml b/lib/kernel/matchers/regexp.ml index c9b95ffe..138c479e 100644 --- a/lib/kernel/matchers/regexp.ml +++ b/lib/kernel/matchers/regexp.ml @@ -23,7 +23,6 @@ type t = (* I think I should just implement the analog of string_ for regex with some bounded buffer size. *) module Make (Regexp : Regexp_engine_intf) = struct - (* https://sourcegraph.com/github.com/comby-tools/mparser/-/blob/src/mParser_Char_Stream.ml#L231:8 *) let match_regexp s pos rex = Regexp.exec ~rex ~pos:(pos - s.buffer_pos) s.buffer let make_regexp pat = Regexp.make pat diff --git a/lib/kernel/matchers/regexp.mli b/lib/kernel/matchers/regexp.mli index 879e264b..10aaae7d 100644 --- a/lib/kernel/matchers/regexp.mli +++ b/lib/kernel/matchers/regexp.mli @@ -8,10 +8,7 @@ module type Regexp_engine_intf = sig val exec : rex:t -> pos:int -> Bytes.t -> substrings option end -(** Represents character stream right now. - Compare char stream interface on t and match_regexp descriptions - in https://sourcegraph.com/github.com/comby-tools/mparser/-/blob/src/mParser_Char_Stream.mli#L102:8 -*) +(** Represents character stream right now. *) type t module Make (Regexp : Regexp_engine_intf) : sig diff --git a/lib/kernel/matchers/rewrite.ml b/lib/kernel/matchers/rewrite.ml index 4b12fd07..49b2efdd 100644 --- a/lib/kernel/matchers/rewrite.ml +++ b/lib/kernel/matchers/rewrite.ml @@ -117,18 +117,24 @@ let substitute_matches (matches : Match.t list) source replacements = "Matches: %d | Replacements: %d@." (List.length matches) (List.length replacements); - let rewritten_source, in_place_substitutions, _ = + let buf = Buffer.create (String.length source) in + let add_source_slice start finish = + if finish > start then + Buffer.add_substring buf source ~pos:start ~len:(finish - start) + in + let in_place_substitutions, _, cursor = (* shift adjusts the difference of the matched part and the replacement part to the matched offsets *) List.fold2_exn matches replacements - ~init:(source, [], 0) - ~f:(fun (rolling_result, replacements, shift) { range; _ } ({ replacement_content; _ } as r) - -> + ~init:([], 0, 0) + ~f:(fun (replacements, shift, cursor) { range; _ } ({ replacement_content; _ } as r) -> + let original_start_index = range.match_start.offset in + let original_end_index = range.match_end.offset in let start_index = range.match_start.offset + shift in let end_index = range.match_end.offset + shift in - let before = if start_index = 0 then "" else String.slice rolling_result 0 start_index in - let after = String.slice rolling_result end_index (String.length rolling_result) in + add_source_slice cursor original_start_index; + Buffer.add_string buf replacement_content; let match_length = end_index - start_index in let difference = String.length replacement_content - match_length in let range = @@ -138,8 +144,10 @@ let substitute_matches (matches : Match.t list) source replacements = } in let replacements = { r with range } :: replacements in - String.concat [ before; replacement_content; after ], replacements, shift + difference) + replacements, shift + difference, original_end_index) in + add_source_slice cursor (String.length source); + let rewritten_source = Buffer.contents buf in { rewritten_source; in_place_substitutions } (* FIXME: all the functors help nothing if we end up calling this without parameterizing by metasyntax, etc. *) diff --git a/lib/kernel/matchers/types.ml b/lib/kernel/matchers/types.ml index 5c96cfd5..2ee0b36f 100644 --- a/lib/kernel/matchers/types.ml +++ b/lib/kernel/matchers/types.ml @@ -224,75 +224,3 @@ module Matcher = struct val set_rewrite_template : string -> unit end end - -module Engine = struct - module type S = sig - module Make (_ : Language.S) (_ : Metasyntax.S) (_ : External.S) : Matcher.S - module Text : Matcher.S - module Paren : Matcher.S - module Dyck : Matcher.S - module JSON : Matcher.S - module JSONC : Matcher.S - module GraphQL : Matcher.S - module Dhall : Matcher.S - module Latex : Matcher.S - module Assembly : Matcher.S - module Clojure : Matcher.S - module Lisp : Matcher.S - module Generic : Matcher.S - module Bash : Matcher.S - module Ruby : Matcher.S - module Elixir : Matcher.S - module Python : Matcher.S - module Html : Matcher.S - module Xml : Matcher.S - module SQL : Matcher.S - module Erlang : Matcher.S - module C : Matcher.S - module Csharp : Matcher.S - module Java : Matcher.S - module CSS : Matcher.S - module Kotlin : Matcher.S - module Scala : Matcher.S - module Nim : Matcher.S - module Matlab : Matcher.S - module Dart : Matcher.S - module Php : Matcher.S - module Go : Matcher.S - module Javascript : Matcher.S - module Jsx : Matcher.S - module Typescript : Matcher.S - module Tsx : Matcher.S - module Swift : Matcher.S - module Rust : Matcher.S - module R : Matcher.S - module OCaml : Matcher.S - module Reason : Matcher.S - module Fsharp : Matcher.S - module Pascal : Matcher.S - module Julia : Matcher.S - module Fortran : Matcher.S - module Haskell : Matcher.S - module HCL : Matcher.S - module Elm : Matcher.S - module Zig : Matcher.S - module Coq : Matcher.S - module Move : Matcher.S - module Solidity : Matcher.S - module C_nested_comments : Matcher.S - - val all : (module Matcher.S) list - - val select_with_extension - : ?metasyntax:Metasyntax.t - -> ?external_handler:External.t - -> string - -> (module Matcher.S) option - - val create - : ?metasyntax:Metasyntax.t - -> ?external_handler:External.t - -> Language.Syntax.t - -> (module Matcher.S) - end -end diff --git a/lib/kernel/parsers/alpha_comments.ml b/lib/kernel/parsers/alpha_comments.ml deleted file mode 100644 index 07409484..00000000 --- a/lib/kernel/parsers/alpha_comments.ml +++ /dev/null @@ -1,86 +0,0 @@ -open Core_kernel -open MParser - -let to_string from until between : string = from ^ String.of_char_list between ^ until - -let anything_including_newlines ~until = - many (not_followed_by (string until) "" >>= fun () -> any_char_or_nl) - -let anything_excluding_newlines ~until = - many (not_followed_by (string until) "" >>= fun () -> any_char) - -(** a parser for comments with delimiters [from] and [until] that do not nest *) -let non_nested_comment from until s = - (between (string from) (string until) (anything_including_newlines ~until) - |>> to_string from until) - s - -let until_newline start s = - (string start - >> anything_excluding_newlines ~until:"\n" - |>> fun l -> start ^ String.of_char_list l) - s - -let any_newline comment_string s = - (string comment_string - >> anything_excluding_newlines ~until:"\n" - |>> fun l -> comment_string ^ String.of_char_list l) - s - -let is_not p s = - if is_ok (p s) then - Empty_failed (unknown_error s) - else ( - match read_char s with - | Some c -> Consumed_ok (c, advance_state s 1, No_error) - | None -> Empty_failed (unknown_error s)) - -(** A nested comment parser *) -let nested_comment from until s = - let reserved = skip (string from <|> string until) in - let rec grammar s = - (comment_delimiters - >>= (fun string -> return string) - <|> (is_not reserved >>= fun c -> return (Char.to_string c))) - s - and comment_delimiters s = - (between - (string from) - (string until) - (many grammar >>= fun result -> return (String.concat result))) - s - in - (comment_delimiters |>> fun content -> from ^ content ^ until) s - -(** a parser for, e.g., /* ... */ style block comments. Non-nested. *) -module Multiline = struct - module type S = sig - val left : string - val right : string - end - - module Make (M : S) = struct - let comment s = non_nested_comment M.left M.right s - end -end - -module Until_newline = struct - module type S = sig - val start : string - end - - module Make (M : S) = struct - let comment s = until_newline M.start s - end -end - -module Nested_multiline = struct - module type S = sig - val left : string - val right : string - end - - module Make (M : S) = struct - let comment s = nested_comment M.left M.right s - end -end diff --git a/lib/kernel/parsers/alpha_string_literals.ml b/lib/kernel/parsers/alpha_string_literals.ml deleted file mode 100644 index 5fa4c722..00000000 --- a/lib/kernel/parsers/alpha_string_literals.ml +++ /dev/null @@ -1,55 +0,0 @@ -open Core_kernel -open MParser - -(** Assumes the left and right delimiter are the same, and that these can be - escaped. Does not parse a string body containing newlines (as usual when - escaping with \n) *) -module Escapable = struct - module type S = sig - val delimiter : string - val escape : char - end - - module Make (M : S) = struct - (* delimiters can be escaped and parsing continues within the string body *) - let escaped_char_s s = any_char s - - let char_token_s s = - (char M.escape - >> escaped_char_s - >>= (fun c -> return (Format.sprintf {|%c%c|} M.escape c)) - <|> (any_char |>> String.of_char)) - s - - let base_string_literal s = - (string M.delimiter - >> many_until char_token_s (string M.delimiter) - |>> String.concat - >>= fun result -> return (Format.sprintf {|%s%s%s|} M.delimiter result M.delimiter)) - s - end -end - -(** Quoted or raw strings. Allows different left and right delimiters, and - disallows any sort of escaping. Does not support raw strings with identifiers - yet, e.g., {blah||blah} (OCaml) or delim``delim - syntax (Go) *) -module Raw = struct - module type S = sig - val left_delimiter : string - val right_delimiter : string - end - - module Make (M : S) = struct - let char_token_s s = (any_char_or_nl |>> String.of_char) s - - let base_string_literal s = - (string M.left_delimiter - >> many_until char_token_s (string M.right_delimiter) - |>> String.concat - "raw string literal body" - >>= fun result -> return (Format.sprintf {|%s%s%s|} M.left_delimiter result M.right_delimiter) - ) - s - end -end diff --git a/lib/kernel/parsers/comments.ml b/lib/kernel/parsers/comments.ml index 6aa03dc0..0a844a33 100644 --- a/lib/kernel/parsers/comments.ml +++ b/lib/kernel/parsers/comments.ml @@ -1,2 +1 @@ module Omega = Omega_comments -module Alpha = Alpha_comments diff --git a/lib/kernel/parsers/dune b/lib/kernel/parsers/dune index 0cc1fa5d..b3affc14 100644 --- a/lib/kernel/parsers/dune +++ b/lib/kernel/parsers/dune @@ -5,4 +5,4 @@ (backend bisect_ppx)) (preprocess (pps ppx_sexp_conv)) - (libraries core_kernel comby-kernel.vangstrom mparser)) + (libraries core_kernel comby-kernel.vangstrom)) diff --git a/lib/kernel/parsers/omega_comments.ml b/lib/kernel/parsers/omega_comments.ml index a8fd5f30..0107dc40 100644 --- a/lib/kernel/parsers/omega_comments.ml +++ b/lib/kernel/parsers/omega_comments.ml @@ -26,6 +26,22 @@ let anything_excluding_newlines () = anything_including_newlines ~until:"\n" let non_nested_comment from until = between (string from) (string until) (anything_including_newlines ~until) |>> to_string from until +let nested_comment from until = + let reserved = choice [ string from *> return (); string until *> return () ] in + let grammar = + fix (fun grammar -> + let comment_delimiters = + between + (string from) + (string until) + (many grammar >>| fun result -> String.concat result) + in + let other = not_followed_by reserved *> any_char >>| Char.to_string in + choice [ comment_delimiters; other ]) + in + between (string from) (string until) (many grammar >>| fun result -> String.concat result) + >>| fun content -> from ^ content ^ until + module Multiline = struct module type S = sig val left : string @@ -51,3 +67,14 @@ module Until_newline = struct let comment = until_newline M.start end end + +module Nested_multiline = struct + module type S = sig + val left : string + val right : string + end + + module Make (M : S) = struct + let comment = nested_comment M.left M.right + end +end diff --git a/lib/kernel/parsers/string_literals.ml b/lib/kernel/parsers/string_literals.ml index 375273dd..c1487551 100644 --- a/lib/kernel/parsers/string_literals.ml +++ b/lib/kernel/parsers/string_literals.ml @@ -1,2 +1 @@ -module Alpha = Alpha_string_literals module Omega = Omega_string_literals diff --git a/lib/kernel/vendored/vangstrom/lib/vangstrom.ml b/lib/kernel/vendored/vangstrom/lib/vangstrom.ml index 0430e6a6..0ad84024 100644 --- a/lib/kernel/vendored/vangstrom/lib/vangstrom.ml +++ b/lib/kernel/vendored/vangstrom/lib/vangstrom.ml @@ -531,7 +531,10 @@ let sep_by s p = let skip_many p = fix (fun m -> - (p *> m) <|> return ()) + ((p >>| fun _ -> true) <|> return false) >>= function + | true -> m + | false -> return () + ) let skip_many1 p = p *> skip_many p diff --git a/scripts/install-with-licenses.sh b/scripts/install-with-licenses.sh index 4aa6bb69..5c55fd67 100755 --- a/scripts/install-with-licenses.sh +++ b/scripts/install-with-licenses.sh @@ -1613,545 +1613,7 @@ echo "${GREEN}------------------------------------------------------------${NORM # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -# -# LICENSE FOR mparser: -# -# This library is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser General Public License (LGPL) as -# published by the Free Software Foundation; either version 2.1 of the -# License (see below), or (at your option) any later version. -# -# As a special exception to the GNU Lesser General Public License, you -# may link, statically or dynamically, a "work that uses the Library" -# with a publicly distributed version of the Library to produce an -# executable file containing portions of the Library, and distribute -# that executable file under terms of your choice, without any of the -# additional requirements listed in clause 6 of the GNU Lesser General -# Public License. By "a publicly distributed version of the Library", we -# mean either the unmodified Library as distributed, or a modified -# version of the Library that is distributed under the conditions -# defined in clause 2 of the GNU Lesser General Public License. This -# exception does not however invalidate any other reasons why the -# executable file might be covered by the GNU Lesser General Public -# License. -# -# This library 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. -# -# ====================================================================== -# -# -# GNU LESSER GENERAL PUBLIC LICENSE -# Version 2.1, February 1999 -# -# Copyright (C) 1991, 1999 Free Software Foundation, Inc. -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# Everyone is permitted to copy and distribute verbatim copies -# of this license document, but changing it is not allowed. -# -# [This is the first released version of the Lesser GPL. It also counts -# as the successor of the GNU Library Public License, version 2, hence -# the version number 2.1.] -# -# Preamble -# -# The licenses for most software are designed to take away your -# freedom to share and change it. By contrast, the GNU General Public -# Licenses are intended to guarantee your freedom to share and change -# free software--to make sure the software is free for all its users. -# -# This license, the Lesser General Public License, applies to some -# specially designated software packages--typically libraries--of the -# Free Software Foundation and other authors who decide to use it. You -# can use it too, but we suggest you first think carefully about whether -# this license or the ordinary General Public License is the better -# strategy to use in any particular case, based on the explanations below. -# -# When we speak of free software, we are referring to freedom of use, -# 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 this service if you wish); that you receive source code or can get -# it if you want it; that you can change the software and use pieces of -# it in new free programs; and that you are informed that you can do -# these things. -# -# To protect your rights, we need to make restrictions that forbid -# distributors to deny you these rights or to ask you to surrender these -# rights. These restrictions translate to certain responsibilities for -# you if you distribute copies of the library or if you modify it. -# -# For example, if you distribute copies of the library, whether gratis -# or for a fee, you must give the recipients all the rights that we gave -# you. You must make sure that they, too, receive or can get the source -# code. If you link other code with the library, you must provide -# complete object files to the recipients, so that they can relink them -# with the library after making changes to the library and recompiling -# it. And you must show them these terms so they know their rights. -# -# We protect your rights with a two-step method: (1) we copyright the -# library, and (2) we offer you this license, which gives you legal -# permission to copy, distribute and/or modify the library. -# -# To protect each distributor, we want to make it very clear that -# there is no warranty for the free library. Also, if the library is -# modified by someone else and passed on, the recipients should know -# that what they have is not the original version, so that the original -# author's reputation will not be affected by problems that might be -# introduced by others. -# -# Finally, software patents pose a constant threat to the existence of -# any free program. We wish to make sure that a company cannot -# effectively restrict the users of a free program by obtaining a -# restrictive license from a patent holder. Therefore, we insist that -# any patent license obtained for a version of the library must be -# consistent with the full freedom of use specified in this license. -# -# Most GNU software, including some libraries, is covered by the -# ordinary GNU General Public License. This license, the GNU Lesser -# General Public License, applies to certain designated libraries, and -# is quite different from the ordinary General Public License. We use -# this license for certain libraries in order to permit linking those -# libraries into non-free programs. -# -# When a program is linked with a library, whether statically or using -# a shared library, the combination of the two is legally speaking a -# combined work, a derivative of the original library. The ordinary -# General Public License therefore permits such linking only if the -# entire combination fits its criteria of freedom. The Lesser General -# Public License permits more lax criteria for linking other code with -# the library. -# -# We call this license the "Lesser" General Public License because it -# does Less to protect the user's freedom than the ordinary General -# Public License. It also provides other free software developers Less -# of an advantage over competing non-free programs. These disadvantages -# are the reason we use the ordinary General Public License for many -# libraries. However, the Lesser license provides advantages in certain -# special circumstances. -# -# For example, on rare occasions, there may be a special need to -# encourage the widest possible use of a certain library, so that it becomes -# a de-facto standard. To achieve this, non-free programs must be -# allowed to use the library. A more frequent case is that a free -# library does the same job as widely used non-free libraries. In this -# case, there is little to gain by limiting the free library to free -# software only, so we use the Lesser General Public License. -# -# In other cases, permission to use a particular library in non-free -# programs enables a greater number of people to use a large body of -# free software. For example, permission to use the GNU C Library in -# non-free programs enables many more people to use the whole GNU -# operating system, as well as its variant, the GNU/Linux operating -# system. -# -# Although the Lesser General Public License is Less protective of the -# users' freedom, it does ensure that the user of a program that is -# linked with the Library has the freedom and the wherewithal to run -# that program using a modified version of the Library. -# -# The precise terms and conditions for copying, distribution and -# modification follow. Pay close attention to the difference between a -# "work based on the library" and a "work that uses the library". The -# former contains code derived from the library, whereas the latter must -# be combined with the library in order to run. -# -# GNU LESSER GENERAL PUBLIC LICENSE -# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION -# -# 0. This License Agreement applies to any software library or other -# program which contains a notice placed by the copyright holder or -# other authorized party saying it may be distributed under the terms of -# this Lesser General Public License (also called "this License"). -# Each licensee is addressed as "you". -# -# A "library" means a collection of software functions and/or data -# prepared so as to be conveniently linked with application programs -# (which use some of those functions and data) to form executables. -# -# The "Library", below, refers to any such software library or work -# which has been distributed under these terms. A "work based on the -# Library" means either the Library or any derivative work under -# copyright law: that is to say, a work containing the Library or a -# portion of it, either verbatim or with modifications and/or translated -# straightforwardly into another language. (Hereinafter, translation is -# included without limitation in the term "modification".) -# -# "Source code" for a work means the preferred form of the work for -# making modifications to it. For a library, complete source code means -# all the source code for all modules it contains, plus any associated -# interface definition files, plus the scripts used to control compilation -# and installation of the library. -# -# Activities other than copying, distribution and modification are not -# covered by this License; they are outside its scope. The act of -# running a program using the Library is not restricted, and output from -# such a program is covered only if its contents constitute a work based -# on the Library (independent of the use of the Library in a tool for -# writing it). Whether that is true depends on what the Library does -# and what the program that uses the Library does. -# -# 1. You may copy and distribute verbatim copies of the Library's -# complete source code as you receive it, in any medium, provided that -# you conspicuously and appropriately publish on each copy an -# appropriate copyright notice and disclaimer of warranty; keep intact -# all the notices that refer to this License and to the absence of any -# warranty; and distribute a copy of this License along with the -# Library. -# -# You may charge a fee for the physical act of transferring a copy, -# and you may at your option offer warranty protection in exchange for a -# fee. -# -# 2. You may modify your copy or copies of the Library or any portion -# of it, thus forming a work based on the Library, and copy and -# distribute such modifications or work under the terms of Section 1 -# above, provided that you also meet all of these conditions: -# -# a) The modified work must itself be a software library. -# -# b) You must cause the files modified to carry prominent notices -# stating that you changed the files and the date of any change. -# -# c) You must cause the whole of the work to be licensed at no -# charge to all third parties under the terms of this License. -# -# d) If a facility in the modified Library refers to a function or a -# table of data to be supplied by an application program that uses -# the facility, other than as an argument passed when the facility -# is invoked, then you must make a good faith effort to ensure that, -# in the event an application does not supply such function or -# table, the facility still operates, and performs whatever part of -# its purpose remains meaningful. -# -# (For example, a function in a library to compute square roots has -# a purpose that is entirely well-defined independent of the -# application. Therefore, Subsection 2d requires that any -# application-supplied function or table used by this function must -# be optional: if the application does not supply it, the square -# root function must still compute square roots.) -# -# These requirements apply to the modified work as a whole. If -# identifiable sections of that work are not derived from the Library, -# and can be reasonably considered independent and separate works in -# themselves, then this License, and its terms, do not apply to those -# sections when you distribute them as separate works. But when you -# distribute the same sections as part of a whole which is a work based -# on the Library, the distribution of the whole must be on the terms of -# this License, whose permissions for other licensees extend to the -# entire whole, and thus to each and every part regardless of who wrote -# it. -# -# Thus, it is not the intent of this section to claim rights or contest -# your rights to work written entirely by you; rather, the intent is to -# exercise the right to control the distribution of derivative or -# collective works based on the Library. -# -# In addition, mere aggregation of another work not based on the Library -# with the Library (or with a work based on the Library) on a volume of -# a storage or distribution medium does not bring the other work under -# the scope of this License. -# -# 3. You may opt to apply the terms of the ordinary GNU General Public -# License instead of this License to a given copy of the Library. To do -# this, you must alter all the notices that refer to this License, so -# that they refer to the ordinary GNU General Public License, version 2, -# instead of to this License. (If a newer version than version 2 of the -# ordinary GNU General Public License has appeared, then you can specify -# that version instead if you wish.) Do not make any other change in -# these notices. -# -# Once this change is made in a given copy, it is irreversible for -# that copy, so the ordinary GNU General Public License applies to all -# subsequent copies and derivative works made from that copy. -# -# This option is useful when you wish to copy part of the code of -# the Library into a program that is not a library. -# -# 4. You may copy and distribute the Library (or a portion or -# derivative of it, under Section 2) in object code or executable form -# under the terms of Sections 1 and 2 above provided that you accompany -# it with the complete corresponding machine-readable source code, which -# must be distributed under the terms of Sections 1 and 2 above on a -# medium customarily used for software interchange. -# -# If distribution of object code is made by offering access to copy -# from a designated place, then offering equivalent access to copy the -# source code from the same place satisfies the requirement to -# distribute the source code, even though third parties are not -# compelled to copy the source along with the object code. -# -# 5. A program that contains no derivative of any portion of the -# Library, but is designed to work with the Library by being compiled or -# linked with it, is called a "work that uses the Library". Such a -# work, in isolation, is not a derivative work of the Library, and -# therefore falls outside the scope of this License. -# -# However, linking a "work that uses the Library" with the Library -# creates an executable that is a derivative of the Library (because it -# contains portions of the Library), rather than a "work that uses the -# library". The executable is therefore covered by this License. -# Section 6 states terms for distribution of such executables. -# -# When a "work that uses the Library" uses material from a header file -# that is part of the Library, the object code for the work may be a -# derivative work of the Library even though the source code is not. -# Whether this is true is especially significant if the work can be -# linked without the Library, or if the work is itself a library. The -# threshold for this to be true is not precisely defined by law. -# -# If such an object file uses only numerical parameters, data -# structure layouts and accessors, and small macros and small inline -# functions (ten lines or less in length), then the use of the object -# file is unrestricted, regardless of whether it is legally a derivative -# work. (Executables containing this object code plus portions of the -# Library will still fall under Section 6.) -# -# Otherwise, if the work is a derivative of the Library, you may -# distribute the object code for the work under the terms of Section 6. -# Any executables containing that work also fall under Section 6, -# whether or not they are linked directly with the Library itself. -# -# 6. As an exception to the Sections above, you may also combine or -# link a "work that uses the Library" with the Library to produce a -# work containing portions of the Library, and distribute that work -# under terms of your choice, provided that the terms permit -# modification of the work for the customer's own use and reverse -# engineering for debugging such modifications. -# -# You must give prominent notice with each copy of the work that the -# Library is used in it and that the Library and its use are covered by -# this License. You must supply a copy of this License. If the work -# during execution displays copyright notices, you must include the -# copyright notice for the Library among them, as well as a reference -# directing the user to the copy of this License. Also, you must do one -# of these things: -# -# a) Accompany the work with the complete corresponding -# machine-readable source code for the Library including whatever -# changes were used in the work (which must be distributed under -# Sections 1 and 2 above); and, if the work is an executable linked -# with the Library, with the complete machine-readable "work that -# uses the Library", as object code and/or source code, so that the -# user can modify the Library and then relink to produce a modified -# executable containing the modified Library. (It is understood -# that the user who changes the contents of definitions files in the -# Library will not necessarily be able to recompile the application -# to use the modified definitions.) -# -# b) Use a suitable shared library mechanism for linking with the -# Library. A suitable mechanism is one that (1) uses at run time a -# copy of the library already present on the user's computer system, -# rather than copying library functions into the executable, and (2) -# will operate properly with a modified version of the library, if -# the user installs one, as long as the modified version is -# interface-compatible with the version that the work was made with. -# -# c) Accompany the work with a written offer, valid for at -# least three years, to give the same user the materials -# specified in Subsection 6a, above, for a charge no more -# than the cost of performing this distribution. -# -# d) If distribution of the work is made by offering access to copy -# from a designated place, offer equivalent access to copy the above -# specified materials from the same place. -# -# e) Verify that the user has already received a copy of these -# materials or that you have already sent this user a copy. -# -# For an executable, the required form of the "work that uses the -# Library" must include any data and utility programs needed for -# reproducing the executable from it. However, as a special exception, -# the materials to be distributed need not include anything that is -# normally distributed (in either source or binary form) with the major -# components (compiler, kernel, and so on) of the operating system on -# which the executable runs, unless that component itself accompanies -# the executable. -# -# It may happen that this requirement contradicts the license -# restrictions of other proprietary libraries that do not normally -# accompany the operating system. Such a contradiction means you cannot -# use both them and the Library together in an executable that you -# distribute. -# -# 7. You may place library facilities that are a work based on the -# Library side-by-side in a single library together with other library -# facilities not covered by this License, and distribute such a combined -# library, provided that the separate distribution of the work based on -# the Library and of the other library facilities is otherwise -# permitted, and provided that you do these two things: -# -# a) Accompany the combined library with a copy of the same work -# based on the Library, uncombined with any other library -# facilities. This must be distributed under the terms of the -# Sections above. -# -# b) Give prominent notice with the combined library of the fact -# that part of it is a work based on the Library, and explaining -# where to find the accompanying uncombined form of the same work. -# -# 8. You may not copy, modify, sublicense, link with, or distribute -# the Library except as expressly provided under this License. Any -# attempt otherwise to copy, modify, sublicense, link with, or -# distribute the Library is void, and will automatically terminate your -# rights under this License. However, parties who have received copies, -# or rights, from you under this License will not have their licenses -# terminated so long as such parties remain in full compliance. -# -# 9. You are not required to accept this License, since you have not -# signed it. However, nothing else grants you permission to modify or -# distribute the Library or its derivative works. These actions are -# prohibited by law if you do not accept this License. Therefore, by -# modifying or distributing the Library (or any work based on the -# Library), you indicate your acceptance of this License to do so, and -# all its terms and conditions for copying, distributing or modifying -# the Library or works based on it. -# -# 10. Each time you redistribute the Library (or any work based on the -# Library), the recipient automatically receives a license from the -# original licensor to copy, distribute, link with or modify the Library -# subject to these terms and conditions. You may not impose any further -# restrictions on the recipients' exercise of the rights granted herein. -# You are not responsible for enforcing compliance by third parties with -# this License. -# -# 11. If, as a consequence of a court judgment or allegation of patent -# infringement or for any other reason (not limited to patent issues), -# 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 -# distribute so as to satisfy simultaneously your obligations under this -# License and any other pertinent obligations, then as a consequence you -# may not distribute the Library at all. For example, if a patent -# license would not permit royalty-free redistribution of the Library by -# all those who receive copies directly or indirectly through you, then -# the only way you could satisfy both it and this License would be to -# refrain entirely from distribution of the Library. -# -# If any portion of this section is held invalid or unenforceable under any -# particular circumstance, the balance of the section is intended to apply, -# and the section as a whole is intended to apply in other circumstances. -# -# It is not the purpose of this section to induce you to infringe any -# patents or other property right claims or to contest validity of any -# such claims; this section has the sole purpose of protecting the -# integrity of the free software distribution system which is -# implemented by public license practices. Many people have made -# generous contributions to the wide range of software distributed -# through that system in reliance on consistent application of that -# system; it is up to the author/donor to decide if he or she is willing -# to distribute software through any other system and a licensee cannot -# impose that choice. -# -# This section is intended to make thoroughly clear what is believed to -# be a consequence of the rest of this License. -# -# 12. If the distribution and/or use of the Library is restricted in -# certain countries either by patents or by copyrighted interfaces, the -# original copyright holder who places the Library under this License may add -# an explicit geographical distribution limitation excluding those countries, -# so that distribution is permitted only in or among countries not thus -# excluded. In such case, this License incorporates the limitation as if -# written in the body of this License. -# -# 13. The Free Software Foundation may publish revised and/or new -# versions of the Lesser 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 Library -# specifies a version number of this License which applies to it and -# "any later version", you have the option of following the terms and -# conditions either of that version or of any later version published by -# the Free Software Foundation. If the Library does not specify a -# license version number, you may choose any version ever published by -# the Free Software Foundation. -# -# 14. If you wish to incorporate parts of the Library into other free -# programs whose distribution conditions are incompatible with these, -# write to the author to ask for permission. For software which is -# copyrighted by the Free Software Foundation, write to the Free -# Software Foundation; we sometimes make exceptions for this. Our -# decision will be guided by the two goals of preserving the free status -# of all derivatives of our free software and of promoting the sharing -# and reuse of software generally. -# -# NO WARRANTY -# -# 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -# WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -# EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -# OTHER PARTIES PROVIDE THE LIBRARY "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 -# LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -# THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. -# -# 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -# WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -# AND/OR REDISTRIBUTE THE LIBRARY 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 -# LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -# SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -# DAMAGES. -# -# END OF TERMS AND CONDITIONS -# -# -# ====================================================================== -# -# How to Apply These Terms to Your New Libraries -# -# If you develop a new library, and you want it to be of the greatest -# possible use to the public, we recommend making it free software that -# everyone can redistribute and change. You can do so by permitting -# redistribution under these terms (or, alternatively, under the terms -# of the ordinary General Public License). -# -# To apply these terms, attach the following notices to the library. -# It is safest to attach them to the start of each source file to most -# effectively convey the exclusion of warranty; and each file should -# have at least the "copyright" line and a pointer to where the full -# notice is found. -# -# -# -# Copyright (C) -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# -# Also add information on how to contact you by electronic and paper mail. -# -# You should also get your employer (if you work as a programmer) or -# your school, if any, to sign a "copyright disclaimer" for the library, -# if necessary. Here is a sample; alter the names: -# -# Yoyodyne, Inc., hereby disclaims all copyright interest in the -# library `Frob' (a library for tweaking knobs) written by James -# Random Hacker. -# -# , 1 April 1990 -# Ty Coon, President of Vice -# -# That's all there is to it! -# -# LICENSE FOR ocaml-ci-scripts: +# # LICENSE FOR ocaml-ci-scripts: # # ## ISC License # diff --git a/src/main.ml b/src/main.ml index bb0041e9..5189660a 100644 --- a/src/main.ml +++ b/src/main.ml @@ -21,15 +21,9 @@ let paths_with_file_size paths = in path, length) -let list_supported_languages_and_exit omega = - let (module Matcher : Matchers.Engine.S) = - if omega then - (module Matchers.Omega) - else - (module Matchers.Alpha) - in +let list_supported_languages_and_exit () = let list = - List.map Matcher.all ~f:(fun (module M) -> + List.map Matchers.all ~f:(fun (module M) -> let ext = List.hd_exn M.extensions in Format.sprintf " -matcher %-10s%-10s\n" ext M.name) |> String.concat @@ -222,7 +216,6 @@ let base_command_parameters : (unit -> 'result) Command.Param.t = Setting this option activates -review mode." and disable_substring_matching = flag "disable-substring-matching" no_arg ~doc:"Allow :[holes] to match substrings" - and omega = flag "omega" no_arg ~doc:"Use Omega matcher engine." and fast_offset_conversion = flag "fast-offset-conversion" @@ -310,7 +303,7 @@ let base_command_parameters : (unit -> 'result) Command.Param.t = else Option.bind ~f:file_filters_to_paths file_filters in - if list then list_supported_languages_and_exit omega; + if list then list_supported_languages_and_exit (); if Option.is_some substitute_environment then substitute_environment_only_and_exit custom_metasyntax @@ -338,8 +331,6 @@ let base_command_parameters : (unit -> 'result) Command.Param.t = | None -> None in let substitute_in_place = not newline_separated_rewrites in - let omega_env = Option.is_some @@ Sys.getenv "OMEGA_COMBY" in - let omega = omega || omega_env in let fast_offset_conversion_env = Option.is_some @@ Sys.getenv "FAST_OFFSET_CONVERSION_COMBY" in let fast_offset_conversion = fast_offset_conversion_env || fast_offset_conversion in let arch = Unix.Utsname.machine (Core.Unix.uname ()) in @@ -370,7 +361,6 @@ let base_command_parameters : (unit -> 'result) Command.Param.t = ; override_matcher ; regex_pattern ; ripgrep_args - ; omega } ; run_options = { verbose diff --git a/test/alpha/dune b/test/alpha/dune deleted file mode 100644 index 020677cd..00000000 --- a/test/alpha/dune +++ /dev/null @@ -1,14 +0,0 @@ -(library - (name alpha_test_integration) - (package comby) - (modules test_special_matcher_cases test_substring_disabled) - (inline_tests) - (preprocess - (pps ppx_expect ppx_sexp_message ppx_deriving_yojson)) - (libraries comby cohttp-lwt-unix core camlzip)) - -(alias - (name runtest) - (deps - (source_tree example) - (source_tree example/src/.ignore-me))) diff --git a/test/common/dune b/test/common/dune index bc3c055f..85e2e536 100644 --- a/test/common/dune +++ b/test/common/dune @@ -45,5 +45,6 @@ (alias (name runtest) (deps + ../../src/main.exe (source_tree example) (source_tree example/src/.ignore-me))) diff --git a/test/common/test_bash.ml b/test/common/test_bash.ml index abd06344..a1751bdb 100644 --- a/test/common/test_bash.ml +++ b/test/common/test_bash.ml @@ -19,11 +19,7 @@ let%expect_test "custom_long_delimiters" = in let match_template = {|case :[1] esac|} in let rewrite_template = {|case nuked blocks esac|} in - run (module Alpha.Bash) source match_template rewrite_template; - [%expect_exact {| - case nuked blocks esac - |}]; - run (module Omega.Bash) source match_template rewrite_template; + run (module Bash) source match_template rewrite_template; [%expect_exact {| case nuked blocks esac |}] @@ -44,14 +40,7 @@ let%expect_test "custom_long_delimiters_doesn't_work_in_go" = in let match_template = {|case :[1] esac|} in let rewrite_template = {|case nuked blocks esac|} in - run (module Alpha.Go) source match_template rewrite_template; - [%expect_exact {| - case nuked blocks esac - - case nuked blocks esac - esac - |}]; - run (module Omega.Go) source match_template rewrite_template; + run (module Go) source match_template rewrite_template; [%expect_exact {| case nuked blocks esac diff --git a/test/common/test_c.ml b/test/common/test_c.ml index 3ad16f25..4c77b47a 100644 --- a/test/common/test_c.ml +++ b/test/common/test_c.ml @@ -7,97 +7,75 @@ let%expect_test "comments_1" = let source = {|match this /**/ expect end|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|expect|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|expect|}] let%expect_test "comments_2" = let source = {|match this /* */ expect end|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|expect|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|expect|}] let%expect_test "comments_3" = let source = {|match this /* blah blah */ expect /**/ end|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|expect|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|expect|}] let%expect_test "comments_4" = let source = {|match this expect/**/end|} in let match_template = {|match this :[1]end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|expect|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|expect|}] let%expect_test "comments_5" = let source = {|match this expect /**/end|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|expect|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|expect|}] let%expect_test "comments_6" = let source = {|/* don't match this (a) end */|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|nothing matches|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|No matches.|}] let%expect_test "comments_7" = let source = {|/* don't match /**/ this (a) end */|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|nothing matches|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|No matches.|}] let%expect_test "comments_8" = let source = {|(/* don't match this (a) end */)|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|nothing matches|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|No matches.|}] let%expect_test "comments_9" = let source = {|/* don't match this (a) end */ do match this (b) end|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|/* don't match this (a) end */ do (b)|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|/* don't match this (a) end */ do (b)|}] let%expect_test "comments_10" = let source = {|/* don't match this (a) end */ do match this () end|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|/* don't match this (a) end */ do ()|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|/* don't match this (a) end */ do ()|}] let%expect_test "comments_11" = let source = {|do match this (b) end /* don't match this (a) end */|} in let match_template = {|match this :[1] end|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|do (b) /* don't match this (a) end */|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|do (b) /* don't match this (a) end */|}] diff --git a/test/common/test_c_separators.ml b/test/common/test_c_separators.ml index a1e25672..bad5f400 100644 --- a/test/common/test_c_separators.ml +++ b/test/common/test_c_separators.ml @@ -7,21 +7,15 @@ let%expect_test "whitespace_should_not_matter_between_separators" = let source = {|*p|} in let match_template = {|*:[1]|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|p|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|p|}]; let source = {|* p|} in let match_template = {|*:[1]|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {| p|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {| p|}]; let source = {|* p|} in let match_template = {|* :[1]|} in let rewrite_template = {|:[1]|} in - run (module Alpha.C) source match_template rewrite_template; - [%expect_exact {|p|}]; - run (module Omega.C) source match_template rewrite_template; + run (module C) source match_template rewrite_template; [%expect_exact {|p|}] diff --git a/test/common/test_c_style_comments.ml b/test/common/test_c_style_comments.ml index f35157e6..0d7d2424 100644 --- a/test/common/test_c_style_comments.ml +++ b/test/common/test_c_style_comments.ml @@ -7,9 +7,7 @@ let%expect_test "rewrite_comments_1" = let template = "replace this :[1] end" in let source = "/* don't replace this () end */ do replace this () end" in let rewrite_template = "X" in - run (module Alpha.C) source template rewrite_template; - [%expect_exact "/* don't replace this () end */ do X"]; - run (module Omega.C) source template rewrite_template; + run (module C) source template rewrite_template; [%expect_exact "/* don't replace this () end */ do X"] let%expect_test "rewrite_comments_2" = @@ -29,11 +27,7 @@ let%expect_test "rewrite_comments_2" = let rewrite_template = {| if (:[1]) {} |} in - run (module Alpha.C) source template rewrite_template; - [%expect_exact {| - if (real_condition_body_must_be_empty) {} - |}]; - run (module Omega.C) source template rewrite_template; + run (module C) source template rewrite_template; [%expect_exact {| if (real_condition_body_must_be_empty) {} |}] @@ -41,11 +35,7 @@ let%expect_test "rewrite_comments_2" = let%expect_test "capture_comments" = let template = {|if (:[1]) { :[2] }|} in let source = {|if (true) { /* some comment */ console.log(z); }|} in - run_all_matches (module Alpha.C) source template; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":48,"line":1,"column":49}},"environment":[{"variable":"1","value":"true","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":8,"line":1,"column":9}}},{"variable":"2","value":"console.log(z);","range":{"start":{"offset":31,"line":1,"column":32},"end":{"offset":46,"line":1,"column":47}}}],"matched":"if (true) { /* some comment */ console.log(z); }"}]} -|}]; - run_all_matches (module Omega.C) source template; + run_all_matches (module C) source template; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":48,"line":1,"column":49}},"environment":[{"variable":"1","value":"true","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":8,"line":1,"column":9}}},{"variable":"2","value":"console.log(z);","range":{"start":{"offset":31,"line":1,"column":32},"end":{"offset":46,"line":1,"column":47}}}],"matched":"if (true) { /* some comment */ console.log(z); }"}]} |}] @@ -59,11 +49,7 @@ let%expect_test "single_quote_in_comment" = let rewrite_template = {| {:[1]} |} in - run (module Alpha.C) source template rewrite_template; - [%expect_exact {| - {test} - |}]; - run (module Omega.C) source template rewrite_template; + run (module C) source template rewrite_template; [%expect_exact {| {test} |}] @@ -83,17 +69,7 @@ let%expect_test "single_quote_in_comment" = let rewrite_template = {| {:[1]} |} in - run (module Alpha.C) source template rewrite_template; - [%expect_exact - {| - { - a = 1; - /* Events with mask == AE_NONE are not set. So let's initiaize the - * vector with it. */ - for (i = 0; i < setsize; i++) - } - |}]; - run (module Omega.C) source template rewrite_template; + run (module C) source template rewrite_template; [%expect_exact {| { @@ -118,16 +94,7 @@ let%expect_test "single_quote_in_comment" = let rewrite_template = {| {:[1]} |} in - run (module Alpha.C) source template rewrite_template; - [%expect_exact - {| - { - a = 1; - /* ' */ - for (i = 0; i < setsize; i++) - } - |}]; - run (module Omega.C) source template rewrite_template; + run (module C) source template rewrite_template; [%expect_exact {| { @@ -147,13 +114,7 @@ let%expect_test "give_back_the_comment_characters_for_newline_comments_too" = let rewrite_template = {| {:[1]} |} in - run (module Alpha.C) source template rewrite_template; - [%expect_exact {| - { - // a comment - } - |}]; - run (module Omega.C) source template rewrite_template; + run (module C) source template rewrite_template; [%expect_exact {| { // a comment @@ -172,7 +133,5 @@ a a |} in let rewrite_template = {|erased|} in - run (module Alpha.C) source template rewrite_template; - [%expect_exact {|erased|}]; - run (module Omega.C) source template rewrite_template; + run (module C) source template rewrite_template; [%expect_exact {|erased|}] diff --git a/test/common/test_cli.ml b/test/common/test_cli.ml index 78290ac0..2dcb3bc8 100644 --- a/test/common/test_cli.ml +++ b/test/common/test_cli.ml @@ -2,7 +2,7 @@ open Core open Camlzip module Time = Core_kernel.Time_ns.Span -let binary_path = "../../../../comby" +let binary_path = Filename.realpath "../../src/main.exe" let read_with_timeout read_from_channels = let read_from_fds = List.map ~f:Unix.descr_of_in_channel read_from_channels in @@ -1305,7 +1305,7 @@ let%expect_test "test_toml_multi_rewrite_with_match_only_in_config" = let%expect_test "dot_comby_with_flags" = let source = "main(void)\n" in Sys.chdir ("example" ^/ "dot-comby"); - let command = Format.sprintf "../../%s %s" binary_path "" in + let command = Format.sprintf "%s %s" binary_path "" in let result = read_expect_stdin_and_stdout command source in Sys.chdir "../.."; print_string result; diff --git a/test/common/test_cli_helper.ml b/test/common/test_cli_helper.ml index 2540fd56..39da1bb0 100644 --- a/test/common/test_cli_helper.ml +++ b/test/common/test_cli_helper.ml @@ -1,7 +1,7 @@ open Core module Time = Core_kernel.Time_ns.Span -let binary_path = "../../../../comby" +let binary_path = Filename.realpath "../../src/main.exe" let read_with_timeout read_from_channels = let read_from_fds = List.map ~f:Unix.descr_of_in_channel read_from_channels in diff --git a/test/common/test_custom_metasyntax.ml b/test/common/test_custom_metasyntax.ml index 818c8f57..67b154ce 100644 --- a/test/common/test_custom_metasyntax.ml +++ b/test/common/test_custom_metasyntax.ml @@ -4,38 +4,26 @@ open Test_helpers let configuration = Matchers.Configuration.create ~match_kind:Fuzzy () -let create (module E : Matchers.Engine.S) syntax = +let create syntax = let metasyntax = Matchers.Metasyntax.{ syntax; identifier = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; aliases = [] } in - Option.value_exn (E.select_with_extension ~metasyntax ".go") + Option.value_exn (Matchers.select_with_extension ~metasyntax ".go") let%expect_test "custom_metasyntax_everything" = let matcher = [ Matchers.Metasyntax.Hole (Everything, Delimited (Some "$", None)) ] in let source = "simple(test)" in - run_all_matches (create (module Matchers.Alpha) matcher) source "simple($A)"; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":12,"line":1,"column":13}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"simple(test)"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) source "simple($A)"; + run_all_matches (create matcher) source "simple($A)"; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":12,"line":1,"column":13}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"simple(test)"}]} |}]; let source = "(nested(test))" in - run_all_matches (create (module Matchers.Alpha) matcher) source "($A)"; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"nested(test)","range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":13,"line":1,"column":14}}}],"matched":"(nested(test))"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) source "($A)"; + run_all_matches (create matcher) source "($A)"; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"nested(test)","range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":13,"line":1,"column":14}}}],"matched":"(nested(test))"}]} |}]; let source = "flat stuff yeah" in - run_all_matches (create (module Matchers.Alpha) matcher) source "flat $A yeah"; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":15,"line":1,"column":16}},"environment":[{"variable":"A","value":"stuff","range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":10,"line":1,"column":11}}}],"matched":"flat stuff yeah"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) source "flat $A yeah"; + run_all_matches (create matcher) source "flat $A yeah"; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":15,"line":1,"column":16}},"environment":[{"variable":"A","value":"stuff","range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":10,"line":1,"column":11}}}],"matched":"flat stuff yeah"}]} |}] @@ -43,11 +31,7 @@ let%expect_test "custom_metasyntax_everything" = let%expect_test "custom_metasyntax_regex" = let matcher = Matchers.Metasyntax.[ Regex ("$", ':', " ") ] in let source = "simple(test)" in - run_all_matches (create (module Matchers.Alpha) matcher) source {|$A:\w+ |}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple"},{"range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"test"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) source {|$A:\w+ |}; + run_all_matches (create matcher) source {|$A:\w+ |}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple"},{"range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"test","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":11,"line":1,"column":12}}}],"matched":"test"}]} |}] @@ -57,19 +41,11 @@ let%expect_test "custom_metasyntax_multiple_holes" = Matchers.Metasyntax. [ Hole (Everything, Delimited (Some "$", None)); Hole (Alphanum, Delimited (Some "?", None)) ] in - run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|$FOO(?BAR)|}; + run_all_matches (create matcher) "simple(bar)" {|$FOO(?BAR)|}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"FOO","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple(bar)"}]} |}]; - run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|$FOO(?BAR)|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"FOO","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple(bar)"}]} -|}]; - run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar)" {|?FOO($BAR)|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}},{"variable":"FOO","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo(bar)"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) "foo(bar)" {|?FOO($BAR)|}; + run_all_matches (create matcher) "foo(bar)" {|?FOO($BAR)|}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"BAR","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}},{"variable":"FOO","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo(bar)"}]} |}]; @@ -79,11 +55,7 @@ let%expect_test "custom_metasyntax_multiple_holes" = ; Hole (Alphanum, Delimited (Some "$$", None)) ] in - run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$$A|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"A","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$$A|}; + run_all_matches (create matcher) "foo(bar.baz)" {|$$A|}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"A","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]} |}]; @@ -94,11 +66,7 @@ let%expect_test "custom_metasyntax_multiple_holes" = ; Regex ("$", ':', " ") ] in - run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$M:\w+ |}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"M","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"M","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"M","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$M:\w+ |}; + run_all_matches (create matcher) "foo(bar.baz)" {|$M:\w+ |}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}},"environment":[{"variable":"M","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo"},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}},"environment":[{"variable":"M","value":"bar","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"bar"},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"M","value":"baz","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":11,"line":1,"column":12}}}],"matched":"baz"}]} |}]; @@ -110,9 +78,7 @@ let%expect_test "custom_metasyntax_multiple_holes" = ; Hole (Alphanum, Delimited (Some "$$", None)) ] in - run_all_matches (create (module Matchers.Alpha) matcher) "foo(bar.baz)" {|$M:\w+ |}; - [%expect_exact {|No matches.|}]; - run_all_matches (create (module Matchers.Omega) matcher) "foo(bar.baz)" {|$M:\w+ |}; + run_all_matches (create matcher) "foo(bar.baz)" {|$M:\w+ |}; [%expect_exact {|No matches.|}] let%expect_test "custom_metasyntax_underscore" = @@ -120,12 +86,8 @@ let%expect_test "custom_metasyntax_underscore" = Matchers.Metasyntax. [ Hole (Everything, Delimited (Some "$", None)); Hole (Alphanum, Delimited (Some "?", None)) ] in - run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|$_(?_)|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"_","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}}],"matched":"simple(bar)"}]} -|}]; - (* different because we record _ the first time and don't subsequently for implicit_equals *) - run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|$_(?_)|}; + (* We record _ the first time and don't subsequently for implicit_equals *) + run_all_matches (create matcher) "simple(bar)" {|$_(?_)|}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"_","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]} |}] @@ -134,36 +96,26 @@ let%expect_test "custom_metasyntax_equivalence" = let matcher = Matchers.Metasyntax.[ Hole (Everything, Delimited (Some "$", None)); Regex ("$", '~', "$") ] in - run_all_matches (create (module Matchers.Alpha) matcher) "foo(foo)" {|$A($A~\w+$)|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}},{"variable":"A_equal_!@#$000000000011","value":"foo","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}}],"matched":"foo(foo)"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) "foo(foo)" {|$A($A~\w+$)|}; + run_all_matches (create matcher) "foo(foo)" {|$A($A~\w+$)|}; [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}},{"variable":"A_equal_!@#$000000000012","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo(foo)"}]} + {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"A","value":"foo","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":7,"line":1,"column":8}}},{"variable":"A_equal_!@#$000000000004","value":"foo","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":3,"line":1,"column":4}}}],"matched":"foo(foo)"}]} |}] let%expect_test "custom_metasyntax_definition_order" = let matcher = Matchers.Metasyntax.[ Regex ("$", '~', "$"); Hole (Everything, Delimited (Some "$", None)) ] in - run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|}; - [%expect_exact {|No matches.|}]; - run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|}; + run_all_matches (create matcher) "simple(bar)baz" {|$A($B)$C~\w+$|}; [%expect_exact {|No matches.|}]; let matcher = Matchers.Metasyntax.[ Hole (Everything, Delimited (Some "$", None)); Regex ("$", '~', "$") ] in - run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"B","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"C","value":"baz","range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":14,"line":1,"column":15}}}],"matched":"simple(bar)baz"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)baz" {|$A($B)$C~\w+$|}; + run_all_matches (create matcher) "simple(bar)baz" {|$A($B)$C~\w+$|}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":14,"line":1,"column":15}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"B","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}},{"variable":"C","value":"baz","range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":14,"line":1,"column":15}}}],"matched":"simple(bar)baz"}]} |}] -let%expect_test "custom_metasyntax_rewrite_alpha" = +let%expect_test "custom_metasyntax_rewrite_fresh_1" = let syntax = Matchers.Metasyntax. [ Hole (Everything, Delimited (Some "$", None)); Hole (Alphanum, Delimited (Some "?", None)) ] @@ -171,7 +123,7 @@ let%expect_test "custom_metasyntax_rewrite_alpha" = let metasyntax = Matchers.Metasyntax.{ syntax; identifier = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; aliases = [] } in - let matcher = Option.value_exn (Matchers.Alpha.select_with_extension ~metasyntax ".go") in + let matcher = Option.value_exn (Matchers.select_with_extension ~metasyntax ".go") in let specification = Matchers.Specification.create ~match_template:"$A(?B)" ~rewrite_template:"??B -> $A$A" () in @@ -200,7 +152,7 @@ let%expect_test "custom_metasyntax_rewrite_alpha" = print_string output; [%expect_exact {|1 2 2|}] -let%expect_test "custom_metasyntax_rewrite_omega" = +let%expect_test "custom_metasyntax_rewrite_fresh_2" = let syntax = Matchers.Metasyntax. [ Hole (Everything, Delimited (Some "$", None)); Hole (Alphanum, Delimited (Some "?", None)) ] @@ -208,7 +160,7 @@ let%expect_test "custom_metasyntax_rewrite_omega" = let metasyntax = Matchers.Metasyntax.{ syntax; identifier = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; aliases = [] } in - let matcher = Option.value_exn (Matchers.Omega.select_with_extension ~metasyntax ".go") in + let matcher = Option.value_exn (Matchers.select_with_extension ~metasyntax ".go") in let specification = Matchers.Specification.create ~match_template:"$A(?B)" ~rewrite_template:"??B -> $A$A" () in @@ -239,11 +191,7 @@ let%expect_test "custom_metasyntax_rewrite_omega" = let%expect_test "custom_metasyntax_greek_letters" = let matcher = Matchers.Metasyntax.[ Hole (Alphanum, Reserved_identifiers [ "α"; "β" ]) ] in - run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|α(β)|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"α","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"β","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|α(β)|}; + run_all_matches (create matcher) "simple(bar)" {|α(β)|}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"α","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"β","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]} |}] @@ -255,11 +203,7 @@ let%expect_test "custom_metasyntax_alphanum_test" = ; Hole (Alphanum, Reserved_identifiers [ "α"; "β" ]) ] in - run_all_matches (create (module Matchers.Alpha) matcher) "simple(bar)" {|[:A:](α)|}; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"α","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]} -|}]; - run_all_matches (create (module Matchers.Omega) matcher) "simple(bar)" {|[:A:](α)|}; + run_all_matches (create matcher) "simple(bar)" {|[:A:](α)|}; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"A","value":"simple","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":6,"line":1,"column":7}}},{"variable":"α","value":"bar","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":10,"line":1,"column":11}}}],"matched":"simple(bar)"}]} |}] @@ -276,14 +220,7 @@ let%expect_test "custom_metasyntax_rewrite_length" = in run ~metasyntax - (create (module Matchers.Alpha) syntax) - "simple(bar)" - {|[:A:](α)|} - {|[:A:].length (α.length)|}; - [%expect_exact {|6 (3)|}]; - run - ~metasyntax - (create (module Matchers.Omega) syntax) + (create syntax) "simple(bar)" {|[:A:](α)|} {|[:A:].length (α.length)|}; @@ -299,13 +236,8 @@ let%expect_test "custom_metasyntax_test_alias" = in (* Need to use default metasyntax because rules don't yet support arbitrary metasyntax *) let metasyntax = { Matchers.Metasyntax.default_metasyntax with aliases } in - let alpha = Option.value_exn (Matchers.Alpha.select_with_extension ~metasyntax ".go") in - let omega = Option.value_exn (Matchers.Omega.select_with_extension ~metasyntax ".go") in - run ~metasyntax alpha "foo(a) foo(ab) foo(abc) foo(abcd)" "foo(_2)" "matched"; - [%expect_exact {|foo(a) matched foo(abc) foo(abcd)|}]; - run ~metasyntax omega "foo(a) foo(ab) foo(abc) foo(abcd)" "foo(_2)" "matched"; + let matcher = Option.value_exn (Matchers.select_with_extension ~metasyntax ".go") in + run ~metasyntax matcher "foo(a) foo(ab) foo(abc) foo(abcd)" "foo(_2)" "matched"; [%expect_exact {|foo(a) matched foo(abc) foo(abcd)|}]; - run ~metasyntax alpha "foo(a) foo(ab) foo(abc) foo(abcd)" "foo(_3)" "matched"; - [%expect_exact {|foo(a) foo(ab) matched foo(abcd)|}]; - run ~metasyntax omega "foo(a) foo(ab) foo(abc) foo(abcd)" "foo(_3)" "matched"; + run ~metasyntax matcher "foo(a) foo(ab) foo(abc) foo(abcd)" "foo(_3)" "matched"; [%expect_exact {|foo(a) foo(ab) matched foo(abcd)|}] diff --git a/test/common/test_generic.ml b/test/common/test_generic.ml index 439fc3e2..88822dbf 100644 --- a/test/common/test_generic.ml +++ b/test/common/test_generic.ml @@ -3,14 +3,8 @@ open Test_helpers open Comby_kernel open Matchers -let run - (module E : Engine.S) - ?(configuration = configuration) - source - match_template - rewrite_template - = - E.Generic.first ~configuration match_template source +let run ?(configuration = configuration) source match_template rewrite_template = + Matchers.Generic.first ~configuration match_template source |> function | Ok result -> Rewrite.all ~source ~rewrite_template [ result ] @@ -46,387 +40,280 @@ let%expect_test "basic" = let source = {|a b c d|} in let match_template = {|:[1]|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|a b c d|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|a b c d|}]; let source = {|a b c d|} in let match_template = {|a :[1] c d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b|}]; let source = {|a b c d|} in let match_template = {|a :[1] d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b c|}]; let source = {|a b c d|} in let match_template = {|a :[1]|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|b c d|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b c d|}]; let source = {|a b c d|} in let match_template = {|:[1] c d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|a b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|a b|}]; let source = {|a b c d|} in let match_template = {|:[1] :[2]|} in let rewrite_template = {|(:[1]) (:[2])|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(a) (b c d)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(a) (b c d)|}]; let source = {|a b c d|} in let match_template = {|:[2] :[1]|} in let rewrite_template = {|(:[2]) (:[1])|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(a) (b c d)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(a) (b c d)|}]; let source = {|a b c d|} in let match_template = {|a :[2] :[1] d|} in let rewrite_template = {|(:[2]) (:[1])|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(b) (c)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(b) (c)|}]; let source = {|a b c d|} in let match_template = {|a :[2] :[1]|} in let rewrite_template = {|(:[2]) (:[1])|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(b) (c d)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(b) (c d)|}]; let source = {|a b c d|} in let match_template = {|a :[2] c :[1]|} in let rewrite_template = {|(:[2]) (:[1])|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(b) (d)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(b) (d)|}]; let source = {|x:|} in let match_template = {|:[1]:|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|x|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|x|}] let%expect_test "basic_failures" = let source = {|a x b bbq|} in let match_template = {|a :[1] b c|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {||}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {||}]; let source = {|a b c d|} in let match_template = {|a :[2] d :[1]|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {||}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {||}]; let source = {|a b c d|} in let match_template = {|a :[2] b :[1]|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {||}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {||}] let%expect_test "delimiter_matching" = let source = {|foo(bar)|} in let match_template = {|:[1](bar)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|foo|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|foo|}]; let source = {|(a b c) d|} in let match_template = {|(:[1]) d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|a b c|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|a b c|}]; let source = {|(a b c) d|} in let match_template = {|(:[1] b :[2]) d|} in let rewrite_template = {|(:[1]) (:[2])|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(a) (c)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(a) (c)|}]; let source = {|q(a b c) d|} in let match_template = {|q(:[1] b :[2]) d|} in let rewrite_template = {|(:[1]) (:[2])|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(a) (c)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(a) (c)|}]; let source = {|((a) b)|} in let match_template = {|(:[1] b)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(a)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(a)|}]; let source = {|((a b c)) d|} in let match_template = {|(:[1]) d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(a b c)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(a b c)|}]; let source = {|((a b c)) d|} in let match_template = {|(:[1]) d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(a b c)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(a b c)|}]; let source = {|((a b c) q) d|} in let match_template = {|((:[1]) q) d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|a b c|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|a b c|}]; let source = {|((a b c) q) d|} in let match_template = {|((:[1] c) q) d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|a b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|a b|}]; let source = {|((a b () c) q) d|} in let match_template = {|((:[1] () c) q) d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|a b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|a b|}]; let source = {|((a ((x) d) b c)) d|} in let match_template = {|((a :[1] :[2] c)) d|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|((x) d)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|((x) d)|}]; let source = {|((a ((x) d) b c)) d|} in let match_template = {|((a (:[1]) :[2] c)) d|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(x) d b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(x) d b|}]; let source = {|(b (c) d)|} in let match_template = {|(:[1])|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|b (c) d|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b (c) d|}]; let source = {|(b (c) d.)|} in let match_template = {|(:[1].)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|b (c) d|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b (c) d|}]; let source = {|(b (c.) d.)|} in let match_template = {|(:[1].)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|b (c.) d|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b (c.) d|}]; let source = {|(b. (c) d.)|} in let match_template = {|(:[1].)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|b. (c) d|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b. (c) d|}]; let source = {|(b (c) d.)|} in let match_template = {|(b :[1] d.)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(c)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(c)|}]; let source = {|outer(inner(dst,src),src)|} in let match_template = {|outer(:[1],src)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|inner(dst,src)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|inner(dst,src)|}]; let source = {|(b ((c)) d.)|} in let match_template = {|(b :[1] d.)|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|((c))|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|((c))|}]; let source = {|a b c|} in let match_template = {|a :[1] c|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|b|}]; let source = {|x = foo;|} in let match_template = {|x = :[1];|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|foo|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|foo|}]; let source = {|((a {{x} d} b c)) d|} in let match_template = {|((a {:[1] d} :[2] c)) d|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|{x} b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|{x} b|}]; let source = {|((a {([{x}]) d} b c)) d|} in let match_template = {|((a {:[1] d} :[2] c)) d|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|([{x}]) b|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|([{x}]) b|}]; let source = {|(((((x)))))|} in let match_template = {|(((:[1])))|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|((x))|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|((x))|}]; let source = {|((((y(x)z))))|} in let match_template = {|(((:[1])))|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(y(x)z)|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(y(x)z)|}]; let source = {|((((y(x)z))))|} in let match_template = {|(((:[1]):[2]))|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(y(x)z) |}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(y(x)z) |}]; let source = {|(((x)z))|} in let match_template = {|(((:[1]):[2]))|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|x z|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|x z|}]; let source = {|((((x))z))|} in let match_template = {|(((:[1]):[2]))|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|(x) z|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|(x) z|}]; let source = {|lolwtfbbq|} in let match_template = {|lol:[1]bbq|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|wtf|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|wtf|}]; let source = {|x = foo; x = bar;|} in let match_template = {|x = :[1];|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|foo x = bar;|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|foo x = bar;|}]; let source = {|[ no match prefix ] x = foo; [ no match suffix ]|} in let match_template = {|x = :[1];|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|[ no match prefix ] foo [ no match suffix ]|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|[ no match prefix ] foo [ no match suffix ]|}]; let source = {|x = a; x = b; x = c|} in let match_template = {|x = :[1];|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|a x = b; x = c|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|a x = b; x = c|}]; let source = {|x = ( x = x; );|} in let match_template = {|x = :[1];|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|( x = x; )|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|( x = x; )|}]; let source = {|( x = x = x; )|} in let match_template = {|x = :[1];|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|( x = x )|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|( x = x )|}]; let source = {|xxx a b d c 1 2 3 b d d blah|} in let match_template = {|a :[1] c :[2] d|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|xxx b d 1 2 3 b d blah|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|xxx b d 1 2 3 b d blah|}]; let source = {|howevenlolwtfbbqispossible|} in let match_template = {|lol:[1]bbq|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|howevenwtfispossible|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|howevenwtfispossible|}]; let source = {|lolhowevenlolwtfbbqispossiblebbq|} in let match_template = {|lol:[1]bbq|} in let rewrite_template = {|:[1]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|howevenlolwtfispossiblebbq|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|howevenlolwtfispossiblebbq|}]; let source = {|hello my name is bob the builder|} in let match_template = {|:[alongidentifiername] :[2] :[3] :[xyz] :[5] :[6]|} in let rewrite_template = {|:[alongidentifiername] :[2] :[3] :[xyz] :[5] :[6]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|hello my name is bob the builder|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|hello my name is bob the builder|}]; let source = {|www.testdofooname.com/picsinsideit/stunningpictureofkays1381737242g8k4n-280x428.jpg|} in let match_template = {|www.:[1]-:[2].jpg|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|testdofooname.com/picsinsideit/stunningpictureofkays1381737242g8k4n 280x428|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|testdofooname.com/picsinsideit/stunningpictureofkays1381737242g8k4n 280x428|}]; let source = {|https://api.github.com/repos/dmjacobsen/slurm/commits/716c1499695c68afcab848a1b49653574b4fc167|} in let match_template = {|:[1]api.:[2]/repos/:[3]s/:[4]|} in let rewrite_template = {|:[1] :[2] :[3] :[4]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact - {|https:// github.com dmjacobsen/slurm/commit 716c1499695c68afcab848a1b49653574b4fc167|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|https:// github.com dmjacobsen/slurm/commit 716c1499695c68afcab848a1b49653574b4fc167|}]; let source = @@ -442,13 +329,7 @@ let%expect_test "delimiter_matching" = in let match_template = {|memcpy(:[1], :[2], :[3]);|} in let rewrite_template = {|:[1], :[2], :[3]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact - {|assert(stream->md_len + md_len - - si.foo_data_begin <= MAD_BUFFER_MDLEN); -*stream->foo_data + stream->md_len, mad_bit_nextbyte(&stream->ptr), frame_used = md_len - si.foo_data_begin -stream->md_len += frame_used;|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|assert(stream->md_len + md_len - si.foo_data_begin <= MAD_BUFFER_MDLEN); @@ -461,9 +342,7 @@ let%expect_test "significant_whitespace" = let source = {|two spaces|} in let match_template = {|:[1] :[2]|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|two spaces|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|two spaces|}]; (* FIXME: this should fail. also test case where separators do or do not need whitespace. e.g., strict about strcpy(src,dst) matching a template @@ -471,43 +350,32 @@ let%expect_test "significant_whitespace" = let source = {|two spaces|} in let match_template = {|:[1] :[2]|} in let rewrite_template = {|:[1] :[2]|} in - run (module Alpha) source match_template rewrite_template; - [%expect_exact {|two spaces|}]; - run (module Omega) source match_template rewrite_template; + run source match_template rewrite_template; [%expect_exact {|two spaces|}] let%expect_test "contextual_matching" = let source = {|memcpy(dst1, src1, 1); memcpy(dst2, src2, 2);|} in let match_template = {|memcpy(:[1], :[2], :[3])|} in let rewrite_template = {|:[1]|} in - run_all (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|dst1; dst2;|}]; - run_all (module Omega.Generic) source match_template rewrite_template; + run_all (module Generic) source match_template rewrite_template; [%expect_exact {|dst1; dst2;|}]; let source = {|memcpy(dst1, src1, 1); memcpy(dst2, src2, 2);|} in let match_template = {|memcpy(:[1], :[2], :[3])|} in let rewrite_template = {|:[1]|} in - run_all (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|dst1; dst2;|}]; - run_all (module Omega.Generic) source match_template rewrite_template; + run_all (module Generic) source match_template rewrite_template; [%expect_exact {|dst1; dst2;|}] let%expect_test "contextual_matching_with_short_hole_syntax" = let source = {|memcpy(dst1, src1, 1); memcpy(dst2, src2, 2);|} in let match_template = {|memcpy(:[[1]], :[2], :[3])|} in let rewrite_template = {|:[[1]]|} in - run_all (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|dst1; dst2;|}]; - run_all (module Omega.Generic) source match_template rewrite_template; + run_all (module Generic) source match_template rewrite_template; [%expect_exact {|dst1; dst2;|}] let%expect_test "trivial_empty_case" = let source = "" in let match_template = "" in - run_match (module Alpha.Generic) source match_template; - [%expect_exact - {|{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":0,"line":1,"column":1}},"environment":[],"matched":""}|}]; - run_match (module Omega.Generic) source match_template; + run_match (module Generic) source match_template; [%expect_exact {|{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":0,"line":1,"column":1}},"environment":[],"matched":""}|}] @@ -531,7 +399,7 @@ let%expect_test "test_top_level_hole_stops_at_newline_false_implies_default_gene let match_template = ":[1] = :[2]" in let rewrite_template = "line" in let configuration = Configuration.create ~match_newline_toplevel:false () in - run_all (module Alpha.Generic) ~configuration source match_template rewrite_template; + run_all (module Generic) ~configuration source match_template rewrite_template; [%expect_exact {| line @@ -546,10 +414,7 @@ line line ) line - |}]; - (* Unimplemented: Does not stop at newline *) - run_all (module Omega.Generic) ~configuration source match_template rewrite_template; - [%expect_exact {|line|}] + |}] let%expect_test "test_top_level_hole_stops_at_newline_for_example_generic_go_false" = let source = @@ -566,18 +431,12 @@ let%expect_test "test_top_level_hole_stops_at_newline_for_example_generic_go_fal let match_template = "for i, x := :[_] { do match }" in let rewrite_template = "erased" in let configuration = Configuration.create ~match_newline_toplevel:false () in - run_all (module Alpha.Generic) ~configuration source match_template rewrite_template; - [%expect_exact - {| + run_all (module Generic) ~configuration source match_template rewrite_template; + [%expect_exact {| for i, x := range derp { do not match } - erased - |}]; - (* Unimplemented: Does not stop at newline *) - run_all (module Omega.Generic) ~configuration source match_template rewrite_template; - [%expect_exact {| erased |}] @@ -596,11 +455,7 @@ let%expect_test "test_top_level_hole_stops_at_newline_for_example_generic_go_tru let match_template = "for i, x := :[_] { do match }" in let rewrite_template = "erased" in let configuration = Configuration.create ~match_newline_toplevel:true () in - run_all (module Alpha.Generic) ~configuration source match_template rewrite_template; - [%expect_exact {| - erased - |}]; - run_all (module Omega.Generic) ~configuration source match_template rewrite_template; + run_all (module Generic) ~configuration source match_template rewrite_template; [%expect_exact {| erased |}] @@ -625,9 +480,7 @@ let%expect_test "test_top_level_hole_stops_at_newline_generic_true" = let match_template = ":[1] = :[2]" in let rewrite_template = "line" in let configuration = Configuration.create ~match_newline_toplevel:true () in - run_all (module Alpha.Generic) ~configuration source match_template rewrite_template; - [%expect_exact {|line|}]; - run_all (module Omega.Generic) ~configuration source match_template rewrite_template; + run_all (module Generic) ~configuration source match_template rewrite_template; [%expect_exact {|line|}] let%expect_test "test_top_level_hole_crosses_newlines_for_html_by_default" = @@ -638,14 +491,8 @@ let%expect_test "test_top_level_hole_crosses_newlines_for_html_by_default" = |} in let match_template = ":[x]" in let rewrite_template = ":[x]" in - run_all (module Alpha.Html) ~configuration source match_template rewrite_template; - [%expect_exact {| - - stuff - - |}]; - (* Unimplemented: Has no effect *) - run_all (module Omega.Html) ~configuration source match_template rewrite_template; + (* HTML intentionally allows top-level holes to cross newlines by default. *) + run_all (module Html) ~configuration source match_template rewrite_template; [%expect_exact {| stuff diff --git a/test/common/test_go.ml b/test/common/test_go.ml index 53a1927e..6332b2d4 100644 --- a/test/common/test_go.ml +++ b/test/common/test_go.ml @@ -20,12 +20,7 @@ let%expect_test "gosimple_s1000" = :[1] := :[2] :[3] |} in - run (module Alpha.Go) source match_template rewrite_template; - [%expect_exact {| - x := <-ch - fmt.Println(x) - |}]; - run (module Omega.Go) source match_template rewrite_template; + run (module Go) source match_template rewrite_template; [%expect_exact {| x := <-ch fmt.Println(x) @@ -50,11 +45,7 @@ let%expect_test "gosimple_s1001" = let rule = {|where :[index_define] == :[index_use], :[src_element_define] == :[src_element_use]|} in - run (module Alpha.Go) ~rule source match_template rewrite_template; - [%expect_exact {| - copy(dst, src) - |}]; - run (module Omega.Go) ~rule source match_template rewrite_template; + run (module Go) ~rule source match_template rewrite_template; [%expect_exact {| copy(dst, src) |}] @@ -67,7 +58,5 @@ let%expect_test "gosimple_s1003" = if strings.:[1](x, y) != -1 { :[_] } |} in let rewrite_template = {|:[1]|} in - run (module Alpha.Go) source match_template rewrite_template; - [%expect_exact {|Index|}]; - run (module Omega.Go) source match_template rewrite_template; + run (module Go) source match_template rewrite_template; [%expect_exact {|Index|}] diff --git a/test/common/test_hole_extensions.ml b/test/common/test_hole_extensions.ml index 218852df..e45245a1 100644 --- a/test/common/test_hole_extensions.ml +++ b/test/common/test_hole_extensions.ml @@ -3,14 +3,8 @@ open Test_helpers open Comby_kernel open Matchers -let run_all - (module E : Engine.S) - ?(configuration = configuration) - source - match_template - rewrite_template - = - E.Generic.all ~configuration ~template:match_template ~source () +let run_all ?(configuration = configuration) source match_template rewrite_template = + Matchers.Generic.all ~configuration ~template:match_template ~source () |> function | [] -> print_string "No matches." | results -> @@ -22,18 +16,14 @@ let%expect_test "non_space" = let source = {| foo. foo.bar.quux derp|} in let match_template = {|:[x.]|} in let rewrite_template = {|{:[x]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {| {foo.} {foo.bar.quux} {derp}|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {| {foo.} {foo.bar.quux} {derp}|}] let%expect_test "only_space" = let source = {| foo. foo.bar.quux derp|} in let match_template = {|:[ x]|} in let rewrite_template = {|{:[x]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|{ }foo.{ }foo.bar.quux{ }derp|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|{ }foo.{ }foo.bar.quux{ }derp|}] let%expect_test "up_to_newline" = @@ -44,13 +34,7 @@ derp |} in let match_template = {|:[x\n]|} in let rewrite_template = {|{:[x]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|{ -}{foo. -}{foo.bar.quux -}{derp -}|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|{ }{foo. }{foo.bar.quux @@ -63,11 +47,7 @@ after |} in let match_template = {|stuff:[x\n]|} in let rewrite_template = {|{->:[x]<-}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|{-> -<-}after -|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|{-> <-}after |}] @@ -80,13 +60,7 @@ let%expect_test "leading_indentation" = |} in let match_template = {|:[ leading_indentation]:[rest\n]|} in let rewrite_template = {|{:[leading_indentation]}:[rest]|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {| -{ }foo. bar bazz -{ }foo.bar.quux -{ }derp -|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {| { }foo. bar bazz { }foo.bar.quux @@ -97,36 +71,28 @@ let%expect_test "non_space_partial_match" = let source = {| foo. foo.bar.quux derp|} in let match_template = {|foo.:[x.]ux|} in let rewrite_template = {|{:[x]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {| foo. {bar.qu} derp|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {| foo. {bar.qu} derp|}] let%expect_test "non_space_does_not_match_reserved_delimiters" = let source = {|fo.o(x)|} in let match_template = {|:[f.]|} in let rewrite_template = {|{:[f]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|{fo.o}({x})|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|{fo.o}({x})|}] let%expect_test "non_space_only_hole" = let source = {|a.b c.d|} in let match_template = {|:[x.]|} in let rewrite_template = {|>:[x]<|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|>a.b< >c.d<|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|>a.b< >c.d<|}] let%expect_test "alphanum_partial_match" = let source = {| foo. foo.bar.quux derp|} in let match_template = {|foo.b:[x]r.quux|} in let rewrite_template = {|{:[x]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {| foo. {a} derp|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {| foo. {a} derp|}] let%expect_test "newline_matcher_should_not_be_sat_on_space" = @@ -134,20 +100,14 @@ let%expect_test "newline_matcher_should_not_be_sat_on_space" = e f g h|} in let match_template = {|:[line\n] |} in let rewrite_template = {|{:[line]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|{a b c d -}e f g h|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|{a b c d }e f g h|}]; let source = {|a b c d e f g h|} in let match_template = {|:[line\n]:[next]|} in let rewrite_template = {|{:[line]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|{a b c d -}|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|{a b c d }|}]; let source = {|a b c d @@ -155,11 +115,7 @@ e f g h |} in let match_template = {|:[line1\n]:[next\n]|} in let rewrite_template = {|{:[line1]|:[next]}|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|{a b c d -|e f g h -}|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|{a b c d |e f g h }|}] @@ -168,52 +124,40 @@ let%expect_test "implicit_equals" = let source = {|a b a|} in let match_template = {|:[[x]] :[[m]] :[[x]]|} in let rewrite_template = {|:[m]|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|b|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|b|}] let%expect_test "implicit_equals_does_not_apply_to_underscore" = let source = {|a b c|} in let match_template = {|:[[x]] :[[_]] :[[_]]|} in let rewrite_template = {|:[x]|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|a|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|a|}] let%expect_test "expression_hole_basic" = let source = {|(b, c, d) [ ] { { } } { } ()()|} in let match_template = {|:[x:e]|} in let rewrite_template = {|>:[x]<|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|>(b, c, d)< >[ ]< >{ { } }< >{ }< >()()<|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|>(b, c, d)< >[ ]< >{ { } }< >{ }< >()()<|}] let%expect_test "expression_hole_basic_2" = let source = {|a(b, c, d)e [][] { { } }|} in let match_template = {|:[x:e]|} in let rewrite_template = {|>:[x]<|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|>a(b, c, d)e< >[][]< >{ { } }<|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|>a(b, c, d)e< >[][]< >{ { } }<|}] let%expect_test "expression_hole_multiple" = let source = {|a(b, c, d)e [][] { { } }|} in let match_template = {|:[x:e] :[y:e] :[z:e]|} in let rewrite_template = {|>:[x]< >:[y]< >:[z]<|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|>a(b, c, d)e< >[][]< >{ { } }<|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|>a(b, c, d)e< >[][]< >{ { } }<|}] let%expect_test "expression_hole_multiple" = let source = {|foo("b", c, 'd') { }|} in let match_template = {|foo(:[x:e], :[y:e], :[z:e])|} in let rewrite_template = {|>:[x]< >:[y]< >:[z]<|} in - run_all (module Alpha) source match_template rewrite_template; - [%expect_exact {|>"b"< >c< >'d'< { }|}]; - run_all (module Omega) source match_template rewrite_template; + run_all source match_template rewrite_template; [%expect_exact {|>"b"< >c< >'d'< { }|}] diff --git a/test/common/test_integration.ml b/test/common/test_integration.ml index 7d6b5ccc..d5e0a4df 100644 --- a/test/common/test_integration.ml +++ b/test/common/test_integration.ml @@ -3,11 +3,11 @@ open Comby_kernel open Matchers open Test_helpers -let all ?(configuration = configuration) (module E : Engine.S) template source = - E.Generic.all ~configuration ~template ~source () +let all ?(configuration = configuration) template source = + Matchers.Generic.all ~configuration ~template ~source () -let rewrite_all engine template source rewrite_template = - all engine template source +let rewrite_all template source rewrite_template = + all template source |> (fun matches -> Option.value_exn (Rewrite.all ~source ~rewrite_template matches)) |> fun { rewritten_source; _ } -> rewritten_source @@ -20,27 +20,13 @@ let print_matches matches = let%expect_test "dont_get_stuck" = let template = "" in let source = "a" in - all (module Alpha) ~configuration template source |> print_matches; - [%expect_exact {|[]|}]; - all (module Omega) ~configuration template source |> print_matches; + all ~configuration template source |> print_matches; [%expect_exact {|[]|}] let%expect_test "dont_get_stuck" = let template = "a" in let source = "a" in - all (module Alpha) template source |> print_matches; - [%expect_exact - {|[ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 1, "line": 1, "column": 2 } - }, - "environment": [], - "matched": "a" - } -]|}]; - all (module Omega) template source |> print_matches; + all template source |> print_matches; [%expect_exact {|[ { @@ -56,35 +42,7 @@ let%expect_test "dont_get_stuck" = let%expect_test "dont_get_stuck" = let template = "a" in let source = "aaa" in - all (module Alpha) template source |> print_matches; - [%expect_exact - {|[ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 1, "line": 1, "column": 2 } - }, - "environment": [], - "matched": "a" - }, - { - "range": { - "start": { "offset": 1, "line": 1, "column": 2 }, - "end": { "offset": 2, "line": 1, "column": 3 } - }, - "environment": [], - "matched": "a" - }, - { - "range": { - "start": { "offset": 2, "line": 1, "column": 3 }, - "end": { "offset": 3, "line": 1, "column": 4 } - }, - "environment": [], - "matched": "a" - } -]|}]; - all (module Omega) template source |> print_matches; + all template source |> print_matches; [%expect_exact {|[ { @@ -117,45 +75,20 @@ let%expect_test "rewrite_awesome_1" = let template = "replace this :[1] end" in let source = "xreplace this () end" in let rewrite_template = "X" in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact "xX"]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact "xX"] let%expect_test "rewrite_whole_template_matches" = let template = {|rewrite :[1] <- this string|} in let source = {|rewrite hello world <- this string|} in let rewrite_template = "?" in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact "?"]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact "?"] let%expect_test "single_token" = let template = {|:[[1]] this|} in let source = {|the problem is this|} in - all (module Alpha) template source |> print_matches; - [%expect_exact - {|[ - { - "range": { - "start": { "offset": 12, "line": 1, "column": 13 }, - "end": { "offset": 19, "line": 1, "column": 20 } - }, - "environment": [ - { - "variable": "1", - "value": "is", - "range": { - "start": { "offset": 12, "line": 1, "column": 13 }, - "end": { "offset": 14, "line": 1, "column": 15 } - } - } - ], - "matched": "is this" - } -]|}]; - all (module Omega) template source |> print_matches; + all template source |> print_matches; [%expect_exact {|[ { @@ -180,28 +113,7 @@ let%expect_test "single_token" = let%expect_test "single_token_with_preceding_whitespace" = let template = {| :[[1]] this|} in let source = {|the problem is this|} in - all (module Alpha) template source |> print_matches; - [%expect_exact - {|[ - { - "range": { - "start": { "offset": 11, "line": 1, "column": 12 }, - "end": { "offset": 19, "line": 1, "column": 20 } - }, - "environment": [ - { - "variable": "1", - "value": "is", - "range": { - "start": { "offset": 12, "line": 1, "column": 13 }, - "end": { "offset": 14, "line": 1, "column": 15 } - } - } - ], - "matched": " is this" - } -]|}]; - all (module Omega) template source |> print_matches; + all template source |> print_matches; [%expect_exact {|[ { @@ -227,36 +139,28 @@ let%expect_test "single_token_rewrite" = let template = {| :[[1]] this|} in let source = {|the problem is this|} in let rewrite_template = ":[1]" in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact "the problemis"]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact "the problemis"] let%expect_test "single_token_match_inside_paren_no_succeeding_whitespace" = let template = {|:[[1]](:[[2]])|} in let source = {|foo(bar)|} in let rewrite_template = ":[1] : :[2]" in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact "foo : bar"]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact "foo : bar"] let%expect_test "whitespace_hole_rewrite" = let template = {|:[ w]this|} in let rewrite_template = "space:[ w]here" in let source = {| this|} in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact "space here"]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact "space here"] let%expect_test "punctuation_hole_rewrite" = let template = {|:[x.]|} in let rewrite_template = "->:[x.]<-" in let source = {|now.this. is,pod|racing|} in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact "->now.this.<- ->is,pod|racing<-"]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact "->now.this.<- ->is,pod|racing<-"] let%expect_test "newline_hole_rewrite" = @@ -265,36 +169,13 @@ let%expect_test "newline_hole_rewrite" = let source = {|now.this. is,pod|racing |} in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact "->now.this.\n<-->is,pod|racing\n<-"]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact "->now.this.\n<-->is,pod|racing\n<-"] let%expect_test "shift_or_at_least_dont_get_stuck" = let template = ":[1]" in let source = "a" in - all (module Alpha) ~configuration template source |> print_matches; - [%expect_exact - {|[ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 1, "line": 1, "column": 2 } - }, - "environment": [ - { - "variable": "1", - "value": "a", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 1, "line": 1, "column": 2 } - } - } - ], - "matched": "a" - } -]|}]; - all (module Omega) ~configuration template source |> print_matches; + all ~configuration template source |> print_matches; [%expect_exact {|[ { @@ -319,28 +200,7 @@ let%expect_test "shift_or_at_least_dont_get_stuck" = let%expect_test "shift_or_at_least_dont_get_stuck" = let template = ":[1]" in let source = "aa" in - all (module Alpha) ~configuration template source |> print_matches; - [%expect_exact - {|[ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 2, "line": 1, "column": 3 } - }, - "environment": [ - { - "variable": "1", - "value": "aa", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 2, "line": 1, "column": 3 } - } - } - ], - "matched": "aa" - } -]|}]; - all (module Omega) ~configuration template source |> print_matches; + all ~configuration template source |> print_matches; [%expect_exact {|[ { @@ -369,9 +229,7 @@ let%expect_test "nested_rewrite1" = let template = {| strcpy(:[1], :[2]) |} in - all (module Alpha) ~configuration template source |> print_matches; - [%expect_exact "[]"]; - all (module Omega) ~configuration template source |> print_matches; + all ~configuration template source |> print_matches; [%expect_exact "[]"] (* FIXME(RVT) nested rewrites *) @@ -397,16 +255,7 @@ let%expect_test "nested_rewrite2" = |} in let rewrite_template = "for :[defines] := range :[var_use] {:[inner_body]}" in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact - {|for _, field := range fields.List { - if field.Names != nil { - for _, fieldName := range field.Names { - stuff with fields and things - } - } - }|}]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact {|for _, field := range fields.List { if field.Names != nil { @@ -425,11 +274,7 @@ let%expect_test "match_:[[1]]" = } |} in let rewrite_template = "next(:[1])" in - rewrite_all (module Alpha) template source rewrite_template |> print_string; - [%expect_exact {| - col_names =next(reader)} - |}]; - rewrite_all (module Omega) template source rewrite_template |> print_string; + rewrite_all template source rewrite_template |> print_string; [%expect_exact {| col_names =next(reader)} |}] diff --git a/test/common/test_match_chunk_conversion.ml b/test/common/test_match_chunk_conversion.ml index 9a7ed0a3..90a011f4 100644 --- a/test/common/test_match_chunk_conversion.ml +++ b/test/common/test_match_chunk_conversion.ml @@ -20,7 +20,7 @@ foo( g|} in let template = ":[x~\\w+](:[y])" in let matches = - Alpha.Generic.all ~configuration ~template ~source () + Generic.all ~configuration ~template ~source () |> List.map ~f:(Match.convert_offset ~fast:true ~source) |> Match.to_chunks source |> (fun m -> `List (List.map m ~f:Match.chunk_match_to_yojson)) diff --git a/test/common/test_match_offsets.ml b/test/common/test_match_offsets.ml index 1fea4eb3..f66eccdb 100644 --- a/test/common/test_match_offsets.ml +++ b/test/common/test_match_offsets.ml @@ -5,12 +5,7 @@ open Matchers let%expect_test "correct_match_offsets_regex" = let source = "foo bar foobar" in let match_template = {|:[x~\s*]|} in - (*let rewrite_template = "(:[x])" in*) - run_all_matches (module Alpha.Generic) source match_template; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":0,"line":1,"column":1}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":0,"line":1,"column":1}}}],"matched":""},{"range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":1,"line":1,"column":2}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":1,"line":1,"column":2}}}],"matched":""},{"range":{"start":{"offset":2,"line":1,"column":3},"end":{"offset":2,"line":1,"column":3}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":2,"line":1,"column":3},"end":{"offset":2,"line":1,"column":3}}}],"matched":""},{"range":{"start":{"offset":3,"line":1,"column":4},"end":{"offset":4,"line":1,"column":5}},"environment":[{"variable":"x","value":" ","range":{"start":{"offset":3,"line":1,"column":4},"end":{"offset":4,"line":1,"column":5}}}],"matched":" "},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":4,"line":1,"column":5}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":4,"line":1,"column":5}}}],"matched":""},{"range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":5,"line":1,"column":6}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":5,"line":1,"column":6}}}],"matched":""},{"range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":6,"line":1,"column":7}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":6,"line":1,"column":7}}}],"matched":""},{"range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"x","value":" ","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":8,"line":1,"column":9}}}],"matched":" "},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":8,"line":1,"column":9}}}],"matched":""},{"range":{"start":{"offset":9,"line":1,"column":10},"end":{"offset":9,"line":1,"column":10}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":9,"line":1,"column":10},"end":{"offset":9,"line":1,"column":10}}}],"matched":""},{"range":{"start":{"offset":10,"line":1,"column":11},"end":{"offset":10,"line":1,"column":11}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":10,"line":1,"column":11},"end":{"offset":10,"line":1,"column":11}}}],"matched":""},{"range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":11,"line":1,"column":12}}}],"matched":""},{"range":{"start":{"offset":12,"line":1,"column":13},"end":{"offset":12,"line":1,"column":13}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":12,"line":1,"column":13},"end":{"offset":12,"line":1,"column":13}}}],"matched":""},{"range":{"start":{"offset":13,"line":1,"column":14},"end":{"offset":13,"line":1,"column":14}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":13,"line":1,"column":14},"end":{"offset":13,"line":1,"column":14}}}],"matched":""}]} -|}]; - run_all_matches (module Omega.Generic) source match_template; + run_all_matches (module Generic) source match_template; [%expect_exact {|{"uri":null,"matches":[{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":0,"line":1,"column":1}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":0,"line":1,"column":1}}}],"matched":""},{"range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":1,"line":1,"column":2}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":1,"line":1,"column":2},"end":{"offset":1,"line":1,"column":2}}}],"matched":""},{"range":{"start":{"offset":2,"line":1,"column":3},"end":{"offset":2,"line":1,"column":3}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":2,"line":1,"column":3},"end":{"offset":2,"line":1,"column":3}}}],"matched":""},{"range":{"start":{"offset":3,"line":1,"column":4},"end":{"offset":4,"line":1,"column":5}},"environment":[{"variable":"x","value":" ","range":{"start":{"offset":3,"line":1,"column":4},"end":{"offset":4,"line":1,"column":5}}}],"matched":" "},{"range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":4,"line":1,"column":5}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":4,"line":1,"column":5},"end":{"offset":4,"line":1,"column":5}}}],"matched":""},{"range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":5,"line":1,"column":6}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":5,"line":1,"column":6},"end":{"offset":5,"line":1,"column":6}}}],"matched":""},{"range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":6,"line":1,"column":7}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":6,"line":1,"column":7},"end":{"offset":6,"line":1,"column":7}}}],"matched":""},{"range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"x","value":" ","range":{"start":{"offset":7,"line":1,"column":8},"end":{"offset":8,"line":1,"column":9}}}],"matched":" "},{"range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":8,"line":1,"column":9}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":8,"line":1,"column":9},"end":{"offset":8,"line":1,"column":9}}}],"matched":""},{"range":{"start":{"offset":9,"line":1,"column":10},"end":{"offset":9,"line":1,"column":10}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":9,"line":1,"column":10},"end":{"offset":9,"line":1,"column":10}}}],"matched":""},{"range":{"start":{"offset":10,"line":1,"column":11},"end":{"offset":10,"line":1,"column":11}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":10,"line":1,"column":11},"end":{"offset":10,"line":1,"column":11}}}],"matched":""},{"range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":11,"line":1,"column":12}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":11,"line":1,"column":12},"end":{"offset":11,"line":1,"column":12}}}],"matched":""},{"range":{"start":{"offset":12,"line":1,"column":13},"end":{"offset":12,"line":1,"column":13}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":12,"line":1,"column":13},"end":{"offset":12,"line":1,"column":13}}}],"matched":""},{"range":{"start":{"offset":13,"line":1,"column":14},"end":{"offset":13,"line":1,"column":14}},"environment":[{"variable":"x","value":"","range":{"start":{"offset":13,"line":1,"column":14},"end":{"offset":13,"line":1,"column":14}}}],"matched":""}]} |}] diff --git a/test/common/test_match_rule.ml b/test/common/test_match_rule.ml index db82d4ee..341626a1 100644 --- a/test/common/test_match_rule.ml +++ b/test/common/test_match_rule.ml @@ -4,15 +4,20 @@ open Matchers open Match open Test_helpers -let sat ?(env = Match.Environment.create ()) (module E : Engine.S) rule = +let sat ?(env = Match.Environment.create ()) rule = let rule = Rule.create rule |> Or_error.ok_exn in Format.sprintf "%b" Rule.( - sat @@ apply ~substitute_in_place:true ~match_all:(E.Generic.all ~rule:[ Ast.True ]) rule env) + sat + @@ apply + ~substitute_in_place:true + ~match_all:(Matchers.Generic.all ~rule:[ Ast.True ]) + rule + env) -let run (module E : Engine.S) template source rule = - let (module M : Matcher.S) = (module E.Generic) in +let run template source rule = + let (module M : Matcher.S) = (module Matchers.Generic) in M.all ~configuration ~template ~source () |> List.filter ~f:(fun { environment; _ } -> Rule.( @@ -21,57 +26,37 @@ let run (module E : Engine.S) template source rule = let%expect_test "rule_sat" = let rule = {| where "x" != "y" |} in - sat (module Alpha) rule |> print_string; - [%expect_exact {|true|}]; - sat (module Omega) rule |> print_string; + sat rule |> print_string; [%expect_exact {|true|}]; let rule = {| where "x" != "x" |} in - sat (module Alpha) rule |> print_string; - [%expect_exact {|false|}]; - sat (module Omega) rule |> print_string; + sat rule |> print_string; [%expect_exact {|false|}]; let rule = {| where "x" == "x" |} in - sat (module Alpha) rule |> print_string; - [%expect_exact {|true|}]; - sat (module Omega) rule |> print_string; + sat rule |> print_string; [%expect_exact {|true|}]; let rule = {| where "x" == "y" |} in - sat (module Alpha) rule |> print_string; - [%expect_exact {|false|}]; - sat (module Omega) rule |> print_string; + sat rule |> print_string; [%expect_exact {|false|}]; let rule = {| where :[x] == "y" |} in - sat (module Alpha) rule |> print_string; - [%expect_exact {|false|}]; - sat (module Omega) rule |> print_string; + sat rule |> print_string; [%expect_exact {|false|}]; let rule = {| where :[x] == :[x] |} in - sat (module Alpha) rule |> print_string; - [%expect_exact {|true|}]; - sat (module Omega) rule |> print_string; + sat rule |> print_string; [%expect_exact {|true|}] let%expect_test "rule_sat_with_env" = let env = make_env [ "1", "x"; "2", "y"; "3", "x" ] in let rule = {| where :[1] == :[3], :[1] != :[2] |} in - sat (module Alpha) ~env rule |> print_string; - [%expect_exact {|true|}]; - sat (module Omega) ~env rule |> print_string; + sat ~env rule |> print_string; [%expect_exact {|true|}]; let rule = {| where :[1] == :[3], :[1] != "y" |} in - sat (module Alpha) ~env rule |> print_string; - [%expect_exact {|true|}]; - sat (module Omega) ~env rule |> print_string; + sat ~env rule |> print_string; [%expect_exact {|true|}]; let rule = {| where :[1] == :[3], :[1] == "x" |} in - sat (module Alpha) ~env rule |> print_string; - [%expect_exact {|true|}]; - sat (module Omega) ~env rule |> print_string; + sat ~env rule |> print_string; [%expect_exact {|true|}]; let rule = {| where :[1] == :[2], :[1] != :[2] |} in - sat (module Alpha) ~env rule |> print_string; - [%expect_exact {|false|}]; - sat (module Omega) ~env rule |> print_string; + sat ~env rule |> print_string; [%expect_exact {|false|}] let%expect_test "where_true" = @@ -83,29 +68,7 @@ let%expect_test "where_true" = |} |> format in let rule = {| where true |} |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 11, "line": 1, "column": 12 } - }, - "environment": [ - { - "variable": "1", - "value": "b,c", - "range": { - "start": { "offset": 1, "line": 1, "column": 2 }, - "end": { "offset": 4, "line": 1, "column": 5 } - } - } - ], - "matched": "(b,c) => {}" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -144,10 +107,7 @@ let%expect_test "match_sat" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect {| - [] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [] |}]; let rule = @@ -159,29 +119,7 @@ let%expect_test "match_sat" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 11, "line": 1, "column": 12 } - }, - "environment": [ - { - "variable": "1", - "value": "b,c", - "range": { - "start": { "offset": 1, "line": 1, "column": 2 }, - "end": { "offset": 4, "line": 1, "column": 5 } - } - } - ], - "matched": "(b,c) => {}" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -217,29 +155,7 @@ let%expect_test "match_sat" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 9, "line": 1, "column": 10 } - }, - "environment": [ - { - "variable": "1", - "value": "a", - "range": { - "start": { "offset": 1, "line": 1, "column": 2 }, - "end": { "offset": 2, "line": 1, "column": 3 } - } - } - ], - "matched": "(a) => {}" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -272,29 +188,7 @@ let%expect_test "match_sat" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 9, "line": 1, "column": 10 } - }, - "environment": [ - { - "variable": "1", - "value": "a", - "range": { - "start": { "offset": 1, "line": 1, "column": 2 }, - "end": { "offset": 2, "line": 1, "column": 3 } - } - } - ], - "matched": "(a) => {}" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -326,10 +220,7 @@ let%expect_test "match_sat" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect {| - [] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [] |}] @@ -338,29 +229,7 @@ let%expect_test "match_s_suffix" = let source = "names" in let rule = {| where true |} |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 5, "line": 1, "column": 6 } - }, - "environment": [ - { - "variable": "1", - "value": "name", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 4, "line": 1, "column": 5 } - } - } - ], - "matched": "names" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -388,29 +257,7 @@ let%expect_test "match_s_suffix" = let source = "names" in let rule = {| where true |} |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 5, "line": 1, "column": 6 } - }, - "environment": [ - { - "variable": "1", - "value": "names", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 5, "line": 1, "column": 6 } - } - } - ], - "matched": "names" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -442,10 +289,7 @@ let%expect_test "configuration_choice_based_on_case" = } |} |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect {| - [] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [] |}]; let template = ":[1]" in @@ -456,29 +300,7 @@ let%expect_test "configuration_choice_based_on_case" = } |} |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 5, "line": 1, "column": 6 } - }, - "environment": [ - { - "variable": "1", - "value": "names", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 5, "line": 1, "column": 6 } - } - } - ], - "matched": "names" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -508,10 +330,7 @@ let%expect_test "configuration_choice_based_on_case" = } |} |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect {| - [] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [] |}] @@ -524,29 +343,7 @@ let%expect_test "match_using_environment_merge" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 21, "line": 1, "column": 22 } - }, - "environment": [ - { - "variable": "1", - "value": "{ a : a } { a : a }", - "range": { - "start": { "offset": 1, "line": 1, "column": 2 }, - "end": { "offset": 20, "line": 1, "column": 21 } - } - } - ], - "matched": "{{ a : a } { a : a }}" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -576,10 +373,7 @@ let%expect_test "match_using_environment_merge" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect {| - [] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [] |}] @@ -598,29 +392,7 @@ let%expect_test "nested_matches" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 37, "line": 1, "column": 38 } - }, - "environment": [ - { - "variable": "1", - "value": "{ { foo : { bar : { baz : qux } } } }", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 37, "line": 1, "column": 38 } - } - } - ], - "matched": "{ { foo : { bar : { baz : qux } } } }" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -656,10 +428,7 @@ let%expect_test "nested_matches" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect {| - [] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [] |}] @@ -674,29 +443,7 @@ let%expect_test "match_on_template" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 6, "line": 1, "column": 7 } - }, - "environment": [ - { - "variable": "1", - "value": "oodles", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 6, "line": 1, "column": 7 } - } - } - ], - "matched": "oodles" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -728,29 +475,7 @@ let%expect_test "match_on_template" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect - {| - [ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 6, "line": 1, "column": 7 } - }, - "environment": [ - { - "variable": "1", - "value": "poodle", - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 6, "line": 1, "column": 7 } - } - } - ], - "matched": "poodle" - } - ] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [ @@ -782,9 +507,6 @@ let%expect_test "match_on_template" = |> Rule.create |> Or_error.ok_exn in - run (module Alpha) template source rule |> print_matches; - [%expect {| - [] |}]; - run (module Omega) template source rule |> print_matches; + run template source rule |> print_matches; [%expect {| [] |}] diff --git a/test/common/test_nested_comments.ml b/test/common/test_nested_comments.ml index 2edda995..0112f731 100644 --- a/test/common/test_nested_comments.ml +++ b/test/common/test_nested_comments.ml @@ -4,16 +4,38 @@ open Matchers open Test_helpers (* See https://stackoverflow.com/questions/6698039/nested-comments-in-c-c *) -let%expect_test "nested_multiline_ocaml" = +let%expect_test "nested_multiline_c" = let source = {|int nest = /*/*/ 0 */**/ 1;|} in let template = {|0 * 1|} in - (* 0 is not commented out *) - Alpha.C.all ~configuration ~template ~source () |> print_only_match; + C.all ~configuration ~template ~source () |> print_only_match; [%expect_exact {|[ "0 */**/ 1" ]|}]; - Omega.C.all ~configuration ~template ~source () |> print_only_match; - [%expect_exact {|[ "0 */**/ 1" ]|}]; - (* 0 is commented out *) - Alpha.C_nested_comments.all ~configuration ~template ~source () |> print_only_match; - [%expect_exact {|[]|}]; - Omega.C_nested_comments.all ~configuration ~template ~source () |> print_only_match; + C_nested_comments.all ~configuration ~template ~source () |> print_only_match; + [%expect_exact {|[]|}] + +let%expect_test "nested_multiline_ocaml_comments_are_skipped" = + let source = {|(* let commented = 2 (* nested *) *) +let live = 1|} in + let template = {|let commented = :[value]|} in + OCaml.all ~configuration ~template ~source () |> print_only_match; + [%expect_exact {|[]|}] + +let%expect_test "nested_multiline_haskell_comments_are_skipped" = + let source = {|{- let commented = 2 {- nested -} -} +let live = 1|} in + let template = {|let commented = :[value]|} in + Haskell.all ~configuration ~template ~source () |> print_only_match; + [%expect_exact {|[]|}] + +let%expect_test "nested_multiline_nim_comments_are_skipped" = + let source = {|#[ let commented = 2 #[ nested ]# ]# +let live = 1|} in + let template = {|let commented = :[value]|} in + Nim.all ~configuration ~template ~source () |> print_only_match; + [%expect_exact {|[]|}] + +let%expect_test "nested_multiline_julia_comments_are_skipped" = + let source = {|#= commented = 2 #= nested =# =# +live = 1|} in + let template = {|commented = :[value]|} in + Julia.all ~configuration ~template ~source () |> print_only_match; [%expect_exact {|[]|}] diff --git a/test/common/test_nested_matches.ml b/test/common/test_nested_matches.ml index 30d27e33..58228332 100644 --- a/test/common/test_nested_matches.ml +++ b/test/common/test_nested_matches.ml @@ -22,17 +22,7 @@ q{ } |} in let match_template = {|:[[f]]{:[x]}|} in - run_all_matches (module Alpha.Generic) ~format source ~rule match_template; - [%expect_exact - {|2:a{\n b{\n c{\n d{e}\n }\n }\n } -3:b{\n c{\n d{e}\n }\n } -4:c{\n d{e}\n } -5:d{e} -10:q{\n b{\n f{}\n }\n} -11:b{\n f{}\n } -12:f{} -|}]; - run_all_matches (module Omega.Generic) ~format source ~rule match_template; + run_all_matches (module Generic) ~format source ~rule match_template; [%expect_exact {|2:a{\n b{\n c{\n d{e}\n }\n }\n } 3:b{\n c{\n d{e}\n }\n } @@ -44,13 +34,7 @@ q{ |}]; let source = {|a(b(c(d(e))))|} in let match_template = {|:[[f]](:[x])|} in - run_all_matches (module Alpha.Generic) ~format source ~rule match_template; - [%expect_exact {|1:a(b(c(d(e)))) -1:b(c(d(e))) -1:c(d(e)) -1:d(e) -|}]; - run_all_matches (module Omega.Generic) ~format source ~rule match_template; + run_all_matches (module Generic) ~format source ~rule match_template; [%expect_exact {|1:a(b(c(d(e)))) 1:b(c(d(e))) 1:c(d(e)) diff --git a/test/common/test_offset_conversion.ml b/test/common/test_offset_conversion.ml index b9f1b863..33e69591 100644 --- a/test/common/test_offset_conversion.ml +++ b/test/common/test_offset_conversion.ml @@ -15,7 +15,7 @@ let run source match_template format : string * string = let run ~fast = let result = Pipeline.process_single_source - (module Matchers.Omega.C) + (module Matchers.C) ~fast_offset_conversion:fast configuration (String source) diff --git a/test/common/test_pipeline.ml b/test/common/test_pipeline.ml index 9866daad..746e9826 100644 --- a/test/common/test_pipeline.ml +++ b/test/common/test_pipeline.ml @@ -3,8 +3,8 @@ open Command_configuration open Comby_kernel open Matchers -let configuration (module E : Engine.S) = - { matcher = (module E.Generic : Matchers.Matcher.S) +let configuration = + { matcher = (module Generic : Matchers.Matcher.S) ; sources = `String "source" ; specifications = [] ; run_options = diff --git a/test/common/test_python_string_literals.ml b/test/common/test_python_string_literals.ml index c4ee555e..53f1dd6d 100644 --- a/test/common/test_python_string_literals.ml +++ b/test/common/test_python_string_literals.ml @@ -3,54 +3,40 @@ open Comby_kernel open Matchers open Test_helpers -let all (module E : Engine.S) ~template ~source = E.Python.all ~configuration ~template ~source () +let all ~template ~source = Python.all ~configuration ~template ~source () let%expect_test "matched_contains_raw_literal_quotes" = let source = {|"""blah"""|} in let template = {|""":[[1]]"""|} in - all (module Alpha) ~template ~source |> print_only_match; - [%expect_exact {|[ "\"\"\"blah\"\"\"" ]|}]; - all (module Omega) ~template ~source |> print_only_match; + all ~template ~source |> print_only_match; [%expect_exact {|[ "\"\"\"blah\"\"\"" ]|}] let%expect_test "interpreted_string_does_not_match_raw_literal" = let source = {|"""blah""" "blah"|} in let template = {|":[[1]]"|} in - all (module Alpha) ~template ~source |> print_only_match; - [%expect_exact {|[ "\"blah\"" ]|}]; - all (module Omega) ~template ~source |> print_only_match; + all ~template ~source |> print_only_match; [%expect_exact {|[ "\"blah\"" ]|}] let%expect_test "interpreted_string_does_not_match_raw_literal_containing_quote" = let source = {|"""blah""" """bl"ah""" "blah"|} in let template = {|":[[1]]"|} in - all (module Alpha) ~template ~source |> print_only_match; - [%expect_exact {|[ "\"blah\"" ]|}]; - all (module Omega) ~template ~source |> print_only_match; + all ~template ~source |> print_only_match; [%expect_exact {|[ "\"blah\"" ]|}] let%expect_test "raw_string_matches_string_containing_quote" = let source = {|"""bl"ah"""|} in let template = {|""":[1]"""|} in - all (module Alpha) ~template ~source |> print_only_match; - [%expect_exact {|[ "\"\"\"bl\"ah\"\"\"" ]|}]; - all (module Omega) ~template ~source |> print_only_match; + all ~template ~source |> print_only_match; [%expect_exact {|[ "\"\"\"bl\"ah\"\"\"" ]|}] let%expect_test "invalid_raw_string_in_python_but_matches_because_ignores_after" = let source = {|"""""""|} in let template = {|""":[1]"""|} in - all (module Alpha) ~template ~source |> print_only_match; - [%expect_exact {|[ "\"\"\"\"\"\"" ]|}]; - all (module Omega) ~template ~source |> print_only_match; + all ~template ~source |> print_only_match; [%expect_exact {|[ "\"\"\"\"\"\"" ]|}] -(* Disabled: this works by luck in Alpha, but it shouldn't. It is empty list in Omega. Should be explicitly supported *) -(* let%expect_test "raw_string_captures_escape_sequences" = let source = {|"""\""""|} in let template = {|""":[1]"""|} in - let matches = Python.all ~configuration ~template ~source in - print_only_match matches; + all ~template ~source |> print_only_match; [%expect_exact {|[ "\"\"\"\\\"\"\"" ]|}] -*) diff --git a/test/common/test_regex_holes.ml b/test/common/test_regex_holes.ml index c361a8c3..b1c53710 100644 --- a/test/common/test_regex_holes.ml +++ b/test/common/test_regex_holes.ml @@ -7,36 +7,28 @@ let%expect_test "regex_holes_simple" = let source = {|foo|} in let match_template = {|:[x~\w+]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|(foo)|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|(foo)|}] let%expect_test "regex_holes_simple_posix" = let source = {|foo|} in let match_template = {|:[x~[[:alpha:]]]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|(f)(o)(o)|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|(f)(o)(o)|}] let%expect_test "regex_holes_substring" = let source = {|foo()|} in let match_template = {|:[x~o\w]()|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|f(oo)|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|f(oo)|}] let%expect_test "regex_holes_empty_string_terminates" = let source = {|foo()|} in let match_template = {|:[x~|]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|()f()o()o()(())|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|()f()o()o()(())|}] let%expect_test "regex_holes_repetition_takes_precedence" = @@ -44,35 +36,26 @@ let%expect_test "regex_holes_repetition_takes_precedence" = (* this will _not_ match because bar is consumed by \w before we look ahead *) let match_template = {|:[x~\w+]bar()|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|No matches.|}] let%expect_test "regex_holes_negated_match" = let source = {|(literally_anyting_except_close_paren?!@#$%^&*[])|} in let match_template = {|(:[x~[^)]+])|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|(literally_anyting_except_close_paren?!@#$%^&*[])|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|(literally_anyting_except_close_paren?!@#$%^&*[])|}]; let source = {|(arg1, arg2, arg3)|} in let match_template = {|:[x~[^,() ]+]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|((arg1), (arg2), (arg3))|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|((arg1), (arg2), (arg3))|}] let%expect_test "regex_holes_dot_star_ok_and_this_is_for_newline" = let source = "foo()\nbar()" in let match_template = {|:[x~.*]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|(foo())() -(bar())|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|(foo())() (bar())|}] @@ -80,61 +63,45 @@ let%expect_test "regex_holes_optional" = let source = "nonovember no november no vember" in let match_template = {|:[x~no(vember)?]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|(no)(november) (no) (november) (no) vember|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|(no)(november) (no) (november) (no) vember|}] let%expect_test "regex_holes_optional_spaces" = let source = "nonovember no november no vember" in let match_template = {|no :[x~(vember)?]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|nonovember ()november (vember)|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|nonovember ()november (vember)|}] let%expect_test "regex_holes_optional_doesnt_work_outside_regex" = let source = "no" in let match_template = {|no:[x~(vember)?]|} in let rewrite_template = {|(:[x])|} in - (* Note: Known Alpha limitation: this behavior does _not_ allow (optional)? to match - empty string to sat template. Because of something tricky. *) - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|()|}]; let source = "foo bar foobar" in let match_template = {|:[x~\s*?]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|()f()o()o() ()b()a()r() ()f()o()o()b()a()r|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|()f()o()o() ()b()a()r() ()f()o()o()b()a()r|}]; let source = "foo bar foobar" in let match_template = {|:[x~\s*]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|()f()o()o( )()b()a()r( )()f()o()o()b()a()r|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|()f()o()o( )()b()a()r( )()f()o()o()b()a()r|}] let%expect_test "regex_holes_optional_strip_no_from_november_outside_regex" = let source = "nonovember no november no vember" in let match_template = {|no:[x~(vember)?]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|()(vember) () (vember) () vember|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|()(vember) () (vember) () vember|}] let%expect_test "regex_holes_optional_strip_no_from_november_inside_regex" = let source = "nonovember no november no vember" in let match_template = {|:[x~no(vember)?]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|(no)(november) (no) (november) (no) vember|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|(no)(november) (no) (november) (no) vember|}] let%expect_test "leading_spaces_beginning_line_anchor" = @@ -145,10 +112,7 @@ let%expect_test "leading_spaces_beginning_line_anchor" = |} in let match_template = {|:[x~^(\s+)]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|( )a( )b( )c -|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|( )a( )b( )c |}] @@ -161,16 +125,7 @@ let%expect_test "spaces_star" = |} in let match_template = {|:[x~\s*]|} in let rewrite_template = {|(:[x])|} in - (* The chars is how this behaves on - https://regexr.com/59ft0 as well, see replace *) - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|( - )()a( - )()b( - )()c( - )()d( -)|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|( )()a( )()b( @@ -186,12 +141,7 @@ ccc ddd |} in let match_template = {|:[x~\w+ bbb$]|} in let rewrite_template = {|(:[x])|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {| -(aaa bbb)aaa bbb ccc -ccc ddd -|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {| (aaa bbb)aaa bbb ccc ccc ddd @@ -206,14 +156,7 @@ foo(bar, baz(), |} in let match_template = {|:[x~\b\w+\b]|} in let rewrite_template = {|(>:[x]<)|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {| -(>foo<)((>bar<), (>baz<)(), - - - (>qux<).(>derp<)) -|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {| (>foo<)((>bar<), (>baz<)(), @@ -233,14 +176,7 @@ foo(bar, baz(), |} in let match_template = {|:[x~[^, ]+]|} in let rewrite_template = {|(>:[x]<)|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {|(> -foo(bar<), (>baz()<),(> - - -<) (>qux.derp) -<)|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {|(> foo(bar<), (>baz()<),(> @@ -257,14 +193,7 @@ foo(bar, baz(), |} in let match_template = {|:[x~[^,\s]+]|} in let rewrite_template = {|(>:[x]<)|} in - run (module Alpha.Generic) source match_template rewrite_template; - [%expect_exact {| -(>foo(bar<), (>baz()<), - - - (>qux.derp)<) -|}]; - run (module Omega.Generic) source match_template rewrite_template; + run (module Generic) source match_template rewrite_template; [%expect_exact {| (>foo(bar<), (>baz()<), @@ -299,23 +228,7 @@ setScore(4/3) |} in let rewrite_template = "setScore( /*CHECK ME*/ :[1])" in - run (module Alpha.Generic) source match_template ~rule rewrite_template; - [%expect_exact - {| -setScore(5) -setScore(6) -setScore( /*CHECK ME*/ 6.5) -setScore( /*CHECK ME*/ "") -setScore( /*CHECK ME*/ "hi") -setScore( /*CHECK ME*/ "hi" + "there") -setScore( /*CHECK ME*/ 'ho') -setScore( /*CHECK ME*/ x) -setScore( /*CHECK ME*/ null) -setScore( /*CHECK ME*/ 4/3.0) -setScore( /*CHECK ME*/ 4.0/3.0) -setScore( /*CHECK ME*/ 4/3) -|}]; - run (module Omega.Generic) source match_template ~rule rewrite_template; + run (module Generic) source match_template ~rule rewrite_template; [%expect_exact {| setScore(5) diff --git a/test/common/test_rewrite_attributes.ml b/test/common/test_rewrite_attributes.ml index 4886545e..a6747051 100644 --- a/test/common/test_rewrite_attributes.ml +++ b/test/common/test_rewrite_attributes.ml @@ -16,7 +16,7 @@ let%expect_test "strings" = |} in run - (module Matchers.Alpha.Generic) + (module Matchers.Generic) source {| :[[a]] @@ -54,17 +54,7 @@ let%expect_test "filepath_rewrite_template" = let source = {|whatever|} in let filepath = "this/is/a/path" in run - (module Matchers.Alpha.Generic) - ~filepath - source - ":[all]" - "\n:[all].file.path\n:[all].file.name\n:[all].file.directory"; - [%expect_exact {| -this/is/a/path -path -this/is/a|}]; - run - (module Matchers.Omega.Generic) + (module Matchers.Generic) ~filepath source ":[all]" @@ -79,9 +69,7 @@ let%expect_test "filepath_rule" = let filepath = "this/is/a/path" in let match_template = ":[x]" in let rule = {|where rewrite :[x] { _ -> :[x].file.path }|} in - run (module Matchers.Alpha.Generic) ~filepath source ~rule match_template "ok: :[x]"; - [%expect_exact {|ok: this/is/a/path|}]; - run (module Matchers.Omega.Generic) ~filepath source ~rule match_template "ok: :[x]"; + run (module Matchers.Generic) ~filepath source ~rule match_template "ok: :[x]"; [%expect_exact {|ok: this/is/a/path|}] let%expect_test "lines" = @@ -96,12 +84,7 @@ let%expect_test "lines" = |} in let match_template = "{:[x]}" in let rewrite_template = {|:[x].lines|} in - run (module Matchers.Alpha.Generic) source match_template rewrite_template; - [%expect_exact {| - 2 - 3 -|}]; - run (module Matchers.Omega.Generic) source match_template rewrite_template; + run (module Matchers.Generic) source match_template rewrite_template; [%expect_exact {| 2 3 @@ -125,38 +108,7 @@ column.start: :[[x]].column.start // can't compute without source yet column.end: :[[x]].column.end // can't compute without source yet |} in - run (module Matchers.Alpha.Generic) source match_template rewrite_template; - [%expect_exact - {| - -offset: 1 -offset.start: 1 -offset.end: 6 -line.start: :[[x]].line.start // can't compute without source yet -line.end: :[[x]].line.end // can't compute without source yet -column.start: :[[x]].column.start // can't compute without source yet -column.end: :[[x]].column.end // can't compute without source yet - -< > -offset: 11 -offset.start: 11 -offset.end: 17 -line.start: :[[x]].line.start // can't compute without source yet -line.end: :[[x]].line.end // can't compute without source yet -column.start: :[[x]].column.start // can't compute without source yet -column.end: :[[x]].column.end // can't compute without source yet - -< > -offset: 25 -offset.start: 25 -offset.end: 30 -line.start: :[[x]].line.start // can't compute without source yet -line.end: :[[x]].line.end // can't compute without source yet -column.start: :[[x]].column.start // can't compute without source yet -column.end: :[[x]].column.end // can't compute without source yet - -|}]; - run (module Matchers.Omega.Generic) source match_template rewrite_template; + run (module Matchers.Generic) source match_template rewrite_template; [%expect_exact {| diff --git a/test/common/test_rewrite_parts.ml b/test/common/test_rewrite_parts.ml index b6c1b7fe..5f80841b 100644 --- a/test/common/test_rewrite_parts.ml +++ b/test/common/test_rewrite_parts.ml @@ -4,7 +4,7 @@ open Comby_kernel open Matchers let all ?(configuration = configuration) template source = - Alpha.C.all ~configuration ~template ~source () + C.all ~configuration ~template ~source () let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_by_fuzzy" = let source = {|123433312343331122|} in diff --git a/test/common/test_rewrite_rule.ml b/test/common/test_rewrite_rule.ml index 84e7885e..cbabf78e 100644 --- a/test/common/test_rewrite_rule.ml +++ b/test/common/test_rewrite_rule.ml @@ -10,9 +10,7 @@ let%expect_test "rewrite_rule" = let rule = {| where rewrite :[1] { "int" -> "expect" } |} in - run (module Alpha.Generic) source match_template rewrite_template ~rule; - [%expect_exact {|expect|}]; - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {|expect|}] let%expect_test "sequenced_rewrite_rule" = @@ -26,9 +24,7 @@ let%expect_test "sequenced_rewrite_rule" = rewrite :[rest] { "{ b : { :[other] } }" -> "{ :[other] }" } |} in - run (module Alpha.Generic) source match_template rewrite_template ~rule; - [%expect_exact {|{ { qqq : { c : d } } }|}]; - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {|{ { qqq : { c : d } } }|}] let%expect_test "rewrite_rule_for_list" = @@ -38,9 +34,7 @@ let%expect_test "rewrite_rule_for_list" = let rule = {| where rewrite :[contents] { ":[[x]]," -> ":[[x]];" } |} in - run (module Alpha.Generic) source match_template rewrite_template ~rule; - [%expect_exact {|[1; 2; 3; 4;]|}]; - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {|[1; 2; 3; 4;]|}] let%expect_test "rewrite_rule_for_list_strip_last" = @@ -50,9 +44,7 @@ let%expect_test "rewrite_rule_for_list_strip_last" = let rule = {| where rewrite :[contents] { ":[x], " -> ":[x]; " } |} in - run (module Alpha.Generic) source match_template rewrite_template ~rule; - [%expect_exact {|[1; 2; 3; 4]|}]; - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {|[1; 2; 3; 4]|}] let%expect_test "haskell_example" = @@ -67,13 +59,7 @@ let%expect_test "haskell_example" = let rule = {| where rewrite :[contents] { "," -> "++" } |} in - run (module Alpha.Generic) source match_template rewrite_template ~rule; - [%expect_exact {| - ( "blah blah blah" - ++ "blah" - ) -|}]; - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {| ( "blah blah blah" ++ "blah" @@ -92,11 +78,7 @@ let%expect_test "rewrite_freeform_antecedent_pattern" = let rule = {| where rewrite :[contents] { concat [:[x]] -> "nice" } |} in - run (module Alpha.Generic) source match_template rewrite_template ~rule; - [%expect_exact {|( - (nice) -)|}]; - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {|( (nice) )|}] diff --git a/test/common/test_rule_options.ml b/test/common/test_rule_options.ml index cf942ec3..c7a955a9 100644 --- a/test/common/test_rule_options.ml +++ b/test/common/test_rule_options.ml @@ -13,13 +13,13 @@ foo( let match_template = {|foo(bar)|} in let rewrite_template = {|>yes<|} in let rule = "where true" in - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {| >yes< >yes< >yes< >yes< >yes< |}]; let rule = "where strict" in - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {| foo( bar) >yes< foo( bar ) foo(bar ) foo( @@ -32,11 +32,11 @@ let%expect_test "strict_rule_with_holes" = let match_template = {|foo(:[1])|} in let rewrite_template = {|:[1]|} in let rule = "where true" in - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {| bar |}]; let source = {|foo( bar,x )|} in let match_template = {|foo(bar,:[1])|} in let rewrite_template = {|:[1]|} in let rule = "where true" in - run (module Omega.Generic) source match_template rewrite_template ~rule; + run (module Generic) source match_template rewrite_template ~rule; [%expect_exact {|x |}] diff --git a/test/common/test_statistics.ml b/test/common/test_statistics.ml index 59af655a..df544b68 100644 --- a/test/common/test_statistics.ml +++ b/test/common/test_statistics.ml @@ -19,13 +19,13 @@ let%expect_test "statistics" = in let rule = {| where true |} |> Rule.create |> Or_error.ok_exn in - Alpha.Go.all ~configuration ~template ~source () + Go.all ~configuration ~template ~source () |> List.filter ~f:(fun { environment; _ } -> Rule.( sat @@ apply ~substitute_in_place:true - ~match_all:(Alpha.Generic.all ~rule:[ Ast.True ]) + ~match_all:(Generic.all ~rule:[ Ast.True ]) rule environment)) |> fun matches -> diff --git a/test/common/test_string_literals.ml b/test/common/test_string_literals.ml index 84e67689..b9cfe757 100644 --- a/test/common/test_string_literals.ml +++ b/test/common/test_string_literals.ml @@ -36,36 +36,20 @@ let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_b let source = {|"/*"(x)|} in let template = {|(:[1])|} in let rewrite_template = {|:[1]|} in - rewrite_all (module Alpha.C) template source rewrite_template; - [%expect_exact {|"/*"x|}]; - rewrite_all (module Omega.C) template source rewrite_template; + rewrite_all (module C) template source rewrite_template; [%expect_exact {|"/*"x|}] let%expect_test "comments_in_string_literals_should_not_be_treated_as_comments_by_fuzzy_go_raw" = let source = {|`//`(x)|} in let template = {|(:[1])|} in let rewrite_template = {|:[1]|} in - rewrite_all (module Alpha.Go) template source rewrite_template; - [%expect_exact {|`//`x|}]; - rewrite_all (module Omega.Go) template source rewrite_template; + rewrite_all (module Go) template source rewrite_template; [%expect_exact {|`//`x|}] let%expect_test "tolerate_unbalanced_stuff_in_string_literals" = let template = {|"("|} in let source = {|"("|} in - all (module Alpha.C) ~configuration template source |> print_matches; - [%expect_exact - {|[ - { - "range": { - "start": { "offset": 0, "line": 1, "column": 1 }, - "end": { "offset": 3, "line": 1, "column": 4 } - }, - "environment": [], - "matched": "\"(\"" - } -]|}]; - all (module Omega.C) ~configuration template source |> print_matches; + all (module C) ~configuration template source |> print_matches; [%expect_exact {|[ { @@ -82,45 +66,35 @@ let%expect_test "base_literal_matching" = let source = {|"hello"|} in let match_template = {|":[1]"|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|hello|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|hello|}] let%expect_test "base_literal_matching" = let source = {|rewrite ("hello") this string|} in let match_template = {|rewrite (":[1]") this string|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|hello|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|hello|}] let%expect_test "match_string_literals" = let source = {|rewrite (".") this string|} in let match_template = {|rewrite (":[1]") this string|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|.|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|.|}] let%expect_test "match_string_literals" = let source = {|rewrite ("") this string|} in let match_template = {|rewrite (":[1]") this string|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {||}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {||}] let%expect_test "match_string_literals" = let source = {|"(" match "a""a" this "(" |} in let match_template = {|match :[1] this|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|"(" "a""a" "(" |}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|"(" "a""a" "(" |}] (* this tests special functionality in non-literal hole parser @@ -129,54 +103,42 @@ let%expect_test "match_string_literals" = let source = {|"(" match "(""(" this "(" |} in let match_template = {|match :[1] this|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|"(" "(""(" "(" |}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|"(" "(""(" "(" |}] let%expect_test "match_string_literals" = let source = {|rewrite ("") this string|} in let match_template = {|rewrite (:[1]) this string|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|""|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|""|}] let%expect_test "base_literal_matching" = let source = {|"("|} in let match_template = {|":[1]"|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|(|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|(|}] let%expect_test "base_literal_matching" = let source = {|"(""("|} in let match_template = {|":[1]"|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|((|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|((|}] let%expect_test "base_literal_matching" = let source = {|"(""("|} in let match_template = {|":[1]"|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|((|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|((|}] let%expect_test "base_literal_matching" = let source = {|"hello world"|} in let match_template = {|":[x] :[y]"|} in let rewrite_template = {|:[x] :[y]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|hello world|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|hello world|}] (* complex test: basically, we are checking that the inside of this literal is only matched by the val b part *) @@ -184,99 +146,77 @@ let%expect_test "base_literal_matching" = let source = {|val a = "class = ${String::class}" val b = "not $a"|} in let match_template = {|":[x]$:[[y]]"|} in let rewrite_template = {|(rewritten part: (:[x]) ([y]))|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|val a = "class = ${String::class}" val b = (rewritten part: (not ) ([y]))|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|val a = "class = ${String::class}" val b = (rewritten part: (not ) ([y]))|}] let%expect_test "base_literal_matching" = let source = {|get("type") rekt ("enabled", True)|} in let match_template = {|(":[1]", :[[3]])|} in let rewrite_template = {|(rewritten part: (:[1]) (:[3]))|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|get("type") rekt (rewritten part: (enabled) (True))|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|get("type") rekt (rewritten part: (enabled) (True))|}] let%expect_test "rewrite_string_literals_8" = let source = {|match "\"" this|} in let match_template = {|match "\"" this|} in let rewrite_template = "" in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {||}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {||}] let%expect_test "rewrite_string_literals_8" = let source = {|match "\"" this|} in let match_template = {|match :[1] this|} in let rewrite_template = ":[1]" in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|"\""|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|"\""|}] let%expect_test "rewrite_string_literals_8" = let source = {|match "\"\"" this|} in let match_template = {|match :[1] this|} in let rewrite_template = ":[1]" in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|"\"\""|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|"\"\""|}] let%expect_test "rewrite_string_literals_8" = let source = {|match "\"(\"" "(\"" this|} in let match_template = {|match :[1] this|} in let rewrite_template = ":[1]" in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|"\"(\"" "(\""|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|"\"(\"" "(\""|}] let%expect_test "rewrite_string_literals_8" = let source = {|match "\"(\"" "(\"" this|} in let match_template = {|match ":[1]" ":[2]" this|} in let rewrite_template = {|:[1] :[2]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|\"(\" (\"|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|\"(\" (\"|}] let%expect_test "rewrite_string_literals_8" = let source = {|match 'sin(gle' 'quo(tes' this|} in let match_template = {|:[1]|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|match 'sin(gle' 'quo(tes' this|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|match 'sin(gle' 'quo(tes' this|}] let%expect_test "rewrite_string_literals_8" = let source = {|match '\''|} in let match_template = {|:[1]|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|match '\''|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|match '\''|}] let%expect_test "rewrite_string_literals_8" = let source = {|match 'asdf'|} in let match_template = {|':[1]'|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|match asdf|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|match asdf|}] let%expect_test "rewrite_string_literals_8" = let source = {|match '\''|} in let match_template = {|':[1]'|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.C) match_template source rewrite_template; - [%expect_exact {|match \'|}]; - rewrite_all' (module Omega.C) match_template source rewrite_template; + rewrite_all' (module C) match_template source rewrite_template; [%expect_exact {|match \'|}] let%expect_test "go_raw_string_literals" = @@ -291,16 +231,7 @@ let%expect_test "go_raw_string_literals" = in let match_template = {|`:[1]`|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.Go) match_template source rewrite_template; - [%expect_exact - {| - x = x - y = multi-line - raw str(ing literal - z = other multi-line - raw stri(ng literal - |}]; - rewrite_all' (module Omega.Go) match_template source rewrite_template; + rewrite_all' (module Go) match_template source rewrite_template; [%expect_exact {| x = x @@ -314,18 +245,14 @@ let%expect_test "go_raw_string_literals" = let source = {|blah `(` quux|} in let match_template = {|:[1]|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.Go) match_template source rewrite_template; - [%expect_exact {|blah `(` quux|}]; - rewrite_all' (module Omega.Go) match_template source rewrite_template; + rewrite_all' (module Go) match_template source rewrite_template; [%expect_exact {|blah `(` quux|}] let%expect_test "match_string_literals" = let source = {|`(` match `(``(` this `(` |} in let match_template = {|match :[1] this|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.Go) match_template source rewrite_template; - [%expect_exact {|`(` `(``(` `(` |}]; - rewrite_all' (module Omega.Go) match_template source rewrite_template; + rewrite_all' (module Go) match_template source rewrite_template; [%expect_exact {|`(` `(``(` `(` |}] let%expect_test "go_raw_string_literals" = @@ -340,16 +267,7 @@ let%expect_test "go_raw_string_literals" = in let match_template = {|`:[1]`|} in let rewrite_template = {|:[1]|} in - rewrite_all' (module Alpha.Go) match_template source rewrite_template; - [%expect_exact - {| - x = x - y = multi-line - raw "str"(ing literal - z = other multi-line - raw '"'\"\\s\\\\\tr\ni(ng literal - |}]; - rewrite_all' (module Omega.Go) match_template source rewrite_template; + rewrite_all' (module Go) match_template source rewrite_template; [%expect_exact {| x = x @@ -363,36 +281,28 @@ let%expect_test "regression_matching_kubernetes" = let source = {|"\n" y = 5|} in let template = {|y = :[1]|} in let rewrite_template = {|:[1]|} in - rewrite_all (module Alpha.Go) template source rewrite_template; - [%expect_exact {|"\n" 5|}]; - rewrite_all (module Omega.Go) template source rewrite_template; + rewrite_all (module Go) template source rewrite_template; [%expect_exact {|"\n" 5|}] let%expect_test "match_escaped_any_char" = let source = {|printf("hello world\n");|} in let template = {|printf(":[1]");|} in let rewrite_template = {|:[1]|} in - rewrite_all (module Alpha.Go) template source rewrite_template; - [%expect_exact {|hello world\n|}]; - rewrite_all (module Omega.Go) template source rewrite_template; + rewrite_all (module Go) template source rewrite_template; [%expect_exact {|hello world\n|}] let%expect_test "match_escaped_escaped" = let source = {|printf("hello world\n\\");|} in let template = {|printf(":[1]");|} in let rewrite_template = {|:[1]|} in - rewrite_all (module Alpha.Go) template source rewrite_template; - [%expect_exact {|hello world\n\\|}]; - rewrite_all (module Omega.Go) template source rewrite_template; + rewrite_all (module Go) template source rewrite_template; [%expect_exact {|hello world\n\\|}] let%expect_test "match_escaped_escaped" = let source = {|printf("hello world\n\");|} in let template = {|printf(":[1]");|} in let rewrite_template = {|:[1]|} in - rewrite_all_want_fail_case (module Alpha.Go) template source rewrite_template; - [%expect_exact {|EXPECT SUCCESS|}]; - rewrite_all_want_fail_case (module Omega.Go) template source rewrite_template; + rewrite_all_want_fail_case (module Go) template source rewrite_template; [%expect_exact {|EXPECT SUCCESS|}] let%expect_test "holes_in_raw_literals" = @@ -416,16 +326,7 @@ let%expect_test "holes_in_raw_literals" = |} in let template = {|`:[1]`|} in - head_match (module Alpha.Typescript) template source; - [%expect_exact - {|` - query ResolveRepo($repoName: String!) { - repository(name: $repoName) { - url - } - } - `|}]; - head_match (module Omega.Typescript) template source; + head_match (module Typescript) template source; [%expect_exact {|` query ResolveRepo($repoName: String!) { @@ -456,16 +357,7 @@ let%expect_test "holes_in_raw_literals_partial" = |} in let template = {|` query ResolveRepo(:[1]) {:[2]} `|} in - head_match (module Alpha.Typescript) template source; - [%expect_exact - {|` - query ResolveRepo($repoName: String!) { - repository(name: $repoName) { - url - } - } - `|}]; - head_match (module Omega.Typescript) template source; + head_match (module Typescript) template source; [%expect_exact {|` query ResolveRepo($repoName: String!) { @@ -479,9 +371,7 @@ let%expect_test "dont_detect_comments_in_strings_with_hole_matcher" = let source = {|"// not a comment"|} in let template = {|":[1]"|} in let rewrite_template = {|:[1]|} in - rewrite_all (module Alpha.Go) template source rewrite_template; - [%expect_exact {|// not a comment|}]; - rewrite_all (module Omega.Go) template source rewrite_template; + rewrite_all (module Go) template source rewrite_template; [%expect_exact {|// not a comment|}] (* Deactivated: this will conflict with division syntax *) diff --git a/test/common/test_template_constraints.ml b/test/common/test_template_constraints.ml index 080c2dd0..e1b7d41d 100644 --- a/test/common/test_template_constraints.ml +++ b/test/common/test_template_constraints.ml @@ -6,11 +6,7 @@ open Test_helpers let%expect_test "implicit_equals" = let source = "(fun i -> j x) (fun x -> x x)" in let match_template = "fun :[[a]] -> :[[a]] :[[a]]" in - run_all_matches (module Alpha.Generic) source match_template; + run_all_matches (module Generic) source match_template; [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":16,"line":1,"column":17},"end":{"offset":28,"line":1,"column":29}},"environment":[{"variable":"a","value":"x","range":{"start":{"offset":20,"line":1,"column":21},"end":{"offset":21,"line":1,"column":22}}},{"variable":"a_equal_!@#$000000000003","value":"x","range":{"start":{"offset":25,"line":1,"column":26},"end":{"offset":26,"line":1,"column":27}}},{"variable":"a_equal_!@#$000000000004","value":"x","range":{"start":{"offset":27,"line":1,"column":28},"end":{"offset":28,"line":1,"column":29}}}],"matched":"fun x -> x x"}]} -|}]; - run_all_matches (module Omega.Generic) source match_template; - [%expect_exact - {|{"uri":null,"matches":[{"range":{"start":{"offset":16,"line":1,"column":17},"end":{"offset":28,"line":1,"column":29}},"environment":[{"variable":"a","value":"x","range":{"start":{"offset":20,"line":1,"column":21},"end":{"offset":21,"line":1,"column":22}}},{"variable":"a_equal_!@#$000000000005","value":"x","range":{"start":{"offset":25,"line":1,"column":26},"end":{"offset":26,"line":1,"column":27}}},{"variable":"a_equal_!@#$000000000006","value":"x","range":{"start":{"offset":27,"line":1,"column":28},"end":{"offset":28,"line":1,"column":29}}}],"matched":"fun x -> x x"}]} + {|{"uri":null,"matches":[{"range":{"start":{"offset":16,"line":1,"column":17},"end":{"offset":28,"line":1,"column":29}},"environment":[{"variable":"a","value":"x","range":{"start":{"offset":20,"line":1,"column":21},"end":{"offset":21,"line":1,"column":22}}},{"variable":"a_equal_!@#$000000000001","value":"x","range":{"start":{"offset":25,"line":1,"column":26},"end":{"offset":26,"line":1,"column":27}}},{"variable":"a_equal_!@#$000000000002","value":"x","range":{"start":{"offset":27,"line":1,"column":28},"end":{"offset":28,"line":1,"column":29}}}],"matched":"fun x -> x x"}]} |}] diff --git a/test/common/test_user_defined_language.ml b/test/common/test_user_defined_language.ml index 6c8927cb..18f40e98 100644 --- a/test/common/test_user_defined_language.ml +++ b/test/common/test_user_defined_language.ml @@ -3,8 +3,8 @@ open Comby_kernel open Matchers open Test_helpers -let run (module E : Engine.S) user_lang source match_template rewrite_template = - let (module M) = E.create user_lang in +let run user_lang source match_template rewrite_template = + let (module M) = Matchers.create user_lang in M.first ~configuration match_template source |> function | Ok result -> @@ -46,20 +46,7 @@ let%expect_test "user_defined_language" = in let match_template = {|case :[1] esac|} in let rewrite_template = {|case nuked blocks esac|} in - run (module Alpha) user_lang source match_template rewrite_template; - [%expect_exact - {| - case nuked blocks esac - /* - case - ignore this - esac - */ - // case - // ignore this - // esac - |}]; - run (module Omega) user_lang source match_template rewrite_template; + run user_lang source match_template rewrite_template; [%expect_exact {| case nuked blocks esac @@ -97,9 +84,7 @@ let%expect_test "user_defined_language_from_json" = let source = "" in let match_template = {|""|} in let rewrite_template = {|""|} in - run (module Alpha) user_lang source match_template rewrite_template; - [%expect_exact {|""|}]; - run (module Omega) user_lang source match_template rewrite_template; + run user_lang source match_template rewrite_template; [%expect_exact {|""|}] let%expect_test "user_defined_language_from_json_optional_escapable" = @@ -122,7 +107,5 @@ let%expect_test "user_defined_language_from_json_optional_escapable" = let source = "" in let match_template = {|""|} in let rewrite_template = {|""|} in - run (module Alpha) user_lang source match_template rewrite_template; - [%expect_exact {|""|}]; - run (module Omega) user_lang source match_template rewrite_template; + run user_lang source match_template rewrite_template; [%expect_exact {|""|}] diff --git a/test/dune b/test/dune index e69de29b..3a118d49 100644 --- a/test/dune +++ b/test/dune @@ -0,0 +1,14 @@ +(library + (name test_integration) + (package comby) + (modules test_special_matcher_cases test_substring_disabled) + (inline_tests) + (preprocess + (pps ppx_expect ppx_sexp_message ppx_deriving_yojson)) + (libraries comby cohttp-lwt-unix core camlzip)) + +(alias + (name runtest) + (deps + (source_tree example) + (source_tree example/src/.ignore-me))) diff --git a/test/omega/dune b/test/omega/dune deleted file mode 100644 index bf68dcbe..00000000 --- a/test/omega/dune +++ /dev/null @@ -1,20 +0,0 @@ -(library - (name omega_test_integration) - (package comby) - (modules - ; - ; TODO - ; - test_optional_holes - test_special_matcher_cases - test_substring_disabled) - (inline_tests) - (preprocess - (pps ppx_expect ppx_sexp_message ppx_deriving_yojson)) - (libraries comby cohttp-lwt-unix core camlzip)) - -(alias - (name runtest) - (deps - (source_tree example) - (source_tree example/src/.ignore-me))) diff --git a/test/omega/test_optional_holes.ml b/test/omega/test_optional_holes.ml deleted file mode 100644 index 7934255a..00000000 --- a/test/omega/test_optional_holes.ml +++ /dev/null @@ -1,218 +0,0 @@ -(*open Core - -open Matchers -open Rewriter - -let configuration = Configuration.create ~match_kind:Fuzzy () - -let run ?(configuration = configuration) source match_template rewrite_template = - Generic.all ~configuration ~template:match_template ~source - |> function - | [] -> print_string "No matches." - | results -> - Option.value_exn (Rewrite.all ~source ~rewrite_template results) - |> (fun { rewritten_source; _ } -> rewritten_source) - |> print_string - -let%expect_test "optional_holes_basic_match" = - let source = {||} in - let match_template = {|:[[?x]]|} in - let rewrite_template = {|/:[?x]/|} in - run source match_template rewrite_template; - [%expect_exact {|//|}]; - - let source = {||} in - let match_template = {|:[[?x]]:[[?y]]|} in - let rewrite_template = {|/:[?x]/:[?y]/|} in - run source match_template rewrite_template; - [%expect_exact {|///|}]; - - let source = {|a |} in - let match_template = {|:[[x]] :[[?y]]|} in - let rewrite_template = {|/:[x]/:[?y]/|} in - run source match_template rewrite_template; - [%expect_exact {|/a//|}]; - - let source = {|a |} in - let match_template = {|:[[x]] :[[?y]]|} in - let rewrite_template = {|/:[x]/:[?y]/|} in - run source match_template rewrite_template; - [%expect_exact {|/a//|}]; - - let source = {|(foo )|} in - let match_template = {|(:[[?x]] :[[?y]])|} in - let rewrite_template = {|/:[?x]/:[?y]/|} in - run source match_template rewrite_template; - [%expect_exact {|/foo//|}]; - - let source = {|(foo)|} in - let match_template = {|(:[[?x]]:[? w])|} in - let rewrite_template = {|/:[?x]/:[?w]/|} in - run source match_template rewrite_template; - [%expect_exact {|/foo//|}]; - - let source = {|()|} in - let match_template = {|(:[[?x]]:[? w]:[?y]:[?z.])|} in - let rewrite_template = {|/:[?x]/:[?w]/:[?y]|} in - run source match_template rewrite_template; - [%expect_exact {|///|}]; - - let source = {|()|} in - let match_template = {|(:[?s\n])|} in - let rewrite_template = {|/:[?s]/|} in - run source match_template rewrite_template; - [%expect_exact {|//|}] - -let%expect_test "optional_holes_match_over_coalesced_whitespace" = - let source = {|a c|} in - let match_template = {|:[[a]] :[[?b]] :[[c]]|} in - let rewrite_template = {|/:[?a]/:[?b]/:[?c]|} in - run source match_template rewrite_template; - [%expect_exact {|/a//c|}]; - - let source = {|a c|} in - let match_template = {|:[[a]] :[[?b]]:[[c]]|} in - let rewrite_template = {|/:[?a]/:[?b]/:[?c]|} in - run source match_template rewrite_template; - [%expect_exact {|/a//c|}]; - - let source = {|a c|} in - let match_template = {|:[[a]]:[[?b]]:[[c]]|} in - let rewrite_template = {|/:[?a]/:[?b]/:[?c]|} in - run source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - - let source = {|a c|} in - let match_template = {|:[[a]]:[[?b]] :[[?c]]|} in - let rewrite_template = {|/:[?a]/:[?b]/:[?c]|} in - run source match_template rewrite_template; - [%expect_exact {|/a//c|}]; - - let source = {|a c|} in - let match_template = {|a :[?b] c|} in - let rewrite_template = {|/:[?b]/|} in - run source match_template rewrite_template; - [%expect_exact {|//|}]; - - let source = {|a c|} in - let match_template = {|a :[?b] c|} in - let rewrite_template = {|/:[?b]/|} in - run source match_template rewrite_template; - [%expect_exact {|//|}]; - - let source = {| - -a - - c - -|} in - let match_template = {| a :[?b] c |} in - let rewrite_template = {|/:[?b]/|} in - run source match_template rewrite_template; - [%expect_exact {|//|}]; - - let source = {|func foo(bar) {}|} in - let match_template = {|func :[?receiver] foo(:[args])|} in - let rewrite_template = {|/:[receiver]/:[args]/|} in - run source match_template rewrite_template; - [%expect_exact {|//bar/ {}|}]; - - let source = {|func foo(bar) {}|} in - let match_template = {|func :[?receiver] foo(:[args])|} in - let rewrite_template = {|/:[receiver]/:[args]/|} in - run source match_template rewrite_template; - [%expect_exact {|//bar/ {}|}]; - - let source = {|func (r *receiver) foo(bar) {}|} in - let match_template = {|func :[?receiver] foo(:[args])|} in - let rewrite_template = {|/:[receiver]/:[args]/|} in - run source match_template rewrite_template; - [%expect_exact {|/(r *receiver)/bar/ {}|}]; - - let source = {|func foo()|} in - let match_template = {|func :[?receiver] foo()|} in - let rewrite_template = {|/:[receiver]/|} in - run source match_template rewrite_template; - [%expect_exact {|//|}]; - - let source = {|a l|} in - let match_template = {|a :[?b]asdfasdfsadf|} in - let rewrite_template = {|/:[?b]/|} in - run source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - - let source = {|func foo (1, 3)|} in - let match_template = {|func :[?receiver] foo (1, :[?args] 3)|} in - let rewrite_template = {|/:[receiver]/:[args]/|} in - run source match_template rewrite_template; - [%expect_exact {|///|}]; - - let source = {| -try { - foo() -} catch (Exception e) { - logger.error(e) - hey -} -|} in - let match_template = {| -catch (:[type] :[var]) { -:[?anything] -logger.:[logMethod](:[var]) -:[?something] -} -|} in - let rewrite_template = {| -catch (:[type] :[var]) { -:[anything] -logger.:[logMethod]("", :[var]) -:[something] -} -|} in - run source match_template rewrite_template; - [%expect_exact {| -try { - foo() -} -catch (Exception e) { - -logger.error("", e) -hey -} -|}]; - - let source = {|

content

more content

|} in - let match_template = {||} in - let rewrite_template = {||} in - run source match_template rewrite_template; - [%expect_exact {|content

more content

|}] - -let%expect_test "optional_holes_match_over_coalesced_whitespace_in_strings" = - let source = {|"a c"|} in - let match_template = {|"a :[?b] c"|} in - let rewrite_template = {|/:[?b]/|} in - run source match_template rewrite_template; - [%expect_exact {|No matches.|}]; - - let source = {|"a c"|} in - let match_template = {|"a :[?b] c"|} in - let rewrite_template = {|/:[?b]/|} in - run source match_template rewrite_template; - [%expect_exact {|//|}]; - - (* Uh, turns out whitespace is significant inside strings, so this is correct - until it is decided otherwise *) - let source = {|"a c"|} in - let match_template = {|"a :[?b] c"|} in - let rewrite_template = {|/:[?b]/|} in - run source match_template rewrite_template; - [%expect_exact {|/ /|}] - -let%expect_test "optional_holes_substitute" = - let source = {|()|} in - let match_template = {|(:[[?x]]:[? w]:[?y]:[?z.])|} in - let rewrite_template = {|/:[x]/:[w]/:[y]/:[z]|} in - run source match_template rewrite_template; - [%expect_exact {|////|}] - *) diff --git a/test/omega/test_special_matcher_cases.ml b/test/omega/test_special_matcher_cases.ml deleted file mode 100644 index 3e4990b6..00000000 --- a/test/omega/test_special_matcher_cases.ml +++ /dev/null @@ -1,459 +0,0 @@ -(*open Core - -open Matchers -open Rewriter - -let configuration = Configuration.create ~match_kind:Fuzzy () - - -let run ?(configuration = configuration) (module M : Matchers.Matcher) source match_template rewrite_template = - M.all ~configuration ~template:match_template ~source - |> function - | [] -> print_string "No matches." - | results -> - Option.value_exn (Rewrite.all ~source ~rewrite_template results) - |> (fun { rewritten_source; _ } -> rewritten_source) - |> print_string - -let%expect_test "parse_rust_apostrophe_ok" = - let source = {|width="1280"|} in - let match_template = {|width=":[1]"|} in - let rewrite_template = {|:[1]|} in - - run (module Matchers.Generic) source match_template rewrite_template; - [%expect_exact {|1280|}] - -let%expect_test "parse_rust_apostrophe_ok" = - let source = {|pub struct GlobBuilder<'a> {}|} in - let match_template = {|{}|} in - let rewrite_template = {|{} // success|} in - - run (module Matchers.Rust) source match_template rewrite_template; - [%expect_exact {|pub struct GlobBuilder<'a> {} // success|}] - -let%expect_test "parse_ocaml_apostrophe_ok" = - let source = {|type 'a t = Poly of 'a | Int of int |} in - let match_template = {|type :[v] t = :[_] Int of :[i]|} in - let rewrite_template = {|:[v], :[i]|} in - - run (module Matchers.OCaml) source match_template rewrite_template; - [%expect_exact {|'a, int |}] - -let%expect_test "strict_nested_matching" = - let source = {|({})|} in - let match_template = {|(:[1])|} in - let rewrite_template = {|:[1]|} in - - run (module Matchers.Dyck) source match_template rewrite_template; - [%expect_exact {|{}|}] - -let%expect_test "strict_nested_matching" = - let source = {|(})|} in - let match_template = {|(:[1])|} in - let rewrite_template = {|:[1]|} in - - run (module Matchers.Dyck) source match_template rewrite_template; - [%expect_exact {|No matches.|}] - - - -let%expect_test "ocaml_blocks" = - let source = {| - module M : sig - type t - end = struct - type t = int - - module Nested_M = struct - type r = int - end - end -|} - in - let match_template = {|struct :[1] end|} in - let rewrite_template = {|struct end|} in - - run (module Matchers.OCaml) source match_template rewrite_template; - [%expect_exact {| - module M : sig - type t - end = struct end -|}] - -let%expect_test "ocaml_complex_blocks_with_same_end" = - let source = {| - begin - match x with - | _ -> - let module M = struct type t end - begin - begin - match y with - | _ -> () - end - end - end -|} - in - let match_template = {|begin :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.OCaml) source match_template rewrite_template; - [%expect_exact {| - <1>match x with - | _ -> - let module M = struct type t end - begin - begin - match y with - | _ -> () - end - end -|}] - -let%expect_test "ruby_blocks" = - let source = {| -class ActionController::Base - before_filter :generate_css_from_less - - def generate_css_from_less - Less::More.generate_all - end -end -|} - in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {| -<1>ActionController::Base - before_filter :generate_css_from_less - - def generate_css_from_less - Less::More.generate_all - end -|}] - -let%expect_test "erlang_blocks" = - let source = {|Big = fun(X) -> if X > 10 -> true; true -> false end end.|} in - let match_template = {|fun(:[1]) :[rest] end|} in - let rewrite_template = {|:[rest]|} in - - run (module Matchers.Erlang) source match_template rewrite_template; - [%expect_exact {|Big = -> if X > 10 -> true; true -> false end.|}] - -let%expect_test "ruby_blocks" = - let source = {|class x end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>x|}] - -let%expect_test "ruby_blocks_1" = - let source = {|class class def body1 end def body2 end end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>class def body1 end def body2 end end|}] - -let%expect_test "ruby_blocks_2" = - let source = {|class class (def body1 end) (def body2 end) end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>class (def body1 end) (def body2 end) end|}] - -let%expect_test "ruby_blocks_3" = - let source = {| def (def b end)(def b end) end |} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {| <1>(def b end)(def b end) |}] - -let%expect_test "ruby_blocks_4" = - let source = {| def (def a end) f (def b end)end |} in - let match_template = {|def :[1]end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {| <1>(def a end) f (def b end) |}] - -(* this is correct: there's no space in the source 'end', so it matches the inner def/end blocks *) -let%expect_test "ruby_blocks_5" = - let source = {| def (def a end) f (def b end) end |} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {| <1>(def a end) f (def b end) |}] - -let%expect_test "ruby_blocks_5" = - let source = {| def(df b ed) (df b ed)end |} in - let match_template = {|def:[1]end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {| <1>(df b ed) (df b ed) |}] - -let%expect_test "ruby_blocks_5" = - let source = {|class class ((def (x) end) f (def body end)) end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>class ((def (x) end) f (def body end)) end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class class (def body1 end) (def body2 end) end end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|class class (<1>body1) (<1>body2) end end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class class (def body1 end) (def body2 end) end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>class (def body1 end) (def body2 end) end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class class def (def body1 end) (def body2 end) end end end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|class class <1>(def body1 end) (def body2 end) end end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class class def () (def body2 end) end end end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|class class <1>() (def body2 end) end end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def (def end) (def end) end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(def end) (def end)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def (def end) a (def end) end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(def end) a (def end)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def (defa aend) (adef aend) end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(defa aend) (adef aend)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def (defa aend) a (adef aend) end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(defa aend) a (adef aend)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def (adef a endq) end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(adef a endq)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def adef a endq end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>adef a endq|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def def foo end end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>def foo end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def def end endq|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|No matches.|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def adef a endq end |} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>adef a endq |}] - -let%expect_test "ruby_blocks_5" = - let source = {|def fadef a qendq end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>fadef a qendq|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def defa aend end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>defa aend|}] - -let%expect_test "ruby_blocks_5" = - let source = {|(adef a endq)|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|No matches.|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def adef a endq end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>adef a endq|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def (adef a endq) end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(adef a endq)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class (def ( body )end) end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(def ( body )end)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class def ( body )end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>def ( body )end|}] - - -let%expect_test "ruby_blocks_5" = - let source = {|class def( body ) end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>def( body ) end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class def() end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>def() end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class def () end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>def () end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class def( body )end end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>def( body )end|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class ( def( body )end) end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>( def( body )end)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|class (def( body )end) end|} in - let match_template = {|class :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>(def( body )end)|}] - -let%expect_test "ruby_blocks_5" = - let source = {|(def a endq)|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|No matches.|}] - -let%expect_test "ruby_blocks_5" = - let source = {|def end|} in - let match_template = {|def :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|No matches.|}] - -let%expect_test "ruby_blocks_5" = - let source = {|(def foo end)|} in - let match_template = {|(def :[1] end)|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.Ruby) source match_template rewrite_template; - [%expect_exact {|<1>foo|}] - -let%expect_test "ocaml_struct_end" = - let source = {|= struct Something end|} in - let match_template = {|= struct :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.OCaml) source match_template rewrite_template; - [%expect_exact {|<1>Something|}] - -let%expect_test "ocaml_struct_end_2" = - let source = {|= struct include Something end|} in - let match_template = {|= struct :[1] end|} in - let rewrite_template = {|<1>:[1]|} in - - run (module Matchers.OCaml) source match_template rewrite_template; - [%expect_exact {|<1>include Something|}] - *) diff --git a/test/omega/test_substring_disabled.ml b/test/omega/test_substring_disabled.ml deleted file mode 100644 index 1f0fdd70..00000000 --- a/test/omega/test_substring_disabled.ml +++ /dev/null @@ -1,433 +0,0 @@ -(*open Core - -open Matchers -open Rewriter - -let configuration = Configuration.create ~disable_substring_matching:true ~match_kind:Fuzzy () - -let format s = - let s = String.chop_prefix_exn ~prefix:"\n" s in - let leading_indentation = Option.value_exn (String.lfindi s ~f:(fun _ c -> c <> ' ')) in - s - |> String.split ~on:'\n' - |> List.map ~f:(Fn.flip String.drop_prefix leading_indentation) - |> String.concat ~sep:"\n" - |> String.chop_suffix_exn ~suffix:"\n" - -let run ?(configuration = configuration) source match_template rewrite_template = - Generic.first ~configuration match_template source - |> function - | Ok result -> - Rewrite.all ~source ~rewrite_template [result] - |> (fun x -> Option.value_exn x) - |> (fun { rewritten_source; _ } -> rewritten_source) - |> print_string - | Error _ -> - (* this is too annoying to fix every time the grammar changes. *) - print_string "" - -let run_all ?(configuration = configuration) source match_template rewrite_template = - Generic.all ~configuration ~template:match_template ~source - |> function - | [] -> print_string "No matches." - | results -> - Option.value_exn (Rewrite.all ~source ~rewrite_template results) - |> (fun { rewritten_source; _ } -> rewritten_source) - |> print_string - - -let%expect_test "basic" = - let source = {|a b c d|} in - let match_template = {|:[1]|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|a b c d|}]; - - let source = {|a b c d|} in - let match_template = {|a :[1] c d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b|}]; - - let source = {|a b c d|} in - let match_template = {|a :[1] d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b c|}]; - - let source = {|a b c d|} in - let match_template = {|a :[1]|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b c d|}]; - - let source = {|a b c d|} in - let match_template = {|:[1] c d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|a b|}]; - - let source = {|a b c d|} in - let match_template = {|:[1] :[2]|} in - let rewrite_template = {|(:[1]) (:[2])|} in - run source match_template rewrite_template; - [%expect_exact {|(a) (b c d)|}]; - - let source = {|a b c d|} in - let match_template = {|:[2] :[1]|} in - let rewrite_template = {|(:[2]) (:[1])|} in - run source match_template rewrite_template; - [%expect_exact {|(a) (b c d)|}]; - - let source = {|a b c d|} in - let match_template = {|a :[2] :[1] d|} in - let rewrite_template = {|(:[2]) (:[1])|} in - run source match_template rewrite_template; - [%expect_exact {|(b) (c)|}]; - - let source = {|a b c d|} in - let match_template = {|a :[2] :[1]|} in - let rewrite_template = {|(:[2]) (:[1])|} in - run source match_template rewrite_template; - [%expect_exact {|(b) (c d)|}]; - - let source = {|a b c d|} in - let match_template = {|a :[2] c :[1]|} in - let rewrite_template = {|(:[2]) (:[1])|} in - run source match_template rewrite_template; - [%expect_exact {|(b) (d)|}]; - - let source = {|x:|} in - let match_template = {|:[1]:|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|x|}] - -let%expect_test "basic_failures" = - let source = {|a x b bbq|} in - let match_template = {|a :[1] b c|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {||}]; - - let source = {|a b c d|} in - let match_template = {|a :[2] d :[1]|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact - {||}]; - - let source = {|a b c d|} in - let match_template = {|a :[2] b :[1]|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {||}] - -let%expect_test "delimiter_matching" = - let source = {|(a b c) d|} in - let match_template = {|(:[1]) d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|a b c|}]; - - let source = {|(a b c) d|} in - let match_template = {|(:[1] b :[2]) d|} in - let rewrite_template = {|(:[1]) (:[2])|} in - run source match_template rewrite_template; - [%expect_exact {|(a) (c)|}]; - - let source = {|q(a b c) d|} in - let match_template = {|q(:[1] b :[2]) d|} in - let rewrite_template = {|(:[1]) (:[2])|} in - run source match_template rewrite_template; - [%expect_exact {|(a) (c)|}]; - - let source = {|((a) b)|} in - let match_template = {|(:[1] b)|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|(a)|}]; - - let source = {|((a b c)) d|} in - let match_template = {|(:[1]) d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|(a b c)|}]; - - let source = {|((a b c)) d|} in - let match_template = {|(:[1]) d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|(a b c)|}]; - - let source = {|((a b c) q) d|} in - let match_template = {|((:[1]) q) d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|a b c|}]; - - let source = {|((a b c) q) d|} in - let match_template = {|((:[1] c) q) d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|a b|}]; - - let source = {|((a b () c) q) d|} in - let match_template = {|((:[1] () c) q) d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|a b|}]; - - let source = {|((a ((x) d) b c)) d|} in - let match_template = {|((a :[1] :[2] c)) d|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|((x) d)|}]; - - let source = {|((a ((x) d) b c)) d|} in - let match_template = {|((a (:[1]) :[2] c)) d|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|(x) d b|}]; - - let source = {|(b (c) d)|} in - let match_template = {|(:[1])|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b (c) d|}]; - - let source = {|(b (c) d.)|} in - let match_template = {|(:[1].)|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b (c) d|}]; - - let source = {|(b (c.) d.)|} in - let match_template = {|(:[1].)|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b (c.) d|}]; - - let source = {|(b. (c) d.)|} in - let match_template = {|(:[1].)|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b. (c) d|}]; - - let source = {|(b (c) d.)|} in - let match_template = {|(b :[1] d.)|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|(c)|}]; - - let source = {|outer(inner(dst,src),src)|} in - let match_template = {|outer(:[1],src)|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|inner(dst,src)|}]; - - let source = {|(b ((c)) d.)|} in - let match_template = {|(b :[1] d.)|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|((c))|}]; - - let source = {|a b c|} in - let match_template = {|a :[1] c|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|b|}]; - - let source = {|x = foo;|} in - let match_template = {|x = :[1];|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|foo|}]; - - let source = {|((a {{x} d} b c)) d|} in - let match_template = {|((a {:[1] d} :[2] c)) d|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|{x} b|}]; - - let source = {|((a {([{x}]) d} b c)) d|} in - let match_template = {|((a {:[1] d} :[2] c)) d|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|([{x}]) b|}]; - - let source = {|(((((x)))))|} in - let match_template = {|(((:[1])))|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|((x))|}]; - - let source = {|((((y(x)z))))|} in - let match_template = {|(((:[1])))|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|(y(x)z)|}]; - - let source = {|((((y(x)z))))|} in - let match_template = {|(((:[1]):[2]))|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|(y(x)z) |}]; - - let source = {|(((x)z))|} in - let match_template = {|(((:[1]):[2]))|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|x z|}]; - - let source = {|((((x))z))|} in - let match_template = {|(((:[1]):[2]))|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|(x) z|}]; - - let source = {|lolwtfbbq|} in - let match_template = {|lol:[1]bbq|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {||}]; - - let source = {|x = foo; x = bar;|} in - let match_template = {|x = :[1];|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|foo x = bar;|}]; - - let source = {|[ no match prefix ] x = foo; [ no match suffix ]|} in - let match_template = {|x = :[1];|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|[ no match prefix ] foo [ no match suffix ]|}]; - - let source = {|x = a; x = b; x = c|} in - let match_template = {|x = :[1];|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|a x = b; x = c|}]; - - let source = {|x = ( x = x; );|} in - let match_template = {|x = :[1];|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|( x = x; )|}]; - - let source = {|( x = x = x; )|} in - let match_template = {|x = :[1];|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|( x = x )|}]; - - let source = {|xxx a b d c 1 2 3 b d d blah|} in - let match_template = {|a :[1] c :[2] d|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|xxx b d 1 2 3 b d blah|}]; - - let source = {|howevenlolwtfbbqispossible|} in - let match_template = {|lol:[1]bbq|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {||}]; - - let source = {|lolhowevenlolwtfbbqispossiblebbq|} in - let match_template = {|lol:[1]bbq|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {||}]; - - let source = {|hello my name is bob the builder|} in - let match_template = {|:[alongidentifiername] :[2] :[3] :[xyz] :[5] :[6]|} in - let rewrite_template = {|:[alongidentifiername] :[2] :[3] :[xyz] :[5] :[6]|} in - run source match_template rewrite_template; - [%expect_exact {|hello my name is bob the builder|}]; - - let source = {|www.testdofooname.com/picsinsideit/stunningpictureofkays1381737242g8k4n-280x428.jpg|} in - let match_template = {|www.:[1]-:[2].jpg|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|testdofooname.com/picsinsideit/stunningpictureofkays1381737242g8k4n 280x428|}]; - - let source = {|https://api.github.com/repos/dmjacobsen/slurm/commits/716c1499695c68afcab848a1b49653574b4fc167|} in - let match_template = {|:[1]api.:[2]/repos/:[3]s/:[4]|} in - let rewrite_template = {|:[1] :[2] :[3] :[4]|} in - run source match_template rewrite_template; - [%expect_exact {||}]; - - let source = - {| - assert(stream->md_len + md_len - - si.foo_data_begin <= MAD_BUFFER_MDLEN); - memcpy(*stream->foo_data + stream->md_len, - mad_bit_nextbyte(&stream->ptr), - frame_used = md_len - si.foo_data_begin); - stream->md_len += frame_used; - |} |> format - in - let match_template = {|memcpy(:[1], :[2], :[3]);|} in - let rewrite_template = {|:[1], :[2], :[3]|} in - run source match_template rewrite_template; - [%expect_exact {|assert(stream->md_len + md_len - - si.foo_data_begin <= MAD_BUFFER_MDLEN); -*stream->foo_data + stream->md_len, mad_bit_nextbyte(&stream->ptr), frame_used = md_len - si.foo_data_begin -stream->md_len += frame_used;|}] - -let%expect_test "significant_whitespace" = - let configuration = Configuration.create ~match_kind:Fuzzy ~significant_whitespace:true () in - let run = run ~configuration in - - let source = {|two spaces|} in - let match_template = {|:[1] :[2]|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|two spaces|}]; - - (* FIXME: this should fail. also test case where separators do or do not need - whitespace. e.g., strict about strcpy(src,dst) matching a template - strcpy(:[1],:[2]) versus strcpy(:[1], :[2]) *) - let source = {|two spaces|} in - let match_template = {|:[1] :[2]|} in - let rewrite_template = {|:[1] :[2]|} in - run source match_template rewrite_template; - [%expect_exact {|two spaces|}] - -let%expect_test "contextual_matching" = - let run = run_all in - - let source = {|memcpy(dst1, src1, 1); memcpy(dst2, src2, 2);|} in - let match_template = {|memcpy(:[1], :[2], :[3])|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|dst1; dst2;|}]; - - let source = {|memcpy(dst1, src1, 1); memcpy(dst2, src2, 2);|} in - let match_template = {|memcpy(:[1], :[2], :[3])|} in - let rewrite_template = {|:[1]|} in - run source match_template rewrite_template; - [%expect_exact {|dst1; dst2;|}] - -let%expect_test "contextual_matching_with_short_hole_syntax" = - let run = run_all in - - let source = {|memcpy(dst1, src1, 1); memcpy(dst2, src2, 2);|} in - let match_template = {|memcpy(:[[1]], :[2], :[3])|} in - let rewrite_template = {|:[[1]]|} in - run source match_template rewrite_template; - [%expect_exact {|dst1; dst2;|}] - -let%expect_test "trivial_empty_case" = - let source = "" in - let match_template = "" in - begin - Generic.all ~configuration ~template:match_template ~source - |> function - | [] -> print_string "No matches." - | hd :: _ -> - print_string (Yojson.Safe.to_string (Match.to_yojson hd)) - end; - [%expect_exact {|{"range":{"start":{"offset":0,"line":1,"column":1},"end":{"offset":0,"line":1,"column":1}},"environment":[],"matched":""}|}] - *) diff --git a/test/alpha/test_special_matcher_cases.ml b/test/test_special_matcher_cases.ml similarity index 99% rename from test/alpha/test_special_matcher_cases.ml rename to test/test_special_matcher_cases.ml index 6c00b8e7..db24067e 100644 --- a/test/alpha/test_special_matcher_cases.ml +++ b/test/test_special_matcher_cases.ml @@ -1,7 +1,6 @@ open Core open Comby_kernel open Matchers -open Matchers.Alpha let configuration = Configuration.create ~match_kind:Fuzzy () diff --git a/test/alpha/test_substring_disabled.ml b/test/test_substring_disabled.ml similarity index 99% rename from test/alpha/test_substring_disabled.ml rename to test/test_substring_disabled.ml index c568a13f..6985f57d 100644 --- a/test/alpha/test_substring_disabled.ml +++ b/test/test_substring_disabled.ml @@ -1,7 +1,6 @@ open Core open Comby_kernel open Matchers -open Matchers.Alpha let configuration = Configuration.create ~disable_substring_matching:true ~match_kind:Fuzzy ()