- Commit
- fd6177929d415097a617bb69d8fbb7a13760ec56
- Author
- Pablo <pablo-pie@riseup.net>
- Date
Initial commit
Rolled my own static website builder π»
Initial commit
117 files changed, 42873 insertions, 0 deletions
diff --git /dev/null b/.gitignore @@ -0,0 +1,3 @@ +Cargo.lock +/target +/exemple/site
diff --git /dev/null b/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "roll" +description = "Rolled my own static site generator" +version = "0.1.0" +edition = "2024" +build = "build.rs" + +[dependencies] +static-toml = "1" +pulldown-cmark = { version = "0.13.0", features = ["simd"] } +katex = "0.4" +syntect = "5.3.0" + +[build-dependencies] +syntect = "5.3.0" + +[profile.release] +debug = true
diff --git /dev/null b/LICENSE @@ -0,0 +1,675 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + <program> Copyright (C) <year> <name of author> + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +<https://www.gnu.org/licenses/>. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +<https://www.gnu.org/licenses/why-not-lgpl.html>. +
diff --git /dev/null b/README.md @@ -0,0 +1,50 @@ +# roll + +Rolled my own static website builder π» + +roll aims to provide a minimalist user interface and implement the following +simple feature set: + +* Accessible and optimized HTML output implementing current best practices +* Fast incremental builds: only render pages and blog posts if necessary + +## usage + +See `example/` for an example of how to set up your blog's tree. You can render +the HTML pages of a blog located in the directory `INPUT_DIR` by running the +following command: + +```console +$ roll INPUT_DIR +``` + +roll will output the HTML pages in the directory `INPUT_DIR/site/`. By default, +roll only renders pages blog posts if they were last modified after the +corresponding HTML pages in `INPUT_DIR/site/`. To overwrite this use the `-B` +flag. + +## installation + +roll can be installed using the following commands: + +```console +$ git clone git://git.pablopie.xyz/roll +$ cargo install --path . +``` + +## configuration & customization + +roll provides a number of configuration keys at compile-time. See `config.toml` +for a full list of configuration keys. + +roll does not support customization of the HTML output: it is entirely tailored +to my personal blog, and _no templating system is provided_. If you want to use +this to your own blog, you should fork it and modify the source code. + +## runtime dependencies + +* [KaTeX](https://katex.org/), for rendering LaTeX equations + +## build dependencies + +* [syntect](https://github.com/trishume/syntect), for syntax-highlighting
diff --git /dev/null b/build.rs @@ -0,0 +1,30 @@ +use std::{env, path::PathBuf, process}; +use syntect::{parsing::SyntaxSet}; + +const SYNTAX_DEFS_SUBDIR: &str = "syntax/"; +const SYNTAX_SET_OUTPUT_FILENAME: &str = "syntax-set.dump"; + +fn main() { + let cargo_root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + + let mut syntax_defs_dir = cargo_root.clone(); + syntax_defs_dir.push(SYNTAX_DEFS_SUBDIR); + + let syntax_set = match SyntaxSet::load_from_folder(&syntax_defs_dir) { + Ok(syntax_set) => syntax_set, + Err(e) => { + println!("cargo::error=Could not compile syntax defitions: {e}"); + process::exit(1); + } + }; + + let mut syntax_set_output_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + syntax_set_output_path.push(SYNTAX_SET_OUTPUT_FILENAME); + if let Err(e) = syntect::dumps::dump_to_uncompressed_file( + &syntax_set, + syntax_set_output_path, + ) { + println!("cargo::error=Could not dump syntax defitions: {e}"); + process::exit(1); + } +}
diff --git /dev/null b/config.toml @@ -0,0 +1,9 @@ +[content] +author = "Pablo" +host_url = "https://pablopie.xyz" +exclude = [ "sync.sh", ] + + +[feed] +title = "pablo's blog" +description = "Some thoughts and ideasβ¦"
diff --git /dev/null b/exemple/content.md @@ -0,0 +1,3 @@ +# content + +This page was typeset in Markdown.
diff --git /dev/null b/exemple/css/chivo.css @@ -0,0 +1,43 @@ +/* This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +@font-face { + font-family: "Chivo"; + src: local("Chivo Bold"), local("Chivo-Bold"), url("/fonts/Chivo-Bold.woff2") format("woff2"); + font-weight: bold; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: "Chivo"; + src: local("Chivo Bold Italic"), local("Chivo-BoldItalic"), url("/fonts/Chivo-BoldItalic.woff2") format("woff2"); + font-weight: bold; + font-style: italic; + font-display: swap; +} + +@font-face { + font-family: "Chivo"; + src: local("Chivo Italic"), local("Chivo-Italic"), url("/fonts/Chivo-Italic.woff2") format("woff2"); + font-weight: normal; + font-style: italic; + font-display: swap; +} + +@font-face { + font-family: "Chivo"; + src: local("Chivo"), local("Chivo-Regular"), url("/fonts/Chivo-Regular.woff2") format("woff2"); + font-weight: normal; + font-style: normal; +}
diff --git /dev/null b/exemple/css/highlighting.css @@ -0,0 +1,81 @@ +/* This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +:root { + --cyan: #9EFFFF; + --pink: var(--accent); + --green: #A5FF90; + --purple: #B362FF; +} + +pre .keyword, +pre .type.function, +pre .separator.function-defition, +pre .separator.function-definition, +pre .separator.function-return, +pre .separator.type-constraint, +pre .separator.variant-definition, +pre .separator.sequence.haskell, +pre .separator.match-definition, +pre .section.ini +{ + font-weight: bold; + color: var(--pink); +} + +pre .name.constant, +pre .separator.user.console +{ + font-weight: bold; +} + +pre .name.function, +pre .builtin.function, +pre .support.function, +pre .variable.function, +pre .keyword.operator, +pre .punctuation.record, +pre .separator.type +{ + font-weight: bold; + color: var(--cyan); +} + +pre .comment { + font-style: italic; + color: var(--purple); +} + +pre .storage.type, +pre .name.type, +pre .type.variant +{ + font-weight: bold; + color: var(--green); +} + +pre .constant.numeric { + color: var(--green); +} + +pre .string, +pre .character.escape +{ + font-style: italic; + color: var(--green); +} + +pre .mapping.key .string { + font-style: normal; + color: var(--cyan); +}
diff --git /dev/null b/exemple/css/katex.css @@ -0,0 +1,1079 @@ +/* stylelint-disable font-family-no-missing-generic-family-keyword */ +@font-face { + font-family: 'KaTeX_AMS'; + src: url(../fonts/KaTeX_AMS-Regular.woff2) format('woff2'), url(../fonts/KaTeX_AMS-Regular.woff) format('woff'), url(../fonts/KaTeX_AMS-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Caligraphic'; + src: url(../fonts/KaTeX_Caligraphic-Bold.woff2) format('woff2'), url(../fonts/KaTeX_Caligraphic-Bold.woff) format('woff'), url(../fonts/KaTeX_Caligraphic-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Caligraphic'; + src: url(../fonts/KaTeX_Caligraphic-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Caligraphic-Regular.woff) format('woff'), url(../fonts/KaTeX_Caligraphic-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Fraktur'; + src: url(../fonts/KaTeX_Fraktur-Bold.woff2) format('woff2'), url(../fonts/KaTeX_Fraktur-Bold.woff) format('woff'), url(../fonts/KaTeX_Fraktur-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Fraktur'; + src: url(../fonts/KaTeX_Fraktur-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Fraktur-Regular.woff) format('woff'), url(../fonts/KaTeX_Fraktur-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Main'; + src: url(../fonts/KaTeX_Main-Bold.woff2) format('woff2'), url(../fonts/KaTeX_Main-Bold.woff) format('woff'), url(../fonts/KaTeX_Main-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Main'; + src: url(../fonts/KaTeX_Main-BoldItalic.woff2) format('woff2'), url(../fonts/KaTeX_Main-BoldItalic.woff) format('woff'), url(../fonts/KaTeX_Main-BoldItalic.ttf) format('truetype'); + font-weight: bold; + font-style: italic; +} +@font-face { + font-family: 'KaTeX_Main'; + src: url(../fonts/KaTeX_Main-Italic.woff2) format('woff2'), url(../fonts/KaTeX_Main-Italic.woff) format('woff'), url(../fonts/KaTeX_Main-Italic.ttf) format('truetype'); + font-weight: normal; + font-style: italic; +} +@font-face { + font-family: 'KaTeX_Main'; + src: url(../fonts/KaTeX_Main-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Main-Regular.woff) format('woff'), url(../fonts/KaTeX_Main-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Math'; + src: url(../fonts/KaTeX_Math-BoldItalic.woff2) format('woff2'), url(../fonts/KaTeX_Math-BoldItalic.woff) format('woff'), url(../fonts/KaTeX_Math-BoldItalic.ttf) format('truetype'); + font-weight: bold; + font-style: italic; +} +@font-face { + font-family: 'KaTeX_Math'; + src: url(../fonts/KaTeX_Math-Italic.woff2) format('woff2'), url(../fonts/KaTeX_Math-Italic.woff) format('woff'), url(../fonts/KaTeX_Math-Italic.ttf) format('truetype'); + font-weight: normal; + font-style: italic; +} +@font-face { + font-family: 'KaTeX_SansSerif'; + src: url(../fonts/KaTeX_SansSerif-Bold.woff2) format('woff2'), url(../fonts/KaTeX_SansSerif-Bold.woff) format('woff'), url(../fonts/KaTeX_SansSerif-Bold.ttf) format('truetype'); + font-weight: bold; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_SansSerif'; + src: url(../fonts/KaTeX_SansSerif-Italic.woff2) format('woff2'), url(../fonts/KaTeX_SansSerif-Italic.woff) format('woff'), url(../fonts/KaTeX_SansSerif-Italic.ttf) format('truetype'); + font-weight: normal; + font-style: italic; +} +@font-face { + font-family: 'KaTeX_SansSerif'; + src: url(../fonts/KaTeX_SansSerif-Regular.woff2) format('woff2'), url(../fonts/KaTeX_SansSerif-Regular.woff) format('woff'), url(../fonts/KaTeX_SansSerif-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Script'; + src: url(../fonts/KaTeX_Script-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Script-Regular.woff) format('woff'), url(../fonts/KaTeX_Script-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Size1'; + src: url(../fonts/KaTeX_Size1-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Size1-Regular.woff) format('woff'), url(../fonts/KaTeX_Size1-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Size2'; + src: url(../fonts/KaTeX_Size2-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Size2-Regular.woff) format('woff'), url(../fonts/KaTeX_Size2-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Size3'; + src: url(../fonts/KaTeX_Size3-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Size3-Regular.woff) format('woff'), url(../fonts/KaTeX_Size3-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Size4'; + src: url(../fonts/KaTeX_Size4-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Size4-Regular.woff) format('woff'), url(../fonts/KaTeX_Size4-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +@font-face { + font-family: 'KaTeX_Typewriter'; + src: url(../fonts/KaTeX_Typewriter-Regular.woff2) format('woff2'), url(../fonts/KaTeX_Typewriter-Regular.woff) format('woff'), url(../fonts/KaTeX_Typewriter-Regular.ttf) format('truetype'); + font-weight: normal; + font-style: normal; +} +.katex { + font: normal 1.21em KaTeX_Main, Times New Roman, serif; + line-height: 1.2; + text-indent: 0; + text-rendering: auto; +} +.katex * { + -ms-high-contrast-adjust: none !important; + border-color: currentColor; +} +.katex .katex-version::after { + content: "0.16.2"; +} +.katex .katex-mathml { + /* Accessibility hack to only show to screen readers + Found at: http://a11yproject.com/posts/how-to-hide-content/ */ + position: absolute; + clip: rect(1px, 1px, 1px, 1px); + padding: 0; + border: 0; + height: 1px; + width: 1px; + overflow: hidden; +} +.katex .katex-html { + /* \newline is an empty block at top level, between .base elements */ +} +.katex .katex-html > .newline { + display: block; +} +.katex .base { + position: relative; + display: inline-block; + white-space: nowrap; + width: -webkit-min-content; + width: -moz-min-content; + width: min-content; +} +.katex .strut { + display: inline-block; +} +.katex .textbf { + font-weight: bold; +} +.katex .textit { + font-style: italic; +} +.katex .textrm { + font-family: KaTeX_Main; +} +.katex .textsf { + font-family: KaTeX_SansSerif; +} +.katex .texttt { + font-family: KaTeX_Typewriter; +} +.katex .mathnormal { + font-family: KaTeX_Math; + font-style: italic; +} +.katex .mathit { + font-family: KaTeX_Main; + font-style: italic; +} +.katex .mathrm { + font-style: normal; +} +.katex .mathbf { + font-family: KaTeX_Main; + font-weight: bold; +} +.katex .boldsymbol { + font-family: KaTeX_Math; + font-weight: bold; + font-style: italic; +} +.katex .amsrm { + font-family: KaTeX_AMS; +} +.katex .mathbb, +.katex .textbb { + font-family: KaTeX_AMS; +} +.katex .mathcal { + font-family: KaTeX_Caligraphic; +} +.katex .mathfrak, +.katex .textfrak { + font-family: KaTeX_Fraktur; +} +.katex .mathtt { + font-family: KaTeX_Typewriter; +} +.katex .mathscr, +.katex .textscr { + font-family: KaTeX_Script; +} +.katex .mathsf, +.katex .textsf { + font-family: KaTeX_SansSerif; +} +.katex .mathboldsf, +.katex .textboldsf { + font-family: KaTeX_SansSerif; + font-weight: bold; +} +.katex .mathitsf, +.katex .textitsf { + font-family: KaTeX_SansSerif; + font-style: italic; +} +.katex .mainrm { + font-family: KaTeX_Main; + font-style: normal; +} +.katex .vlist-t { + display: inline-table; + table-layout: fixed; + border-collapse: collapse; +} +.katex .vlist-r { + display: table-row; +} +.katex .vlist { + display: table-cell; + vertical-align: bottom; + position: relative; +} +.katex .vlist > span { + display: block; + height: 0; + position: relative; +} +.katex .vlist > span > span { + display: inline-block; +} +.katex .vlist > span > .pstrut { + overflow: hidden; + width: 0; +} +.katex .vlist-t2 { + margin-right: -2px; +} +.katex .vlist-s { + display: table-cell; + vertical-align: bottom; + font-size: 1px; + width: 2px; + min-width: 2px; +} +.katex .vbox { + display: inline-flex; + flex-direction: column; + align-items: baseline; +} +.katex .hbox { + display: inline-flex; + flex-direction: row; + width: 100%; +} +.katex .thinbox { + display: inline-flex; + flex-direction: row; + width: 0; + max-width: 0; +} +.katex .msupsub { + text-align: left; +} +.katex .mfrac > span > span { + text-align: center; +} +.katex .mfrac .frac-line { + display: inline-block; + width: 100%; + border-bottom-style: solid; +} +.katex .mfrac .frac-line, +.katex .overline .overline-line, +.katex .underline .underline-line, +.katex .hline, +.katex .hdashline, +.katex .rule { + min-height: 1px; +} +.katex .mspace { + display: inline-block; +} +.katex .llap, +.katex .rlap, +.katex .clap { + width: 0; + position: relative; +} +.katex .llap > .inner, +.katex .rlap > .inner, +.katex .clap > .inner { + position: absolute; +} +.katex .llap > .fix, +.katex .rlap > .fix, +.katex .clap > .fix { + display: inline-block; +} +.katex .llap > .inner { + right: 0; +} +.katex .rlap > .inner, +.katex .clap > .inner { + left: 0; +} +.katex .clap > .inner > span { + margin-left: -50%; + margin-right: 50%; +} +.katex .rule { + display: inline-block; + border: solid 0; + position: relative; +} +.katex .overline .overline-line, +.katex .underline .underline-line, +.katex .hline { + display: inline-block; + width: 100%; + border-bottom-style: solid; +} +.katex .hdashline { + display: inline-block; + width: 100%; + border-bottom-style: dashed; +} +.katex .sqrt > .root { + /* These values are taken from the definition of `\r@@t`, + `\mkern 5mu` and `\mkern -10mu`. */ + margin-left: 0.27777778em; + margin-right: -0.55555556em; +} +.katex .sizing.reset-size1.size1, +.katex .fontsize-ensurer.reset-size1.size1 { + font-size: 1em; +} +.katex .sizing.reset-size1.size2, +.katex .fontsize-ensurer.reset-size1.size2 { + font-size: 1.2em; +} +.katex .sizing.reset-size1.size3, +.katex .fontsize-ensurer.reset-size1.size3 { + font-size: 1.4em; +} +.katex .sizing.reset-size1.size4, +.katex .fontsize-ensurer.reset-size1.size4 { + font-size: 1.6em; +} +.katex .sizing.reset-size1.size5, +.katex .fontsize-ensurer.reset-size1.size5 { + font-size: 1.8em; +} +.katex .sizing.reset-size1.size6, +.katex .fontsize-ensurer.reset-size1.size6 { + font-size: 2em; +} +.katex .sizing.reset-size1.size7, +.katex .fontsize-ensurer.reset-size1.size7 { + font-size: 2.4em; +} +.katex .sizing.reset-size1.size8, +.katex .fontsize-ensurer.reset-size1.size8 { + font-size: 2.88em; +} +.katex .sizing.reset-size1.size9, +.katex .fontsize-ensurer.reset-size1.size9 { + font-size: 3.456em; +} +.katex .sizing.reset-size1.size10, +.katex .fontsize-ensurer.reset-size1.size10 { + font-size: 4.148em; +} +.katex .sizing.reset-size1.size11, +.katex .fontsize-ensurer.reset-size1.size11 { + font-size: 4.976em; +} +.katex .sizing.reset-size2.size1, +.katex .fontsize-ensurer.reset-size2.size1 { + font-size: 0.83333333em; +} +.katex .sizing.reset-size2.size2, +.katex .fontsize-ensurer.reset-size2.size2 { + font-size: 1em; +} +.katex .sizing.reset-size2.size3, +.katex .fontsize-ensurer.reset-size2.size3 { + font-size: 1.16666667em; +} +.katex .sizing.reset-size2.size4, +.katex .fontsize-ensurer.reset-size2.size4 { + font-size: 1.33333333em; +} +.katex .sizing.reset-size2.size5, +.katex .fontsize-ensurer.reset-size2.size5 { + font-size: 1.5em; +} +.katex .sizing.reset-size2.size6, +.katex .fontsize-ensurer.reset-size2.size6 { + font-size: 1.66666667em; +} +.katex .sizing.reset-size2.size7, +.katex .fontsize-ensurer.reset-size2.size7 { + font-size: 2em; +} +.katex .sizing.reset-size2.size8, +.katex .fontsize-ensurer.reset-size2.size8 { + font-size: 2.4em; +} +.katex .sizing.reset-size2.size9, +.katex .fontsize-ensurer.reset-size2.size9 { + font-size: 2.88em; +} +.katex .sizing.reset-size2.size10, +.katex .fontsize-ensurer.reset-size2.size10 { + font-size: 3.45666667em; +} +.katex .sizing.reset-size2.size11, +.katex .fontsize-ensurer.reset-size2.size11 { + font-size: 4.14666667em; +} +.katex .sizing.reset-size3.size1, +.katex .fontsize-ensurer.reset-size3.size1 { + font-size: 0.71428571em; +} +.katex .sizing.reset-size3.size2, +.katex .fontsize-ensurer.reset-size3.size2 { + font-size: 0.85714286em; +} +.katex .sizing.reset-size3.size3, +.katex .fontsize-ensurer.reset-size3.size3 { + font-size: 1em; +} +.katex .sizing.reset-size3.size4, +.katex .fontsize-ensurer.reset-size3.size4 { + font-size: 1.14285714em; +} +.katex .sizing.reset-size3.size5, +.katex .fontsize-ensurer.reset-size3.size5 { + font-size: 1.28571429em; +} +.katex .sizing.reset-size3.size6, +.katex .fontsize-ensurer.reset-size3.size6 { + font-size: 1.42857143em; +} +.katex .sizing.reset-size3.size7, +.katex .fontsize-ensurer.reset-size3.size7 { + font-size: 1.71428571em; +} +.katex .sizing.reset-size3.size8, +.katex .fontsize-ensurer.reset-size3.size8 { + font-size: 2.05714286em; +} +.katex .sizing.reset-size3.size9, +.katex .fontsize-ensurer.reset-size3.size9 { + font-size: 2.46857143em; +} +.katex .sizing.reset-size3.size10, +.katex .fontsize-ensurer.reset-size3.size10 { + font-size: 2.96285714em; +} +.katex .sizing.reset-size3.size11, +.katex .fontsize-ensurer.reset-size3.size11 { + font-size: 3.55428571em; +} +.katex .sizing.reset-size4.size1, +.katex .fontsize-ensurer.reset-size4.size1 { + font-size: 0.625em; +} +.katex .sizing.reset-size4.size2, +.katex .fontsize-ensurer.reset-size4.size2 { + font-size: 0.75em; +} +.katex .sizing.reset-size4.size3, +.katex .fontsize-ensurer.reset-size4.size3 { + font-size: 0.875em; +} +.katex .sizing.reset-size4.size4, +.katex .fontsize-ensurer.reset-size4.size4 { + font-size: 1em; +} +.katex .sizing.reset-size4.size5, +.katex .fontsize-ensurer.reset-size4.size5 { + font-size: 1.125em; +} +.katex .sizing.reset-size4.size6, +.katex .fontsize-ensurer.reset-size4.size6 { + font-size: 1.25em; +} +.katex .sizing.reset-size4.size7, +.katex .fontsize-ensurer.reset-size4.size7 { + font-size: 1.5em; +} +.katex .sizing.reset-size4.size8, +.katex .fontsize-ensurer.reset-size4.size8 { + font-size: 1.8em; +} +.katex .sizing.reset-size4.size9, +.katex .fontsize-ensurer.reset-size4.size9 { + font-size: 2.16em; +} +.katex .sizing.reset-size4.size10, +.katex .fontsize-ensurer.reset-size4.size10 { + font-size: 2.5925em; +} +.katex .sizing.reset-size4.size11, +.katex .fontsize-ensurer.reset-size4.size11 { + font-size: 3.11em; +} +.katex .sizing.reset-size5.size1, +.katex .fontsize-ensurer.reset-size5.size1 { + font-size: 0.55555556em; +} +.katex .sizing.reset-size5.size2, +.katex .fontsize-ensurer.reset-size5.size2 { + font-size: 0.66666667em; +} +.katex .sizing.reset-size5.size3, +.katex .fontsize-ensurer.reset-size5.size3 { + font-size: 0.77777778em; +} +.katex .sizing.reset-size5.size4, +.katex .fontsize-ensurer.reset-size5.size4 { + font-size: 0.88888889em; +} +.katex .sizing.reset-size5.size5, +.katex .fontsize-ensurer.reset-size5.size5 { + font-size: 1em; +} +.katex .sizing.reset-size5.size6, +.katex .fontsize-ensurer.reset-size5.size6 { + font-size: 1.11111111em; +} +.katex .sizing.reset-size5.size7, +.katex .fontsize-ensurer.reset-size5.size7 { + font-size: 1.33333333em; +} +.katex .sizing.reset-size5.size8, +.katex .fontsize-ensurer.reset-size5.size8 { + font-size: 1.6em; +} +.katex .sizing.reset-size5.size9, +.katex .fontsize-ensurer.reset-size5.size9 { + font-size: 1.92em; +} +.katex .sizing.reset-size5.size10, +.katex .fontsize-ensurer.reset-size5.size10 { + font-size: 2.30444444em; +} +.katex .sizing.reset-size5.size11, +.katex .fontsize-ensurer.reset-size5.size11 { + font-size: 2.76444444em; +} +.katex .sizing.reset-size6.size1, +.katex .fontsize-ensurer.reset-size6.size1 { + font-size: 0.5em; +} +.katex .sizing.reset-size6.size2, +.katex .fontsize-ensurer.reset-size6.size2 { + font-size: 0.6em; +} +.katex .sizing.reset-size6.size3, +.katex .fontsize-ensurer.reset-size6.size3 { + font-size: 0.7em; +} +.katex .sizing.reset-size6.size4, +.katex .fontsize-ensurer.reset-size6.size4 { + font-size: 0.8em; +} +.katex .sizing.reset-size6.size5, +.katex .fontsize-ensurer.reset-size6.size5 { + font-size: 0.9em; +} +.katex .sizing.reset-size6.size6, +.katex .fontsize-ensurer.reset-size6.size6 { + font-size: 1em; +} +.katex .sizing.reset-size6.size7, +.katex .fontsize-ensurer.reset-size6.size7 { + font-size: 1.2em; +} +.katex .sizing.reset-size6.size8, +.katex .fontsize-ensurer.reset-size6.size8 { + font-size: 1.44em; +} +.katex .sizing.reset-size6.size9, +.katex .fontsize-ensurer.reset-size6.size9 { + font-size: 1.728em; +} +.katex .sizing.reset-size6.size10, +.katex .fontsize-ensurer.reset-size6.size10 { + font-size: 2.074em; +} +.katex .sizing.reset-size6.size11, +.katex .fontsize-ensurer.reset-size6.size11 { + font-size: 2.488em; +} +.katex .sizing.reset-size7.size1, +.katex .fontsize-ensurer.reset-size7.size1 { + font-size: 0.41666667em; +} +.katex .sizing.reset-size7.size2, +.katex .fontsize-ensurer.reset-size7.size2 { + font-size: 0.5em; +} +.katex .sizing.reset-size7.size3, +.katex .fontsize-ensurer.reset-size7.size3 { + font-size: 0.58333333em; +} +.katex .sizing.reset-size7.size4, +.katex .fontsize-ensurer.reset-size7.size4 { + font-size: 0.66666667em; +} +.katex .sizing.reset-size7.size5, +.katex .fontsize-ensurer.reset-size7.size5 { + font-size: 0.75em; +} +.katex .sizing.reset-size7.size6, +.katex .fontsize-ensurer.reset-size7.size6 { + font-size: 0.83333333em; +} +.katex .sizing.reset-size7.size7, +.katex .fontsize-ensurer.reset-size7.size7 { + font-size: 1em; +} +.katex .sizing.reset-size7.size8, +.katex .fontsize-ensurer.reset-size7.size8 { + font-size: 1.2em; +} +.katex .sizing.reset-size7.size9, +.katex .fontsize-ensurer.reset-size7.size9 { + font-size: 1.44em; +} +.katex .sizing.reset-size7.size10, +.katex .fontsize-ensurer.reset-size7.size10 { + font-size: 1.72833333em; +} +.katex .sizing.reset-size7.size11, +.katex .fontsize-ensurer.reset-size7.size11 { + font-size: 2.07333333em; +} +.katex .sizing.reset-size8.size1, +.katex .fontsize-ensurer.reset-size8.size1 { + font-size: 0.34722222em; +} +.katex .sizing.reset-size8.size2, +.katex .fontsize-ensurer.reset-size8.size2 { + font-size: 0.41666667em; +} +.katex .sizing.reset-size8.size3, +.katex .fontsize-ensurer.reset-size8.size3 { + font-size: 0.48611111em; +} +.katex .sizing.reset-size8.size4, +.katex .fontsize-ensurer.reset-size8.size4 { + font-size: 0.55555556em; +} +.katex .sizing.reset-size8.size5, +.katex .fontsize-ensurer.reset-size8.size5 { + font-size: 0.625em; +} +.katex .sizing.reset-size8.size6, +.katex .fontsize-ensurer.reset-size8.size6 { + font-size: 0.69444444em; +} +.katex .sizing.reset-size8.size7, +.katex .fontsize-ensurer.reset-size8.size7 { + font-size: 0.83333333em; +} +.katex .sizing.reset-size8.size8, +.katex .fontsize-ensurer.reset-size8.size8 { + font-size: 1em; +} +.katex .sizing.reset-size8.size9, +.katex .fontsize-ensurer.reset-size8.size9 { + font-size: 1.2em; +} +.katex .sizing.reset-size8.size10, +.katex .fontsize-ensurer.reset-size8.size10 { + font-size: 1.44027778em; +} +.katex .sizing.reset-size8.size11, +.katex .fontsize-ensurer.reset-size8.size11 { + font-size: 1.72777778em; +} +.katex .sizing.reset-size9.size1, +.katex .fontsize-ensurer.reset-size9.size1 { + font-size: 0.28935185em; +} +.katex .sizing.reset-size9.size2, +.katex .fontsize-ensurer.reset-size9.size2 { + font-size: 0.34722222em; +} +.katex .sizing.reset-size9.size3, +.katex .fontsize-ensurer.reset-size9.size3 { + font-size: 0.40509259em; +} +.katex .sizing.reset-size9.size4, +.katex .fontsize-ensurer.reset-size9.size4 { + font-size: 0.46296296em; +} +.katex .sizing.reset-size9.size5, +.katex .fontsize-ensurer.reset-size9.size5 { + font-size: 0.52083333em; +} +.katex .sizing.reset-size9.size6, +.katex .fontsize-ensurer.reset-size9.size6 { + font-size: 0.5787037em; +} +.katex .sizing.reset-size9.size7, +.katex .fontsize-ensurer.reset-size9.size7 { + font-size: 0.69444444em; +} +.katex .sizing.reset-size9.size8, +.katex .fontsize-ensurer.reset-size9.size8 { + font-size: 0.83333333em; +} +.katex .sizing.reset-size9.size9, +.katex .fontsize-ensurer.reset-size9.size9 { + font-size: 1em; +} +.katex .sizing.reset-size9.size10, +.katex .fontsize-ensurer.reset-size9.size10 { + font-size: 1.20023148em; +} +.katex .sizing.reset-size9.size11, +.katex .fontsize-ensurer.reset-size9.size11 { + font-size: 1.43981481em; +} +.katex .sizing.reset-size10.size1, +.katex .fontsize-ensurer.reset-size10.size1 { + font-size: 0.24108004em; +} +.katex .sizing.reset-size10.size2, +.katex .fontsize-ensurer.reset-size10.size2 { + font-size: 0.28929605em; +} +.katex .sizing.reset-size10.size3, +.katex .fontsize-ensurer.reset-size10.size3 { + font-size: 0.33751205em; +} +.katex .sizing.reset-size10.size4, +.katex .fontsize-ensurer.reset-size10.size4 { + font-size: 0.38572806em; +} +.katex .sizing.reset-size10.size5, +.katex .fontsize-ensurer.reset-size10.size5 { + font-size: 0.43394407em; +} +.katex .sizing.reset-size10.size6, +.katex .fontsize-ensurer.reset-size10.size6 { + font-size: 0.48216008em; +} +.katex .sizing.reset-size10.size7, +.katex .fontsize-ensurer.reset-size10.size7 { + font-size: 0.57859209em; +} +.katex .sizing.reset-size10.size8, +.katex .fontsize-ensurer.reset-size10.size8 { + font-size: 0.69431051em; +} +.katex .sizing.reset-size10.size9, +.katex .fontsize-ensurer.reset-size10.size9 { + font-size: 0.83317261em; +} +.katex .sizing.reset-size10.size10, +.katex .fontsize-ensurer.reset-size10.size10 { + font-size: 1em; +} +.katex .sizing.reset-size10.size11, +.katex .fontsize-ensurer.reset-size10.size11 { + font-size: 1.19961427em; +} +.katex .sizing.reset-size11.size1, +.katex .fontsize-ensurer.reset-size11.size1 { + font-size: 0.20096463em; +} +.katex .sizing.reset-size11.size2, +.katex .fontsize-ensurer.reset-size11.size2 { + font-size: 0.24115756em; +} +.katex .sizing.reset-size11.size3, +.katex .fontsize-ensurer.reset-size11.size3 { + font-size: 0.28135048em; +} +.katex .sizing.reset-size11.size4, +.katex .fontsize-ensurer.reset-size11.size4 { + font-size: 0.32154341em; +} +.katex .sizing.reset-size11.size5, +.katex .fontsize-ensurer.reset-size11.size5 { + font-size: 0.36173633em; +} +.katex .sizing.reset-size11.size6, +.katex .fontsize-ensurer.reset-size11.size6 { + font-size: 0.40192926em; +} +.katex .sizing.reset-size11.size7, +.katex .fontsize-ensurer.reset-size11.size7 { + font-size: 0.48231511em; +} +.katex .sizing.reset-size11.size8, +.katex .fontsize-ensurer.reset-size11.size8 { + font-size: 0.57877814em; +} +.katex .sizing.reset-size11.size9, +.katex .fontsize-ensurer.reset-size11.size9 { + font-size: 0.69453376em; +} +.katex .sizing.reset-size11.size10, +.katex .fontsize-ensurer.reset-size11.size10 { + font-size: 0.83360129em; +} +.katex .sizing.reset-size11.size11, +.katex .fontsize-ensurer.reset-size11.size11 { + font-size: 1em; +} +.katex .delimsizing.size1 { + font-family: KaTeX_Size1; +} +.katex .delimsizing.size2 { + font-family: KaTeX_Size2; +} +.katex .delimsizing.size3 { + font-family: KaTeX_Size3; +} +.katex .delimsizing.size4 { + font-family: KaTeX_Size4; +} +.katex .delimsizing.mult .delim-size1 > span { + font-family: KaTeX_Size1; +} +.katex .delimsizing.mult .delim-size4 > span { + font-family: KaTeX_Size4; +} +.katex .nulldelimiter { + display: inline-block; + width: 0.12em; +} +.katex .delimcenter { + position: relative; +} +.katex .op-symbol { + position: relative; +} +.katex .op-symbol.small-op { + font-family: KaTeX_Size1; +} +.katex .op-symbol.large-op { + font-family: KaTeX_Size2; +} +.katex .op-limits > .vlist-t { + text-align: center; +} +.katex .accent > .vlist-t { + text-align: center; +} +.katex .accent .accent-body { + position: relative; +} +.katex .accent .accent-body:not(.accent-full) { + width: 0; +} +.katex .overlay { + display: block; +} +.katex .mtable .vertical-separator { + display: inline-block; + min-width: 1px; +} +.katex .mtable .arraycolsep { + display: inline-block; +} +.katex .mtable .col-align-c > .vlist-t { + text-align: center; +} +.katex .mtable .col-align-l > .vlist-t { + text-align: left; +} +.katex .mtable .col-align-r > .vlist-t { + text-align: right; +} +.katex .svg-align { + text-align: left; +} +.katex svg { + display: block; + position: absolute; + width: 100%; + height: inherit; + fill: currentColor; + stroke: currentColor; + fill-rule: nonzero; + fill-opacity: 1; + stroke-width: 1; + stroke-linecap: butt; + stroke-linejoin: miter; + stroke-miterlimit: 4; + stroke-dasharray: none; + stroke-dashoffset: 0; + stroke-opacity: 1; +} +.katex svg path { + stroke: none; +} +.katex img { + border-style: none; + min-width: 0; + min-height: 0; + max-width: none; + max-height: none; +} +.katex .stretchy { + width: 100%; + display: block; + position: relative; + overflow: hidden; +} +.katex .stretchy::before, +.katex .stretchy::after { + content: ""; +} +.katex .hide-tail { + width: 100%; + position: relative; + overflow: hidden; +} +.katex .halfarrow-left { + position: absolute; + left: 0; + width: 50.2%; + overflow: hidden; +} +.katex .halfarrow-right { + position: absolute; + right: 0; + width: 50.2%; + overflow: hidden; +} +.katex .brace-left { + position: absolute; + left: 0; + width: 25.1%; + overflow: hidden; +} +.katex .brace-center { + position: absolute; + left: 25%; + width: 50%; + overflow: hidden; +} +.katex .brace-right { + position: absolute; + right: 0; + width: 25.1%; + overflow: hidden; +} +.katex .x-arrow-pad { + padding: 0 0.5em; +} +.katex .cd-arrow-pad { + padding: 0 0.55556em 0 0.27778em; +} +.katex .x-arrow, +.katex .mover, +.katex .munder { + text-align: center; +} +.katex .boxpad { + padding: 0 0.3em; +} +.katex .fbox, +.katex .fcolorbox { + box-sizing: border-box; + border: 0.04em solid; +} +.katex .cancel-pad { + padding: 0 0.2em; +} +.katex .cancel-lap { + margin-left: -0.2em; + margin-right: -0.2em; +} +.katex .sout { + border-bottom-style: solid; + border-bottom-width: 0.08em; +} +.katex .angl { + box-sizing: border-box; + border-top: 0.049em solid; + border-right: 0.049em solid; + margin-right: 0.03889em; +} +.katex .anglpad { + padding: 0 0.03889em; +} +.katex .eqn-num::before { + counter-increment: katexEqnNo; + content: "(" counter(katexEqnNo) ")"; +} +.katex .mml-eqn-num::before { + counter-increment: mmlEqnNo; + content: "(" counter(mmlEqnNo) ")"; +} +.katex .mtr-glue { + width: 50%; +} +.katex .cd-vert-arrow { + display: inline-block; + position: relative; +} +.katex .cd-label-left { + display: inline-block; + position: absolute; + right: calc(50% + 0.3em); + text-align: left; +} +.katex .cd-label-right { + display: inline-block; + position: absolute; + left: calc(50% + 0.3em); + text-align: right; +} +.katex-display { + display: block; + margin: 1em 0; + text-align: center; +} +.katex-display > .katex { + display: block; + text-align: center; + white-space: nowrap; +} +.katex-display > .katex > .katex-html { + display: block; + position: relative; +} +.katex-display > .katex > .katex-html > .tag { + position: absolute; + right: 0; +} +.katex-display.leqno > .katex > .katex-html > .tag { + left: 0; + right: auto; +} +.katex-display.fleqn > .katex { + text-align: left; + padding-left: 2em; +} +body { + counter-reset: katexEqnNo mmlEqnNo; +} +
diff --git /dev/null b/exemple/css/styles.css @@ -0,0 +1,393 @@ +/* This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ + +@import url("chivo.css"); + +:root { + --lighter-background: #1a2533; + --light-background: #101322; + --dark-background: #070d15; + --foreground: #dfdfdf; + --accent: #ff6ac1; +} + +body { + background: var(--light-background); + color: var(--foreground); +} + +body { + padding: 1em; + margin: 0; + + font-size: 14pt; + font-family: "Chivo", sans-serif; +} + +@media (min-width: 800px) { + body { + padding: 1em 20vw; + } +} + +main { + padding: 2em 0; +} + +main > *:first-child { + margin-top: 0; +} + +main > *:last-child { + margin-bottom: 0; +} + +body > footer { + text-align: center; + display: block; +} + +nav#site-map { + display: grid; + grid-gap: 0.75rem; + grid-template-columns: 20px auto; +} + +nav#site-map img { + margin-top: 2px; +} + +nav#site-map ul { + display: flex; + list-style: none; + margin: 0; + flex-wrap: wrap; +} + +nav#site-map ul li { + margin-right: 1em; +} + +nav#site-map ul li:last-child { + margin: 0; +} + +nav#site-map ul li a { + text-decoration: none; +} + +nav#site-map ul li a:hover { + color: var(--foreground); + text-decoration: underline dotted; + text-decoration-thickness: calc(1em/9); +} + +nav#site-map ul li:last-child { + margin: 0; +} + +nav#site-map ul li:has(a:hover)::marker { + content: ""; +} + +p { + margin: .5em 0; +} + +ul, ol { + padding: 0; +} + +ul { + margin: .5em 0 .5em 1em; + list-style-type: square; +} + +li ul { + margin-top: 0; + margin-bottom: 0; +} + +ol { + margin: .5em 0 .5em 2em; + list-style-type: decimal; +} + +ul li::marker, ol li::marker { + font-weight: bold; + font-style: normal; + color: var(--accent); +} + +ul li:has(a:hover)::marker { + content: "β "; +} + +li > p:first-child { + margin-top: 0; +} + +li > p:last-child { + margin-bottom: 0; +} + +ul#main-links { + column-count: 2; +} + +::selection { + background: var(--accent); + color: var(--light-background); +} + +.admonition { + margin-top: 1em; + margin-bottom: 1em; + padding: 1em; + + background: var(--dark-background); + border-left: 5px solid var(--accent); + + font-style: normal; + font-weight: normal; +} + +.admonition { + display: grid; + grid-template-columns: 1em auto; + grid-gap: 1em; +} + +.admonition .icon { + width: 20px; + height: 20px; +} + +.admonition div:nth-child(2) *:first-child { + margin-top: 0; +} + +.admonition div:nth-child(2) *:last-child { + margin-bottom: 0; +} + +.icon { + user-select: none; + width: 1em !important; +} + +dl dt { + font-weight: bold; +} + +dl dd, .admonition *:nth-child(2) { + overflow-x: scroll; + scrollbar-width: none; +} + +dl dd::-webkit-scrollbar, +.admonition *:nth-child(2)::-webkit-scrollbar { + display: none; +} + +dl dd > *:first-child { + margin-top: 0; +} + +dl dd > *:last-child { + margin-bottom: 0; +} + +table { + min-width: 100%; + margin: 0; + table-layout: fixed; + + font-style: normal; + font-weight: normal; + border-collapse: collapse; +} + +td, th { + overflow: scroll; + scrollbar-width: none; + + padding: 1em; + border: none; + + vertical-align: top; + text-align: left; +} + +thead tr, tbody tr:nth-child(2n) { + background: var(--lighter-background); +} + +table::::-webkit-scrollbar, td::-webkit-scrollbar, th::-webkit-scrollbar { + display: none; +} + +a { + color: var(--foreground); + text-decoration: underline dotted; + text-decoration-thickness: calc(1em/9); + transition: color 0.15s; +} + +a:hover { + color: var(--accent); +} + +h1, h2, h3, h4, h5, h6 { + margin: 0; + font-size: 20pt; + + font-weight: bold; + text-align: left; + color: var(--accent); +} + +figure { + margin: .5em 0; +} + +figure figcaption { + margin-top: 1em; + + font-style: italic; + text-align: center; +} + +figure.equation { + overflow-x: scroll; + scrollbar-width: none; + + text-align: center; +} + +img { + max-width: 100%; + max-height: 100%; +} + +video { + max-width: 100%; +} + +figure img, figure iframe, figure video { + display: block; + margin: 0 auto; + max-width: 100%; + max-height: 60vh; +} + +.table-container { + display: block; + margin: .5em 0; + + overflow-x: scroll; + scrollbar-width: none; +} + +.code-block { + background: var(--dark-background); + border-left: 5px solid var(--accent); + + overflow-x: scroll; + scrollbar-width: none; + + margin: .5em 0; +} + +.code-block::-webkit-scrollbar { + display: none; +} + +.code-block > pre { + font-family: monospace; + width: max-content; + margin: 1em 0; + padding: 0 1em; +} + +code { + font-family: monospace; + font-size: .9em; +} + +time { + display: inline-block; + + padding: .1em .3em; + margin-top: .5em; + + background: var(--foreground); + color: #070d15; +} + +blockquote { + margin-left: 1em; + margin-right: 0; +} + +@media (min-width: 800px) { + blockquote { + margin: 0 2em; + } +} + +blockquote p { + font-style: italic; +} + +blockquote footer { + font-style: normal; + text-align: right; +} + +hr { + border-top: solid 1.5pt var(--foreground); + overflow: visible; +} + +#feed article { + display: grid; + grid-template-rows: fit-content fit-content; + gap: 1em; + + background: var(--dark-background); + padding: 1em; + margin: .5em 0; +} + +#feed p { + margin: 0; +} + +#feed article header { + text-align: left !important; +} + +#feed article h6 { + font-size: 1em; + font-style: italic; + font-weight: bold; +} + +math, time { + white-space: nowrap; +} + +form { + text-align: left; +}
diff --git /dev/null b/exemple/fonts/CHIVO-LICENSE @@ -0,0 +1,94 @@ +Copyright (c) 2023, Omnibus-Type (https://www.omnibus-type.com), +with Reserved Font Name "Chivo". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE.
diff --git /dev/null b/exemple/fonts/Chivo-Bold.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/Chivo-BoldItalic.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/Chivo-Italic.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/Chivo-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_AMS-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_AMS-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_AMS-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Caligraphic-Bold.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Caligraphic-Bold.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Caligraphic-Bold.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Caligraphic-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Caligraphic-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Caligraphic-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Fraktur-Bold.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Fraktur-Bold.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Fraktur-Bold.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Fraktur-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Fraktur-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Fraktur-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Bold.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Bold.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Bold.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-BoldItalic.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-BoldItalic.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-BoldItalic.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Italic.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Italic.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Italic.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Main-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Math-BoldItalic.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Math-BoldItalic.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Math-BoldItalic.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Math-Italic.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Math-Italic.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Math-Italic.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Bold.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Bold.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Bold.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Italic.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Italic.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Italic.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_SansSerif-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Script-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Script-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Script-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size1-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size1-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size1-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size2-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size2-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size2-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size3-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size3-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size3-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size4-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size4-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Size4-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Typewriter-Regular.ttf Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Typewriter-Regular.woff Binary files differ
diff --git /dev/null b/exemple/fonts/KaTeX_Typewriter-Regular.woff2 Binary files differ
diff --git /dev/null b/exemple/images/icons/caution.svg @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg viewBox="0 0 13.229 13.229" + height="20" + width="20" + version="1.1" + xmlns="http://www.w3.org/2000/svg"> + <path fill="#ff6ac1" + d="M 6.6150168 0.88675641 L 0 12.343794 L 13.228483 12.343794 L 6.6150168 0.88675641 z M 5.6941543 5.3825494 L 7.5348457 5.3825494 L 7.5348457 8.4102334 L 5.6941543 8.4102334 L 5.6941543 5.3825494 z M 6.6051984 9.2489313 C 6.8734313 9.2489313 7.1112866 9.3098828 7.3162571 9.4313468 C 7.5111055 9.5528108 7.6082253 9.7894012 7.6082253 10.142406 C 7.6082253 10.506799 7.5044064 10.744652 7.2981706 10.853464 A 1.4056923 1.4056923 0 0 1 6.6051984 11.035363 C 5.9497992 11.035363 5.6207747 10.738339 5.6207747 10.142406 C 5.6207747 9.7894012 5.7245936 9.5528108 5.9308294 9.4313468 C 6.1370651 9.3098828 6.3622705 9.2489313 6.6051984 9.2489313 z " /> +</svg>
diff --git /dev/null b/exemple/images/icons/favicon.svg @@ -0,0 +1,10 @@ +<svg viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"> + <rect x="1" + y="1" + width="18" + height="18" + fill="transparent" + stroke="#ff6ac1" + stroke-width="4" + shape-rendering="crispEdges" /> +</svg>
diff --git /dev/null b/exemple/images/icons/feed.svg @@ -0,0 +1,4 @@ +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 13.229 13.229" height="50" width="50"> + <path d="M1.75 10.054c.477 0 .9.108 1.263.323.347.216.52.636.52 1.265 0 .646-.183 1.07-.551 1.262a2.498 2.498 0 01-1.232.325c-1.165 0-1.75-.528-1.75-1.587 0-.631.184-1.05.552-1.265a2.323 2.323 0 011.198-.323z" fill="#ff6ac1"/> + <path d="M12.035 12.014A12.396 12.396 0 001.217 1.194h0M7.8 12.021a7.706 7.706 0 00-6.592-6.592h0" fill="none" stroke="#ff6ac1" stroke-width="2.146" stroke-linecap="square" paint-order="markers stroke fill"/> +</svg>
diff --git /dev/null b/exemple/images/icons/important.svg @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg viewBox="0 0 13.229 13.229" + height="20" + width="20" + version="1.1" + xmlns="http://www.w3.org/2000/svg"> + <path fill="#ff6ac1" + d="m 6.6150172,13.230034 c 0.9126667,0 1.7682193,-0.172825 2.5662193,-0.518825 0.7973334,-0.336 1.5030065,-0.811585 2.1176735,-1.426251 0.604667,-0.605334 1.080618,-1.3063881 1.427285,-2.1037215 0.336,-0.7973333 0.503839,-1.6528859 0.503839,-2.5662193 0,-0.9126666 -0.167839,-1.7678524 -0.503839,-2.5651857 C 12.380195,3.2524981 11.904243,2.546825 11.29891,1.932158 10.684243,1.326825 9.9785699,0.855859 9.1812365,0.519859 8.3839032,0.173192 7.5283506,0 6.6150172,0 5.7023506,0 4.8471648,0.173192 4.0498315,0.519859 3.2524981,0.855859 2.551444,1.326825 1.94611,1.932158 1.331444,2.546825 0.855859,3.2524981 0.519859,4.0498315 0.173192,4.8471648 0,5.7023506 0,6.6150172 c 0,0.9126667 0.173192,1.7682193 0.519859,2.5662193 0.336,0.7973334 0.811585,1.4983875 1.426251,2.1037215 0.605334,0.614666 1.3063881,1.090251 2.1037215,1.426251 0.7973333,0.346 1.6525191,0.518825 2.5651857,0.518825 z m -0.00155,-1.976082 c -0.6419535,0 -0.9632366,-0.291293 -0.9632366,-0.873837 0,-0.344906 0.1011792,-0.5767372 0.3033368,-0.6955564 0.2021577,-0.1196433 0.4222614,-0.1793149 0.6598998,-0.1793149 0.2615672,0 0.4933984,0.05967 0.695556,0.1793149 0.1906052,0.1188192 0.2857671,0.3506504 0.2857671,0.6955564 0,0.356457 -0.1011792,0.588288 -0.3033369,0.695556 C 7.0769186,11.19449 6.8511053,11.253952 6.613467,11.253952 Z M 7.5229607,8.6846323 H 5.7220597 V 2.121291 h 1.800901 z" /> +</svg>
diff --git /dev/null b/exemple/images/icons/note.svg @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg viewBox="0 0 13.229 13.229" + height="20" + width="20" + version="1.1" + xmlns="http://www.w3.org/2000/svg"> + <path fill="#ff6ac1" + d="M 6.6150168 0 C 5.7023501 0 4.8467975 0.17282484 4.0487975 0.51882484 C 3.2514641 0.85482484 2.5457906 1.3304097 1.9311239 1.9450764 C 1.3264573 2.5504097 0.85050553 3.2514641 0.50383887 4.0487975 C 0.16783887 4.8461308 7.8331415e-17 5.7016834 0 6.6150168 C 0 7.5276834 0.16783887 8.3828692 0.50383887 9.1802025 C 0.84983887 9.9775359 1.3257906 10.683209 1.9311239 11.297876 C 2.5457906 11.903209 3.2514641 12.374175 4.0487975 12.710175 C 4.8461308 13.056842 5.7016834 13.230034 6.6150168 13.230034 C 7.5276834 13.230034 8.3828692 13.056842 9.1802025 12.710175 C 9.9775359 12.374175 10.67859 11.903209 11.283924 11.297876 C 11.89859 10.683209 12.374175 9.9775359 12.710175 9.1802025 C 13.056842 8.3828692 13.230034 7.5276834 13.230034 6.6150168 C 13.230034 5.7023501 13.056842 4.8467975 12.710175 4.0487975 C 12.374175 3.2514641 11.89859 2.5504097 11.283924 1.9450764 C 10.67859 1.3304097 9.9775359 0.85482484 9.1802025 0.51882484 C 8.3828692 0.17282484 7.5276834 3.9165708e-17 6.6150168 0 z M 6.616567 1.9760819 C 7.2585205 1.9760819 7.5798036 2.2673754 7.5798036 2.8499193 C 7.5798036 3.1948249 7.4786244 3.4266562 7.2764668 3.5454754 C 7.0743091 3.6651187 6.8542054 3.7247903 6.616567 3.7247903 C 6.3549998 3.7247903 6.1231686 3.6651201 5.921011 3.5454754 C 5.7304058 3.4266562 5.6352439 3.1948249 5.6352439 2.8499193 C 5.6352439 2.4934619 5.7364231 2.261631 5.9385808 2.1543633 C 6.1531154 2.0355435 6.3789287 1.9760819 6.616567 1.9760819 z M 5.7070733 4.5454017 L 7.5079743 4.5454017 L 7.5079743 11.108743 L 5.7070733 11.108743 L 5.7070733 4.5454017 z " /> +</svg>
diff --git /dev/null b/exemple/images/icons/tip.svg @@ -0,0 +1,6 @@ +<svg xmlns="http://www.w3.org/2000/svg" + viewBox="0 0 13.229 13.229" + height="20" + width="20"> + <path d="M1.944 2.976v7.277h7.795V8.798H6.827v-.485H9.74V6.857H6.827v-.485H9.74V4.916H6.827v-.485h6.402V2.976H6.827zM0 2.039v9.152h1.456V2.039z" fill="#ff6ac1"/> +</svg>
diff --git /dev/null b/exemple/images/icons/warning.svg @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg viewBox="0 0 13.229 13.229" + height="20" + width="20" + version="1.1" + xmlns="http://www.w3.org/2000/svg"> + <path fill="#ff6ac1" + d="M 6.6150168 0.88675641 L 0 12.343794 L 13.228483 12.343794 L 6.6150168 0.88675641 z M 5.6941543 5.3825494 L 7.5348457 5.3825494 L 7.5348457 8.4102334 L 5.6941543 8.4102334 L 5.6941543 5.3825494 z M 6.6051984 9.2489313 C 6.8734313 9.2489313 7.1112866 9.3098828 7.3162571 9.4313468 C 7.5111055 9.5528108 7.6082253 9.7894012 7.6082253 10.142406 C 7.6082253 10.506799 7.5044064 10.744652 7.2981706 10.853464 A 1.4056923 1.4056923 0 0 1 6.6051984 11.035363 C 5.9497992 11.035363 5.6207747 10.738339 5.6207747 10.142406 C 5.6207747 9.7894012 5.7245936 9.5528108 5.9308294 9.4313468 C 6.1370651 9.3098828 6.3622705 9.2489313 6.6051984 9.2489313 z " /> +</svg>
diff --git /dev/null b/exemple/index.md @@ -0,0 +1,5 @@ +# home page + +Example home page. Your content comes here. + +* [content](/content.html) π
diff --git /dev/null b/exemple/js/vim-controls.js @@ -0,0 +1,32 @@ +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +function process_cmd_buffer(key) { + switch (key) { + case "k": case "K": + window.scrollBy(0, -100); + break; + case "j": case "J": + window.scrollBy(0, 100); + break; + case "g": + window.scrollTo(0, 0); + break; + case "G": + window.scrollTo(0, document.body.scrollHeight); + break; + } +} + +window.addEventListener("keydown", (e) => process_cmd_buffer(e.key)); +
diff --git /dev/null b/exemple/posts/a-post.md @@ -0,0 +1,56 @@ +--- +date: 16/07/2026 +excerpt: Post description comes here +--- + +# example post + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc bibendum massa +dolor, ornare tincidunt felis sollicitudin sit amet. Proin condimentum rutrum +dictum. Proin id fermentum dolor, ut iaculis ex. Curabitur in consectetur +tellus, eget tincidunt tortor. Aliquam erat volutpat. Maecenas scelerisque +tristique finibus. Sed rhoncus ornare tellus, vitae ultricies mi venenatis nec. +Sed viverra ultrices ligula id mattis. Integer nisl velit, tincidunt in tortor +id, feugiat auctor massa. Aliquam dignissim ultrices mauris, et sagittis nunc +cursus quis. Class aptent taciti sociosqu ad litora torquent per conubia +nostra, per inceptos himenaeos. Donec ex nulla, placerat ut posuere at, +volutpat a tellus. Morbi id varius urna. Proin ut metus aliquet, vehicula nisi +sit amet, mattis metus. Phasellus cursus quam nec augue dapibus, in cursus +tellus facilisis. + +In elit nibh, dapibus ut turpis vitae, pretium dignissim purus. Sed efficitur +odio sapien, eu molestie est interdum ac. Pellentesque et libero suscipit, +sodales dolor sed, mollis lectus. In non pretium quam. Curabitur sit amet +posuere purus. Pellentesque eu libero et nisi rutrum dapibus. Fusce sed mollis +arcu. Fusce massa quam, condimentum eu odio nec, malesuada porta elit. +Curabitur mollis interdum blandit. Duis eu lacus tincidunt, malesuada est sit +amet, tincidunt nisi. + +Ut fringilla bibendum dolor, id dapibus lorem venenatis in. Maecenas accumsan +ipsum eu maximus posuere. Donec mollis sit amet ligula et aliquet. Vestibulum +iaculis est sed elit dapibus, vel efficitur lorem pulvinar. Sed sodales, diam +eget facilisis consequat, lorem massa euismod mauris, sagittis gravida mauris +justo at risus. Aenean nec tristique elit, quis aliquet elit. Nunc aliquet +ultrices viverra. Phasellus sed gravida mauris, nec consequat enim. Etiam +dictum quam id facilisis venenatis. Curabitur fringilla, est sit amet porta +malesuada, velit felis pretium enim, euismod gravida urna lacus eget nibh. + +Sed ullamcorper efficitur odio at fringilla. Integer eget viverra eros, et +cursus lorem. Fusce mattis pulvinar eros, a ultrices mi semper eget. Duis +luctus cursus metus, sed consectetur dolor dignissim in. Sed a lectus cursus, +tincidunt diam at, ornare nisi. Etiam vestibulum purus quis dolor efficitur +tristique. Aliquam non eleifend purus, ut convallis ligula. + +Maecenas et semper sapien, ac molestie velit. Phasellus vulputate, lorem in +consectetur pharetra, felis magna lacinia nisl, non facilisis erat est at nisl. +Praesent mattis sapien in vestibulum tempus. Pellentesque convallis erat nunc, +at porttitor lectus pellentesque in. Nunc felis ex, convallis vel diam non, +accumsan faucibus urna. Praesent sit amet dignissim lectus, ut facilisis dolor. +Donec et neque tristique, consequat felis nec, malesuada nisi. Etiam ac +sollicitudin tellus. Duis pharetra rutrum odio ac venenatis. Nulla blandit, +orci eget finibus interdum, risus lectus finibus enim, vel euismod massa velit +sit amet massa. Cras congue rhoncus velit, sed vehicula sem sodales sed. Nunc +egestas rhoncus nunc, sit amet consequat augue venenatis et. Nulla at nulla +finibus, elementum dui in, imperdiet massa. Nullam porta congue pellentesque. +Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere +cubilia curae; Donec vel bibendum tortor, eu ornare ex.
diff --git /dev/null b/exemple/posts/b-post.md @@ -0,0 +1,56 @@ +--- +date: 15/07/2026 +excerpt: Post description comes here +--- + +# another example post + +Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc bibendum massa +dolor, ornare tincidunt felis sollicitudin sit amet. Proin condimentum rutrum +dictum. Proin id fermentum dolor, ut iaculis ex. Curabitur in consectetur +tellus, eget tincidunt tortor. Aliquam erat volutpat. Maecenas scelerisque +tristique finibus. Sed rhoncus ornare tellus, vitae ultricies mi venenatis nec. +Sed viverra ultrices ligula id mattis. Integer nisl velit, tincidunt in tortor +id, feugiat auctor massa. Aliquam dignissim ultrices mauris, et sagittis nunc +cursus quis. Class aptent taciti sociosqu ad litora torquent per conubia +nostra, per inceptos himenaeos. Donec ex nulla, placerat ut posuere at, +volutpat a tellus. Morbi id varius urna. Proin ut metus aliquet, vehicula nisi +sit amet, mattis metus. Phasellus cursus quam nec augue dapibus, in cursus +tellus facilisis. + +In elit nibh, dapibus ut turpis vitae, pretium dignissim purus. Sed efficitur +odio sapien, eu molestie est interdum ac. Pellentesque et libero suscipit, +sodales dolor sed, mollis lectus. In non pretium quam. Curabitur sit amet +posuere purus. Pellentesque eu libero et nisi rutrum dapibus. Fusce sed mollis +arcu. Fusce massa quam, condimentum eu odio nec, malesuada porta elit. +Curabitur mollis interdum blandit. Duis eu lacus tincidunt, malesuada est sit +amet, tincidunt nisi. + +Ut fringilla bibendum dolor, id dapibus lorem venenatis in. Maecenas accumsan +ipsum eu maximus posuere. Donec mollis sit amet ligula et aliquet. Vestibulum +iaculis est sed elit dapibus, vel efficitur lorem pulvinar. Sed sodales, diam +eget facilisis consequat, lorem massa euismod mauris, sagittis gravida mauris +justo at risus. Aenean nec tristique elit, quis aliquet elit. Nunc aliquet +ultrices viverra. Phasellus sed gravida mauris, nec consequat enim. Etiam +dictum quam id facilisis venenatis. Curabitur fringilla, est sit amet porta +malesuada, velit felis pretium enim, euismod gravida urna lacus eget nibh. + +Sed ullamcorper efficitur odio at fringilla. Integer eget viverra eros, et +cursus lorem. Fusce mattis pulvinar eros, a ultrices mi semper eget. Duis +luctus cursus metus, sed consectetur dolor dignissim in. Sed a lectus cursus, +tincidunt diam at, ornare nisi. Etiam vestibulum purus quis dolor efficitur +tristique. Aliquam non eleifend purus, ut convallis ligula. + +Maecenas et semper sapien, ac molestie velit. Phasellus vulputate, lorem in +consectetur pharetra, felis magna lacinia nisl, non facilisis erat est at nisl. +Praesent mattis sapien in vestibulum tempus. Pellentesque convallis erat nunc, +at porttitor lectus pellentesque in. Nunc felis ex, convallis vel diam non, +accumsan faucibus urna. Praesent sit amet dignissim lectus, ut facilisis dolor. +Donec et neque tristique, consequat felis nec, malesuada nisi. Etiam ac +sollicitudin tellus. Duis pharetra rutrum odio ac venenatis. Nulla blandit, +orci eget finibus interdum, risus lectus finibus enim, vel euismod massa velit +sit amet massa. Cras congue rhoncus velit, sed vehicula sem sodales sed. Nunc +egestas rhoncus nunc, sit amet consequat augue venenatis et. Nulla at nulla +finibus, elementum dui in, imperdiet massa. Nullam porta congue pellentesque. +Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere +cubilia curae; Donec vel bibendum tortor, eu ornare ex.
diff --git /dev/null b/exemple/robots.txt @@ -0,0 +1,98 @@ +# === crap =================================================================== + +User-agent: AhrefsBot +Disallow: / + +User-agent: AliyunSecBot +Disallow: / + +User-agent: Amazonbot +Disallow: / + +User-agent: Bytespider +Disallow: / + +User-agent: CensysInspect +Disallow: / + +User-agent: ChatGPT-User +Disallow: / + +User-agent: ClaudeBot +Disallow: / + +User-agent: FreePBX-Scanner +Disallow: / + +User-agent: GPTBot +Disallow: / + +User-agent: GoogleOther +Disallow: / + +User-agent: InternetMeasurement +Disallow: / + +User-agent: Mediapartners-Google +Disallow: / + +User-agent: MetaSr +Disallow: / + +User-agent: ModatScanner +Disallow: / + +User-agent: OAI-SearchBot +Disallow: / + +User-agent: Odin +Disallow: / + +User-agent: PerplexityBot +Disallow: / + +User-agent: SERankingBacklinksBot +Disallow: / + +User-agent: SemrushBot +Disallow: / + +User-agent: SocketSpyGlass +Disallow: / + +User-agent: TikTokSpider +Disallow: / + +User-agent: YandexBot +Disallow: / + +User-agent: YandexFavicons +Disallow: / + +User-agent: xfa1 +Disallow: / + +# === search engines ========================================================== + +User-agent: Googlebot +Allow: / + +User-agent: bingbot +Allow: / + +User-agent: Baiduspider +Allow: / + +User-agent: PetalBot +Allow: / + +User-agent: MJ12bot +Allow: / + +User-agent: YouBot +Allow: / + +# === other =================================================================== + +User-agent: * +Allow: /
diff --git /dev/null b/src/escape.rs @@ -0,0 +1,199 @@ +#![allow(unsafe_op_in_unsafe_fn)] +//! HTML Escaping +//! +//! Stolen from pulldown-cmark-escape +//! <https://github.com/pulldown-cmark/pulldown-cmark/> + +use std::fmt::{self, Display}; + +const ESCAPE_TABLE: [Option<&str>; 256] = create_escape_table(); +const fn create_escape_table() -> [Option<&'static str>; 256] { + let mut table = [None; 256]; + table[b'<' as usize] = Some("<"); + table[b'>' as usize] = Some(">"); + table[b'&' as usize] = Some("&"); + table[b'"' as usize] = Some("""); + table[b'\'' as usize] = Some("'"); + table +} + +/// A wrapper for HTML-escaped strings +pub struct Escaped<'a>(pub &'a str); + +// stolen from pulldown-cmark-escape +impl Display for Escaped<'_> { + #[cfg(target_arch = "x86_64")] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // the SIMD accelerated code uses the PSHUFB instruction, which is part + // of the SSSE3 instruction set + if is_x86_feature_detected!("ssse3") { + simd::fmt_escaped_html(self.0, f) + } else { + fmt_escaped_html_scalar(self.0, f) + } + } + + #[cfg(not(target_arch = "x86_64"))] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt_escaped_html_scalar(self.0, f) + } +} + +// stolen from pulldown-cmark-escape +fn fmt_escaped_html_scalar( + s: &str, + f: &mut fmt::Formatter<'_> +) -> fmt::Result { + let bytes = s.as_bytes(); + let mut mark = 0; + let mut i = 0; + + while i < s.len() { + let next_escaped = bytes[i..] + .iter() + .enumerate() + .find_map(|(offset, c)| Some((offset, ESCAPE_TABLE[*c as usize]?))); + + if let Some((offset, escape_seq)) = next_escaped { + i += offset; + f.write_str(&s[mark..i])?; + f.write_str(escape_seq)?; + + i += 1; + mark = i; // all escaped characters are ASCII + } else { + break; + } + } + + f.write_str(&s[mark..]) +} + +// stolen from pulldown-cmark-escape +#[cfg(target_arch = "x86_64")] +mod simd { + use std::{arch::x86_64::*, mem, fmt}; + + const VECTOR_SIZE: usize = mem::size_of::<__m128i>(); + + #[inline] + pub fn fmt_escaped_html(s: &str, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // the strategy here is to walk s in chunks of VECTOR_SIZE (16) bytes at + // a time: + // + // 1. for each chunk, we compute a a bitmask indicating whether the + // corresponding byte is a HTML special byte + // 2. for each bit set in this mask, we print the escaped character + // accordingly, as well as the surrounding characters that don't need + // escaping + // + // when the number of HTML special bytes in the buffer is relatively low, + // this allows us to quickly go through the buffer without a lookup and + // for every single byte + if s.len() < VECTOR_SIZE { + return super::fmt_escaped_html_scalar(s, f); + } + + let bytes = s.as_bytes(); + let mut mark = 0; + let mut offset = 0; + + unsafe { + let upperbound = bytes.len() - VECTOR_SIZE; + while offset < upperbound { + let mut mask = compute_mask(bytes, offset); + + while mask != 0 { + let first_special = mask.trailing_zeros(); + let i = offset + first_special as usize; + let c = *bytes.get_unchecked(i) as usize; + + // here we know c = s[i] is a character that should be escaped, + // so it is safe to unwrap ESCAPE_TABLE[c] + let escape_seq = super::ESCAPE_TABLE[c].unwrap(); + f.write_str(s.get_unchecked(mark..i))?; + f.write_str(escape_seq)?; + + mark = i + 1; // all escaped characters are ASCII + mask ^= mask & -mask; + } + + offset += VECTOR_SIZE; + } + + // ====================================================================== + // final iteration: we align the read with the end of the slice + // and shift off the bytes at start we have already scanned + let mut mask = compute_mask(bytes, upperbound); + mask >>= offset - upperbound; + + while mask != 0 { + let first_special = mask.trailing_zeros(); + let i = offset + first_special as usize; + let c = *bytes.get_unchecked(i) as usize; + + // here we know c = s[i] is a character that should be escaped, + // so it is safe to unwrap ESCAPE_TABLE[c] + let escape_seq = super::ESCAPE_TABLE[c].unwrap(); + f.write_str(s.get_unchecked(mark..i))?; + f.write_str(escape_seq)?; + + mark = i + 1; // all escaped characters are ASCII + mask ^= mask & -mask; + } + + f.write_str(s.get_unchecked(mark..)) + } + } + + + #[inline] + #[target_feature(enable = "ssse3")] + /// Computes a byte mask at given offset in the byte buffer. Its first 16 + /// (least significant) bits correspond to whether there is an HTML special + /// byte at the first VECTOR_SIZE bytes `bytes[offset..]`. + /// + /// It is only safe to call this function when `bytes.len() >= offset + + /// VECTOR_SIZE`. + unsafe fn compute_mask(bytes: &[u8], offset: usize) -> i32 { + debug_assert!(bytes.len() >= offset + VECTOR_SIZE); + + const LOOKUP_TABLE: [u8; VECTOR_SIZE] = create_lookup(); + const fn create_lookup() -> [u8; VECTOR_SIZE] { + let mut table = [0; VECTOR_SIZE]; + table[(b'<' & 0x0f) as usize] = b'<'; + table[(b'>' & 0x0f) as usize] = b'>'; + table[(b'&' & 0x0f) as usize] = b'&'; + table[(b'"' & 0x0f) as usize] = b'"'; + table[(b'\'' & 0x0f) as usize] = b'\''; + table[0] = 0b01111111; + table + } + + let lookup_table = _mm_loadu_si128( + LOOKUP_TABLE.as_ptr() as *const __m128i + ); + let raw_ptr = bytes.as_ptr().add(offset) as *const __m128i; + let vector = _mm_loadu_si128(raw_ptr); + + // mask the vector using the lookup table: + // + // 1. bytes whose lower nibbles are special HTML characters get mapped to + // their lower nibbles + // 2. bytes whose lower nibbles are nonzero and *not* special HTML + // characters get mapped to 0 + // 3. bytes whose lower nibbles are 0 get mapped to 0b01111111 + let masked = _mm_shuffle_epi8(lookup_table, vector); + + // compare the original vector to the masked one: + // + // 1. bytes that shared a lower nibble with an HTML special byte match + // *only* if they are that special byte + // 2. all other bytes will never match + let matches = _mm_cmpeq_epi8(masked, vector); + + // translate matches to a bitmask: every 1 corresponds to a HTML + // special character and a 0 is a non-HTML byte + _mm_movemask_epi8(matches) + } +}
diff --git /dev/null b/src/html.rs @@ -0,0 +1,688 @@ +use std::{ + io::{self, Write}, + fmt::{self, Display}, + iter::Peekable, + collections::HashMap, + cell::{RefCell, LazyCell}, +}; + +use pulldown_cmark::{ + Parser, + Options, + Event, + Tag, + TagEnd, + LinkType, + CodeBlockKind, + BlockQuoteKind, + CowStr, +}; +use syntect::parsing::SyntaxSet; + +use crate::{ + escape::Escaped, + Post, + Page, + Date, + PostInfo, + errorln, +}; + +use crate::config::*; + +#[derive(Debug)] +pub struct Renderer { + buff: RefCell<Vec<u8>>, + syntax_set: LazyCell<SyntaxSet>, +} + +/// Wrapper for displaying a date in the "%Y-%m-%d" format +struct DateTime(Date); + +/// Wrapper for displaying a date in the "%d %M %Y 00:00:00 +0000" format +struct RssDateTime(Date); + +#[derive(Debug)] +pub enum RenderingError { + IO(io::Error), + Katex(katex::Error), +} + +impl Renderer { + pub fn render_post<W: Write>( + &self, + w: &mut W, + post: &Post, + post_index: &HashMap<String, PostInfo>, + ) -> Result<(), RenderingError> { + self.render_md_page( + w, + &post.info.title, + &post.contents, + Some(&post.info.excerpt), + Some(post.info.date), + post_index, + ) + } + + pub fn render_page<W: Write>( + &self, + w: &mut W, + page: &Page, + post_index: &HashMap<String, PostInfo>, + ) -> Result<(), RenderingError> { + self.render_md_page(w, &page.title, &page.contents, None, None, post_index) + } + + #[allow(clippy::too_many_arguments)] + fn render_md_page<W: Write>( + &self, + w: &mut W, + title: &str, + contents: &str, + description: Option<&str>, + date: Option<Date>, + post_index: &HashMap<String, PostInfo>, + ) -> Result<(), RenderingError> { + let mut opt = Options::empty(); + opt.insert(Options::ENABLE_TABLES); + opt.insert(Options::ENABLE_STRIKETHROUGH); + opt.insert(Options::ENABLE_SMART_PUNCTUATION); + opt.insert(Options::ENABLE_MATH); + opt.insert(Options::ENABLE_GFM); + opt.insert(Options::ENABLE_DEFINITION_LIST); + opt.insert(Options::ENABLE_SUPERSCRIPT); + opt.insert(Options::ENABLE_SUBSCRIPT); + opt.insert(Options::ENABLE_WIKILINKS); + + let mut p = Parser::new_ext(contents, opt).peekable(); + + // ======================================================================== + let head_info = { + let mut buff = self.buff.borrow_mut(); + buff.clear(); + render_md_to_html(&mut *buff, post_index, &self.syntax_set, &mut p)? + }; + + // ======================================================================== + render_copyright(w)?; + writeln!(w, "<html lang=\"en\">")?; + render_head(w, title, description, &head_info)?; + writeln!(w, "<body>")?; + render_nav(w)?; + writeln!(w, "<main>")?; + writeln!(w, "<h1>{}</h1>", Escaped(title))?; + if let Some(date) = date { + writeln!(w, "<time datetime=\"{}\">{}</time>", DateTime(date), date)?; + } + w.write_all(&self.buff.borrow())?; + writeln!(w, "</main>")?; + render_footer(w)?; + writeln!(w, "</body>")?; + writeln!(w, "</html>")?; + + Ok(()) + } +} + +impl Default for Renderer { + fn default() -> Self { + // TODO(2): read this from ~/.config/roll/ too + fn load_syntax_set() -> SyntaxSet { + const SYNTAX_SET_DUMP: &[u8] = include_bytes!( + concat!(env!("OUT_DIR"), "/syntax-set.dump") + ); + syntect::dumps::from_uncompressed_data(SYNTAX_SET_DUMP).unwrap() + } + + let buff = RefCell::new(Vec::new()); + let syntax_set = LazyCell::new(load_syntax_set as fn() -> SyntaxSet); + Self { buff, syntax_set, } + } +} + +pub fn render_feed<W: Write>( + w: &mut W, + posts: &[(String, PostInfo)], +) -> io::Result<()> { + const DESCRIPTION: &str = "blog articles feed"; + + render_copyright(w)?; + writeln!(w, "<html lang=\"en\">")?; + render_head( + w, + FEED_TITLE, + Some(DESCRIPTION), + &HeadInfo::default(), + )?; + writeln!(w, "<body>")?; + render_nav(w)?; + + writeln!(w, "<main>")?; + writeln!(w, "<h1>{FEED_TITLE}</h1>")?; + + writeln!(w, "<p>")?; + writeln!(w, "{FEED_DESCRIPTION}")?; + writeln!(w, "</p>")?; + + writeln!(w, "<ul>")?; + writeln!(w, "<li><a href=\"/{POSTS_SUBDIR}/{RSS_FILE}\">RSS feed</a></li>")?; + writeln!(w, "</ul>")?; + + writeln!(w, "<div id=\"feed\" role=\"feed\" aria-label=\"{}\" aria-busy=\"false\">", + Escaped(DESCRIPTION))?; + for (post_name, PostInfo { title, excerpt, date, }) in posts { + writeln!(w, "<article>")?; // TODO: custom aria-label? + writeln!(w, "<header>")?; + writeln!(w, "<h6>")?; + writeln!(w, "<a href=\"/{POSTS_SUBDIR}/{post_name}.html\">{}</a>", Escaped(title))?; + writeln!(w, "</h6>")?; + writeln!(w, "<time datetime=\"{}\">{}</time>", DateTime(*date), date)?; + writeln!(w, "</header>")?; + writeln!(w, "<div>")?; + writeln!(w, "<p>")?; + writeln!(w, "{}", Escaped(excerpt))?; + writeln!(w, "</p>")?; + writeln!(w, "</div>")?; + writeln!(w, "</article>")?; + } + writeln!(w, "</div>")?; + + writeln!(w, "</main>")?; + render_footer(w)?; + writeln!(w, "</body>")?; + writeln!(w, "</html>")?; + + Ok(()) +} + +pub fn render_rss<W: Write>( + w: &mut W, + posts: &[(String, PostInfo)], +) -> io::Result<()> { + let today = Date::today(); + + writeln!(w, "<?xml version=\"1.0\" encoding=\"utf-8\"?>")?; + writeln!(w, "<rss version=\"2.0\">")?; + writeln!(w, "<channel>")?; + + writeln!(w, "<title>{FEED_TITLE}</title>")?; + writeln!(w, "<description>{FEED_DESCRIPTION}</description>")?; + writeln!(w, "<author>{AUTHOR}</author>")?; + writeln!(w, "<language>en-us</language>")?; + writeln!(w, "<copyright>Copyright {}, {AUTHOR}</copyright>", today.year)?; + writeln!(w, "<link>{HOST_URL}</link>")?; + writeln!(w, "<lastBuildDate>{}</lastBuildDate>", RssDateTime(today))?; + writeln!(w, "<generator>{} {}</generator>", + env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))?; + + for (post_name, PostInfo { title, excerpt, date, }) in posts { + writeln!(w, "<item>")?; + writeln!(w, "<title>{}</title>", Escaped(title))?; + writeln!(w, "<descrition>{}</description>", Escaped(excerpt))?; + writeln!(w, "<author>{AUTHOR}</author>")?; + writeln!(w, "<link>{HOST_URL}/{POSTS_SUBDIR}/{post_name}.html</link>")?; + writeln!(w, "<pubDate>{}</pubDate>", RssDateTime(*date))?; + writeln!(w, "<guid isPermaLink=\"false\">{post_name}</guid>")?; + writeln!(w, "</item>")?; + } + + writeln!(w, "</channel>")?; + writeln!(w, "</rss>")?; + Ok(()) +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +struct State { + in_table_head: bool, +} + +// Addapted from pulldown_cmark/html.rs +// <https://github.com/pulldown-cmark/pulldown-cmark/> +fn render_md_to_html<'h, W: Write>( + w: &mut W, + post_index: &HashMap<String, PostInfo>, + syntax_set: &LazyCell<SyntaxSet>, + p: &'h mut Peekable<Parser<'_>>, +) -> Result<HeadInfo<'h>, RenderingError> { + let mut state = State { in_table_head: true, }; + let mut head_info = HeadInfo::default(); + + let display_math_opt = katex::Opts::builder() + .display_mode(true) + .build() + .unwrap(); + + while let Some(event) = p.next() { + match event { + Event::Start(tag) => { + start_tag( + w, + tag, + post_index, + &mut head_info, + syntax_set, + &mut state, + p, + )? + } + Event::End(tag) => end_tag(w, tag, &mut state)?, + Event::Text(text) => write!(w, "{}", Escaped(&text))?, + Event::Code(text) => { + write!(w, "<code>{}</code>", Escaped(&text))?; + } + Event::InlineMath(math) => { + head_info.needs_katex = true; + // TODO(2): row our own katex bindings + let html = match katex::render(&math) { + Ok(html) => html, + Err(e) => { + errorln!("could not render article: {e}"); + return Err(e.into()); + } + }; + + write!(w, "{html}")?; + } + Event::DisplayMath(math) => { + head_info.needs_katex = true; + // TODO(2): row our own katex bindings + let html = match katex::render_with_opts(&math, &display_math_opt) { + Ok(html) => html, + Err(e) => { + errorln!("could not render article: {e}"); + return Err(e.into()); + } + }; + + writeln!(w, "<figure class=\"equation\">")?; + writeln!(w, "{html}")?; + writeln!(w, "</figure>")?; + } + Event::SoftBreak => writeln!(w)?, + Event::HardBreak => writeln!(w, "<br/>")?, + Event::Rule => writeln!(w, "<hr/>")?, + Event::Html(html) | Event::InlineHtml(html) => write!(w, "{html}")?, + Event::TaskListMarker(_) => { + unreachable!("task lists are not supported"); + } + Event::FootnoteReference(_) => { + unreachable!("footnotes are not supported"); + } + } + } + Ok(head_info) +} + +// Addapted from pulldown_cmark/html.rs +// <https://github.com/pulldown-cmark/pulldown-cmark/> +fn start_tag<'h, W: Write>( + w: &mut W, + tag: Tag<'h>, + post_index: &HashMap<String, PostInfo>, + head_info: &mut HeadInfo<'h>, + syntax_set: &LazyCell<SyntaxSet>, + state: &mut State, + p: &mut Peekable<Parser<'h>>, +) -> io::Result<()> { + match tag { + Tag::HtmlBlock => {} + Tag::Paragraph => { + // horrible hack to wrap block images with <figure> + if !matches!(p.peek(), Some(Event::Start(Tag::Image { .. }))) { + writeln!(w, "<p>")?; + return Ok(()); + } + + let (dest_url, caption) = match p.next() { + Some(Event::Start(Tag::Image { dest_url, title: caption, .. })) => { + (dest_url, caption) + } + _ => unreachable!(), + }; + + writeln!(w, "<figure>")?; + process_image(w, p, dest_url, head_info)?; + if !caption.is_empty() { + writeln!(w, "<figcaption>")?; + writeln!(w, "{}", Escaped(&caption))?; + writeln!(w, "</figcaption>")?; + } + writeln!(w, "</figure>")?; + + assert_eq!(p.next(), Some(Event::End(TagEnd::Paragraph))); + } + Tag::Heading { level, .. } => write!(w, "<{level}>")?, + Tag::Subscript => write!(w, "<sub>")?, + Tag::Superscript => write!(w, "<sup>")?, + Tag::Table(_alignments) => write!(w, "<table>")?, + Tag::TableHead => { + state.in_table_head = true; + write!(w, "<thead><tr>")?; + } + Tag::TableRow => write!(w, "<tr>")?, + Tag::TableCell => if state.in_table_head { + write!(w, "<th>")?; + } else { + write!(w, "<td>")?; + }, + Tag::CodeBlock(block_kind) => { + use syntect::{ + html::{ClassedHTMLGenerator, ClassStyle}, + util::LinesWithEndings, + }; + + head_info.needs_highlighting = true; + + let mut code = String::new(); + for event in p { + match event { + Event::Text(text) => code.push_str(&text), + Event::SoftBreak => {}, + Event::End(TagEnd::CodeBlock) => break, + _ => unreachable!("should not get {event:?} inside of code block"), + } + } + + let code_html = get_highlighted_code(code, block_kind, syntax_set); + fn get_highlighted_code( + code: String, + block_kind: CodeBlockKind, + syntax_set: &LazyCell<SyntaxSet>, + ) -> String { + let lang = if let CodeBlockKind::Fenced(lang) = block_kind { + lang + } else { + return code; + }; + if lang.is_empty() { return code; } + + if let Some(syntax_ref) = syntax_set.find_syntax_by_token(&lang) { + let mut html_generator = ClassedHTMLGenerator::new_with_class_style( + syntax_ref, + syntax_set, + ClassStyle::Spaced, + ); + + for line in LinesWithEndings::from(&code) { + // TODO: warn the user somehow? + if html_generator + .parse_html_for_line_which_includes_newline(line) + .is_err() { + return code; + } + } + + html_generator.finalize() + } else { + code + } + } + + writeln!(w, "<div class=\"code-block\">")?; + writeln!(w, "<pre>{code_html}</pre>")?; + writeln!(w, "</div>")?; + } + Tag::BlockQuote(None) => writeln!(w, "<blockquote>")?, + Tag::BlockQuote(Some(kind)) => { // admonitions + let label = match kind { + BlockQuoteKind::Note => "note", + BlockQuoteKind::Tip => "tip", + BlockQuoteKind::Important => "important", + BlockQuoteKind::Warning => "warning", + BlockQuoteKind::Caution => "caution", + }; + + writeln!(w, "<div class=\"admonition\" aria-label=\"{label}\" role=\"note\">")?; + writeln!(w, "<div aria-hidden=\"true\">")?; + writeln!(w, "<img class=\"icon\" src=\"/{ICONS_SUBDIR}/{label}.svg\" width=\"20\" height=\"20\" alt=\"{label} icon\">")?; + writeln!(w, "</div>")?; + writeln!(w, "<div>")?; + } + Tag::List(Some(1)) => writeln!(w, "<ol>")?, + Tag::List(Some(start)) => writeln!(w, "<ol start=\"{start}\">")?, + Tag::List(None) => writeln!(w, "<ul>")?, + Tag::Item => writeln!(w, "<li>")?, + Tag::DefinitionList => writeln!(w, "<dl>")?, + Tag::DefinitionListTitle => write!(w, "<dt>")?, + Tag::DefinitionListDefinition => write!(w, "<dd>")?, + Tag::Emphasis => write!(w, "<em>")?, + Tag::Strong => write!(w, "<strong>")?, + Tag::Strikethrough => write!(w, "<del>")?, + Tag::Link { link_type: LinkType::Email, dest_url, .. } => { + write!(w, "<a href=\"mailto:{url}\">", url = Escaped(&dest_url))?; + } + Tag::Link { link_type: LinkType::WikiLink { .. }, dest_url, .. } => { + write!(w, "<a href=\"/{POSTS_SUBDIR}/{}.html\">", Escaped(&dest_url))?; + if let Some(PostInfo { title, .. }) = post_index + .get(&dest_url.to_string()) { + write!(w, "{title}")?; + // NOTE: the next event should cotain the content that goes inside the + // link tag, which in this case is just the post tag we already + // know from `dest_url` (API quirck?) + let _ = p.next(); + } + } + Tag::Link { dest_url, .. } => { + write!(w, "<a href=\"{url}\">", url = Escaped(&dest_url))?; + } + Tag::Image { dest_url, .. } => { + process_image(w, p, dest_url, head_info)?; + } + Tag::FootnoteDefinition(_) => { + unreachable!("footnotes are not supported"); + } + Tag::MetadataBlock(_) => { + unreachable!("metadata blocks should be at the beginning"); + } + } + + Ok(()) +} + +// Addapted from pulldown_cmark/html.rs +// <https://github.com/pulldown-cmark/pulldown-cmark/> +fn end_tag<W: Write>( + w: &mut W, + tag: TagEnd, + state: &mut State, +) -> io::Result<()> { + match tag { + TagEnd::HtmlBlock => {} + TagEnd::Paragraph => writeln!(w, "\n</p>")?, + TagEnd::Heading(level) => writeln!(w, "</{level}>")?, + TagEnd::Subscript => write!(w, "</sub>")?, + TagEnd::Superscript => write!(w, "</sup>")?, + TagEnd::Table => { + writeln!(w, "</tbody>")?; + writeln!(w, "</table>")?; + } + TagEnd::TableHead => { + writeln!(w, "</tr>")?; + writeln!(w, "</thead>")?; + writeln!(w, "<tbody>")?; + state.in_table_head = false; + } + TagEnd::TableRow => writeln!(w, "</tr>")?, + TagEnd::TableCell => if state.in_table_head { + write!(w, "</th>")?; + } else { + write!(w, "</td>")?; + }, + TagEnd::CodeBlock => { + unreachable!("should have been handled in `start_tag`"); + } + TagEnd::BlockQuote(None) => writeln!(w, "</blockquote>")?, + TagEnd::BlockQuote(Some(_)) => writeln!(w, "</div>\n</div>")?, + TagEnd::List(true) => writeln!(w, "</ol>")?, + TagEnd::List(false) => writeln!(w, "</ul>")?, + TagEnd::Item => writeln!(w, "</li>")?, + TagEnd::DefinitionList => writeln!(w, "</dl>")?, + TagEnd::DefinitionListTitle => writeln!(w, "</dt>")?, + TagEnd::DefinitionListDefinition => writeln!(w, "</dd>")?, + TagEnd::Emphasis => write!(w, "</em>")?, + TagEnd::Strong => write!(w, "</strong>")?, + TagEnd::Strikethrough => write!(w, "</del>")?, + TagEnd::Link => write!(w, "</a>")?, + TagEnd::Image => {} // handled in start_tag + TagEnd::FootnoteDefinition => { + unreachable!("footnotes are not supported"); + } + TagEnd::MetadataBlock(_) => { + unreachable!("metadata blocks should be filtered in the begenning?"); + } + } + + Ok(()) +} + +fn process_image<'h, W: Write>( + w: &mut W, + p: &mut Peekable<Parser<'_>>, + dest_url: CowStr<'h>, + head_info: &mut HeadInfo<'h>, +) -> io::Result<()> { + write!(w, "<img")?; + + // TODO: support other link kinds? + if dest_url.starts_with("https://") || dest_url.starts_with("http://") { + write!(w, " src=\"{url}\"", url = Escaped(&dest_url))?; + } else { // relative URL + head_info.preload_imgs.push(dest_url.clone()); + write!(w, " src=\"/{IMGS_SUBDIR}/{url}\"", url = Escaped(&dest_url))?; + }; + + writeln!(w, " alt=\"")?; + for event in &mut *p { + match event { + Event::End(TagEnd::Image) => break, + Event::Text(alt_part) | Event::Code(alt_part) => { + write!(w, "{}", Escaped(&alt_part))?; + } + Event::SoftBreak => {}, + Event::Start(_) | Event::End(_) => {}, + event => unreachable!("expeceted image alt, got {event:?}"), + } + } + writeln!(w, "\">")?; + Ok(()) +} + +fn render_copyright<W: Write>(w: &mut W) -> io::Result<()> { + const COPYRIGHT: &str = include_str!("html/copyright.html"); + writeln!(w, "{}", COPYRIGHT) +} + +// TODO(2): prealoads? +#[derive(Debug, Default)] +struct HeadInfo<'h> { + needs_katex: bool, + needs_highlighting: bool, + preload_imgs: Vec<CowStr<'h>>, +} + +fn render_head<W: Write>( + w: &mut W, + title: &str, + description: Option<&str>, + head_info: &HeadInfo, +) -> io::Result<()> { + const PRELOAD_MAX: usize = 2; + writeln!(w, "<head>")?; + writeln!(w, "<title>{}</title>", Escaped(title))?; + writeln!(w, "<meta charset=\"utf-8\" />")?; + writeln!(w, "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />")?; + if let Some(description) = description { + writeln!(w, "<meta name=\"description\" content=\"{}\" />", + Escaped(description))?; + } + writeln!(w, "<meta name=\"author\" content=\"{AUTHOR}\" />")?; + // TODO: this apparently is not complient with the standards: + // https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/meta/name + writeln!(w, "<meta name=\"copyright\" content=\"GPLv3\" />")?; + writeln!(w, "<link rel=\"stylesheet\" href=\"/css/styles.css\" />")?; + if head_info.needs_katex { + writeln!(w, "<link rel=\"stylesheet\" href=\"/css/katex.css\" />")?; + } + if head_info.needs_highlighting { + writeln!(w, "<link rel=\"stylesheet\" href=\"/css/highlighting.css\" />")?; + } + writeln!(w, "<link rel=\"icon\" type=\"image/svg+xml\" sizes=\"16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512\" href=\"/{IMGS_SUBDIR}/icons/favicon.svg\">")?; + writeln!(w, "<script type=\"module\" src=\"/js/vim-controls.js\"></script>")?; + for img_path in head_info.preload_imgs.iter().take(PRELOAD_MAX) { + writeln!(w, "<link rel=\"preload\" as=\"image\" href=\"/{IMGS_SUBDIR}/{img_path}\" />")?; + } + writeln!(w, "</head>")?; + + Ok(()) +} + +fn render_nav<W: Write>(w: &mut W) -> io::Result<()> { + writeln!(w, "<header>")?; + writeln!(w, "<nav id=\"site-map\">")?; + writeln!(w, "<img src=\"/{ICONS_SUBDIR}/favicon.svg\" width=\"20px\" height=\"20px\">")?; + writeln!(w, "<ul>")?; + writeln!(w, "<li><strong><a href=\"/\">pablo</a></strong></li>")?; + writeln!(w, "<li><a href=\"/{POSTS_SUBDIR}/\">blog</a></li>")?; + writeln!(w, "<li><a href=\"https://git.pablopie.xyz/\">projects</a></li>")?; + writeln!(w, "</ul>")?; + writeln!(w, "</nav>")?; + writeln!(w, "</header>")?; + + Ok(()) +} + +fn render_footer<W: Write>(w: &mut W) -> io::Result<()> { + const FOOTER: &str = include_str!("html/footer.html"); + writeln!(w, "{}", FOOTER) +} + +impl From<io::Error> for RenderingError { + fn from(e: io::Error) -> Self { + Self::IO(e) + } +} + +impl From<katex::Error> for RenderingError { + fn from(e: katex::Error) -> Self { + Self::Katex(e) + } +} + +impl Display for RenderingError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::IO(e) => write!(f, "{e}"), + Self::Katex(e) => write!(f, "{e}"), + } + } +} + +impl Display for DateTime { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Date { year, month, day, } = self.0; + write!(f, "{year}-{month:02}-{day:02}") + } +} + +impl Display for RssDateTime { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let Date { year, month, day, } = self.0; + let month = match month { + 1 => "Jan", + 2 => "Feb", + 3 => "Mar", + 4 => "Apr", + 5 => "May", + 6 => "Jun", + 7 => "Jul", + 8 => "Aug", + 9 => "Sep", + 10 => "Oct", + 11 => "Nov", + 12 => "Dec", + _ => unreachable!("invalid month in date"), + }; + write!(f, "{day} {month} {year} 00:00:00 +0000") + } +}
diff --git /dev/null b/src/html/copyright.html @@ -0,0 +1,12 @@ +<!-- This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. -->
diff --git /dev/null b/src/html/footer.html @@ -0,0 +1 @@ +<footer>made with β€οΈ by <a href="/index.html">@pablo</a></footer>
diff --git /dev/null b/src/log.rs @@ -0,0 +1,123 @@ +//! Macros for logging. +//! +//! This implementation is NOT thread safe, since yagit is only expected to run +//! on my single-threaded server. +#![allow(static_mut_refs)] + +use std::{fmt::Arguments, time::Duration}; + +const BOLD_RED: &str = "\u{001b}[1;31m"; +const BOLD_GREEN: &str = "\u{001b}[1;32m"; +const BOLD_YELLOW: &str = "\u{001b}[1;33m"; +const BOLD_BLUE: &str = "\u{001b}[1;34m"; +const BOLD_WHITE: &str = "\u{001b}[1;37m"; +const RESET: &str = "\u{001b}[0m"; + +const PROGRAM_NAME: &str = env!("CARGO_PKG_NAME"); +const PROGRAM_VERSION: &str = env!("CARGO_PKG_VERSION"); + +#[derive(Clone, Copy, Debug)] +#[allow(dead_code)] +pub(crate) enum Level { + Error, + Info, + Warn, + Rendered, + Usage, +} + +#[allow(dead_code)] +pub(crate) fn log(level: Level, args: &Arguments<'_>) { + match level { + Level::Error => { + eprintln!(" {BOLD_RED}Error{RESET} {args}"); + // shouldn't print the job counter because we are about to die + } + Level::Info => { + println!(" {BOLD_BLUE}Info{RESET} {args}"); + } + Level::Rendered => { + println!(" {BOLD_GREEN}Rendered{RESET} {args}"); + } + Level::Warn => { + println!(" {BOLD_YELLOW}Warning{RESET} {args}"); + } + Level::Usage => { + println!(" {BOLD_YELLOW}Usage{RESET} {BOLD_WHITE}{PROGRAM_NAME}{RESET} {args}"); + } + } +} + +#[macro_export] +macro_rules! infoln { + // infoln!("a {} event", "log"); + ($($arg:tt)+) => ({ + $crate::log::log( + $crate::log::Level::Info, + &std::format_args!($($arg)+), + ); + }); +} + +#[macro_export] +macro_rules! errorln { + // errorln!("a {} event", "log"); + ($($arg:tt)+) => ({ + $crate::log::log( + $crate::log::Level::Error, + &std::format_args!($($arg)+), + ); + }); +} + +#[macro_export] +macro_rules! warnln { + // warnln!("a {} event", "log"); + ($($arg:tt)+) => ({ + $crate::log::log( + $crate::log::Level::Warn, + &std::format_args!($($arg)+), + ); + }); +} + +#[macro_export] +macro_rules! renderedln { + // renderedln!("a {} event", "log"); + ($($arg:tt)+) => ({ + $crate::log::log( + $crate::log::Level::Rendered, + &std::format_args!($($arg)+), + ); + }); +} + +#[macro_export] +macro_rules! usageln { + // usageln!("a {} event", "log"); + ($($arg:tt)+) => ({ + $crate::log::log( + $crate::log::Level::Usage, + &std::format_args!($($arg)+), + ); + }); +} + +pub fn finished(duration: Duration) { + let ms = duration.as_millis(); + println!(" {BOLD_GREEN}Finished{RESET} processing took {ms}ms"); +} + +#[cfg(target_arch = "x86_64")] +pub fn version() { + if is_x86_feature_detected!("ssse3") { + infoln!("running {BOLD_WHITE}{PROGRAM_NAME} {PROGRAM_VERSION}{RESET} (SIMD optimizations enabled)"); + } else { + infoln!("running {BOLD_WHITE}{PROGRAM_NAME} {PROGRAM_VERSION}{RESET}"); + } +} + +#[cfg(not(target_arch = "x86_64"))] +pub fn version() { + infoln!("Running {BOLD_WHITE}{PROGRAM_NAME} {PROGRAM_VERSION}{RESET}"); +}
diff --git /dev/null b/src/main.rs @@ -0,0 +1,699 @@ +#![allow(clippy::result_unit_err)] +#![allow(clippy::non_canonical_partial_ord_impl)] +#![allow(clippy::derive_ord_xor_partial_ord)] +use std::{ + io, + fs::{self, File, Metadata}, + path::{PathBuf, Path}, + env, + process::ExitCode, + collections::HashMap, + fmt::{self, Display}, + cmp, + time::{self, Instant}, +}; + +mod log; +mod escape; +mod html; + +#[derive(Clone, Debug)] +pub struct PostInfo { + pub title: String, + pub excerpt: String, + pub date: Date, +} + +#[derive(Debug)] +pub struct Post { + pub info: PostInfo, + + /// Contents of the corresponding Markdown file, not including the title + pub contents: String, +} + +#[derive(Debug)] +pub struct Page { + title: String, + + /// Contents of the corresponding Markdown file, not including the title + contents: String, +} + +// TODO(1) +//pub struct BlogConfig { +// pub author: String, +// pub host_url: String, +// pub feed_title: String, +// pub feed_description: String, +// pub exclude_files: Vec<String>, +//} + +mod config { + static_toml::static_toml! { + static CONFIG = include_toml!("config.toml"); + } + + pub const AUTHOR: &str = CONFIG.content.author; + pub const HOST_URL: &str = CONFIG.content.host_url; + pub const EXCLUDE_FILES: &[&str] = &CONFIG.content.exclude; + pub const FEED_TITLE: &str = CONFIG.feed.title; + pub const FEED_DESCRIPTION: &str = CONFIG.feed.description; + + pub const OUTPUT_SUBDIR: &str = "site"; + pub const POSTS_SUBDIR: &str = "posts"; + pub const IMGS_SUBDIR: &str = "images"; + pub const ICONS_SUBDIR: &str = "images/icons"; + pub const RSS_FILE: &str = "feed.rss"; +} + +use config::*; + +fn main() -> ExitCode { + let mut args = env::args(); + let _program_name = args.next().unwrap(); + + const FULL_BUILD_FLAG: &str = "-B"; + + let mut full_build = false; + let mut input_dir = None; + for arg in args { + if arg == FULL_BUILD_FLAG { + full_build = true; + } else if arg.starts_with('-') { + errorln!("unknown flag {arg:?}"); + usageln!("[{FULL_BUILD_FLAG}] [INPUT_DIR]"); + return ExitCode::FAILURE; + } else if input_dir.is_none() { + input_dir = Some(arg); + } else { + errorln!("unknown argument {arg:?}"); + usageln!("[{FULL_BUILD_FLAG}] [INPUT_DIR]"); + return ExitCode::FAILURE; + } + } + + let input_dir = input_dir.unwrap_or(".".into()); + log::version(); + infoln!("processing blog at {input_dir:?}"); + + if do_it(&input_dir, full_build).is_ok() { + ExitCode::SUCCESS + } else { + ExitCode::FAILURE + } +} + +fn do_it(input_dir: &str, full_build: bool) -> Result<(), ()> { + let start = Instant::now(); + + let JobList { + posts_to_index, + posts_to_render, + pages_to_render, + files_to_copy, + dirs_to_create, + + pages_total, + } = collect_jobs(input_dir, full_build).map_err(|_| ())?; + + // ========================================================================== + for output_path in dirs_to_create { + if !fs::exists(&output_path).unwrap_or(false) + && let Err(e) = fs::create_dir(&output_path) { + errorln!("could not create {output_path:?}: {e}"); + return Err(()); + } + } + + for CpJob { input_path, output_path, } in files_to_copy { + if let Err(e) = fs::copy(&input_path, &output_path) { + errorln!("could not copy {input_path:?} to {output_path:?}: {e}"); + return Err(()); + } + } + + // ========================================================================== + let posts_total = posts_to_index.len()+posts_to_render.len(); + let mut post_index = HashMap::with_capacity(posts_total); + let mut parsed_posts_to_render = Vec::with_capacity(posts_total); + for PostIndexJob { name, input_path, } in posts_to_index { + let post = Post::read_from_file(&input_path).map_err(|_| ())?; + let _ = post_index.insert(name, post.info); + } + for PostRenderJob { name, input_path, output_path, } in posts_to_render { + let post = Post::read_from_file(&input_path).map_err(|_| ())?; + let job_name = name.clone(); + let _ = post_index.insert(name, post.info.clone()); + + parsed_posts_to_render.push((job_name, output_path, post)); + } + parsed_posts_to_render.sort_by(|(name1, _, _), (name2, _, _)| name1.cmp(name2)); + + let mut pages = Vec::with_capacity(pages_to_render.len()); + for PageRenderJob { + name: job_name, + input_path, + output_path, + } in pages_to_render { + let page = Page::read_from_file(&input_path)?; + pages.push((job_name, output_path, page)); + } + pages.sort_by(|(name1, _, _), (name2, _, _)| name1.cmp(name2)); + + match (parsed_posts_to_render.len(), pages.len()) { + (0, 0) => { + warnln!("skipping rendering {posts_total} blog posts and {pages_total} pages, run with -B to override"); + } + (0, n_pages) => { + infoln!("rendering {n_pages} pages"); + warnln!("skipping rendering {posts_total} blog posts, run with -B to override"); + } + (n_posts, 0) => { + infoln!("rendering {n_posts} blog posts"); + warnln!("skipping rendering {pages_total} pages, run with -B to override"); + } + (n_posts, n_pages) => { + infoln!("rendering {n_posts} blog posts and {n_pages} pages"); + } + } + + let r = html::Renderer::default(); + + for (job_name, output_path, post) in parsed_posts_to_render { + let mut f = create_file(&output_path).map_err(|_| ())?; + r.render_post(&mut f, &post, &post_index).map_err(|_| ())?; + renderedln!("{}.md", job_name); + } + + for (job_name, output_path, page) in pages { + let mut f = create_file(&output_path).map_err(|_| ())?; + r.render_page(&mut f, &page, &post_index).map_err(|_| ())?; + renderedln!("{}.md", job_name); + } + + // ========================================================================== + let mut post_index = post_index.into_iter().collect::<Vec<_>>(); + post_index.sort_by(|(_, post1), (_, post2)| { + (post2.date, &post1.title).cmp(&(post1.date, &post2.title)) + }); + + let mut feed_path = PathBuf::from(input_dir); + feed_path.push(OUTPUT_SUBDIR); + feed_path.push(POSTS_SUBDIR); + feed_path.push("index.html"); + let mut feed_f = create_file(&feed_path).map_err(|_| ())?; + html::render_feed(&mut feed_f, &post_index).map_err(|_| ())?; + drop(feed_f); + renderedln!("feed"); + + let mut rss_path = PathBuf::from(input_dir); + rss_path.push(OUTPUT_SUBDIR); + rss_path.push(POSTS_SUBDIR); + rss_path.push(RSS_FILE); + let mut rss_f = create_file(&rss_path).map_err(|_| ())?; + html::render_rss(&mut rss_f, &post_index).map_err(|_| ())?; + drop(rss_f); + renderedln!("RSS feed"); + + // ========================================================================== + log::finished(start.elapsed()); + + Ok(()) +} + +#[derive(Debug, Default)] +struct JobList { + posts_to_index: Vec<PostIndexJob>, + posts_to_render: Vec<PostRenderJob>, + pages_to_render: Vec<PageRenderJob>, + files_to_copy: Vec<CpJob>, + dirs_to_create: Vec<CreateDirJob>, + + /// Total number of files, not including posts + pages_total: usize, +} + +#[derive(Debug)] +struct PostIndexJob { + name: String, + input_path: PathBuf, +} + +#[derive(Debug)] +struct PostRenderJob { + name: String, + input_path: PathBuf, + output_path: PathBuf, +} + +#[derive(Debug)] +struct PageRenderJob { + name: String, + input_path: PathBuf, + output_path: PathBuf, +} + +#[derive(Debug)] +struct CpJob { + input_path: PathBuf, + output_path: PathBuf, +} + +type CreateDirJob = PathBuf; + +fn collect_jobs( + input_dir: &str, + full_build: bool, +) -> io::Result<JobList> { + fn collect_post_jobs( + posts_src_dir: &Path, + result: &mut JobList, + input_dir: &str, + full_build: bool, + ) -> io::Result<()> { + let dir_reader = match fs::read_dir(posts_src_dir) { + Ok(dir_reader) => dir_reader, + Err(e) => { + errorln!("could not read files in {posts_src_dir:?}: {e}"); + return Err(e); + } + }; + + for entry in dir_reader.flatten() { + let file_name = entry.file_name(); + let file_name = file_name.to_string_lossy(); + + if let Some(post_name) = file_name.strip_suffix(".md") { + let input_path = entry.path(); + let mut output_path = PathBuf::from(input_dir); + output_path.push(OUTPUT_SUBDIR); + output_path.push(POSTS_SUBDIR); + output_path.push(format!("{post_name}.html")); + + if full_build + || needs_update(entry.metadata(), &output_path) { + result.posts_to_render.push(PostRenderJob { + name: post_name.to_string(), + input_path, + output_path, + }); + } else { + result.posts_to_index.push(PostIndexJob { + name: post_name.to_string(), + input_path, + }); + } + } + } + + Ok(()) + } + + #[allow(clippy::ptr_arg)] + fn collect_other_jobs( + dir_path: &Path, + parent_path: &PathBuf, + result: &mut JobList, + on_root: bool, + full_build: bool, + ) -> io::Result<bool> { + let mut contains_changes = false; + let dir_reader = match fs::read_dir(dir_path) { + Ok(dir_reader) => dir_reader, + Err(e) => { + errorln!("could not read files in {dir_path:?}: {e}"); + return Err(e); + } + }; + + for entry in dir_reader.flatten() { + let file_type = entry.file_type()?; + if file_type.is_symlink() { + continue; + } + + let file_name = entry.file_name(); + if file_type.is_file() { + const STD_EXCLUDE_FILES: &[&str] = &[ ".gitignore", ]; + if STD_EXCLUDE_FILES.contains(&file_name.to_string_lossy().as_ref()) { + continue; + } + + if EXCLUDE_FILES.contains(&file_name.to_string_lossy().as_ref()) { + continue; + } + + let input_path = entry.path(); + + // TODO: parse and render HTML files too? + if let Some(file_name) = file_name + .to_string_lossy() + .strip_suffix(".md") { + result.pages_total += 1; + + let mut output_path = parent_path.clone(); + output_path.push(format!("{file_name}.html")); + + if full_build || needs_update(entry.metadata(), &output_path) { + contains_changes = true; + let name = file_name.into(); + result.pages_to_render.push(PageRenderJob { + name, + input_path, + output_path, + }); + } + } else { + let mut output_path = parent_path.clone(); + output_path.push(file_name); + + if full_build || needs_update(entry.metadata(), &output_path) { + contains_changes = true; + result.files_to_copy.push(CpJob { input_path, output_path }); + } + } + } else if file_type.is_dir() { + const SKIP_SUBDIRS: &[&str] = &[ POSTS_SUBDIR, OUTPUT_SUBDIR, ".git" ]; + + let mut output_path = parent_path.clone(); + output_path.push(&file_name); + + let file_name = file_name.to_string_lossy(); + if on_root && SKIP_SUBDIRS.contains(&file_name.as_ref()) { + continue; + } + + let this_contains_changes = collect_other_jobs( + &entry.path(), + &output_path, + result, + false, + full_build, + )?; + contains_changes |= this_contains_changes; + if full_build || this_contains_changes { + result.dirs_to_create.push(output_path); + } + } + } + + Ok(contains_changes) + } + + let mut result = JobList::default(); + + let mut posts_src_dir = PathBuf::from(input_dir); + posts_src_dir.push(POSTS_SUBDIR); + collect_post_jobs(&posts_src_dir, &mut result, input_dir, full_build)?; + + let mut output_root = PathBuf::from(input_dir); + output_root.push(OUTPUT_SUBDIR); + + let mut posts_subdir = output_root.clone(); + posts_subdir.push(POSTS_SUBDIR); + + let mut imgs_subdir = output_root.clone(); + imgs_subdir.push(IMGS_SUBDIR); + + let mut icons_subdir = output_root.clone(); + icons_subdir.push(ICONS_SUBDIR); + + result.dirs_to_create.push(output_root.clone()); + result.dirs_to_create.push(posts_subdir); + result.dirs_to_create.push(imgs_subdir); + result.dirs_to_create.push(icons_subdir); + + let _ = collect_other_jobs( + Path::new(input_dir), + &output_root, + &mut result, + true, + full_build, + )?; + + Ok(result) +} + +impl Post { + pub fn read_from_file(path: &Path) -> Result<Self, ()> { + let src = match fs::read_to_string(path) { + Ok(src) => src, + Err(e) => { + errorln!("could not read {path:?}: {e}"); + return Err(()); + } + }; + + let (info, rest) = parse_post_info(&src, &path.to_string_lossy())?; + + Ok(Self { info, contents: rest.into() }) + } +} + +fn parse_post_info<'a>( + src: &'a str, + path: &str, +) -> Result<(PostInfo, &'a str), ()> { + #[derive(Debug)] + struct Lexer<'b> { + line_n: usize, + rest: &'b str, + } + + fn next_line<'a>(l: &mut Lexer<'a>) -> Result<&'a str, ()> { + let mut bound = 0; + for c in l.rest.chars() { + if !c.is_whitespace() { break; } + if c == '\n' { + l.line_n += 1; + } + + bound += c.len_utf8(); + } + + l.rest = &l.rest[bound..]; + match l.rest.split_once('\n') { + Some((line, rest)) => { + l.line_n += 1; + l.rest = rest; + + Ok(line) + } + None => Err(()) + } + } + + let mut l = Lexer { line_n: 0, rest: src, }; + + let line = next_line(&mut l) + .map_err(|_| errorln!("{path}:{}: expected \"---\", got EOF", l.line_n))?; + if line.trim() != "---" { + errorln!("{path}:{}: could not parse metadata: expected \"---\", got {line:?}", + l.line_n); + return Err(()); + } + + let mut date = None; + let mut excerpt = None; + while let Ok(line) = next_line(&mut l) { + if line.trim() == "---" { + break; + } + + if let Some((key, val)) = line.split_once(':') { + let key = key.trim(); + let val = val.trim(); + + match key { + "date" => { + fn parse_date(date: &str) -> Option<Date> { + let (day_str, rest) = date.split_once('/')?; + let (month_str, year_str) = rest.split_once('/')?; + + let day: u8 = day_str.parse().ok()?; + let month: u8 = month_str.parse().ok()?; + let year: u16 = year_str.parse().ok()?; + + if day == 0 || day > 31 { return None; } + if month == 0 || month > 12 { return None; } + + Some(Date { day, month, year, }) + } + + if let Some(d) = parse_date(val) { + date = Some(d); + } else { + errorln!("{path}:{}: could not parse metadata: invalid date {val:?}", + l.line_n); + return Err(()); + } + } + "excerpt" => excerpt = Some(val), + _ => { + errorln!("{path}:{}: could not parse metadata: expected \"date\" or \"excerpt\", got {key:?}", + l.line_n); + return Err(()); + } + } + } else { + errorln!("{path}:{}: could not parse metadata: expected key-value pair, got {line:?}", + l.line_n); + return Err(()); + } + } + + if date.is_none() { + errorln!("{path}:{}: could not parse metadata: \"date\" key was not specified", + l.line_n); + return Err(()); + } + + if excerpt.is_none() { + errorln!("{path}:{}: could not parse metadata: \"excerpt\" key was not specified", + l.line_n); + return Err(()); + } + + let (date, excerpt) = (date.unwrap(), excerpt.unwrap().into()); + + let title_line = next_line(&mut l) + .map_err(|_| errorln!("{path}:{}: expected post title, got EOF", l.line_n))?; + let title_line = title_line.trim(); + + let title = match title_line.strip_prefix("# ") { + Some(title) => title, + None => { + errorln!("{path}:{}: expected post title, got {title_line:?}", + l.line_n); + return Err(()); + } + }; + let title = title.trim().into(); + + Ok((PostInfo { title, excerpt, date, }, l.rest)) +} + +impl Page { + pub fn read_from_file(path: &Path) -> Result<Self, ()> { + let src = match fs::read_to_string(path) { + Ok(src) => src, + Err(e) => { + errorln!("{path}: could not read {path:?}: {e}", + path = path.to_string_lossy()); + return Err(()); + } + }; + let src = src.trim(); + + let path = path.to_string_lossy(); + if let Some((title_line, rest)) = src.split_once('\n') { + if let Some(title) = title_line.strip_prefix("# ") { + let title = title.into(); + let contents = rest.trim().into(); + + Ok(Self { title, contents, }) + } else { + errorln!("{path}: expected post title, got {title_line:?}"); + Err(()) + } + } else { + errorln!("{path}: expected post title, got {src:?}"); + Err(()) + } + } +} + +fn needs_update<P: AsRef<Path>>(src: io::Result<Metadata>, dst: &P) -> bool { + let dst_meta = fs::metadata(dst); + if let (Ok(dst_meta), Ok(src_meta)) = (&dst_meta, src) + && dst_meta.modified().unwrap() > src_meta.modified().unwrap() { + return false; + } + + true +} + +fn create_file<P: AsRef<Path> + fmt::Debug>(path: &P) -> io::Result<File> { + File::create(path) + .map_err(|e| { errorln!("Failed to create {:?}: {e}", &path); e }) +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Ord)] +pub struct Date { + pub year: u16, + pub month: u8, + pub day: u8, +} + +impl Date { + pub fn today() -> Self { + use time::SystemTime; + + // NOTE: copied from https://howardhinnant.github.io/date_algorithms.html#civil_from_days + fn civil_from_days(days_since_epoch: i64) -> Date { + let z = days_since_epoch + 719468; + let era = if z >= 0 { z } else { z - 146096 } / 146097; + let doe = z - era * 146097; // [0, 146096] + let yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; // [0, 399] + let y = yoe + era * 400; + let doy = doe - (365*yoe + yoe/4 - yoe/100); // [0, 365] + let mp = (5*doy + 2) / 153; // [0, 11] + let day = doy - (153*mp + 2) / 5 + 1; // [1, 31] + let month = mp + if mp < 10 { 3 } else { -9 }; // [1, 12] + let year = y + if month <= 2 { 1 } else { 0 }; + + let day = day as u8; + let month = month as u8; + let year = year as u16; + + Date { day, month, year, } + } + + let days_since_epoch = SystemTime::now() + .duration_since(time::UNIX_EPOCH) + .unwrap() + .as_secs() / 86_400; + + civil_from_days(days_since_epoch as i64) + } +} + +impl Display for Date { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let month = match self.month { + 0 => unreachable!("month is too small: month = 0"), + 1 => "Jan", + 2 => "Feb", + 3 => "Mar", + 4 => "Apr", + 5 => "May", + 6 => "Jun", + 7 => "Jul", + 8 => "Aug", + 9 => "Sep", + 10 => "Oct", + 11 => "Nov", + 12 => "Dec", + month => unreachable!("month is too big: month = {month}"), + }; + + let suffix = match self.day { + 0 => unreachable!("day is too small: day = 0"), + 1 => "st", + 2 => "nd", + 3 => "rd", + _ => "th", + }; + + write!(f, "{month} {}{suffix}, {}", self.day, self.year) + } +} + +impl PartialOrd for Date { + fn partial_cmp(&self, date: &Date) -> Option<cmp::Ordering> { + Some( + (self.year, self.month, self.day).cmp(&(date.year, date.month, date.day)) + ) + } +}
diff --git /dev/null b/syntax/Assembly/Assembly x86.sublime-syntax @@ -0,0 +1,89 @@ +%YAML 1.2 +--- +# Based on: https://github.com/Nessphoro/sublimeassembly +name: Assembly X86 +scope: source.asm + +file_extensions: + - asm + - nasm + +contexts: + main: + - include: instructions + - include: registers + - include: directives + - include: labels + - include: comments + - include: strings + - include: numbers + - include: operators + + instructions: + - match: '\b(?i)(aaa|aad|aam|aas|adc|adcx|add|addpd|addps|addsd|addss|addsubpd|addsubps|adox|aesdec|vaesdec|aesdec128kl|aesdec256kl|aesdeclast|vaesdeclast|aesdecwide128kl|aesdecwide256kl|aesenc|vaesenc|aesenc128kl|aesenc256kl|aesenclast|aesencwide128kl|aesencwide256kl|aesimc|vaesimc|aeskeygenassist|and|andn|andnpd|vandnpd|andnps|vandnps|andpd|andps|vandps|arpl|bextr|blendpd|vblendpd|blendps|blendvpd|vblendvpd|blendvps|vblendvps|blsi|blsmsk|blsr|bndcl|bndcu|bndcn|bndldx|bndmk|bndmov|bndstx|bound|bsf|bsr|bswap|bt|btc|btr|bts|bzhi|call|cbw|cwde|cdqe|cwd|cdq|cqo|clac|clc|cld|cldemote|clflush|clflushopt|cli|clrssbsy|clts|clui|clwb|cmc|cmova/cmovnbe|cmovae/cmovnb|cmovb/cmovc|cmovbe/cmovna|cmove/cmovz|cmovne/cmovnz|cmovg/cmovnle|cmovge/cmovnl|cmovl/cmovnge|cmovle/cmovng|cmovo|cmovno|cmovs|cmovns|cmovp/cmovpe|cmovnp/cmovpo|cmp|cmppd|cmpps|cmps|cmpsb|cmpsw|cmpsd|cmpsq|cmpss|cmpxchg|cmpxchg8b|cmpxchg16b|comisd|comiss|cpuid|crc32|cvtdq2pd|cvtdq2ps|cvtpd2dq|cvtpd2pi|cvtpd2ps|cvtpi2pd|cvtpi2ps|cvtps2dq|cvtps2pd|cvtps2pi|cvtsd2si|cvtsd2ss|cvtsi2sd|cvtsi2ss|cvtss2sd|cvtss2si|cvttpd2dq|cvttpd2pi|cvttps2dq|cvttps2pi|cvttsd2si|cvttss2si|daa|das|dec|div|divpd|vdivpd|divps|divsd|divss|dppd|vdppd|dpps|emms|encodekey128|encodekey256|endbr32|endbr64|enqcmd|enqcmds|enter|extractps|f2xm1|fabs|fadd|faddp|fiadd|fbld|fbstp|fchs|fclex|fnclex|fcmovb|fcmove|fcmovbe|fcmovu|fcmovnb|fcmovne|fcmovnbe|fcmovnu|fcom|fcomp|fcompp|fcomi|fcomip|fucomi|fucomip|fcos|fdecstp|fdiv|fdivp|fidiv|fdivr|fdivrp|fidivr|ffree|ficom|ficomp|fild|fmul|fmulp|fimul|fincstp|finit|fninit|fist|fistp|fisttp|fsub|fsubp|fisub|fsubr|fsubrp|fisubr|fld|fld1|fldl2t|fldl2e|fldpi|fldlg2|fldln2|fldz|fldcw|fldenv|fnop|fsave|fnsave|fstcw|fnstcw|fstenv|fnstenv|fstsw|fnstsw|fpatan|fprem|fprem1|fptan|frndint|frstor|fscale|fsin|fsincos|fsqrt|fst|fstp|ftst|fucom|fucomp|fucompp|wait|fwait|fxam|fxch|fxrstor|fxrstor64|fxsave|fxsave64|fxtract|fyl2x|fyl2xp1|gf2p8affineinvqb|vgfp8affineinvqb|gf2p8affineqb|vgfp8affineqb|gf2p8mulb|vgf2p8mulb|haddpd|vhaddpd|haddps|hlt|hreset|hsubpd|vhsubpd|hsubps|vhsubps|idiv|imul|in|inc|incsspd|incsspq|ins|insb|insw|insd|insertps|int|into|int3|int1|invd|invlpg|invpcid|iret|iretd|iretq|jmp|ja|jae|jb|jbe|jc|jcxz|jecxz|jrcxz|je|jg|jge|jl|jle|jna|jnae|jnb|jnbe|jnc|jne|jng|jnge|jnl|jnle|jno|jnp|jns|jnz|jo|jp|jpe|jpo|js|jz|kaddw|kaddb|kaddq|kaddd|kandw|kandb|kandq|kandd|kandnw|kandnb|kandnq|kandnd|kmovw|kmovb|kmovq|kmovd|knotw|knotb|knotq|knotd|korw|korb|korq|kord|kortestw|kortestb|kortestq|kortestd|kshiftlw|kshiftlb|kshiftlq|kshiftld|kshiftrw|kshiftrb|kshiftrq|kshiftrd|ktestw|ktestb|ktestq|ktestd|kunpckbw|kunpckwd|kunpckdq|kxnorw|kxnorb|kxnorq|kxnord|kxorw|kxorb|kxorq|kxord|lahf|lar|lddqu|vlddqu|ldmxcsr|vldmxcsr|lds|les|lfs|lgs|lss|ldtilecfg|lea|leave|lfence|lgdt|lidt|lldt|lmsw|loadiwkey|lock|lods|lodsb|lodsw|lodsd|lodsq|loop|loope|loopne|lsl|ltr|lzcnt|maskmovdqu|maskmovq|maxpd|maxps|maxsd|vmaxsd|maxss|vmaxss|mfence|minpd|minps|minsd|minss|monitor|mov|movapd|movaps|movbe|movd|movq|movddup|movdir64b|movdiri|movdq2q|movdqa|vmovdqa32|vmovdqa64|movdqu|vmovdqu8|vmovdqu16|vmovdqu32|vmovdqu64|movhlps|movhpd|movhps|movlhps|movlpd|movlps|movmskpd|movmskps|movntdq|movntdqa|vmovntdqa|movnti|movntpd|movntps|vmovntps|movntq|vmovq|movq2dq|movs|movsb|movsw|movsd|movsq|movshdup|movsldup|vmovsldup|movss|vmovss|movsx|movsxd|movupd|vmovupd|movups|vmovups|movzx|mpsadbw|mul|mulpd|mulps|mulsd|mulss|mulx|mwait|neg|nop|not|or|orpd|vorpd|orps|vorps|out|outs|outsb|outsw|outsd|pabsb|pabsw|pabsd|pabsq|vpabsb|vpabsw|vpabsd|vpabsq|packsswb|packssdw|packusdw|packuswb|paddb|paddw|paddd|paddq|vpaddb|vpaddw|vpaddd|vpaddq|paddsb|paddsw|paddusb|paddusw|palignr|pand|vpand|vpandd|vpandq|pandn|vpandn|vpandnd|vpandnq|pause|pavgb|pavgw|vpavgb|vpavgw|pblendvb|vpblendvb|pblendw|vpblendw|pclmulqdq|vpclmulqdq|pcmpeqb|pcmpeqw|pcmpeqd|pcmpeqq|vpcmpeqq|pcmpestri|pcmpestrm|pcmpgtb|pcmpgtw|pcmpgtd|vpcmpgtb|vpcmpgtw|vpcmpgtd|pcmpgtq|vpcmpgtq|pcmpistri|pcmpistrm|pconfig|pdep|pext|pextrb|pextrd|pextrq|pextrw|phaddw|phaddd|vphaddw|vphaddd|phaddsw|phminposuw|vphminposuw|phsubw|phsubd|phsubsw|pinsrb|pinsrd|pinsrq|pinsrw|pmaddubsw|vpmaddubsw|pmaddwd|pmaxsb|pmaxsw|pmaxsd|pmaxsq|pmaxub|pmaxuw|vpmaxub|vpmaxuw|pmaxud|vpmaxud|vpmaxuq|pminsb|pminsw|vpminsb|vpminsw|pminsd|pminsq|pminub|pminuw|vpminub|vpminuw|pminud|vpminud|vpminuq|pmovmskb|pmovsxbw|pmovsxbd|pmovsxbq|pmovsxwd|pmovsxwq|pmovsxdq|vpmovsxbw|vpmovsxbd|vpmovsxbq|vpmovsxwd|vpmovsxwq|vpmovsxdq|pmovzxbw|pmovzxbd|pmovzxbq|pmovzxwd|pmovzxwq|pmovzxdq|pmuldq|pmulhrsw|pmulhuw|pmulhw|pmulld|pmullq|pmullw|pmuludq|pop|popa|popad|popcnt|popf|popfd|popfq|por|vpor|vpord|vporq|prefetchw|prefetcht0|prefetcht1|prefetcht2|prefetchnta|psadbw|pshufb|vpshufb|pshufd|pshufhw|vpshufhw|pshuflw|vpshuflw|pshufw|psignb|psignw|psignd|psllw|pslld|psllq|vpsllw|vpslld|vpsllq|pslldq|psraw|psrad|vpsraw|vpsrad|vpsraq|psrlw|psrld|psrlq|psrldq|psubb|psubw|psubd|vpsubb|vpsubw|vpsubd|psubq|vpsubq|psubsb|psubsw|vpsubsb|vpsubsw|psubusb|psubusw|ptest|vptest|ptwrite|punpckhbw|punpckhwd|punpckhdq|punpckhqdq|punpcklbw|punpcklwd|punpckldq|punpcklqdq|push|pusha|pushad|pushf|pushfd|pushfq|pxor|vpxor|vpxord|vpxorq|rcl|rcr|rol|ror|rcpps|rcpss|rdfsbase|rdgsbase|rdmsr|rdpid|rdpkru|rdpmc|rdrand|rdseed|rdsspd|rdsspq|rdtsc|rdtscp|rep|repe/repz|repne/repnz|ret|rorx|roundpd|roundps|roundsd|roundss|rsm|rsqrtps|rsqrtss|rstorssp|sahf|sal|sar|shl|shr|sarx|shlx|shrx|saveprevssp|sbb|scas|scasb|scasw|scasd|scasq|senduipi|serialize|setssbsy|sfence|sgdt|sha1msg1|sha1msg2|sha1nexte|sha1rnds4|sha256msg1|sha256msg2|sha256rnds2|shld|shrd|shufpd|vshufpd|shufps|vshufps|sidt|sldt|smsw|sqrtpd|sqrtps|vsqrtps|sqrtsd|sqrtss|stac|stc|std|sti|stmxcsr|vstmxcsr|stos|stosb|stosw|stosd|stosq|str|sttilecfg|stui|sub|subpd|subps|subsd|subss|swapgs|syscall|sysenter|sysexit|sysret|tdpbf16ps|tdpbssd|tdpbsud|tdpbusd|tdpbuud|test|testui|tileloadd|tileloaddt1|tilerelease|tilestored|tilezero|tpause|tzcnt|ucomisd|ucomiss|ud0|ud1|ud2|uiret|umonitor|umwait|unpckhpd|unpckhps|vunpckhps|unpcklpd|vunpcklpd|unpcklps|vaddph|vaddsh|valignd|valignq|vblendmpd|vblendmps|vbroadcastss|vbroadcastsd|vbroadcastf128|vbroadcastf32x2|vbroadcastf32x4|vbroadcastf64x2|vbroadcastf32x8|vbroadcastf64x4|vcmpph|vcmpsh|vcomish|vcompresspd|vcompressps|vpcompressb|vpcompressw|vcvtdq2ph|vcvtne2ps2bf16|vcvtneps2bf16|vcvtpd2ph|vcvtpd2qq|vcvtpd2udq|vcvtpd2uqq|vcvtph2dq|vcvtph2pd|vcvtph2ps|vcvtph2psx|vcvtph2qq|vcvtph2udq|vcvtph2uqq|vcvtph2uw|vcvtph2w|vcvtps2ph|vcvtps2phx|vcvtps2qq|vcvtps2udq|vcvtps2uqq|vcvtqq2pd|vcvtqq2ph|vcvtqq2ps|vcvtsd2sh|vcvtsd2usi|vcvtsh2sd|vcvtsh2si|vcvtsh2ss|vcvtsh2usi|vcvtsi2sh|vcvtss2sh|vcvtss2usi|vcvttpd2qq|vcvttpd2udq|vcvttpd2uqq|vcvttph2dq|vcvttph2qq|vcvttph2udq|vcvttph2uqq|vcvttph2uw|vcvttph2w|vcvttps2qq|vcvttps2udq|vcvttps2uqq|vcvttsd2usi|vcvttsh2si|vcvttsh2usi|vcvttss2usi|vcvtudq2pd|vcvtudq2ph|vcvtudq2ps|vcvtuqq2pd|vcvtuqq2ph|vcvtuqq2ps|vcvtusi2sd|vcvtusi2sh|vcvtusi2ss|vcvtuw2ph|vcvtw2ph|vdbpsadbw|vdivph|vdivsh|vdpbf16ps|verr|verw|vexpandpd|vexpandps|vextractf128|vextractf32x4|vextractf64x2|vextractf32x8|vextractf64x4|vextracti128|vextracti32x4|vextracti64x2|vextracti32x8|vextracti64x4|vfcmaddcph|vfmaddcph|vfcmaddcsh|vfmaddcsh|vfcmulcph|vfmulcph|vfcmulcsh|vfmulcsh|vfixupimmpd|vfixupimmps|vfixupimmsd|vfixupimmss|vfmadd132pd|vfmadd213pd|vfmadd231pd|vfmadd132ph|vfnmadd132ph|vfmadd213ph|vfnmadd213ph|vfmadd231ph|vfnmadd231ph|vfmadd132ps|vfmadd213ps|vfmadd231ps|vfmadd132sd|vfmadd213sd|vfmadd231sd|vfmadd132sh|vfnmadd132sh|vfmadd213sh|vfnmadd213sh|vfmadd231sh|vfnmadd231sh|vfmadd132ss|vfmadd213ss|vfmadd231ss|vfmaddrnd231pd|vfmaddsub132pd|vfmaddsub213pd|vfmaddsub231pd|vfmaddsub132ph|vfmaddsub213ph|vfmaddsub231ph|vfmaddsub132ps|vfmaddsub213ps|vfmaddsub231ps|vfmsub132pd|vfmsub213pd|vfmsub231pd|vfmsub132ph|vfnmsub132ph|vfmsub213ph|vfnmsub213ph|vfmsub231ph|vfnmsub231ph|vfmsub132ps|vfmsub213ps|vfmsub231ps|vfmsub132sd|vfmsub213sd|vfmsub231sd|vfmsub132sh|vfnmsub132sh|vfmsub213sh|vfnmsub213sh|vfmsub231sh|vfnmsub231sh|vfmsub132ss|vfmsub213ss|vfmsub231ss|vfmsubadd132pd|vfmsubadd213pd|vfmsubadd231pd|vfmsubadd132ph|vfmsubadd213ph|vfmsubadd231ph|vfmsubadd132ps|vfmsubadd213ps|vfmsubadd231ps|vfnmadd132pd|vfnmadd213pd|vfnmadd231pd|vfnmadd132ps|vfnmadd213ps|vfnmadd231ps|vfnmadd132sd|vfnmadd213sd|vfnmadd231sd|vfnmadd132ss|vfnmadd213ss|vfnmadd231ss|vfnmsub132pd|vfnmsub213pd|vfnmsub231pd|vfnmsub132ps|vfnmsub213ps|vfnmsub231ps|vfnmsub132sd|vfnmsub213sd|vfnmsub231sd|vfnmsub132ss|vfnmsub213ss|vfnmsub231ss|vfpclasspd|vfpclassph|vfpclassps|vfpclasssd|vfpclasssh|vfpclassss|vgatherdpd|vgatherqpd|vgatherdps|vgatherqps|vgetexppd|vgetexpph|vgetexpps|vgetexpsd|vgetexpsh|vgetexpss|vgetmantpd|vgetmantph|vgetmantps|vgetmantsd|vgetmantsh|vgetmantss|vinsertf128|vinsertf32x4|vinsertf64x2|vinsertf32x8|vinsertf64x4|vinserti128|vinserti32x4|vinserti64x2|vinserti32x8|vinserti64x4|vmaskmovps|vmaskmovpd|vmaxph|vmaxsh|vminph|vminsh|vmovsh|vmovw|vmulph|vmulsh|vp2intersectd|vp2intersectq|vpblendd|vpblendmb|vpblendmw|vpblendmd|vpblendmq|vpbroadcastb|vpbroadcastw|vpbroadcastd|vpbroadcastq|vbroadcasti32x2|vbroadcasti128|vbroadcasti32x4|vbroadcasti64x2|vbroadcasti32x8|vbroadcasti64x4|vpbroadcastmb2q|vpbroadcastmw2d|vpcmpb|vpcmpub|vpcmpd|vpcmpud|vpcmpq|vpcmpuq|vpcmpw|vpcmpuw|vpcompressd|vpcompressq|vpconflictd|vpconflictq|vpdpbusd|vpdpbusds|vpdpwssd|vpdpwssds|vperm2f128|vperm2i128|vpermb|vpermd|vpermw|vpermi2b|vpermi2w|vpermi2d|vpermi2q|vpermi2ps|vpermi2pd|vpermilpd|vpermilps|vpermpd|vpermps|vpermq|vpermt2b|vpermt2w|vpermt2d|vpermt2q|vpermt2ps|vpermt2pd|vpexpandb|vpexpandw|vpexpandd|vpexpandq|vpgatherdd|vpgatherqd|vpgatherdq|vpgatherqq|vplzcntd|vplzcntq|vpmadd52huq|vpmadd52luq|vpmaskmovd|vpmaskmovq|vpmovb2m|vpmovw2m|vpmovd2m|vpmovq2m|vpmovdb|vpmovsdb|vpmovusdb|vpmovdw|vpmovsdw|vpmovusdw|vpmovm2b|vpmovm2w|vpmovm2d|vpmovm2q|vpmovqb|vpmovsqb|vpmovusqb|vpmovqd|vpmovsqd|vpmovusqd|vpmovqw|vpmovsqw|vpmovusqw|vpmovwb|vpmovswb|vpmovuswb|vpmultishiftqb|vpopcntb|vpopcntw|vpopcntd|vpopcntq|vprold|vprolvd|vprolq|vprolvq|vprord|vprorvd|vprorq|vprorvq|vpscatterdd|vpscatterdq|vpscatterqd|vpscatterqq|vpshldw|vpshldd|vpshldq|vpshldvw|vpshldvd|vpshldvq|vpshrdw|vpshrdd|vpshrdq|vpshrdvw|vpshrdvd|vpshrdvq|vpshufbitqmb|vpsllvw|vpsllvd|vpsllvq|vpsravw|vpsravd|vpsravq|vpsrlvw|vpsrlvd|vpsrlvq|vpternlogd|vpternlogq|vptestmb|vptestmw|vptestmd|vptestmq|vptestnmb|vptestnmw|vptestnmd|vptestnmq|vrangepd|vrangeps|vrangesd|vrangess|vrcp14pd|vrcp14ps|vrcp14sd|vrcp14ss|vrcpph|vrcpsh|vreducepd|vreduceph|vreduceps|vreducesd|vreducesh|vreducess|vrndscalepd|vrndscaleph|vrndscaleps|vrndscalesd|vrndscalesh|vrndscaless|vrsqrt14pd|vrsqrt14ps|vrsqrt14sd|vrsqrt14ss|vrsqrtph|vrsqrtsh|vscalefpd|vscalefph|vscalefps|vscalefsd|vscalefsh|vscalefss|vscatterdps|vscatterdpd|vscatterqps|vscatterqpd|vshuff32x4|vshuff64x2|vshufi32x4|vshufi64x2|vsqrtph|vsqrtsh|vsubph|vsubsh|vtestps|vtestpd|vucomish|vzeroall|vzeroupper|wbinvd|wbnoinvd|wrfsbase|wrgsbase|wrmsr|wrpkru|wrssd|wrssq|wrussd|wrussq|xabort|xacquire|xrelease|xadd|xbegin|xchg|xend|xgetbv|xlat|xlatb|xor|xorpd|xorps|xresldtrk|xrstor|xrstors|xrstors64|xsave|xsavec|xsaveopt|xsaves|xsetbv|xsusldtrk|xtest|encls|eadd|eaug|eblock|ecreate|edbgrd|edbgwr|eextend|einit|eldb|eldu|eldbc|elduc|emodpr|emodt|epa|erdinfo|eremove|etrackc|etrack|ewb|enclu|eacceptcopy|eaccept|edeccssa|eenter|eexit|egetkey|emodpe|ereport|eresume|enclv|edecvirtchild|eincvirtchild|esetcontext|getsec[capabilities]|getsec[enteraccs]|getsec[exitac]|getsec[parameters]|getsec[senter]|getsec[sexit]|getsec[smctrl]|getsec[wakeup]|invept|invvpid|vmcall|vmclear|vmfunc|vmlaunch|vmresume|vmptrld|vmptrst|vmread|vmwrite|vmxoff|vmxon|prefetchwt1|v4fmaddps|v4fnmaddps|v4fmaddss|v4fnmaddss|vexp2pd|vexp2ps|vgatherpf0dps|vgatherpf0qps|vgatherpf0dpd|vgatherpf0qpd|vgatherpf1dps|vgatherpf1qps|vgatherpf1dpd|vgatherpf1qpd|vp4dpwssd|vp4dpwssds|vrcp28pd|vrcp28ps|vrcp28sd|vrcp28ss|vrsqrt28pd|vrsqrt28ps|vrsqrt28sd|vrsqrt28ss|vscatterpf0dps|vscatterpf0qps|vscatterpf0dpd|vscatterpf0qpd|vscatterpf1dps|vscatterpf1qps|vscatterpf1dpd|vscatterpf1qpd|halt)\b' + scope: keyword.control.assembly + + registers: + - match: '\b(?i)(RBP|EBP|BP|CS|DS|ES|FS|GS|SS|RAX|EAX|RBX|EBX|RCX|ECX|RDX|EDX|RIP|EIP|IP|RSP|ESP|SP|RSI|ESI|SI|RDI|EDI|DI|RFLAGS|EFLAGS|FLAGS|R(8|9|10|11|12|13|14|15)(d|w|b)?|(Z|Y|X)MM([0-9]|10|11|12|13|14|15)|(A|B|C|D)(X|H|L)|CR[0-4]|DR[0-7]|TR6|TR7|EFER)\b' + scope: variable.parameter.register.assembly + + numbers: + - match: '\b0x[A-Fa-f0-9]+\b' + scope: constant.numeric.hexadecimal.assembly + - match: '\b[A-Fa-f0-9]+h\b' + scope: constant.numeric.hexadecimal.assembly + - match: '\b[01]+b\b' + scope: constant.numeric.binary.assembly + - match: '\b[0-9]+\b' + scope: constant.numeric.decimal.assembly + + directives: + - include: block-directives + - include: struc-directives + - include: macro-directives + - include: preprocessor-directives + - include: data-directives + + block-directives: + - match: '^\[.*?\]' + scope: support.function.directive.assembly + + struc-directives: + - match: '^(struc)\s+([_a-zA-Z][_a-zA-Z0-9]*)' + captures: + 1: { scope: support.function.directive.assembly } + 2: { scope: entity.name.function.assembly } + - match: '^endstruc' + scope: support.function.directive.assembly + + macro-directives: + - match: '^(%macro)\s+([_a-zA-Z][_a-zA-Z0-9]*)\s+([0-9]+)' + captures: + 1: { scope: support.function.directive.assembly } + 2: { scope: entity.name.function.assembly } + 3: { scope: constant.numeric.assembly } + - match: '^%endmacro' + scope: support.function.directive.assembly + + preprocessor-directives: + - match: '\s*(?i)(%define|%ifndef|%xdefine|%idefine|%undef|%assign|%defstr|%strcat|%strlen|%substr|%00|%0|%rotate|%rep|%endrep|%include|\$\$|\$|%unmacro|%if|%elif|%else|%endif|%(el)?ifdef|%(el)?ifmacro|%(el)?ifctx|%(el)?ifidn|%(el)?ifidni|%(el)?ifid|%(el)?ifnum|%(el)?ifstr|%(el)?iftoken|%(el)?ifempty|%(el)?ifenv|%pathsearch|%depend|%use|%push|%pop|%repl|%arg|%stacksize|%local|%error|%warning|%fatal|%line|%!|__NASM_VERSION_ID__|__NASM_VER__|__FILE__|__LINE__|__BITS__|__OUTPUT_FORMAT__|__DATE__|__TIME__|__DATE_NUM__|_TIME__NUM__|__UTC_DATE__|__UTC_TIME__|__UTC_DATE_NUM__|__UTC_TIME_NUM__|__POSIX_TIME__|__PASS__|ISTRUC|AT|IEND|BITS\s+16|BITS\s+32|BITS\s+64|USE16|USE32|__SECT__|ABSOLUTE|EXTERN|GLOBAL|COMMON|CPU|FLOAT)\b' + scope: support.function.directive.assembly + + data-directives: + - match: '\b(?i)(db|dw|dd|dq|dt|do|dy|resb|resw|resd|resq|rest|reso|equ|times|align|alignb|sectalign|section|ptr|byte|word|dword|qword|incbin)\b' + scope: support.function.directive.assembly + + labels: + - match: '^\s*%%((?:[^;])+?):$' + scope: entity.name.function.assembly + - match: '^\s*%\$((?:[^;])+?):$' + scope: entity.name.function.assembly + - match: '^\.?((?:[^;])+?):$' + scope: entity.name.function.assembly + - match: '^\.?((?:[^;])+?)\b' + scope: entity.name.function.assembly + + operators: + - match: '[,\[\]\+\-\*]' + scope: source.assembly +
diff --git /dev/null b/syntax/Assembly/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2015, Pavlo Malynin +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git /dev/null b/syntax/C#/C#.sublime-syntax @@ -0,0 +1,3445 @@ +%YAML 1.2 +--- +# https://learn.microsoft.com/en-us/dotnet/csharp/specification/ +# https://github.com/dotnet/csharpstandard/blob/standard-v7/standard/ +# https://www.sublimetext.com/docs/syntax.html +name: C# +scope: source.cs +version: 2 + +file_extensions: + - cs + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* // .*? -\*- .*? \b(c\#|cs|csharp)\b .*? -\*- # editorconfig + ) + +contexts: + prototype: + - include: comments + - include: preprocessor-directives + + main: + - meta_include_prototype: false + - match: '' + push: [csharp, shebang] + + csharp: + - include: csharp-blocks + - include: stray-punctuation + - include: terminators + - include: attributes + - include: modifiers + - include: visibility + # global declarations + - include: namespace-declarations + - include: using-declarations + - include: class-declarations + - include: enum-declarations + - include: interface-declarations + - include: record-declarations + - include: struct-declarations + - include: union-declarations + - include: delegate-declarations + # class level declarations (fallback only) + - include: event-declarations + - include: extension-declarations + - include: conversion-declarations + # statements and expressions (fallback only) + - include: embedded-statements + - include: local-declarations + - include: label-declarations + - include: else-expression + +###[ COMMENTS ]################################################################ + + comments: + - match: ^\s*(///) + captures: + 1: punctuation.definition.comment.documentation.cs + push: inside-doc-comment + - match: // + scope: punctuation.definition.comment.cs + push: inside-line-comment + - match: /\*\*+/ + scope: comment.block.empty.cs punctuation.definition.comment.cs + - match: /\*+ + scope: punctuation.definition.comment.begin.cs + push: inside-block-comment + - include: merge-conflict-markers + + inside-block-comment: + - meta_scope: comment.block.cs + - match: \*+/ + scope: punctuation.definition.comment.end.cs + pop: 1 + - match: ^\s*(\*)(?!\**/) + captures: + 1: punctuation.definition.comment.cs + - include: comment-content + + inside-doc-comment: + - meta_include_prototype: false + - meta_scope: comment.line.documentation.cs + - match: ^\s*(///) + captures: + 1: punctuation.definition.comment.documentation.cs + - match: ^ + pop: 1 + - match: (<)({{name}}) + captures: + 1: punctuation.definition.tag.begin.cs + 2: entity.name.tag.begin.cs + push: inside-doc-comment-tag + - match: (</)({{name}})(>) + scope: meta.tag.xml + captures: + 1: punctuation.definition.tag.begin.cs + 2: entity.name.tag.end.cs + 3: punctuation.definition.tag.end.cs + - include: comment-content + + inside-doc-comment-tag: + - meta_include_prototype: false + - meta_scope: meta.tag.xml + - match: /?> + scope: punctuation.definition.tag.end.cs + pop: 1 + - match: ^\s*(///) + captures: + 1: punctuation.definition.comment.documentation.cs + - match: ^ + pop: 2 + - match: ({{name}})\s*(=) + captures: + 1: entity.other.attribute-name.cs + 2: punctuation.separator.key-value.cs + - match: \" + scope: punctuation.definition.string.begin.cs + push: inside-string + + inside-line-comment: + - meta_scope: comment.line.double-slash.cs + - match: $\n? + pop: 1 + - include: comment-content + + comment-content: + - include: merge-conflict-markers + - match: \b(?i:todo|hack|xxx)\b + scope: comment.line.todo.cs + - match: /!\\ + scope: comment.line.todo.cs + - match: \b[a-z+]+://\S*(?:[:/#?&=]|\b) + scope: markup.underline.link.cs + + shebang: + - meta_include_prototype: false + - match: ^\s*(\#!) + captures: + 1: punctuation.definition.comment.cs + set: inside-shebang + - match: ^|(?=\S) # Note: Ensure to highlight shebang if C# is embedded. + pop: 1 + + inside-shebang: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.cs + - match: '{{shebang_language}}' + scope: constant.language.shebang.cs + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ ANNOTATIONS ]############################################################# + + attributes: + - match: \[ + scope: punctuation.definition.annotation.begin.cs + push: + - inside-attribute + - attribute-modifier + + attribute-modifier: + - match: (assembly|module|field|event|method|param|property|return|type)\s*(:) + captures: + 1: storage.modifier.target.cs + 2: punctuation.separator.key-value.cs + pop: 1 + - include: else-pop + + inside-attribute: + - meta_scope: meta.annotation.cs + - match: \] + scope: punctuation.definition.annotation.end.cs + pop: 1 + - include: separators + - include: accessors + - match: \( + scope: meta.group.cs punctuation.section.group.begin.cs + push: inside-argument-list + - match: (GeneratedRegex)\s*(\() + captures: + 1: variable.annotation.cs + 2: meta.group.cs punctuation.section.group.begin.cs + push: + - inside-argument-list + - regex-string + - include: namespace-variables + - match: '{{name}}' + scope: variable.annotation.cs + push: + - type-suffix + - type-argument-list + + inside-argument-list: + - meta_content_scope: meta.group.cs + - match: \) + scope: meta.group.cs punctuation.section.group.end.cs + pop: 1 + - include: arguments + +###[ PREPROCESSOR DIRECTIVES ]################################################# + + preprocessor-directives: + - match: ^(?=\s*#) + push: preprocessor-directive + + preprocessor-directive: + - meta_include_prototype: false + - meta_scope: meta.preprocessor.cs + # Note: Repeated `\s*(#)` is required as some of them are to be scoped + # fold markers to support syntax based folding of blocks. + - match: \s*(#:)(\w+)\b(?:\s*(\S.*?))?{{wspace_eol}} + captures: + 1: punctuation.definition.preprocessor.cs + 2: variable.language.cs + 3: meta.string.cs string.unquoted.cs + pop: 1 + - match: \s*(#)\s*(region)\b(?:\s*(\S.*?))?({{wspace_eol}}) + captures: + 1: punctuation.definition.preprocessor.cs + 2: keyword.control.directive.region.cs + 3: entity.name.section.cs + 4: meta.fold.block.begin.cs + pop: 1 + - match: \s*(#)\s*(endregion)\b(?:\s*(\S.*?))?{{wspace_eol}} + captures: + 1: meta.fold.block.end.cs punctuation.definition.preprocessor.cs + 2: keyword.control.directive.endregion.cs + 3: variable.other.section.cs + pop: 1 + - match: \s*(#)\s*(?:(error)|(warning))\b(?:\s*(\S.*?))?{{wspace_eol}} + captures: + 1: punctuation.definition.preprocessor.cs + 2: keyword.control.directive.error.cs + 3: keyword.control.directive.warning.cs + 4: meta.string.cs string.unquoted.cs + pop: 1 + - match: \s*(#)\s*(line)\b + captures: + 1: punctuation.definition.preprocessor.cs + 2: keyword.control.directive.line.cs + set: preprocessor-line + - match: \s*(#)\s*(if)\b + captures: + 1: punctuation.definition.preprocessor.cs + 2: keyword.control.directive.conditional.if.cs + set: preprocessor-if-condition + - match: \s*(#)\s*(elif)\b + captures: + 1: meta.fold.block.end.cs punctuation.definition.preprocessor.cs + 2: keyword.control.directive.conditional.elseif.cs + set: preprocessor-if-condition + - match: \s*(#)\s*(else)\b + captures: + 1: meta.fold.block.end.cs punctuation.definition.preprocessor.cs + 2: keyword.control.directive.conditional.else.cs + set: expect-preprocessor-fold-begin + - match: \s*(#)\s*(endif)\b + captures: + 1: meta.fold.block.end.cs punctuation.definition.preprocessor.cs + 2: keyword.control.directive.conditional.end.cs + set: expect-preprocessor-end + - match: \s*(#)\s*(?:(define)|(undef))\b(?:\s*({{name}}))? + captures: + 1: punctuation.definition.preprocessor.cs + 2: keyword.control.directive.define.cs + 3: keyword.control.directive.undefine.cs + 4: entity.name.constant.preprocessor.cs + set: expect-preprocessor-end + - match: \s*(#)\s*(nullable)(?:\s+(enable|disable|restore)(?:\s+(annotations|warnings))?)?\b + captures: + 1: punctuation.definition.preprocessor.cs + 2: keyword.control.directive.nullable.cs + 3: keyword.control.directive.other.cs + 4: constant.language.messages.cs + set: expect-preprocessor-end + - match: \s*(#)\s*(pragma)\b + captures: + 1: punctuation.definition.preprocessor.cs + 2: keyword.control.directive.pragma.cs + set: preprocessor-pragma-name + - match: \s*(#)\s*({{name}}) + captures: + 1: punctuation.definition.preprocessor.cs + - include: noeol-pop + + preprocessor-if-condition: + - meta_content_scope: meta.preprocessor.cs + - match: \( + scope: punctuation.section.group.begin.cs + push: inside-preprocessor-if-condition-group + - match: (?:&&|\|\||!) + scope: keyword.operator.logical.cs + - include: constants + - match: '{{name}}' + scope: constant.other.preprocessor.cs + - include: expect-preprocessor-fold-begin + + inside-preprocessor-if-condition-group: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: preprocessor-if-condition + + preprocessor-line: + - meta_content_scope: meta.preprocessor.cs + - match: \" + scope: punctuation.definition.string.begin.cs + push: inside-string + - match: (?:default|hidden)\b + scope: constant.language.preprocessor.cs + - match: \d+ + scope: meta.number.integer.decimal.cs constant.numeric.value.cs + - include: expect-preprocessor-end + + preprocessor-pragma-name: + - meta_content_scope: meta.preprocessor.cs + - match: checksum\b + scope: meta.preprocessor.cs entity.name.pragma.checksum.cs + set: preprocessor-pragma-checksum-args + - match: warning\b + scope: meta.preprocessor.cs entity.name.pragma.warning.cs + set: preprocessor-pragma-warning-args + - match: '{{name}}' + scope: meta.preprocessor.cs entity.name.pragma.other.cs + set: preprocessor-pragma-other-args + - include: expect-preprocessor-end + + preprocessor-pragma-checksum-args: + - meta_content_scope: meta.preprocessor.cs + - match: \"\{ + scope: punctuation.definition.string.begin.cs + push: inside-preprocessor-pragma-checksum-hash + - match: \" + scope: punctuation.definition.string.begin.cs + push: inside-string + - include: expect-preprocessor-end + + inside-preprocessor-pragma-checksum-hash: + - meta_include_prototype: false + - meta_scope: meta.string.hash.cs string.quoted.double.cs + - meta_content_scope: meta.number.integer.hexadecimal.cs constant.numeric.value.cs + - match: \}\" + scope: punctuation.definition.string.end.cs + pop: 1 + - match: $\n? + scope: invalid.illegal.unclosed-string.cs + pop: 1 + - match: '[^-\h]+' + scope: invalid.illegal.cs + + preprocessor-pragma-other-args: + - meta_content_scope: meta.preprocessor.cs + - match: \" + scope: punctuation.definition.string.begin.cs + push: inside-string + - match: \d+ + scope: meta.number.integer.decimal.cs constant.numeric.value.cs + - match: '[\p{L}_-]+' + scope: meta.string.cs string.unquoted.cs + - include: expect-preprocessor-end + + preprocessor-pragma-warning-args: + - meta_content_scope: meta.preprocessor.cs + - match: (disable|restore)(?:\s+([\w-]+))? + scope: meta.preprocessor.cs + captures: + 1: keyword.control.directive.other.cs + 2: meta.string.cs string.unquoted.cs + set: expect-preprocessor-end + - include: expect-preprocessor-end + + expect-preprocessor-end: + - meta_include_prototype: false + - meta_content_scope: meta.preprocessor.cs + - match: $\n?|(?=\s*/[/*]) + scope: meta.preprocessor.cs + pop: 1 + - match: \S+ + scope: invalid.illegal.cs + + expect-preprocessor-fold-begin: + - meta_include_prototype: false + - meta_content_scope: meta.preprocessor.cs + - match: '{{wspace_eol}}' + scope: meta.preprocessor.cs meta.fold.block.begin.cs + pop: 1 + - match: \s*(?=/[/*]) + scope: meta.fold.block.begin.cs + pop: 1 + - match: \S+ + scope: invalid.illegal.cs + +###[ GLOBAL BLOCKS ]########################################################### + + csharp-blocks: + - match: \{ + scope: punctuation.section.block.begin.cs + push: inside-csharp-block + + inside-csharp-block: + - meta_scope: meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: csharp + +###[ USING DECLARATIONS ]###################################################### + + using-declarations: + - match: (?:(global)\s+)?(using)\b + captures: + 1: storage.modifier.cs + 2: keyword.declaration.using.cs + push: + - using-meta + - using-type + + using-meta: + - meta_include_prototype: false + - meta_scope: meta.using.cs + - include: immediately-pop + + using-type: + - match: static\b + scope: storage.modifier.static.cs + set: using-namespace + - match: ({{name}})\s*(=)\s*(?=\() + captures: + 1: entity.name.type.cs + 2: keyword.operator.assignment.cs + set: type-tuple + - match: ({{name}})\s*(=) + captures: + 1: variable.other.import.cs + 2: keyword.operator.assignment.cs + set: using-namespace + - match: (?=var\b|{{namespaced_name}}\s+{{name}}) + set: + - expression-list + - var-declaration + - match: (?=\S) + set: using-namespace + + using-namespace: + - include: accessors + - include: namespace-variables + - match: '{{unreserved_name}}' + scope: variable.namespace.cs + push: + - type-suffix + - type-argument-list + - include: else-pop + +###[ NAMESPACE DECLARATIONS ]################################################## + + namespace-declarations: + # package declaration + - match: namespace\b + scope: meta.namespace.cs keyword.declaration.namespace.cs + push: + - namespace-declaration-block + - namespace-declaration-name + + namespace-declaration-name: + - match: ({{unreserved_name}})\s*(\.) + captures: + 1: variable.namespace.cs + 2: punctuation.accessor.dot.cs + - match: '{{unreserved_name}}' + scope: entity.name.namespace.cs + pop: 1 + - include: else-pop + + namespace-declaration-block: + - meta_content_scope: meta.namespace.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-namespace-declaration-block + - include: else-pop + + inside-namespace-declaration-block: + - meta_scope: meta.namespace.body.cs meta.block.cs + - include: inside-csharp-block + +###[ CLASS DECLARATIONS ]###################################################### + + class-declarations: + - match: class\b + scope: meta.class.cs keyword.declaration.class.cs + push: + - class-block + - class-base + - class-parameter-list + - type-parameter-list + - class-declaration-name + + class-declaration-name: + - match: '{{unreserved_name}}' + scope: entity.name.class.cs + pop: 1 + - include: else-pop + + class-parameter-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-class-parameter-list + - include: else-pop + + inside-class-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.class.parameters.cs meta.group.cs + - include: inside-method-parameter-list + + class-base: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-class-base + - match: (?=where\b) + set: type-constraints + - include: else-pop + + inside-class-base: + - clear_scopes: 1 + - meta_scope: meta.class.base.cs + - include: inherited-classes + + class-block: + - meta_content_scope: meta.class.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-class-block + - include: else-pop + + inside-class-block: + - meta_scope: meta.class.body.cs meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: stray-punctuation + - include: terminators + - include: attributes + - include: modifiers + - include: visibility + # nested global declarations + - include: class-declarations + - include: enum-declarations + - include: interface-declarations + - include: record-declarations + - include: struct-declarations + - include: union-declarations + - include: delegate-declarations + # class level declarations + - include: event-declarations + - include: extension-declarations + - include: conversion-declarations + - include: constructor-declarations + - include: embedded-statements + - include: member-declarations + # fallbacks + - include: statement-blocks + - include: else-expression + +###[ ENUM DECLARATIONS ]####################################################### + + enum-declarations: + - match: enum\b + scope: meta.enum.cs keyword.declaration.enum.cs + push: + - enum-block + - enum-base + - enum-declaration-name + + enum-declaration-name: + - match: '{{unreserved_name}}' + scope: entity.name.enum.cs + pop: 1 + - include: else-pop + + enum-base: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-enum-base + - include: else-pop + + inside-enum-base: + - clear_scopes: 1 + - meta_scope: meta.enum.base.cs + - match: (?:byte|sbyte|short|ushort|int|uint|nint|nuint|long|ulong)\b + scope: storage.type.primitive.cs + pop: 1 + - match: '{{base_type}}' + scope: invalid.illegal.type.cs + pop: 1 + - match: '{{unreserved_name}}' + scope: entity.other.inherited-class.cs + pop: 1 + - include: else-pop + + enum-block: + - meta_content_scope: meta.enum.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-enum-block + - include: else-pop + + inside-enum-block: + - meta_scope: meta.enum.body.cs meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: attributes + - include: separators + - include: assignment-expressions + - match: '{{unreserved_name}}' + scope: entity.name.constant.cs + - include: else-pop + +###[ INTERFACE DECLARATIONS ]################################################## + + interface-declarations: + - match: interface\b + scope: meta.interface.cs keyword.declaration.interface.cs + push: + - interface-block + - interface-base + - type-parameter-list + - interface-declaration-name + + interface-declaration-name: + - match: '{{unreserved_name}}' + scope: entity.name.interface.cs + pop: 1 + - include: else-pop + + interface-base: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-interface-base + - match: (?=where\b) + set: type-constraints + - include: else-pop + + inside-interface-base: + - clear_scopes: 1 + - meta_scope: meta.interface.base.cs + - include: inherited-classes + + interface-block: + - meta_content_scope: meta.interface.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-interface-block + - include: else-pop + + inside-interface-block: + - meta_scope: meta.interface.body.cs meta.block.cs + - include: inside-class-block + +###[ RECORD DECLARATIONS ]##################################################### + + record-declarations: + - match: record\b + scope: meta.record.cs keyword.declaration.record.cs + push: + - record-block + - record-base + - record-parameter-list + - type-parameter-list + - record-name + + record-name: + - match: struct\b + scope: keyword.declaration.struct.cs + set: struct-declaration-name + - match: class\b + scope: keyword.declaration.class.cs + set: class-declaration-name + - include: class-declaration-name + + record-parameter-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-record-parameter-list + - include: else-pop + + inside-record-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.record.parameters.cs meta.group.cs + - include: inside-method-parameter-list + + record-base: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-record-base + - match: (?=where\b) + set: type-constraints + - include: else-pop + + inside-record-base: + - clear_scopes: 1 + - meta_scope: meta.record.base.cs + - include: inherited-classes + + record-block: + - meta_content_scope: meta.record.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-record-block + - include: else-pop + + inside-record-block: + - meta_scope: meta.record.body.cs meta.block.cs + - include: inside-class-block + +###[ STRUCT DECLARATIONS ]##################################################### + + struct-declarations: + - match: struct\b + scope: meta.struct.cs keyword.declaration.struct.cs + push: + - struct-block + - struct-base + - struct-parameter-list + - type-parameter-list + - struct-declaration-name + + struct-declaration-name: + - match: '{{unreserved_name}}' + scope: entity.name.struct.cs + pop: 1 + - include: else-pop + + struct-parameter-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-struct-parameter-list + - include: else-pop + + inside-struct-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.struct.parameters.cs meta.group.cs + - include: inside-method-parameter-list + + struct-base: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-struct-base + - match: (?=where\b) + set: type-constraints + - include: else-pop + + inside-struct-base: + - clear_scopes: 1 + - meta_scope: meta.struct.base.cs + - include: inherited-classes + + struct-block: + - meta_content_scope: meta.struct.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-struct-block + - include: else-pop + + inside-struct-block: + - meta_scope: meta.struct.body.cs meta.block.cs + - include: inside-class-block + +###[ UNION DECLARATIONS ]###################################################### + + union-declarations: + - match: union\b + scope: meta.union.cs keyword.declaration.union.cs + push: + - union-block + - union-base + - union-parameter-list + - type-parameter-list + - union-declaration-name + + union-declaration-name: + - match: '{{unreserved_name}}' + scope: entity.name.union.cs + pop: 1 + - include: else-pop + + union-parameter-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-union-parameter-list + - include: else-pop + + inside-union-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.union.parameters.cs meta.group.cs + - include: inside-method-parameter-list + + union-base: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-union-base + - match: (?=where\b) + set: type-constraints + - include: else-pop + + inside-union-base: + - clear_scopes: 1 + - meta_scope: meta.union.base.cs + - include: inherited-classes + + union-block: + - meta_content_scope: meta.union.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-union-block + - include: else-pop + + inside-union-block: + - meta_scope: meta.union.body.cs meta.block.cs + - include: inside-class-block + +###[ TYPE DECLARATION SIGNATURES ]############################################# + + inherited-classes: + - match: (?=where\b) + set: type-constraints + - include: separators + - include: accessors + - include: namespace-variables + - include: base-types + - match: '{{unreserved_name}}(?={{generic_declaration}}?\s*\.)' + scope: support.type.cs + push: + - type-suffix + - type-argument-list + - match: '{{unreserved_name}}' + scope: entity.other.inherited-class.cs + push: + - inherited-class-argument-list + - type-suffix + - type-argument-list + - include: else-pop + + inherited-class-argument-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-inherited-class-argument-list + - include: else-pop + + inside-inherited-class-argument-list: + - meta_include_prototype: false + - meta_scope: meta.constructor.arguments.cs meta.group.cs + - include: inside-function-call-argument-list + + type-constraints: + - meta_scope: meta.constraints.cs + - match: (where)\b\s*({{unreserved_name}})?\s*(:)? + captures: + 1: storage.modifier.where.cs + 2: support.type.cs + 3: punctuation.separator.colon.cs + push: primary-type-constraint + - match: ',' + scope: punctuation.separator.comma.cs + push: secondary-type-constraint + - include: else-pop + + primary-type-constraint: + - match: (?:default|notnull|unmanaged)\b + scope: storage.modifier.cs + pop: 1 + - match: (?:class|struct)\b + scope: storage.type.primitive.cs + set: + - type-suffix + - type-argument-list + - include: secondary-type-constraint + + secondary-type-constraint: + - match: (new)\s*((\()\s*(\))) + scope: meta.constructor.cs + captures: + 1: keyword.operator.new.cs + 2: meta.group.cs + 3: punctuation.section.group.begin.cs + 4: punctuation.section.group.end.cs + pop: 1 + - include: maybe-object-type + +###[ MEMBER DECLARATIONS ]##################################################### + + member-declarations: + - match: (?=[(@]|{{start_char}}) + push: + - member-name + - maybe-type + + member-name: + - include: member-qualifiers + - include: method-declarator + - include: indexer-declarator + - include: operator-declarator + - include: field-declarator + - include: stray-names + - include: else-pop + + member-qualifiers: + - include: accessors + - match: '{{unreserved_name}}(?={{generic_declaration}}?\s*\.)' + scope: entity.other.inherited-class.cs + push: + - type-suffix + - type-argument-list + +###[ CONSTRUCTOR MEMBER DECLARATIONS ]######################################### + + constructor-declarations: + - match: '~{{unreserved_name}}(?=\s*\()' + scope: meta.method.cs entity.name.function.destructor.cs + push: + - destructor-meta + - method-body + - method-parameter-list + - match: '{{unreserved_name}}(?=\s*\()' + scope: meta.method.cs entity.name.function.constructor.cs + push: + - constructor-meta + - method-body + - constructor-initializer + - method-parameter-list + + constructor-meta: + - meta_include_prototype: false + - meta_scope: meta.constructor.cs + - include: immediately-pop + + constructor-initializer: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-constructor-initializer + - include: else-pop + + inside-constructor-initializer: + - match: ((?:(this)|(base))\s*)(\() + captures: + 1: meta.initializer.cs + 2: variable.language.this.cs + 3: variable.language.super.cs + 4: meta.initializer.arguments.cs meta.group.cs punctuation.section.group.begin.cs + set: inside-constructor-initializer-argument-list + - include: else-pop + + inside-constructor-initializer-argument-list: + - meta_content_scope: meta.initializer.arguments.cs meta.group.cs + - match: \) + scope: meta.initializer.arguments.cs meta.group.cs punctuation.section.group.end.cs + pop: 1 + - include: arguments + + destructor-meta: + - meta_include_prototype: false + - meta_scope: meta.destructor.cs + - include: immediately-pop + +###[ DELEGATE MEMBER DECLARATIONS ]############################################ + + delegate-declarations: + - match: delegate\b(?!\s*\*) + scope: meta.delegate.cs keyword.declaration.delegate.cs + push: + - delegate-parameter-list + - type-parameter-list + - delegate-declaration-name + - maybe-type + + delegate-declaration-name: + - match: '{{unreserved_name}}' + scope: entity.name.type.delegate.cs + pop: 1 + - include: else-pop + + delegate-parameter-list: + - meta_content_scope: meta.delegate.cs + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-delegate-parameter-list + - include: else-pop + + inside-delegate-parameter-list: + - meta_scope: meta.delegate.parameters.cs meta.group.cs + - include: inside-method-parameter-list + +###[ EVENT MEMBER DECLARATIONS ]############################################### + + event-declarations: + - match: event\b + scope: keyword.declaration.event.cs + push: + - event-declaration-meta + - event-declaration-initializer + - event-declaration-name + - maybe-type + + event-declaration-meta: + - meta_include_prototype: false + - meta_scope: meta.event.cs + - include: immediately-pop + + event-declaration-name: + - meta_include_prototype: false + - include: member-qualifiers + - match: '{{unreserved_name}}' + scope: variable.other.member.cs + pop: 1 + - include: else-pop + + event-declaration-initializer: + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-event-accessor-declaration + - match: (?=\S) + set: inside-field-declarations + + inside-event-accessor-declaration: + - meta_scope: meta.accessors.cs meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: stray-punctuation + - include: terminators + - include: attributes + - match: add\b + scope: meta.method.cs keyword.declaration.function.accessor.add.cs + push: method-body + - match: remove\b + scope: meta.method.cs keyword.declaration.function.accessor.remove.cs + push: method-body + - include: stray-names + +###[ EXTENSION MEMBER DECLARATIONS ]########################################### + + extension-declarations: + - match: extension\b + scope: meta.extension.cs keyword.declaration.trait.cs + push: + - extension-block + - extension-base + - extension-parameter-list + - type-parameter-list + + extension-parameter-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-extension-parameter-list + - include: else-pop + + inside-extension-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.extension.parameters.cs meta.group.cs + - include: inside-method-parameter-list + + extension-base: + - match: ':' + scope: punctuation.separator.colon.cs + set: inside-extension-base + - match: (?=where\b) + set: type-constraints + - include: else-pop + + inside-extension-base: + - clear_scopes: 1 + - meta_scope: meta.extension.base.cs + - include: inherited-classes + + extension-block: + - meta_content_scope: meta.extension.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-extension-block + - include: else-pop + + inside-extension-block: + - meta_scope: meta.extension.body.cs meta.block.cs + - include: inside-class-block + +###[ FIELD MEMBER DECLARATIONS ]############################################### + + field-declarator: + - match: '{{unreserved_name}}' + scope: variable.other.member.cs + set: + - field-meta + - field-body + + field-meta: + - meta_include_prototype: false + - meta_scope: meta.field.cs + - include: immediately-pop + + field-body: + # property + - match: \{ + scope: punctuation.section.block.begin.cs + set: + - maybe-assignment-expression + - inside-field-accessor-declaration + - match: => + scope: keyword.declaration.function.accessor.get.cs + set: + - expression + - maybe-pointer + # field + - match: (?=\S) + set: inside-field-declarations + + inside-field-accessor-declaration: + - meta_scope: meta.accessors.cs meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: stray-punctuation + - include: terminators + - include: attributes + - include: visibility + - match: readonly\b + scope: storage.modifier.cs + - match: init\b + scope: meta.method.cs keyword.declaration.function.accessor.init.cs + push: method-body + - match: get\b + scope: meta.method.cs keyword.declaration.function.accessor.get.cs + push: method-body + - match: set\b + scope: meta.method.cs keyword.declaration.function.accessor.set.cs + push: method-body + - include: stray-names + + inside-field-declarations: + - include: member-qualifiers + - match: '{{unreserved_name}}' + scope: variable.other.member.cs + - include: separators + - include: assignment-expressions + - include: else-pop + +###[ INDEXER DECLARATIONS ]#################################################### + + indexer-declarator: + - match: this\b + scope: meta.indexer.cs variable.language.this.cs + set: + - indexer-body + - indexer-parameter-list + + indexer-parameter-list: + - match: \[ + scope: punctuation.section.brackets.begin.cs + set: inside-indexer-parameter-list + - include: else-pop + + inside-indexer-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.indexer.parameters.cs meta.brackets.cs + - match: \] + scope: punctuation.section.brackets.end.cs + pop: 1 + - include: method-parameters + + indexer-body: + - meta_content_scope: meta.indexer.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-indexer-accessor-declaration + - match: => + scope: meta.indexer.cs keyword.declaration.function.accessor.get.cs + set: + - indexer-expression + - maybe-pointer + - include: else-pop + + inside-indexer-accessor-declaration: + - meta_scope: meta.indexer.cs meta.accessors.cs meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: stray-punctuation + - include: terminators + - include: attributes + - include: visibility + - match: get\b + scope: meta.method.cs keyword.declaration.function.accessor.get.cs + push: method-body + - match: set\b + scope: meta.method.cs keyword.declaration.function.accessor.set.cs + push: method-body + - include: stray-names + + indexer-expression: + - meta_content_scope: meta.indexer.body.cs + - include: expression + +###[ METHOD MEMBER DECLARATIONS ]############################################## + + method-declarator: + - match: '{{unreserved_name}}(?={{generic_declaration}}?\s*\()' + scope: meta.method.cs entity.name.function.cs + set: + - method-body + - method-parameter-list + - type-parameter-list + + method-parameter-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-method-parameter-list + - include: else-pop + + inside-method-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.method.parameters.cs meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: method-parameters + + method-parameters: + - include: separators + - match: (?=[;{}]|=>) + pop: 1 + - match: (?=\S) + push: + - maybe-assignment-expression + - method-param-name + - maybe-type + - method-param-modifier + + method-param-modifier: + - include: attributes + - match: '{{method_param_type_modifier}}' + scope: storage.modifier.parameter.cs + - include: else-pop + + method-param-name: + - match: '{{unreserved_name}}' + scope: variable.parameter.cs + pop: 1 + - include: else-pop + + method-body: + - meta_content_scope: meta.method.cs + - match: (?=where\b) + push: type-constraints + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-method-block + - match: => + scope: meta.method.cs keyword.declaration.function.arrow.cs + set: + - inside-method-expression + - maybe-pointer + - include: else-pop + + inside-method-block: + - meta_scope: meta.method.body.cs meta.block.cs + - include: inside-statement-block + + inside-method-expression: + - meta_content_scope: meta.method.body.cs + - include: expression + +###[ OPERATOR DECLARATIONS ]################################################### + + conversion-declarations: + - match: operator\b + scope: meta.method.cs keyword.declaration.operator.cs + push: + - method-body + - method-parameter-list + - maybe-object-type + + operator-declarator: + - match: operator\b + scope: meta.method.cs keyword.declaration.operator.cs + set: + - method-body + - method-parameter-list + - operator-name + + operator-name: + # overloadable unary and binary operators + - match: (?:\+\+|--|<<|>>>?|<=?|>=?|==|!=|[-+*/%&|^~!]|false|true)(?=[\s(]) + scope: entity.name.function.cs + pop: 1 + # illegal operator tokens + - match: '[^\s(};]+' + scope: invalid.illegal.operator.cs + pop: 1 + - include: else-pop + +###[ VARIABLE DECLARATIONS ]################################################### + + local-declarations: + - match: (delegate)\s*(\*) + captures: + 1: keyword.declaration.delegate.cs + 2: keyword.operator.pointer.cs + push: + - expression-list + - funcptr-type-meta + - type-argument-list + - funcptr-type-modifier + - match: var\b + scope: storage.type.variant.cs + push: + - maybe-assignment-expression + - var-declarator + - match: '{{base_type}}' + scope: storage.type.primitive.cs + push: + - local-declarator + - type-suffix + - match: (?={{namespaced_name}}\s+{{name}}) + push: + - local-declarator + - maybe-type + + local-declarator: + - include: method-declarator + - match: (?=\S) + set: expression-list + + var-declaration: + - match: var\b + scope: storage.type.variant.cs + set: var-declarator + - match: (?=\S) + set: [variable-declaration-name, maybe-type] + + var-declarator: + - include: tuple-literal + - include: variable-declaration-name + + variable-declaration-name: + - match: _\b + scope: variable.language.anonymous.cs + pop: 1 + - match: '{{unreserved_name}}' + scope: variable.other.cs + pop: 1 + - include: else-pop + +###[ STATEMENTS ]############################################################## + + maybe-statement-block: + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-statement-block + - include: else-pop + + statement-blocks: + - match: \{ + scope: punctuation.section.block.begin.cs + push: inside-statement-block + + inside-statement-block: + - meta_scope: meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: stray-punctuation + - include: terminators + - include: statement-blocks + - include: embedded-statements + - include: local-declarations + - include: label-declarations + - include: else-expression + + embedded-statements: + # conditional statements + - match: else\s+if\b + scope: keyword.control.conditional.elseif.cs + push: maybe-expression-group + - match: else\b + scope: keyword.control.conditional.else.cs + - match: if\b + scope: keyword.control.conditional.if.cs + push: maybe-expression-group + - match: switch\b + scope: keyword.control.conditional.switch.cs + push: maybe-expression-group + - match: case\b + scope: meta.case.cs keyword.control.conditional.case.cs + push: + - case-pattern + - expect-pattern + - match: ((default)\s*)({{colon}}) + captures: + 1: meta.case.pattern.cs + 2: keyword.control.conditional.default.cs + 3: meta.case.cs punctuation.separator.colon.cs + # exception statements + - match: catch\b + scope: keyword.control.exception.catch.cs + push: + - catch-guard + - catch-group + - match: finally\b + scope: keyword.control.exception.finally.cs + - match: try\b + scope: keyword.control.exception.try.cs + # loop statements + - match: do\b + scope: keyword.control.loop.do.cs + - match: foreach\b + scope: keyword.control.loop.foreach.cs + push: foreach-group + - match: for\b + scope: keyword.control.loop.for.cs + push: for-group + - match: while\b + scope: keyword.control.loop.while.cs + push: maybe-expression-group + # control flow statements + - match: (?:break|yield\s+break)\b + scope: keyword.control.flow.break.cs + - match: continue\b + scope: keyword.control.flow.continue.cs + - match: goto\b + scope: keyword.control.flow.goto.cs + push: goto-target + - match: lock\b + scope: keyword.control.flow.lock.cs + push: maybe-expression-group + # declarations + - match: fixed\b + scope: keyword.declaration.fixed.cs + push: fixed-group + - match: using\b + scope: keyword.declaration.using.cs + push: using-body + # reserved expression keywords + - include: keywords + + goto-target: + - match: case\b + scope: keyword.control.conditional.case.cs + set: expression + - match: '{{unreserved_name}}' + scope: constant.other.label.cs + pop: 1 + - include: else-pop + + label-declarations: + - match: ({{name}})\s*({{colon}}) + captures: + 1: entity.name.label.cs + 2: punctuation.separator.colon.cs + +###[ CONDITIONAL STATEMENTS ]################################################## + + case-pattern: + - meta_content_scope: meta.case.pattern.cs + - match: \bwhen\b + scope: meta.case.guard.cs keyword.control.conditional.when.cs + set: inside-case-guard + - include: inside-case-guard + + inside-case-guard: + - meta_content_scope: meta.case.guard.cs + - match: '{{colon}}' + scope: meta.case.cs punctuation.separator.colon.cs + pop: 1 + - include: expression + +###[ EXCEPTION STATEMENTS ]#################################################### + + catch-group: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - catch-group-end + - var-declaration + - include: else-pop + + catch-group-end: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: else-pop + + catch-guard: + - match: when\b + scope: keyword.control.conditional.when.cs + set: maybe-expression-group + - include: else-pop + +###[ FIXED STATEMENTS ]######################################################## + + fixed-group: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - inside-fixed-group + - var-declaration + - include: else-pop + + inside-fixed-group: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: expression-list + +###[ FOR STATEMENTS ]########################################################## + + for-group: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - for-iteration + - for-separator + - expression + - for-separator + - expression-list + - for-declaration + - include: else-pop + + for-declaration: + - match: (?={{namespaced_name}}\s+{{name}}) + set: var-declaration + - include: else-pop + + for-separator: + - match: ';' + scope: punctuation.terminator.statement.cs + pop: 1 + - include: else-pop + + for-iteration: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: expression-list + + foreach-group: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - inside-expression-group + - foreach-in + - var-declaration + - include: else-pop + + foreach-in: + - match: in\b + scope: keyword.control.loop.in.cs + pop: 1 + - include: else-pop + +###[ USING STATEMENTS ]######################################################## + + using-body: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - inside-using-group + - var-declaration + - match: (?=\S) + set: + - expression-list + - var-declaration + + inside-using-group: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: expression-list + +###[ EXPRESSIONS ]############################################################# + + expression-list: + - include: separators + - include: expression + + else-expression: + - match: (?=\S) + push: + - expression + - maybe-pointer + + expression: + - include: parens + - include: lambdas + - include: expression-common + - include: else-pop + + expression-common: + # accessors and operators (Note: order matters!) + - match: -> + scope: punctuation.accessor.arrow.cs + push: maybe-pointer + - match: '(?x: << | >>>? | \?\? | [-+*/%|&^] )=' + scope: keyword.operator.assignment.augmented.cs + push: maybe-pointer + - match: '(?x: \+\+? | --? | [*/%] )' + scope: keyword.operator.arithmetic.cs + push: maybe-pointer + - match: '(?x: && | \|\| | !(?!=) )' + scope: keyword.operator.logical.cs + push: maybe-pointer + - match: '(?x: << | >>>? | [|&^~] )' + scope: keyword.operator.bitwise.cs + push: maybe-pointer + - match: '(?x: <=? | >=? | == | != )' + scope: keyword.operator.comparison.cs + push: maybe-pointer + - match: = + scope: keyword.operator.assignment.cs + push: assignment-value + - match: \.\. + scope: keyword.operator.range.cs + push: maybe-pointer + - match: (\?)?(\.) + captures: + 1: keyword.operator.null-coalescing.cs + 2: punctuation.accessor.dot.cs + push: maybe-pointer + - match: (\?)?\s*(\[) + captures: + 1: keyword.operator.null-coalescing.cs + 2: meta.brackets.cs punctuation.section.brackets.begin.cs + push: + - inside-item-access + - maybe-pointer + - match: \?\? + scope: keyword.operator.null-coalescing.cs + push: maybe-pointer + - match: \? + scope: keyword.operator.ternary.cs + push: + - inside-ternary-expression + - maybe-pointer + # keywords + - match: '{{sql_keywords}}' + scope: keyword.other.sql.cs + - include: keywords + - include: switch-expressions + - include: base-types + - include: constants + - match: (?={{statement_keywords}}|{{visibility}}) + pop: 1 + # literals + - include: characters + - include: numbers + - include: strings + # language variables + - match: _\b + scope: variable.language.anonymous.cs + - match: value\b + scope: variable.language.cs + - include: namespace-variables + # expressions + - match: (?:(?:(?:(System)(\.))?(Text)(\.))?(RegularExpressions)(\.))?(Regex)(\.)(Match|IsMatch|Replace)(?=\s*\() + captures: + 1: variable.other.cs + 2: punctuation.accessor.dot.cs + 3: variable.other.cs + 4: punctuation.accessor.dot.cs + 5: variable.other.cs + 6: punctuation.accessor.dot.cs + 7: support.type.cs + 8: punctuation.accessor.dot.cs + 9: meta.function-call.identifier.cs variable.function.cs + push: regex-function-call-argument-list + - match: '{{name}}(?={{generic_declaration}}?\s*\()' + scope: meta.function-call.identifier.cs variable.function.cs + push: + - function-call-argument-list + - type-argument-list + - match: '{{name}}(?={{generic_declaration}}\s*\.)' + scope: support.type.cs + push: + - type-suffix + - type-argument-list + - match: '{{name}}' + scope: variable.other.cs + - match: '@' + scope: invalid.illegal.reserved-char.cs + + inside-ternary-expression: + - match: ':' + scope: keyword.operator.ternary.cs + pop: 1 + - include: expression + + keywords: + - include: instantiations + - include: modifiers + - match: delegate\b(?!\s*\*) + scope: meta.function.anonymous.cs keyword.declaration.delegate.cs + push: + - delegate-lambda-body + - delegate-lambda-parameter-list + - match: this\b + scope: variable.language.this.cs + push: + - maybe-member-access + - maybe-item-access + - match: base\b + scope: variable.language.super.cs + push: + - maybe-member-access + - maybe-item-access + - match: await\b + scope: keyword.control.flow.await.cs + - match: (?:return|yield\s+return)\b + scope: keyword.control.flow.return.cs + push: expression + - match: throw\b + scope: keyword.control.flow.throw.cs + push: expression + - match: (?:and|not|or)\b + scope: keyword.operator.logical.cs + - match: (?:checked|unchecked)\b + scope: keyword.other.cs + push: maybe-expression-group + - match: as\b + scope: keyword.operator.cast.cs + push: maybe-type + - match: is\b + scope: keyword.operator.comparison.type.cs + push: expect-pattern + - match: nameof\b + scope: keyword.other.cs + push: maybe-nameof-group + - match: (?:sizeof|typeof|default)\b + scope: keyword.other.cs + push: maybe-type-group + +###[ ASSIGNMENT EXPRESSIONS ]################################################## + + maybe-assignment-expression: + - match: \s*(=) + captures: + 1: keyword.operator.assignment.cs + set: assignment-value + - include: noeol-pop + + assignment-expressions: + - match: = + scope: keyword.operator.assignment.cs + push: assignment-value + + assignment-value: + - match: (?=\[) + branch_point: array-initializer + branch: + - array-initializer + - annotated-expression + pop: 1 + - match: \{ + scope: meta.braces.cs punctuation.section.braces.begin.cs + set: inside-variable-initializer + - match: (?=\S) + set: + - expression + - maybe-pointer + + array-initializer: + - meta_include_prototype: false + - match: \[ + scope: meta.brackets.cs punctuation.section.brackets.begin.cs + set: + - check-array-initializer + - inside-array-initializer + - maybe-pointer + - maybe-array-with-arguments + + maybe-array-with-arguments: + - match: with\b + scope: meta.function-call.identifier.cs keyword.other.with.cs + set: function-call-argument-list + - include: else-pop + + inside-array-initializer: + - meta_content_scope: meta.brackets.cs + - match: \] + scope: meta.brackets.cs punctuation.section.brackets.end.cs + pop: 1 + - include: expression-list + + check-array-initializer: + - match: (?=[,;)\]}]) + pop: 1 + - match: (?=\S) + fail: array-initializer + + annotated-expression: + - include: attributes + - match: (?=\S) + set: expression + +###[ COMMON PARENTHESIZED EXPRESSIONS ]######################################## + + parens: + - match: (?=\() + branch_point: parens + branch: + - paren-lambda + - paren-tuple-deconstruction + - paren-cast + - paren-group + - paren-tuple-type + - tuple-literal + + paren-cast: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.cs + set: + - paren-cast-operand + - paren-cast-end + - maybe-type + + paren-cast-end: + - meta_scope: meta.cast.cs meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - match: (?=\S) + fail: parens + + paren-cast-operand: + - include: cast-end + - match: (?=\S) + fail: parens + + cast-end: + # cast expressions may be followed by: + # - `(` : cast, lambda, tuple or group expression + # - `!` : unary operator + # - `~` : unary operator + # - `--` : unary operator + # - `++` : unary operator + # - literal : variable, type or method + - match: (?=(?!and|not|or|as|is|switch\b){{start_char}}|[!~(]|--|\+\+) + pop: 1 + + paren-group: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.cs + set: + - paren-group-end + - expression + - maybe-pointer + + paren-group-end: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - match: (?=\S) + fail: parens + + paren-lambda: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-paren-lambda-parameter-list + + inside-paren-lambda-parameter-list: + - meta_scope: meta.function.anonymous.parameters.cs meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + set: paren-lambda-body + - include: attributes + - include: separators + - match: '{{method_param_type_modifier}}\b' + scope: storage.modifier.parameter.cs + - match: '{{name}}(?=\s*[,)])' + scope: variable.parameter.cs + - match: var\b + scope: storage.type.variant.cs + push: method-param-name + - match: (?=[@(]|{{start_char}}) + push: + - method-param-name + - maybe-type + - match: (?=\S) + fail: parens + + paren-lambda-body: + - meta_content_scope: meta.function.anonymous.cs + - match: => + scope: meta.function.anonymous.cs keyword.declaration.function.arrow.cs + set: lambda-body + - match: (?=\{) + set: lambda-body + - match: (?=\S) + fail: parens + + paren-tuple-deconstruction: + # (type name, name, name) = + - meta_include_prototype: false + - match: \( + scope: punctuation.section.sequence.begin.cs + set: + - paren-tuple-deconstruction-operator + - inside-paren-tuple-deconstruction + + inside-paren-tuple-deconstruction: + - meta_scope: meta.sequence.tuple.cs + - match: \) + scope: punctuation.section.sequence.end.cs + pop: 1 + - include: separators + - match: _\b + scope: variable.language.anonymous.cs + - match: '{{name}}(?=\s*[,)])' + scope: variable.other.cs + - match: var\b + scope: storage.type.variant.cs + push: var-declarator + - match: (?=[@(]|{{start_char}}) + push: + - variable-declaration-name + - maybe-type + - match: (?=\S) + fail: parens + + paren-tuple-deconstruction-operator: + - match: (?==) + pop: 1 + - match: (?=\S) + fail: parens + + paren-tuple-type: + # (type name, type, type) func() + # (type name, type, type) variable + - meta_include_prototype: false + - match: \( + scope: punctuation.section.sequence.begin.cs + set: + - paren-tuple-type-operand + - type-suffix + - inside-type-tuple + + paren-tuple-type-operand: + - include: method-declarator + - match: '{{unreserved_name}}' + scope: variable.other.cs + pop: 1 + - match: (?=\S) + fail: parens + + tuple-literal: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.sequence.begin.cs + set: + - inside-tuple-literal + - maybe-pointer + + inside-tuple-literal: + - meta_scope: meta.sequence.tuple.cs + - match: \) + scope: punctuation.section.sequence.end.cs + pop: 1 + - include: member-variables + - include: expression-list + +###[ GROUP EXPRESSIONS ]####################################################### + + maybe-expression-group: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - inside-expression-group + - maybe-pointer + - include: else-pop + + inside-expression-group: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: expression + + maybe-nameof-group: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - inside-nameof-group + - maybe-pointer + - include: else-pop + + inside-nameof-group: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: accessors + - include: namespace-variables + - include: instance-variables + - include: base-types + # It is not possible to distinguish types and variables syntactically. + # Hence assume uppercase names to be types, and all remaining ones to be + # variables. + - match: '{{lower_name}}(?=\s*\))' + scope: variable.other.cs + - match: '{{unreserved_name}}' + scope: support.type.cs + push: + - type-suffix + - type-argument-list + - include: stray-names + - include: else-pop + + maybe-type-group: + - match: \( + scope: punctuation.section.group.begin.cs + set: + - type-group-end + - maybe-type + - include: else-pop + + type-group-end: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: stray-names + - include: else-pop + +###[ FUNCTION CALL EXPRESSIONS ]############################################### + + regex-function-call-argument-list: + - meta_content_scope: meta.function-call.identifier.cs + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-regex-function-call-argument-list + - include: else-pop + + inside-regex-function-call-argument-list: + - meta_scope: meta.function-call.arguments.cs meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - match: (?=[@$]*") + push: regex-string + - include: arguments + + function-call-argument-list: + - meta_content_scope: meta.function-call.identifier.cs + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-function-call-argument-list + - include: else-pop + + inside-function-call-argument-list: + - meta_scope: meta.function-call.arguments.cs meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - include: arguments + + arguments: + - match: out\b + scope: storage.modifier.argument.cs + push: out-argument + - match: ref\b + scope: storage.modifier.argument.cs + - match: ({{name}})\s*({{colon}}|{{equal}}) + captures: + 1: variable.parameter.cs + 2: keyword.operator.assignment.cs + push: assignment-value + - include: expression-list + + out-argument: + - match: ref\b + scope: storage.modifier.argument.cs + - match: (?={{namespaced_name}}\s+{{name}}) + set: var-declaration + - include: else-pop + +###[ INSTANTIATION EXPRESSIONS ]############################################### + + instantiations: + - match: new\b + scope: keyword.operator.new.cs + push: + - instantiation-meta + - maybe-variable-initializer + - instantiation-type + - match: stackalloc\b + scope: keyword.operator.stackalloc.cs + push: + - instantiation-meta + - maybe-variable-initializer + - instantiation-type + - match: with(?=\s*\{) + scope: keyword.operator.with.cs + push: maybe-variable-initializer + + instantiation-meta: + - meta_include_prototype: false + - meta_scope: meta.instantiation.cs + - include: immediately-pop + + instantiation-type: + - match: (?:(?:(?:(System)(\.))?(Text)(\.))?(RegularExpressions)(\.))?(Regex)\b + captures: + 1: variable.other.cs + 2: punctuation.accessor.dot.cs + 3: variable.other.cs + 4: punctuation.accessor.dot.cs + 5: variable.other.cs + 6: punctuation.accessor.dot.cs + 7: meta.function-call.identifier.cs support.type.cs + set: regex-function-call-argument-list + - match: (?=\S) + set: + - function-call-argument-list + - maybe-object-type + + maybe-variable-initializer: + # collection or object initializer + - match: \s*(\{) + captures: + 1: meta.braces.cs punctuation.section.braces.begin.cs + set: inside-variable-initializer + - include: noeol-pop + + inside-variable-initializer: + - meta_content_scope: meta.braces.cs + - match: \} + scope: meta.braces.cs punctuation.section.braces.end.cs + pop: 1 + - match: \{ + scope: meta.braces.cs punctuation.section.braces.begin.cs + push: inside-variable-initializer + - match: ({{name}})\s*({{equal}}) + captures: + 1: variable.other.member.cs + 2: keyword.operator.assignment.cs + push: maybe-pointer + - match: '{{unreserved_name}}(?=<)' + scope: support.type.cs + push: + - type-suffix + - type-argument-list + - match: (\?)?(\.) + captures: + 1: keyword.operator.null-coalescing.cs + 2: punctuation.accessor.dot.cs + push: member-access + - include: expression-list + +###[ ITEM ACCESS EXPRESSIONS ]################################################# + + maybe-item-access: + - match: \s*(\[) + captures: + 1: meta.brackets.cs punctuation.section.brackets.begin.cs + push: + - inside-item-access + - maybe-pointer + - include: noeol-pop + + inside-item-access: + - meta_content_scope: meta.brackets.cs + - match: \] + scope: meta.brackets.cs punctuation.section.brackets.end.cs + pop: 1 + - include: member-variables + - include: expression-list + + maybe-member-access: + - match: (\?)?(\.) + captures: + 1: keyword.operator.null-coalescing.cs + 2: punctuation.accessor.dot.cs + set: member-access + - include: else-pop + + member-access: + - match: '{{unreserved_name}}(?={{generic_declaration}}?\s*\()' + scope: meta.function-call.identifier.cs variable.function.cs + set: + - maybe-member-access + - function-call-argument-list + - type-argument-list + - match: '{{unreserved_name}}(?={{generic_declaration}})' + scope: support.type.cs + set: + - maybe-member-access + - type-suffix + - type-argument-list + - match: '{{unreserved_name}}' + scope: variable.other.member.cs + set: + - maybe-member-access + - type-argument-list + - include: else-pop + +###[ LAMBDA EXPRESSIONS ]###################################################### + + delegate-lambda-parameter-list: + - match: \( + scope: punctuation.section.group.begin.cs + set: inside-delegate-lambda-parameter-list + - include: else-pop + + inside-delegate-lambda-parameter-list: + - clear_scopes: 1 + - meta_scope: meta.function.anonymous.parameters.cs meta.group.cs + - include: inside-method-parameter-list + + delegate-lambda-body: + - meta_content_scope: meta.function.anonymous.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: + - inside-lambda-block + - maybe-pointer + - include: else-pop + + lambdas: + - match: ({{name}})(\s+(=>)) + captures: + 1: meta.function.anonymous.parameters.cs variable.parameter.cs + 2: meta.function.anonymous.cs + 3: keyword.declaration.function.arrow.cs + push: lambda-body + + lambda-body: + - meta_content_scope: meta.function.anonymous.cs + - match: \{ + scope: punctuation.section.block.begin.cs + set: + - inside-lambda-block + - maybe-pointer + - match: (?=\S) + set: + - inside-lambda-expression + - maybe-pointer + + inside-lambda-block: + - meta_scope: meta.function.anonymous.body.cs meta.block.cs + - include: inside-statement-block + + inside-lambda-expression: + - meta_content_scope: meta.function.anonymous.body.cs + - include: expression + +###[ SWITCH EXPRESSIONS ]###################################################### + + switch-expressions: + - match: switch\b + scope: keyword.control.conditional.switch.cs + push: switch-expression-block + + switch-expression-block: + - match: \{ + scope: punctuation.section.block.begin.cs + set: + - inside-switch-expression-block + - switch-expression-case-pattern + - expect-pattern + - include: else-pop + + inside-switch-expression-block: + - meta_scope: meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - match: ',' + scope: punctuation.separator.comma.cs + push: + - switch-expression-case-pattern + - expect-pattern + - include: expression + + switch-expression-case-pattern: + - meta_content_scope: meta.case.pattern.cs + - match: when\b + scope: meta.case.guard.cs keyword.control.conditional.when.cs + set: inside-switch-expression-case-guard + - include: inside-switch-expression-case-guard + + inside-switch-expression-case-guard: + - meta_content_scope: meta.case.guard.cs + - match: => + scope: meta.case.cs punctuation.separator.case-expression.cs + pop: 1 + - include: switch-expression-case-guard-expression + + switch-expression-case-guard-expression: + - match: (?=\() + branch_point: switch-expression-case-guard-parens + branch: + - switch-expression-case-guard-cast + - switch-expression-case-guard-group + - tuple-literal + - include: expression-common + - include: else-pop + + switch-expression-case-guard-cast: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.cs + set: + - after-switch-expression-case-guard-cast + - inside-switch-expression-case-guard-cast + - maybe-type + + inside-switch-expression-case-guard-cast: + - meta_scope: meta.cast.cs meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - match: (?=\S) + fail: switch-expression-case-guard-parens + + after-switch-expression-case-guard-cast: + - include: cast-end + - match: (?=\S) + fail: switch-expression-case-guard-parens + + switch-expression-case-guard-group: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.cs + set: + - inside-switch-expression-case-guard-group + - switch-expression-case-guard-expression + - maybe-pointer + + inside-switch-expression-case-guard-group: + - meta_scope: meta.group.cs + - match: \) + scope: punctuation.section.group.end.cs + pop: 1 + - match: (?=\S) + fail: switch-expression-case-guard-parens + +###[ TYPE PATTERNS ]########################################################### + + expect-pattern: + - include: tuple-literal + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-member-pattern + - match: not\b + scope: keyword.operator.logical.cs + - match: var\b + scope: storage.type.variant.cs + pop: 1 + - match: '{{base_type}}' + scope: storage.type.primitive.cs + set: + - maybe-member-pattern + - maybe-member-access + - type-suffix + - match: '{{cap_name}}' + scope: support.type.cs + set: + - maybe-member-pattern + - maybe-member-access + - type-suffix + - type-argument-list + - include: else-pop + + maybe-member-pattern: + - match: \{ + scope: punctuation.section.block.begin.cs + set: inside-member-pattern + - include: else-pop + + inside-member-pattern: + - meta_scope: meta.class.body.cs meta.block.cs + - match: \} + scope: punctuation.section.block.end.cs + pop: 1 + - include: separators + - match: ({{name}})\s*(\.) + captures: + 1: variable.other.member.cs + 2: punctuation.accessor.dot.cs + - match: ({{name}})\s*({{colon}})? + captures: + 1: variable.other.member.cs + 2: keyword.operator.assignment.cs + push: + - expression + - expect-pattern + +###[ TYPES ]################################################################### + + modifiers: + - match: '{{modifiers}}' + scope: storage.modifier.cs + + visibility: + - match: '{{visibility}}' + scope: storage.modifier.access.cs + - match: file\b # soft keyword + scope: storage.modifier.access.cs + + base-types: + - match: '{{base_type}}' + scope: storage.type.primitive.cs + push: + - type-suffix + - type-argument-list + + maybe-type: + - include: type-tuple + - include: maybe-object-type + + maybe-object-type: + - include: namespace-variables + - match: (delegate)\s*(\*) + captures: + 1: keyword.declaration.delegate.cs + 2: keyword.operator.pointer.cs + set: + - funcptr-type-meta + - type-argument-list + - funcptr-type-modifier + - match: '{{base_type}}' + scope: storage.type.primitive.cs + set: + - type-suffix + - type-argument-list + - match: '{{unreserved_name}}' + scope: support.type.cs + set: + - maybe-type-accessor + - type-suffix + - type-argument-list + - match: \[ + scope: meta.brackets.cs punctuation.section.brackets.begin.cs + push: inside-rank-specifier + - include: else-pop + + maybe-type-accessor: + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.cs + set: maybe-user-type + - include: noeol-pop + + maybe-user-type: + - match: \s*({{unreserved_name}}) + captures: + 1: support.type.cs + set: + - maybe-type-accessor + - type-suffix + - type-argument-list + - include: noeol-pop + + type-tuple: + - match: \( + scope: punctuation.section.sequence.begin.cs + set: + - type-suffix + - inside-type-tuple + + inside-type-tuple: + - meta_scope: meta.sequence.tuple.cs + - match: \) + scope: punctuation.section.sequence.end.cs + pop: 1 + - include: separators + - match: (?=\S) + push: var-declaration + +###[ TYPE PARAMETER LISTS ]#################################################### + + type-argument-list: + - match: \s*(<) + captures: + 1: meta.generic.cs punctuation.definition.generic.begin.cs + set: + - inside-type-argument-list + - maybe-type + - type-param-modifier + - include: noeol-pop + + inside-type-argument-list: + - meta_content_scope: meta.generic.cs + - match: '>' + scope: meta.generic.cs punctuation.definition.generic.end.cs + pop: 1 + - match: ',' + scope: punctuation.separator.comma.cs + push: + - maybe-type + - type-param-modifier + - include: else-pop + + type-parameter-list: + - match: \s*(<) + captures: + 1: meta.generic.cs punctuation.definition.generic.begin.cs + set: + - inside-type-parameter-list + - type-suffix + - type-param-name + - type-param-modifier + - include: noeol-pop + + inside-type-parameter-list: + - meta_content_scope: meta.generic.cs + - match: '>' + scope: meta.generic.cs punctuation.definition.generic.end.cs + pop: 1 + - match: ',' + scope: punctuation.separator.comma.cs + push: + - type-suffix + - type-param-name + - type-param-modifier + - include: else-pop + + type-param-modifier: + - include: attributes + - match: '{{generic_param_type_modifier}}' + scope: storage.modifier.cs + - include: else-pop + + type-param-name: + - match: '{{unreserved_name}}' + scope: variable.parameter.type.cs + pop: 1 + - include: else-pop + + type-suffix: + - meta_include_prototype: false + - match: \s*(\?) + captures: + 1: storage.modifier.nullable.cs + set: inside-type-suffix + - include: inside-type-suffix + + inside-type-suffix: + - meta_include_prototype: false + - match: \s*(\*) + captures: + 1: keyword.operator.pointer.cs + pop: 1 + - match: \s*(\[) + scope: meta.brackets.cs punctuation.section.brackets.begin.cs + push: inside-rank-specifier + - include: noeol-pop + + inside-rank-specifier: + - meta_content_scope: meta.brackets.cs + - match: \] + scope: meta.brackets.cs punctuation.section.brackets.end.cs + pop: 1 + - include: expression-list + +###[ FUNCTION POINTER TYPES ]################################################## + + funcptr-type-meta: + - meta_include_prototype: false + - meta_scope: meta.type.funcptr.cs + - include: immediately-pop + + funcptr-type-modifier: + - match: \s*(managed)\b + captures: + 1: storage.modifier.delegate.cs + pop: 1 + - match: \s*(unmanaged)\b + captures: + 1: storage.modifier.delegate.cs + set: funcptr-type-calling-convention + - include: noeol-pop + + funcptr-type-calling-convention: + - match: \s*(\[) + captures: + 1: meta.brackets.cs punctuation.section.brackets.begin.cs + set: + - inside-funcptr-type-calling-convention + - maybe-type + - funcptr-convention-modifier + - include: noeol-pop + + inside-funcptr-type-calling-convention: + - meta_content_scope: meta.brackets.cs + - match: \] + scope: meta.brackets.cs punctuation.section.brackets.end.cs + pop: 1 + - match: ',' + scope: punctuation.separator.comma.cs + push: + - maybe-type + - funcptr-convention-modifier + - include: else-pop + + funcptr-convention-modifier: + - match: (?:Cdecl|Stdcall|Thiscall|Fastcall)\b + scope: storage.modifier.funcptr.cs + - include: attributes + - include: else-pop + +###[ OPERATORS ]############################################################### + + maybe-pointer: + - match: '[*&]' + scope: keyword.operator.pointer.cs + pop: 1 + - include: attributes + - include: else-pop + + accessors: + - match: \. + scope: punctuation.accessor.dot.cs + push: maybe-pointer + + separators: + - match: ',' + scope: punctuation.separator.comma.cs + + terminators: + - match: ';' + scope: punctuation.terminator.statement.cs + + stray-punctuation: + - match: '[]}),:]' + scope: invalid.illegal.stray.cs + +###[ VARIABLES ]############################################################### + + instance-variables: + - match: this\b + scope: variable.language.this.cs + - match: base\b + scope: variable.language.super.cs + + member-variables: + - match: ({{name}})\s*({{colon}}) + captures: + 1: variable.other.member.cs + 2: keyword.operator.assignment.cs + push: assignment-value + + namespace-variables: + - match: (?:(global)|({{name}}))\s*(::) + captures: + 1: support.namespace.global.cs + 2: variable.namespace.cs + 3: punctuation.accessor.double-colon.namespace.cs + + stray-names: + - match: '{{name}}' + scope: invalid.illegal.unexpected-token.cs + +###[ LITERALS ]################################################################ + + characters: + - match: (')(?:({{escape_base}})|({{escape_hex}})|({{escape_uni16}})|({{escape_uni32}})|([^'\\]))(') + scope: meta.string.cs string.quoted.single.cs + captures: + 1: punctuation.definition.string.begin.cs + 2: constant.character.escape.cs + 3: constant.character.escape.hex.cs + 4: constant.character.escape.unicode.16bit.cs + 5: constant.character.escape.unicode.32bit.cs + 6: constant.character.literal.cs + 7: punctuation.definition.string.end.cs + - match: \'.*\' + scope: invalid.illegal.character.cs + + constants: + - match: false\b + scope: constant.language.boolean.false.cs + - match: true\b + scope: constant.language.boolean.true.cs + - match: null\b + scope: constant.language.null.cs + + numbers: + - match: (0[xX])([\h_]*\h)({{integer_suffix}})? + scope: meta.number.integer.hexadecimal.cs + captures: + 1: constant.numeric.base.cs + 2: constant.numeric.value.cs + 3: constant.numeric.suffix.cs + - match: (0[bB])([01_]*[01])({{integer_suffix}})? + scope: meta.number.integer.binary.cs + captures: + 1: constant.numeric.base.cs + 2: constant.numeric.value.cs + 3: constant.numeric.suffix.cs + - match: (\d{{dec_digits}}?)(?:(?:((\.){{dec_digits}})({{dec_exponent}})?|({{dec_exponent}}))({{float_suffix}})?|({{float_suffix}})) + scope: meta.number.float.decimal.cs + captures: + 1: constant.numeric.value.cs + 2: constant.numeric.value.cs + 3: punctuation.separator.decimal.cs + 4: constant.numeric.value.exponent.cs + 5: constant.numeric.value.exponent.cs + 6: constant.numeric.suffix.cs + 7: constant.numeric.suffix.cs + - match: (\d{{dec_digits}}?)({{integer_suffix}})? + scope: meta.number.integer.decimal.cs + captures: + 1: constant.numeric.value.cs + 2: constant.numeric.suffix.cs + +###[ REGULAR EXPRESSIONS ]##################################################### + + regex-string: + # literal raw literal string + - match: ("""+) + scope: punctuation.definition.string.begin.cs + set: inside-raw-string + # literal quoted regexp string + - match: '"' + scope: punctuation.definition.string.begin.cs + set: inside-literal-regex-string + # interpolated raw format strings + - match: \${1}("""+) + scope: punctuation.definition.string.begin.cs + set: inside-raw-format-string-1 + - match: \${2}("""+) + scope: punctuation.definition.string.begin.cs + set: inside-raw-format-string-2 + - match: \${3}("""+) + scope: punctuation.definition.string.begin.cs + set: inside-raw-format-string-3 + - match: \${4}("""+) + scope: punctuation.definition.string.begin.cs + set: inside-raw-format-string-4 + # interpolated quoted format strings + - match: \$" + scope: punctuation.definition.string.begin.cs + set: inside-format-string + # Verbatim regexp string + - match: '@"' + scope: punctuation.definition.string.begin.cs + set: inside-verbatim-regex-string + # interpolated verbatim format strings + - match: (?:@\$|\$@)" + scope: punctuation.definition.string.begin.cs + set: inside-verbatim-format-string-syntax + - include: else-pop + + inside-literal-regex-string: + - meta_include_prototype: false + - meta_scope: meta.string.regexp.cs string.quoted.double.cs + - meta_content_scope: source.regexp.embedded.cs + - match: '"' + scope: punctuation.definition.string.end.cs + pop: 1 + - match: $\n? + scope: invalid.illegal.unclosed-string.cs + pop: 1 + - include: scope:source.regexp.embedded.cs.literal-string + apply_prototype: true + + inside-verbatim-regex-string: + - meta_include_prototype: false + - meta_scope: meta.string.regexp.cs string.quoted.double.verbatim.cs + - meta_content_scope: source.regexp.embedded.cs + - match: '"(?!")' + scope: punctuation.definition.string.end.cs + pop: 1 + - include: scope:source.regexp.embedded.cs.verbatim-string + apply_prototype: true + +###[ STRINGS ]################################################################# + + strings: + # literal raw strings + - match: '(""""+)' + scope: punctuation.definition.string.begin.cs + push: inside-raw-string + - match: '"""' + scope: punctuation.definition.string.begin.cs + push: inside-triple-quoted-raw-string-syntax + # literal quoted strings + - match: '"' + scope: punctuation.definition.string.begin.cs + push: inside-string + # interpolated raw format strings + - match: '\${1}("""+)' + scope: punctuation.definition.string.begin.cs + push: inside-raw-format-string-1 + - match: '\${2}("""+)' + scope: punctuation.definition.string.begin.cs + push: inside-raw-format-string-2 + - match: '\${3}("""+)' + scope: punctuation.definition.string.begin.cs + push: inside-raw-format-string-3 + - match: '\${4}("""+)' + scope: punctuation.definition.string.begin.cs + push: inside-raw-format-string-4 + # interpolated quoted format strings + - match: '\$"' + scope: punctuation.definition.string.begin.cs + push: inside-format-string + # literal verbatim strings + - match: '@"' + scope: punctuation.definition.string.begin.cs + push: inside-verbatim-string-syntax + # interpolated verbatim format strings + - match: '(?:@\$|\$@)"' + scope: punctuation.definition.string.begin.cs + push: inside-verbatim-format-string-syntax + +###[ QUOTED STRINGS ]########################################################## + + inside-string: + - meta_include_prototype: false + - meta_scope: meta.string.cs string.quoted.double.cs + - match: '"' + scope: punctuation.definition.string.end.cs + pop: 1 + - match: $\n? + scope: invalid.illegal.unclosed-string.cs + pop: 1 + - include: string-prototype + - include: string-escapes + - include: string-placeholder-escapes + - include: string-guids + - include: extended-string-placeholders + + extended-string-placeholders: + - match: (?=\{\d) + branch_point: extended-string-placeholder + branch: + - extended-string-placeholder + - string-placeholder-fallback + + extended-string-placeholder: + - match: (\{)(\d+) + captures: + 1: punctuation.definition.placeholder.begin.cs + 2: meta.number.integer.decimal.cs constant.numeric.value.cs + set: inside-extended-string-placeholder + + inside-extended-string-placeholder: + - meta_scope: constant.other.placeholder.cs + - include: string-placeholder-end + - include: string-placeholder-formatspec + - include: string-placeholder-width + - match: (?=\S) + fail: extended-string-placeholder + + string-placeholder-formatspec: + - match: ':' + scope: punctuation.separator.colon.cs + push: inside-extended-string-placeholder-formatspec + + inside-extended-string-placeholder-formatspec: + - meta_scope: meta.format-spec.cs + - meta_content_scope: constant.other.format-spec.cs + - include: string-escapes + - include: string-placeholder-escapes + - match: (?=\}) + pop: 1 + - match: (?=["{]) + fail: extended-string-placeholder + +###[ QUOTED FORMAT STRINGS ]################################################### + + inside-format-string: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs string.quoted.double.cs + - match: '"' + scope: punctuation.definition.string.end.cs + pop: 1 + - match: $\n? + scope: invalid.illegal.unclosed-string.cs + pop: 1 + - include: string-prototype + - include: string-escapes + - include: string-placeholder-escapes + - include: string-interpolations + - include: invalid-string-placeholders + + string-interpolations: + - match: (?=\{) + branch_point: string-interpolation + branch: + - string-interpolation + - string-placeholder-fallback + + string-interpolation: + - match: \{ + scope: punctuation.section.interpolation.begin.cs + set: inside-string-interpolation + + inside-string-interpolation: + - clear_scopes: 1 + - meta_scope: meta.interpolation.cs + - meta_content_scope: source.cs + - include: string-interpolation-end + - include: string-interpolation-formatspec + - include: string-interpolation-width + - include: parens + - include: lambdas + - include: expression-common + - match: (?=\S) + set: string-interpolation + + string-interpolation-formatspec: + - match: ':' + scope: punctuation.separator.colon.cs + push: inside-string-interpolation-formatspec + + inside-string-interpolation-formatspec: + - meta_scope: meta.format-spec.cs + - meta_content_scope: constant.other.format-spec.cs + - include: string-escapes + - include: string-placeholder-escapes + - match: (?=\}) + pop: 1 + - match: (?=["{]) + fail: string-interpolation + +###[ VERBATIM STRINGS ]######################################################## + + inside-verbatim-string-syntax: + - meta_include_prototype: false + - meta_scope: meta.string.cs string.quoted.double.verbatim.cs + - match: (?={{sql_indicator}}) + set: inside-verbatim-string-sql + - match: (?=\S) + set: inside-verbatim-string-plain + + inside-verbatim-string-sql: + - meta_scope: meta.string.cs + - meta_content_scope: source.sql.embedded.cs + - match: '"(?!")' + scope: string.quoted.double.verbatim.cs punctuation.definition.string.end.cs + pop: 1 + - include: scope:source.sql.embedded.cs.verbatim-string + apply_prototype: true + + inside-verbatim-string-plain: + - meta_include_prototype: false + - meta_scope: meta.string.cs string.quoted.double.verbatim.cs + - include: verbatim-string-escapes + - match: '"' + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - include: string-placeholder-escapes + - include: string-guids + - include: extended-verbatim-string-placeholders + + extended-verbatim-string-placeholders: + - match: (?=\{\d) + branch_point: extended-verbatim-string-placeholder + branch: + - extended-verbatim-string-placeholder + - string-placeholder-fallback + + extended-verbatim-string-placeholder: + - match: (\{)(\d+) + captures: + 1: punctuation.definition.placeholder.begin.cs + 2: meta.number.integer.decimal.cs constant.numeric.value.cs + set: inside-extended-verbatim-string-placeholder + + inside-extended-verbatim-string-placeholder: + - meta_scope: constant.other.placeholder.cs + - include: string-placeholder-end + - include: extended-verbatim-string-placeholder-formatspec + - include: string-placeholder-width + - match: (?=\S) + fail: extended-verbatim-string-placeholder + + extended-verbatim-string-placeholder-formatspec: + - match: ':' + scope: punctuation.separator.colon.cs + push: inside-extended-verbatim-string-placeholder-formatspec + + inside-extended-verbatim-string-placeholder-formatspec: + - meta_scope: meta.format-spec.cs + - meta_content_scope: constant.other.format-spec.cs + - include: verbatim-string-escapes + - include: string-placeholder-escapes + - match: \\(?:""|[^"]) + scope: constant.character.escape.cs + - match: (?=\}) + pop: 1 + - match: (?=["{]) + fail: extended-verbatim-string-placeholder + +###[ VERBATIM FOMRAT STRINGS ]################################################# + + inside-verbatim-format-string-syntax: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs string.quoted.double.verbatim.cs + - match: (?={{sql_indicator}}) + set: inside-verbatim-format-string-sql + - match: (?=\S) + set: inside-verbatim-format-string-plain + + inside-verbatim-format-string-sql: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs + - meta_content_scope: source.sql.embedded.cs + - match: '"(?!")' + scope: string.quoted.double.verbatim.cs punctuation.definition.string.end.cs + pop: 1 + - include: scope:source.sql.embedded.cs.verbatim-format-string + apply_prototype: true + + inside-verbatim-format-string-plain: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs string.quoted.double.verbatim.cs + - include: verbatim-string-escapes + - match: '"' + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - include: string-placeholder-escapes + - include: verbatim-string-interpolations + - include: invalid-string-placeholders + + verbatim-string-interpolations: + - match: (?=\{) + branch_point: verbatim-string-interpolation + branch: + - verbatim-string-interpolation + - string-placeholder-fallback + + verbatim-string-interpolation: + - match: \{ + scope: punctuation.section.interpolation.begin.cs + set: inside-verbatim-string-interpolation + + inside-verbatim-string-interpolation: + - clear_scopes: 1 + - meta_scope: meta.interpolation.cs + - meta_content_scope: source.cs + - include: string-interpolation-end + - include: verbatim-string-interpolation-formatspec + - include: string-interpolation-width + - include: parens + - include: lambdas + - include: expression-common + - match: (?=\S) + set: verbatim-string-interpolation + + verbatim-string-interpolation-formatspec: + - match: ':' + scope: punctuation.separator.colon.cs + push: inside-verbatim-string-interpolation-formatspec + + inside-verbatim-string-interpolation-formatspec: + - meta_scope: meta.format-spec.cs + - meta_content_scope: constant.other.format-spec.cs + - include: verbatim-string-escapes + - include: string-placeholder-escapes + - match: \\(?:""|[^"]) + scope: constant.character.escape.cs + - match: (?=\}) + pop: 1 + - match: (?=["{]) + fail: verbatim-string-interpolation + + verbatim-string-escapes: + - match: '""' + scope: constant.character.escape.cs + +###[ RAW STRINGS ]############################################################# + + inside-triple-quoted-raw-string-syntax: + - meta_include_prototype: false + - meta_scope: meta.string.cs string.quoted.double.block.cs + - match: (?={{sql_indicator}}) + set: inside-triple-quoted-raw-string-sql + - match: (?=\S) + set: inside-triple-quoted-raw-string-plain + + inside-triple-quoted-raw-string-sql: + - meta_include_prototype: false + - meta_scope: meta.string.cs + - meta_content_scope: source.sql.embedded.cs + - match: '"""' + scope: string.quoted.double.block.cs punctuation.definition.string.end.cs + pop: 1 + - include: scope:source.sql.embedded.cs.raw-string + apply_prototype: true + + inside-triple-quoted-raw-string-plain: + - meta_include_prototype: false + - meta_scope: meta.string.cs string.quoted.double.block.cs + - match: '"""' + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - include: string-placeholder-escapes + - include: string-guids + - include: extended-raw-string-placeholders + + inside-raw-string: + - meta_include_prototype: false + - meta_scope: meta.string.cs string.quoted.double.block.cs + - match: \1 + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - include: string-placeholder-escapes + - include: string-guids + - include: extended-raw-string-placeholders + + extended-raw-string-placeholders: + - match: (?=\{\d) + branch_point: extended-raw-string-placeholder + branch: + - extended-raw-string-placeholder + - string-placeholder-fallback + + extended-raw-string-placeholder: + - match: (\{)(\d+) + captures: + 1: punctuation.definition.placeholder.begin.cs + 2: meta.number.integer.decimal.cs constant.numeric.value.cs + set: inside-extended-raw-string-placeholder + + inside-extended-raw-string-placeholder: + - meta_scope: constant.other.placeholder.cs + - include: string-placeholder-end + - include: extended-raw-string-placeholder-formatspec + - include: string-placeholder-width + - match: (?=\S) + fail: extended-raw-string-placeholder + + extended-raw-string-placeholder-formatspec: + - match: ':' + scope: punctuation.separator.colon.cs + push: inside-extended-raw-string-placeholder-formatspec + + inside-extended-raw-string-placeholder-formatspec: + - meta_scope: meta.format-spec.cs + - meta_content_scope: constant.other.format-spec.cs + - match: (?=\}) + pop: 1 + - match: (?=") + pop: 2 + - match: (?=[\\\{]) + fail: extended-raw-string-placeholder + +###[ RAW FORMAT STRINGS ]###################################################### + + inside-raw-format-string-1: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs string.quoted.double.block.cs + - match: \1 + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - match: \{{2,}|\}{1,} + scope: invalid.illegal.unexpected-token.cs + - match: \{ + scope: punctuation.section.interpolation.begin.cs + push: inside-raw-format-string-interpolation-1 + + inside-raw-format-string-interpolation-1: + - clear_scopes: 1 + - meta_scope: meta.interpolation.cs + - meta_content_scope: source.cs + - include: string-interpolation-end + - include: raw-string-interpolation-formatspec + - include: string-interpolation-width + - include: expression + + inside-raw-format-string-2: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs string.quoted.double.block.cs + - match: \1 + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - match: \{{2}(?!\{) + scope: punctuation.section.interpolation.begin.cs + push: inside-raw-format-string-interpolation-2 + - match: \}{2,} + scope: invalid.illegal.unexpected-token.cs + + inside-raw-format-string-interpolation-2: + - clear_scopes: 1 + - meta_scope: meta.interpolation.cs + - meta_content_scope: source.cs + - match: \}{2} + scope: punctuation.section.interpolation.end.cs + pop: 1 + - include: raw-string-interpolation-formatspec + - include: string-interpolation-width + - include: expression + + inside-raw-format-string-3: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs string.quoted.double.block.cs + - match: \1 + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - match: \{{3}(?!\{) + scope: punctuation.section.interpolation.begin.cs + push: inside-raw-format-string-interpolation-3 + - match: \}{3,} + scope: invalid.illegal.unexpected-token.cs + + inside-raw-format-string-interpolation-3: + - clear_scopes: 1 + - meta_scope: meta.interpolation.cs + - meta_content_scope: source.cs + - match: \}{3} + scope: punctuation.section.interpolation.end.cs + pop: 1 + - include: raw-string-interpolation-formatspec + - include: string-interpolation-width + - include: expression + + inside-raw-format-string-4: + - meta_include_prototype: false + - meta_scope: meta.string.interpolated.cs string.quoted.double.block.cs + - match: \1 + scope: punctuation.definition.string.end.cs + pop: 1 + - include: string-prototype + - match: \{{4}(?!\{) + scope: punctuation.section.interpolation.begin.cs + push: inside-raw-format-string-interpolation-4 + - match: \}{4,} + scope: invalid.illegal.unexpected-token.cs + + inside-raw-format-string-interpolation-4: + - clear_scopes: 1 + - meta_scope: meta.interpolation.cs + - meta_content_scope: source.cs + - match: \}{4} + scope: punctuation.section.interpolation.end.cs + pop: 1 + - include: raw-string-interpolation-formatspec + - include: string-interpolation-width + - include: expression + + raw-string-interpolation-formatspec: + - match: ':' + scope: punctuation.separator.colon.cs + push: inside-raw-string-interpolation-formatspec + + inside-raw-string-interpolation-formatspec: + - meta_scope: meta.format-spec.cs + - meta_content_scope: constant.other.format-spec.cs + - match: (?=\}) + pop: 1 + - match: (?=") + pop: 2 + - match: \\ + scope: invalid.illegal.lone-escape.cs + - match: \{ + scope: invalid.illegal.unescaped-placeholder.cs + +###[ STRING PROTOTYPES ]####################################################### + + string-escapes: + # https://github.com/dotnet/csharpstandard/blob/standard-v6/standard/lexical-structure.md#6455-character-literals + - match: '{{escape_base}}' + scope: constant.character.escape.cs + - match: '{{escape_hex}}' + scope: constant.character.escape.hex.cs + - match: '{{escape_uni16}}' + scope: constant.character.escape.unicode.16bit.cs + - match: '{{escape_uni32}}' + scope: constant.character.escape.unicode.32bit.cs + - match: \\ + scope: invalid.illegal.lone-escape.cs + + string-guids: + - match: \{\h{8}-(?:\h{4}-){3}\h{12}\} + scope: constant.other.guid.cs + + string-placeholder-escapes: + - match: \{\{|\}\} + scope: constant.character.escape.cs + + string-placeholder-end: + - match: \} + scope: punctuation.definition.placeholder.end.cs + pop: 1 + + string-placeholder-fallback: + - match: \{ + pop: 1 + + invalid-string-placeholders: + - match: \} + scope: invalid.illegal.unescaped-placeholder.cs + + string-placeholder-width: + - match: \s*(?:(,)\s*((-?)\d+)\s*)? + scope: meta.format-spec.cs + captures: + 1: punctuation.separator.comma.cs + 2: meta.number.integer.decimal.cs constant.numeric.value.cs + 3: keyword.operator.arithmetic.cs + 4: variable.other.cs + + string-interpolation-end: + - match: \} + scope: punctuation.section.interpolation.end.cs + pop: 1 + + string-interpolation-width: + - match: \s*(?:(,)\s*(?:((-?)\d+)|({{name}}))\s*)? + scope: meta.format-spec.cs + captures: + 1: punctuation.separator.comma.cs + 2: meta.number.integer.decimal.cs constant.numeric.value.cs + 3: keyword.operator.arithmetic.cs + 4: variable.other.cs + + string-prototype: [] + +###[ PROTOTYPES ]############################################################## + + else-pop: + - meta_include_prototype: false + - match: (?=\S) + pop: 1 + + immediately-pop: + - meta_include_prototype: false + - match: '' + pop: 1 + + noeol-pop: + - meta_include_prototype: false + # immediately pop, but not before newlines + - match: (?=[^\n]) + pop: 1 + +###[ VARIABLES ]############################################################### + +variables: + shebang_language: \bdotnet\s+run\b + + colon: :(?!:) + equal: =(?![=>]) + + # numbers + dec_digits: (?:[\d_]*\d) + dec_exponent: (?:[eE][-+]??{{dec_digits}}) + float_suffix: '[fFdDmM]' + integer_suffix: '[uU][lL]?|[lL][uU]?' + + # characters + escape_base: \\[0abfnrtv"'\\] + escape_hex: \\x\h{1,4} + escape_uni16: \\u\h{4} + escape_uni32: \\U\h{8} + + reserved: |- + (?x: + {{statement_keywords}} + | {{expression_keywords}} + | {{modifiers}} + | {{visibility}} + | {{base_type}} + | {{language_literals}} + ) + + modifiers: (?x:abstract|async|const|explicit|extern|implicit|new|override|partial|readonly|ref|required|sealed|static|unsafe|virtual|volatile)\b + method_param_type_modifier: (?:in|out|params|ref|this)\b + generic_param_type_modifier: (?:in|out|readonly|ref)\b + + visibility: (?:internal|private|protected|public)\b + + base_type: (?x:bool|byte|sbyte|char|decimal|double|float|int|uint|nint|nuint|long|ulong|short|ushort|dynamic|object|string|void)\b + type_suffix: (?:\s*(?:\[,*\]|\*|\?)*) + generic_declaration: (?:\s*<[^={};]*>) + + statement_keywords: (?:break|case|catch|class|continue|do|else|enum|event|finally|fixed|for|foreach|goto|if|interface|namespace|operator|return|switch|try|union|using|while)\b + expression_keywords: (?:as|checked|default|delegate|in|is|lock|nameof|new|not|params|sizeof|stackalloc|throw|typeof|unchecked)\b + language_literals: (?:base|false|null|this|true)\b + + namespaced_name: (?:(?:{{name}}\s*::\s*)*(?:{{name}}{{generic_declaration}}?{{type_suffix}}?\s*\.\s*)*{{name}}{{generic_declaration}}?{{type_suffix}}?) + unreserved_name: (?:@|(?!{{reserved}}\b)){{name_normal}} + name: (?:@?{{name_normal}}) + name_normal: '{{start_char}}{{other_char}}*\b' + cap_name: '[[:upper:]]{{other_char}}*\b' + lower_name: '[[:lower:]]{{other_char}}*\b' + start_char: (?:{{escape_uni16}}|{{escape_uni32}}|[_[[:alpha:]]]) + other_char: (?:{{escape_uni16}}|{{escape_uni32}}|[_[[:alnum:]]]) + + wspace_eol: \s*(?:\n|$) + + sql_indicator: |- + (?x: \s* (?: + # dml statements + SELECT | INSERT | REPLACE | DELETE | TRUNCATE | UPDATE | MERGE\s+INTO + # ddl statements + | ADD | ALTER | CREATE | DROP + # conditional + | IF \s+ (?: NOT \s+ )? EXISTS + # declaration + | DECLARE | WITH | BEGIN + ) \s ) + + sql_keywords: |- + (?x: let | select | equals | from | in | where | join | orderby | group | by + | on | into | into | ascending | descending )\b(?!\s*[.,;+=&\|\[\]\)])
diff --git /dev/null b/syntax/C/C++.sublime-syntax @@ -0,0 +1,2406 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: C++ +scope: source.c++ + +file_extensions: + - cpp + - hpp + +first_line_match: |- + (?xi: + ^ \s* // .*? -\*- .*? \b(c\+\+|cpp\b) .*? -\*- # editorconfig + ) + +variables: + # number digits + bin_digit: '[01'']' + oct_digit: '[0-7'']' + dec_digit: '[\d'']' + hex_digit: '[\h'']' + + dec_digits: '(?:\d(?:{{dec_digit}}*\d)?)' + + # number exponents + dec_exponent: '(?:[eE][-+]?{{dec_digit}}*)' + hex_exponent: '(?:[pP][-+]?{{dec_digit}}*)' + + # number suffixes + # note: nearly everything can be defined as suffix + # a) see user literals + # https://en.cppreference.com/w/cpp/language/user_literal + # b) see complex `operator` keyword + # https://en.cppreference.com/w/cpp/numeric/complex/operator%22%22i + bin_suffix: '[2-9a-zA-Z_][[:alnum:]_]*' + oct_suffix: '[8-9g-zG-Z_][[:alnum:]_]*' + dec_suffix: '[a-zA-Z_][[:alnum:]_]*' + hex_suffix: '[g-zG-Z_][[:alnum:]_]*' + float_suffix: '[fF]' + + identifier: \b[[:alpha:]_][[:alnum:]_]*\b # upper and lowercase + macro_identifier: \b[[:upper:]_][[:upper:][:digit:]_]{2,}\b # only uppercase, at least 3 chars + path_lookahead: '(?:::\s*)?(?:{{identifier}}\s*::\s*)*(?:template\s+)?{{identifier}}' + operator_method_name: '\boperator\s*(?:[-+*/%^&|~!=<>]|[-+*/%^&|=!<>]=|<=>|<<=?|>>=?|&&|\|\||\+\+|--|,|->\*?|\(\)|\[\]|""\s*{{identifier}})' + casts: 'const_cast|dynamic_cast|reinterpret_cast|static_cast' + operator_keywords: 'and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|xor|xor_eq|noexcept' + coroutine_keywords: co_(?:await|return|yield) + control_keywords: 'break|case|catch|continue|default|do|else|for|goto|if|_Pragma|switch|throw|try|while|{{coroutine_keywords}}' + memory_operators: 'new|delete' + basic_types: 'asm|__asm__|auto|bool|_Bool|char|_Complex|double|float|_Imaginary|int|long|short|signed|unsigned|void' + before_tag: 'struct|union|enum\s+class|enum\s+struct|enum|class|concept' + declspec: '__declspec\(\s*\w+(?:\([^)]+\))?\s*\)' + storage_classes: 'static|export|extern|friend|explicit|virtual|register|thread_local' + type_qualifier: 'const|mutable|typename|volatile' + constant_expression_specifiers: 'consteval|constexpr|constinit' + compiler_directive: 'inline|restrict|__restrict__|__restrict' + visibility_modifiers: 'private|protected|public' + other_keywords: 'typedef|nullptr|{{visibility_modifiers}}|static_assert|sizeof|using|typeid|alignof|alignas|namespace|template' + modifiers: '{{storage_classes}}|{{type_qualifier}}|{{compiler_directive}}|{{constant_expression_specifiers}}' + non_angle_brackets: '(?=<<|<=)' + module_identifier: '{{identifier}}(?:\.{{identifier}})*' + # A single token inside a macro argument list: a non-paren character, or a + # balanced parenthesised group with one level of further nesting. Repeated, + # this matches macro arguments with up to two levels of nested parentheses + # (e.g. `FOO(a = (b))`). + nested_parens: '(?:[^()]|\((?:[^()]|\([^()]*\))*\))' + + regular: '[^(){}&;*^%=<>-]*' + regular_plus: '[^(){}&;*^%=<>-]+' + paren_open: (?:\( + paren_close: '\))?' + generic_open: (?:{{regular_plus}}(?:< + generic_close: '>)?)?' + balance_parentheses: '{{regular}}{{paren_open}}{{regular}}{{paren_close}}{{regular}}' + generic_lookahead: <{{generic_open}}{{generic_open}}{{regular}}{{generic_close}}\s*{{generic_close}}{{balance_parentheses}}> + + data_structures_forward_decl_lookahead: '(\s+{{macro_identifier}})*\s*(:\s*({{path_lookahead}}|{{visibility_modifiers}}|,|\s|<[^;]*>)+)?;' + non_func_keywords: 'if|for|switch|while|decltype|sizeof|__declspec|__attribute__|typeid|alignof|alignas|static_assert' + + attribute_token: '({{identifier}}|{{identifier}}::{{identifier}}|{{identifier}}\(.*\)|{{identifier}}::{{identifier}}\(.*\))' + attribute_list: '({{attribute_token}}|({{attribute_token}},\s*)+({{attribute_token}}|\.\.\.))' + attribute_namespace_list: '(using\s+{{identifier}}:\s*{{attribute_list}})' + attribute_body: '{{attribute_list}}|{{attribute_namespace_list}}' + + +contexts: + main: + - include: preprocessor-global + - include: global + + ############################################################################# + # Reusable contexts + # + # The follow contexts are currently constructed to be reused in the + # Objective-C++ syntax. They are specifically constructed to not push into + # sub-contexts, which ensures that Objective-C++ code isn't accidentally + # lexed as plain C++. + # + # The "unique-*" contexts are additions that C++ makes over C, and thus can + # be directly reused in Objective-C++ along with contexts from Objective-C + # and C. + ############################################################################# + + unique-late-expressions: + # This is highlighted after all of the other control keywords + # to allow operator overloading to be lexed properly + - match: \boperator\b + scope: keyword.control.c++ + + unique-modifiers: + - match: \b({{modifiers}})\b + scope: storage.modifier.c++ + + unique-variables: + - match: \bthis\b + scope: variable.language.this.c++ + # common C++ instance var naming idiom -- fMemberName + - match: '\b(f|m)[[:upper:]]\w*\b' + scope: variable.other.readwrite.member.c++ + # common C++ instance var naming idiom -- m_member_name + - match: '\bm_[[:alnum:]_]+\b' + scope: variable.other.readwrite.member.c++ + + unique-constants: + - match: \bnullptr\b + scope: constant.language.c++ + + unique-keywords: + - match: \busing\b + scope: keyword.control.c++ + - match: \bbreak\b + scope: keyword.control.flow.break.c++ + - match: \bcontinue\b + scope: keyword.control.flow.continue.c++ + - match: \bgoto\b + scope: keyword.control.flow.goto.c++ + - match: \breturn\b + scope: keyword.control.flow.return.c++ + - match: \bthrow\b + scope: keyword.control.flow.throw.c++ + - match: \b({{control_keywords}})\b + scope: keyword.control.c++ + - match: '\bdelete\b(\s*\[\])?|\bnew\b(?!])' + scope: keyword.control.c++ + - match: \b({{operator_keywords}})\b + scope: keyword.operator.word.c++ + + unique-types: + - match: \bclass\b + scope: keyword.declaration.class.c++ + + unique-strings: + - match: '((?:L|u8|u|U)?R)("([^\(\)\\ ]{0,16})\()' + captures: + 1: storage.type.string.c++ + 2: punctuation.definition.string.begin.c++ + push: + - meta_scope: string.quoted.double.c++ + - match: '\)\3"' + scope: punctuation.definition.string.end.c++ + pop: true + + numbers: + # https://en.cppreference.com/w/cpp/language/floating_literal + + # decimal floats + - match: |- + (?x: + \b({{dec_digits}}) + (?: + ( (\.) + (?: + # 1.1, 1.1e1, 1.1e-1, 1.1f, 1.1e1f, 1.1e-1f, 1.1L, 1.1e1L, 1.1e-1L + {{dec_digit}}+ {{dec_exponent}}? + # 1.e1, 1.e-1, 1.e1f, 1.e-1f, 1.e1L, 1.e-1L + | {{dec_exponent}} + # 1., 1.f, 1.L # but not `..` + | (?!\.) + ) + # 1e1 1e1f 1e1L + | {{dec_exponent}} + ) ({{dec_suffix}})? + # 1f + | ({{float_suffix}}) + ) + # .1, .1e1, .1e-1, .1f, .1e1f, .1e-1f, .1L, .1e1L, .1e-1L + | ( (\.) {{dec_digit}}+ {{dec_exponent}}? ) ({{dec_suffix}})? + ) + scope: meta.number.float.decimal.c++ + captures: + 1: constant.numeric.value.c++ + 2: constant.numeric.value.c++ + 3: punctuation.separator.decimal.c++ + 4: constant.numeric.suffix.c++ + 5: constant.numeric.suffix.c++ + 6: constant.numeric.value.c++ + 7: punctuation.separator.decimal.c++ + 8: constant.numeric.suffix.c++ + + # hexadecimal float + - match: \b(0[xX])({{hex_digit}}*(\.){{hex_digit}}*{{hex_exponent}})({{dec_suffix}})? + scope: meta.number.float.hexadecimal.c++ + captures: + 1: constant.numeric.base.c++ + 2: constant.numeric.value.c++ + 3: punctuation.separator.decimal.c++ + 4: constant.numeric.suffix.c++ + + # https://en.cppreference.com/w/cpp/language/integer_literal + + # hexadecimal integer + - match: \b(0[xX])({{hex_digit}}*)({{hex_suffix}})? + scope: meta.number.integer.hexadecimal.c++ + captures: + 1: constant.numeric.base.c++ + 2: constant.numeric.value.c++ + 3: constant.numeric.suffix.c++ + + # binary integer (C++14) + - match: \b(0[bB])({{bin_digit}}*)({{bin_suffix}})? + scope: meta.number.integer.binary.c++ + captures: + 1: constant.numeric.base.c++ + 2: constant.numeric.value.c++ + 3: constant.numeric.suffix.c++ + + # octal integer + - match: \b(0)({{oct_digit}}+)({{oct_suffix}})? + scope: meta.number.integer.octal.c++ + captures: + 1: constant.numeric.base.c++ + 2: constant.numeric.value.c++ + 3: constant.numeric.suffix.c++ + + # decimal integer + - match: \b({{dec_digits}})({{dec_suffix}})? + scope: meta.number.integer.decimal.c++ + captures: + 1: constant.numeric.value.c++ + 2: constant.numeric.suffix.c++ + + identifiers: + - match: '(?:(::)\s*)?{{identifier}}\s*(::)\s*' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: punctuation.accessor.double-colon.c++ + - match: '(?:(::)\s*)?{{identifier}}' + captures: + 1: punctuation.accessor.double-colon.c++ + + identifier-path-generic: + - include: angle-brackets + - match: '(?:(::)\s*)?{{identifier}}\s*(?=(<.*>)?\s*(::))\s*' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: punctuation.accessor.double-colon.c++ + + function-specifiers: + - match: \b(const|final|noexcept|override)\b + scope: storage.modifier.c++ + + ############################################################################# + # The following are C++-specific contexts that should not be reused. This is + # because they push into subcontexts and use variables that are C++-specific. + ############################################################################# + + ## Common context layout + + global: + - match: '(?=\btemplate\b)' + push: + - include: template + - match: (?=\S) + set: global-modifier + - include: using-namespace + - include: namespace + - include: module + - include: keywords-angle-brackets + - match: '(?={{path_lookahead}}\s*<)' + push: global-modifier + - include: global-block-comments + - include: early-expressions + - match: ^\s*\b(extern)(?=\s+"C(\+\+)?") + scope: storage.modifier.c++ + push: + - include: comments + - include: strings + - match: '\{' + scope: punctuation.section.block.begin.c++ + set: + - meta_scope: meta.extern-c.c++ + - match: '^\s*(#\s*ifdef)\s*__cplusplus\s*' + scope: meta.preprocessor.c++ + captures: + 1: keyword.control.directive.conditional.if.c++ + set: + - match: '\}' + scope: punctuation.section.block.end.c++ + pop: true + - include: preprocessor-global + - include: global + - match: '\}' + scope: punctuation.section.block.end.c++ + pop: true + - include: preprocessor-global + - include: global + - match: (?=\S) + set: global-modifier + - match: ^\s*(?=(\w|\[\[{{attribute_body}}\]\])) + push: global-modifier + - include: late-expressions + + global-block-comments: + # NOTE: This context overrides `comments` context, which re-uses scopes + # from `source.c#comments`. So keep the trailing `c` for consistency reasons! + - match: ^(/\*) =\s*(.*?)\s*= (\*/)$\n? + scope: comment.block.banner.c + captures: + 1: punctuation.definition.comment.begin.c + 2: meta.toc-list.banner.block.c + 3: punctuation.definition.comment.end.c + # empty block comments + - match: /\*\*+/ + scope: comment.block.empty.c punctuation.definition.comment.c + push: global-block-comment-after + # documentation block comments + - match: (?:/\*!|/\*{2,}) + scope: punctuation.definition.comment.begin.c + push: + - global-block-comment-after + - scope:source.c#block-comment-documentation-body + # normal block comments + - match: /\* + scope: punctuation.definition.comment.begin.c + push: + - global-block-comment-after + - scope:source.c#block-comment-body + + global-block-comment-after: + - match: \s*(?=\w) + set: global-modifier + - match: '' + pop: true + + statements: + - include: preprocessor-statements + - include: scope:source.c#label + - include: expressions + + statements-enum: + - include: comments + - include: preprocessor-statements + - include: scope:source.c#label + - match: '{{identifier}}' + scope: entity.name.constant.c++ + push: constant-value + - match: ',' + scope: punctuation.separator.c++ + + constant-value: + - match: (?=[,;}]) + pop: true + - include: expressions + + expressions: + - include: early-expressions + - include: late-expressions + + early-expressions: + - include: early-expressions-before-generic-type + - include: generic-type + - include: early-expressions-after-generic-type + + early-expressions-before-generic-type: + - include: preprocessor-expressions + - include: comments + - include: case-default + - include: using-namespace + - include: typedef + - include: using-alias + - include: keywords-angle-brackets + - include: keywords-parens + - include: keywords + - include: numbers + # Prevent a '<' from getting scoped as the start of another template + # parameter list, if in reality a less-than-or-equals sign or + # three-way comparison operator is meant. + - match: '<=>?' + scope: keyword.operator.comparison.c + + early-expressions-after-generic-type: + - include: members-arrow + - include: operators + - include: members-dot + - include: strings + - include: parens + - include: brackets + - include: block + - include: variables + - include: constants + - match: ',' + scope: punctuation.separator.c++ + - match: '\)|\}' + scope: invalid.illegal.stray-bracket-end.c++ + + expressions-minus-generic-type: + - include: early-expressions-before-generic-type + - include: angle-brackets + - include: early-expressions-after-generic-type + - include: late-expressions + + expressions-minus-generic-type-function-call: + - include: early-expressions-before-generic-type + - include: angle-brackets + - include: early-expressions-after-generic-type + - include: late-expressions-before-function-call + - include: identifiers + - match: ';' + scope: punctuation.terminator.c++ + + late-expressions: + - include: late-expressions-before-function-call + - include: function-call + - include: identifiers + - match: ';' + scope: punctuation.terminator.c++ + + late-expressions-before-function-call: + - include: unique-late-expressions + - include: modifiers-parens + - include: modifiers + - include: types + + expressions-minus-function-call: + - include: early-expressions + - include: late-expressions-before-function-call + - include: identifiers + - match: ';' + scope: punctuation.terminator.c++ + + comments: + - include: scope:source.c#comments + + operators: + - include: scope:source.c#operators + + attribute_list: + - meta_scope: meta.attribute.c++ + - match: '\b(noreturn|carries_dependency|deprecated|fallthrough|maybe_unused|nodiscard|likely|unlikely|no_unique_address|assume|indeterminate)\b' + scope: storage.modifier.c++ + - include: parens + - match: ',' + scope: punctuation.separator.c++ + - match: '\.\.\.' + scope: keyword.operator.variadic.c++ + - match: \]\] + scope: punctuation.section.attribute.end.c++ + pop: true + + attributes: + - match: '\[\[(?={{attribute_namespace_list}}\]\])' + scope: punctuation.section.attribute.begin.c++ + push: + - meta_scope: meta.attribute.c++ + - match: 'using' + scope: keyword.control.c++ + push: + - match: '{{identifier}}' + push: + - match: ':' + scope: punctuation.separator.c++ + pop: 2 + - match: (?=) + set: attribute_list + - match: '\[\[(?={{attribute_list}}\]\])' + scope: punctuation.section.attribute.begin.c++ + push: attribute_list + + modifiers: + - include: attributes + - include: unique-modifiers + - include: scope:source.c#modifiers + + variables: + - include: unique-variables + - include: scope:source.c#variables + + constants: + - include: unique-constants + - include: scope:source.c#constants + + keywords: + - include: unique-keywords + - include: scope:source.c#keywords + + types: + - include: unique-types + - include: types-parens + - include: scope:source.c#types + + strings: + - include: unique-strings + - include: scope:source.c#strings + + ## C++-specific contexts + + case-default: + - match: '\b(default|case)\b' + scope: keyword.control.c++ + push: + - match: (?=[);,]) + pop: true + - match: ':' + scope: punctuation.separator.c++ + pop: true + - include: expressions + + modifiers-parens: + - match: '\b(alignas)\b\s*(\()' + captures: + 1: storage.modifier.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - match: \b(__attribute__)\s*(\(\() + captures: + 1: storage.modifier.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push : + - meta_scope: meta.attribute.c++ + - meta_content_scope: meta.group.c++ + - include: parens + - include: strings + - match: \)\) + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - match: \b(__declspec)(\() + captures: + 1: storage.modifier.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - match: '\b(align|allocate|code_seg|deprecated|property|uuid)\b\s*(\()' + captures: + 1: storage.modifier.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: numbers + - include: strings + - match: \b(get|put)\b + scope: variable.parameter.c++ + - match: ',' + scope: punctuation.separator.c++ + - match: '=' + scope: keyword.operator.assignment.c++ + - match: '\b(appdomain|deprecated|dllimport|dllexport|jintrinsic|naked|noalias|noinline|noreturn|nothrow|novtable|process|restrict|safebuffers|selectany|thread)\b' + scope: constant.other.c++ + + types-parens: + - match: '\b(decltype)\b\s*(\()' + captures: + 1: keyword.declaration.type.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + + keywords-angle-brackets: + - match: \b({{casts}})\b\s* + scope: keyword.operator.word.cast.c++ + push: + - match: '>' + scope: punctuation.definition.generic.end.c++ + pop: true + - match: '<' + scope: punctuation.definition.generic.begin.c++ + push: + - match: '(?=>)' + pop: true + - include: expressions-minus-generic-type-function-call + + keywords-parens: + - match: '\b(alignof|typeid|static_assert|sizeof)\b\s*(\()' + captures: + 1: keyword.operator.word.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + + using-namespace: + - match: '\b(using)\s+(namespace)\b' + captures: + 1: keyword.control.c++ + 2: keyword.control.c++ + push: + - include: identifiers + - match: '' + pop: true + + namespace: + - match: '\b(namespace)\s+(?=({{path_lookahead}})?(?!\s*[;,]))' + scope: meta.namespace.c++ + captures: + 1: keyword.control.c++ + push: + - meta_content_scope: meta.namespace.c++ entity.name.namespace.c++ + - include: identifiers + - match: '' + set: + - meta_scope: meta.namespace.c++ + - include: comments + - match: '=' + scope: keyword.operator.alias.c++ + - match: '(?=;)' + pop: true + - match: '\}' + scope: meta.block.c++ punctuation.section.block.end.c++ + pop: true + - match: '\{' + scope: punctuation.section.block.begin.c++ + push: + - meta_scope: meta.block.c++ + - match: '(?=\})' + pop: true + - include: preprocessor-global + - include: global + - include: expressions + + module-identifier: + # Special handling for trailing periods to prevent color changing while typing. + # Exit to catch invalid trailing period. + - match: '(?=\.\s*[\:;])' + pop: true + # Prevent color changing. + - match: \. + scope: entity.name.module.c++ + # Upcoming partition. + - match: (?=\s*\:) + pop: true + # Forgotten semmi-colon, fully abort out to handle upcoming syntax. + - match: (?=\s*\S) + pop: 2 + - match: '' #safety pop + pop: true + + module-error-handling: + # Stray periods in the name are invalid. + # Only mark the first period as invalid, even though trailing periods are also invalid. + - match: '\B\.' + scope: invalid.illegal.unexpected-character.c++ + # Stray period at end of module name. + - match: '(\.)(?=\s*\:)' + captures: + 1: invalid.illegal.unexpected-character.c++ + # Module partition - check for invalid partition names. + - match: (\:)\s*({{module_identifier}})(?:\s*(\:))? + captures: + 1: punctuation.accessor.c++ + 2: entity.name.partition.other + 3: invalid.illegal.unexpected-character.c++ + # End of line, but also check for stray period. + - match: '(\.\s*)?(;)' + captures: + 1: invalid.illegal.unexpected-character.c++ + 2: punctuation.terminator.c++ + pop: true + - match: (?=\S|$) # safety pop + pop: true + + module: + # The export keyword can go before most anything. + - match: '\b(export)\s+' + captures: + 1: keyword.control.c++ + push: + # export {...} block. + - match: '\}' + scope: meta.block.c++ punctuation.section.block.end.c++ + pop: true + - match: '\{' + scope: punctuation.section.block.begin.c++ + push: + - meta_scope: meta.block.c++ + - match: '(?=\})' + pop: true + - include: preprocessor-global + - include: global + # If this is exporting a module declaration, pop so we can handle it. + - match: '(?=(module|import))' + pop: true + # Otherwise, set into a normal declaration. We are exporting a function or something. + - match: '' + set: global-type + + - match: '\b(import)\s+' + captures: + 1: keyword.control.c++ + push: + - meta_scope: meta.module.c++ + # Module name. + - match: '{{module_identifier}}' + scope: entity.name.module.c++ + push: module-identifier + # import "header"; + - match: '"' + scope: punctuation.definition.string.begin.c++ + push: + - meta_scope: meta.module.import.c++ string.quoted.double.import.c++ + - match: '"' + scope: punctuation.definition.string.end.c++ + pop: true + # import <header>; + - match: \< + scope: punctuation.definition.string.begin.c++ + push: + - meta_scope: meta.module.import.c++ string.quoted.other.lt-gt.import.c++ + - match: '>' + scope: punctuation.definition.string.end.c++ + pop: true + - include: module-error-handling + + - match: '\b(module)(\s+)?' + captures: + 1: keyword.control.c++ + push: + - meta_scope: meta.module.c++ + # Module name. + - match: '{{module_identifier}}' + scope: entity.name.module.c++ + push: module-identifier + # Module partition - check for invalid partition names. + - match: (\:)\s*(private)(?:\s*(\:))? + captures: + 1: punctuation.accessor.c++ + 2: entity.name.partition.private + 3: invalid.illegal.unexpected-character.c++ + - include: module-error-handling + + template-common: + # Exit the template scope if we hit some basic invalid characters. This + # helps when a user is in the middle of typing their template types and + # prevents re-highlighting the whole file until the next > is found. + - match: (?=[{};]) + pop: true + - include: expressions + + template: + - match: \btemplate\b + scope: keyword.declaration.template.c++ + push: + - meta_scope: meta.template.c++ + # Explicitly include comments here at the top, in order to NOT match the + # \S lookahead in the case of comments. + - include: comments + - match: < + scope: punctuation.definition.generic.begin.c++ + set: + - meta_content_scope: meta.template.c++ + - match: '>' + scope: meta.template.c++ punctuation.definition.generic.end.c++ + set: + - include: constraint-requires + - match: (?=\S) + pop: true + - match: \.{3} + scope: keyword.operator.variadic.c++ + - match: \b(typename|{{before_tag}})\b + scope: keyword.declaration.c++ + - include: template # include template here for nested templates + - include: template-common + - match: (?=\S) + set: + - meta_content_scope: meta.template.c++ + - match: \b({{before_tag}})\b + scope: keyword.declaration.c++ + - include: template-common + + requires: + - match: \brequires\b + scope: keyword.operator.word.c++ + push: function-definition-params + + constraint: + - match: (?=;) + pop: true + - include: requires + - include: expressions-minus-generic-type-function-call + + constraint-requires: + - match: '\brequires\b' + scope: storage.modifier.c++ + push: + - meta_scope: meta.constraint.c++ + - match: (?=\{|{{identifier}}\s*{{identifier}}\(|{{before_tag}}|:) + pop: true + - include: constraint + + generic-type: + - match: '(?=(?!template){{path_lookahead}}\s*{{generic_lookahead}}\s*(\(|\{))' + push: + - meta_scope: meta.function-call.c++ + - match: \btemplate\b + scope: keyword.declaration.template.c++ + - match: (?:(::)\s*)?({{identifier}})\s*(<) + captures: + 1: punctuation.accessor.double-colon.c++ + 2: variable.function.c++ + 3: punctuation.definition.generic.begin.c++ + push: + - match: '>' + scope: punctuation.definition.generic.end.c++ + pop: true + - include: expressions-minus-generic-type-function-call + - match: (?:(::)\s*)?({{identifier}})\s*(\() + captures: + 1: punctuation.accessor.double-colon.c++ + 2: variable.function.c++ + 3: punctuation.section.group.begin.c++ + set: + - meta_scope: meta.function-call.c++ + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - match: (?:(::)\s*)?({{identifier}})\s*(\{) + captures: + 1: punctuation.accessor.double-colon.c++ + 2: variable.function.c++ + 3: punctuation.section.group.begin.c++ + set: + - meta_scope: meta.function-call.c++ + - meta_content_scope: meta.group.c++ + - match: '\}' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - include: identifiers + - include: angle-brackets + - match: '\(' + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_scope: meta.function-call.c++ + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - match: '\{' + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_scope: meta.function-call.c++ + - meta_content_scope: meta.group.c++ + - match: '\}' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - match: '(?=(?!template){{path_lookahead}}\s*{{generic_lookahead}})' + push: + - include: identifiers + - match: '<' + scope: punctuation.definition.generic.begin.c++ + set: + - match: '>' + scope: punctuation.definition.generic.end.c++ + pop: true + - include: expressions-minus-generic-type-function-call + + angle-brackets: + - match: '<(?!<)' + scope: punctuation.definition.generic.begin.c++ + push: + - match: '>' + scope: punctuation.definition.generic.end.c++ + pop: true + - include: expressions-minus-generic-type-function-call + + block: + - match: '\{' + scope: punctuation.section.block.begin.c++ + push: + - meta_scope: meta.block.c++ + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else|endif)\b) + pop: true + - match: '\}' + scope: punctuation.section.block.end.c++ + pop: true + - include: statements + + function-call: + - match: (?={{path_lookahead}}\s*(\(|\{)) + push: + - meta_scope: meta.function-call.c++ + - include: scope:source.c#c99 + - match: '(?:(::)\s*)?{{identifier}}\s*(::)\s*' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: punctuation.accessor.double-colon.c++ + - match: '(?:(::)\s*)?({{identifier}})' + captures: + 1: punctuation.accessor.c++ + 2: variable.function.c++ + - match: '\(' + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_content_scope: meta.function-call.c++ meta.group.c++ + - match: '\)' + scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - match: '\{' + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_content_scope: meta.function-call.c++ meta.group.c++ + - match: '\}' + scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + + members-inside-function-call: + - meta_content_scope: meta.method-call.c++ meta.group.c++ + - match: \) + scope: meta.method-call.c++ meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + + members-after-accessor-junction: + # After we've seen an accessor (dot or arrow), this context decides what + # kind of entity we're accessing. + - include: comments + - match: \btemplate\b + scope: meta.method-call.c++ keyword.declaration.template.c++ + # Guaranteed to be a template member function call after we match this + set: + - meta_content_scope: meta.method-call.c++ + - include: comments + - match: '{{identifier}}' + scope: variable.function.member.c++ + set: + - meta_content_scope: meta.method-call.c++ + - match: \( + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: members-inside-function-call + - include: comments + - include: angle-brackets + - match: (?=\S) # safety pop + pop: true + - match: (?=\S) # safety pop + pop: true + # Operator overloading + - match: '({{operator_method_name}})\s*(\()' + captures: + 0: meta.method-call.c++ + 1: variable.function.member.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + set: members-inside-function-call + # Non-templated member function call + - match: (~?{{identifier}})\s*(\() + captures: + 0: meta.method-call.c++ + 1: variable.function.member.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + set: members-inside-function-call + # Templated member function call + - match: (~?{{identifier}})\s*(?={{generic_lookahead}}) + captures: + 1: variable.function.member.c++ + set: + - meta_scope: meta.method-call.c++ + - match: < + scope: punctuation.definition.generic.begin.c++ + set: + - meta_content_scope: meta.method-call.c++ + - match: '>' + scope: punctuation.definition.generic.end.c++ + set: + - meta_content_scope: meta.method-call.c++ + - include: comments + - match: \( + scope: punctuation.section.group.begin.c++ + set: members-inside-function-call + - match: (?=\S) # safety pop + pop: true + - include: expressions + # Explicit base-class access + - match: ({{identifier}})\s*(::) + captures: + 1: variable.other.base-class.c++ + 2: punctuation.accessor.double-colon.c++ + set: members-after-accessor-junction # reset + # Just a regular member variable + - match: '{{identifier}}' + scope: variable.other.readwrite.member.c++ + pop: true + + members-dot: + - include: scope:source.c#access-illegal + # No lookahead required because members-dot goes after operators in the + # early-expressions-after-generic-type context. This means triple dots + # (i.e. "..." or "variadic") is attempted first. + - match: \. + scope: punctuation.accessor.dot.c++ + push: members-after-accessor-junction + + members-arrow: + # This needs to be before operators in the + # early-expressions-after-generic-type context because otherwise the "->" + # from the C language will match. + - match: -> + scope: punctuation.accessor.arrow.c++ + push: members-after-accessor-junction + + using-alias: + # consume keyword if followed by typename + - match: '\b(using)\b(?=\s+typename\b)' + captures: + 1: keyword.control.c++ + - match: '\b(using)\b\s+({{identifier}})(?!\s*(<|::))' + captures: + 1: keyword.control.c++ + 2: entity.name.type.using.c++ + + typedef: + - match: \btypedef\b + scope: keyword.declaration.type.c++ + push: + - match: ({{identifier}})?\s*(?=;) + captures: + 1: entity.name.type.typedef.c++ + pop: true + - match: '(?=\b({{before_tag}})\b)' + push: data-structures + - include: expressions-minus-generic-type + + parens: + - match: \( + scope: punctuation.section.group.begin.c++ + push: + - meta_scope: meta.group.c++ + - match: \) + scope: punctuation.section.group.end.c++ + pop: true + - include: expressions + + brackets: + - match: \[(?!\[{{attribute_body}}\]\]) + scope: punctuation.section.brackets.begin.c++ + push: + - meta_scope: meta.brackets.c++ + - match: \] + scope: punctuation.section.brackets.end.c++ + pop: true + - include: expressions + + function-trailing-return-type: + - match: '{{non_angle_brackets}}' + pop: true + - include: angle-brackets + - include: types + - include: modifiers-parens + - include: modifiers + - include: identifiers + - match: \*|& + scope: keyword.operator.c++ + - include: function-trailing-return-type-parens + - match: '(?=\S)' + pop: true + + function-trailing-return-type-parens: + - match: \( + scope: punctuation.section.group.begin.c++ + push: + - meta_scope: meta.group.c++ + - match: \) + scope: punctuation.section.group.end.c++ + pop: true + - include: function-trailing-return-type + + ## Detection of function and data structure definitions at the global level + + global-modifier: + - include: comments + - include: modifiers-parens + - include: modifiers + # Constructors and destructors don't have a type + - match: '(?={{path_lookahead}}\s*(?:{{generic_lookahead}})?\s*::\s*{{identifier}}\s*\()' + set: + - meta_content_scope: meta.function.c++ meta.toc-list.full-identifier.c++ + - include: identifier-path-generic + - match: '(?:(::)\s*)?({{identifier}})' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: entity.name.function.constructor.c++ + - match: '(?=[^\w\s])' + set: function-definition-params + - match: '(?={{path_lookahead}}\s*(?:{{generic_lookahead}})?\s*::\s*~{{identifier}}\s*(\(|$))' + set: + - meta_content_scope: meta.function.c++ meta.toc-list.full-identifier.c++ + - include: identifier-path-generic + - match: '(?:(::)\s*)?(~{{identifier}})' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: entity.name.function.destructor.c++ + - match: '(?=[^\w\s])' + set: function-definition-params + # If we see a path ending in :: before a newline, we don't know if it is + # a constructor or destructor, or a long return type, so we are just going + # to treat it like a regular function. Most likely it is a constructor, + # since it doesn't seem most developers would create such a long typename. + - match: '(?={{path_lookahead}}\s*(?:{{generic_lookahead}})?::\s*$)' + set: + - meta_content_scope: meta.function.c++ meta.toc-list.full-identifier.c++ + - include: identifier-path-generic + - match: '(::)\s*$' + captures: + 1: punctuation.accessor.double-colon.c++ + - match: '(?:(::)\s*)?(~?{{identifier}})(?=\s*\()' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: entity.name.function.c++ + - match: '(?=[^\w\s])' + set: function-definition-params + - include: unique-strings + - match: '(?=\S)' + set: global-type + + global-type: + - include: comments + - match: \*|& + scope: keyword.operator.c++ + - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}}|operator)\b)' + pop: true + - match: '(?=\s)' + set: global-maybe-function + # If a class/struct/enum followed by a name that is not a macro or declspec + # then this is likely a return type of a function. This is uncommon. + - match: |- + (?x: + ({{before_tag}}) + \s+ + (?= + (?![[:upper:][:digit:]_]+\b|__declspec|{{before_tag}}) + {{path_lookahead}} + (\s+{{identifier}}\s*\(|\s*[*&]) + ) + ) + captures: + 1: keyword.declaration.c++ + set: + - include: identifiers + - match: '' + set: global-maybe-function + # The previous match handles return types of struct/enum/etc from a func, + # there this one exits the context to allow matching an actual struct/class + - match: '(?=\b({{before_tag}})\b)' + set: data-structures + - match: '(?=\b({{casts}})\b\s*<)' + pop: true + - match: '{{non_angle_brackets}}' + pop: true + - include: angle-brackets + - include: types + # Allow a macro call + - match: '({{identifier}})\s*(\()(?={{nested_parens}}+\))' + captures: + 1: variable.function.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_scope: meta.function-call.c++ + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - match: '(?={{path_lookahead}}\s*\()' + set: + - include: function-call + - match: '' + pop: true + - include: variables + - include: constants + - include: identifiers + - match: (?=\W) + pop: true + + global-maybe-function: + - include: comments + # Consume pointer info, macros and any type info that was offset by macros + - match: \*|& + scope: keyword.operator.c++ + - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}})\b)' + pop: true + - match: '\b({{type_qualifier}})\b' + scope: storage.modifier.c++ + - match: '{{non_angle_brackets}}' + pop: true + - include: angle-brackets + - include: types + - include: modifiers-parens + - include: modifiers + # All uppercase identifier just before a newline is most likely a macro + - match: '[[:upper:][:digit:]_]+\s*$' + # Operator overloading + - match: '(?=({{path_lookahead}}\s*(?:{{generic_lookahead}})?::\s*)?{{operator_method_name}}\s*(\(|$))' + set: + - meta_content_scope: meta.function.c++ meta.toc-list.full-identifier.c++ + - include: identifier-path-generic + - match: '(?:(::)\s*)?({{operator_method_name}})(?=\s*\()' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: entity.name.function.c++ + - match: '(?=\s*(\(|$))' + set: function-definition-params + # Identifier that is not the function name - likely a macro or type + - match: '(?={{path_lookahead}}([ \t]+|[*&])(?!\s*(<|::|\(|$)))' + push: + - include: identifiers + - match: '' + pop: true + # Real function definition + - match: '(?={{path_lookahead}}({{generic_lookahead}}({{path_lookahead}})?)\s*(\(|$))' + set: [function-definition-params, global-function-identifier-generic] + - match: '(?={{path_lookahead}}\s*(\(|$))' + set: [function-definition-params, global-function-identifier] + - match: '(?={{path_lookahead}}\s*::\s*$)' + set: [function-definition-params, global-function-identifier] + - match: '(?=\S)' + pop: true + + global-function-identifier-generic: + - meta_content_scope: meta.toc-list.full-identifier.c++ + - include: identifier-path-generic + - match: '(?:(::)\s*)?({{identifier}})(?=\s*(<.*>)?\s*\()' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: entity.name.function.c++ + - match: '(?=\()' + pop: true + + global-function-identifier: + - meta_content_scope: meta.toc-list.full-identifier.c++ + - match: '(?:(::)\s*)?({{identifier}})(?!\s*(::))' + captures: + 1: punctuation.accessor.double-colon.c++ + 2: entity.name.function.c++ + - include: identifiers + - match: '(?=\S)' + pop: true + + function-definition-params: + - meta_content_scope: meta.function.c++ + - include: comments + - match: '(?=\()' + set: + - match: \( + scope: meta.function.parameters.c++ meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_content_scope: meta.function.parameters.c++ meta.group.c++ + - match : \) + scope: punctuation.section.group.end.c++ + set: function-definition-continue + - include: modifiers + - include: types + - match: '{{identifier}}(?=\s*(\[|,|\)|=))' + scope: variable.parameter.c++ + - match: '=' + scope: keyword.operator.assignment.c++ + push: + - match: '(?=,|\))' + pop: true + - include: expressions-minus-generic-type + - include: scope:source.c#preprocessor-line-continuation + - include: expressions-minus-generic-type + - include: scope:source.c#preprocessor-line-continuation + - match: (?=\S) + pop: true + + function-definition-continue: + - meta_content_scope: meta.function.c++ + - include: comments + - match: '(?=;)' + pop: true + - match: '->' + scope: punctuation.separator.c++ + set: function-definition-trailing-return + - include: function-specifiers + - include: constraint-requires + - match: '=' + scope: keyword.operator.assignment.c++ + - match: '&' + scope: keyword.operator.c++ + - match: \b0\b + scope: meta.number.integer.decimal.c++ constant.numeric.value.c++ + - match: \b(default|delete)\b + scope: storage.modifier.c++ + - match: '(?=\{)' + set: function-definition-body + - match: '(?=\S)' + pop: true + + function-definition-trailing-return: + - include: comments + - match: '(?=;)' + pop: true + - match: '(?=\{)' + set: function-definition-body + - include: function-specifiers + - include: constraint-requires + - include: function-trailing-return-type + + function-definition-body: + - meta_content_scope: meta.function.c++ meta.block.c++ + - match: '\{' + scope: punctuation.section.block.begin.c++ + set: + - meta_content_scope: meta.function.c++ meta.block.c++ + - match: '\}' + scope: meta.function.c++ meta.block.c++ punctuation.section.block.end.c++ + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else|endif)\b) + pop: true + - match: '(?=({{before_tag}})([^(;]+$|.*\{))' + push: data-structures + - include: statements + + ## Data structures including classes, structs, unions and enums + + data-structures: + - match: '\bclass\b' + scope: keyword.declaration.class.c++ + set: data-structures-class-definition + # Detect variable type definitions using struct/enum/union followed by a tag + - match: '\b({{before_tag}})(?=\s+{{path_lookahead}}\s+{{path_lookahead}}\s*[=;\[])' + scope: keyword.declaration.c++ + - match: '\bstruct\b' + scope: keyword.declaration.struct.type.c++ + set: data-structures-struct-definition + - match: '\benum(\s+(class|struct))?\b' + scope: keyword.declaration.enum.type.c++ + set: data-structures-enum-definition + - match: '\bunion\b' + scope: keyword.declaration.union.type.c++ + set: data-structures-union-definition + - match: '\bconcept\b' + scope: meta.concept.c++ keyword.declaration.concept.c++ + set: data-structures-concept-definition + - match: '(?=\S)' + pop: true + + preprocessor-workaround-eat-macro-before-identifier: + # Handle macros so they aren't matched as the class name + - match: ({{macro_identifier}})(?=\s+~?{{identifier}}) + captures: + 1: meta.assumed-macro.c + - match: '({{macro_identifier}})\s*(\()(?={{nested_parens}}+\))' + captures: + 1: variable.function.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_scope: meta.function-call.c++ + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + + data-structures-class-definition: + - meta_scope: meta.class.c++ + - include: data-structures-definition-common-begin + - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})' + scope: entity.name.class.forward-decl.c++ + set: data-structures-class-definition-after-identifier + - match: '(?={{path_lookahead}})' + set: + - meta_scope: meta.class.c++ + - match: '{{identifier}}(?!\s*::)' + scope: entity.name.class.c++ + set: data-structures-class-definition-after-identifier + - include: identifiers + - match: '(?=[^\w\s])' + set: data-structures-class-definition-after-identifier + - match: '(?=[:{])' + set: data-structures-class-definition-after-identifier + - match: '(?=;)' + pop: true + + data-structures-class-definition-after-identifier: + - meta_content_scope: meta.class.c++ + - include: data-structures-definition-common-begin + # No matching of identifiers since they should all be macros at this point + - include: data-structures-definition-common-end + - match: '\{' + scope: meta.block.c++ punctuation.section.block.begin.c++ + set: + - meta_content_scope: meta.class.c++ meta.block.c++ + - match: '\}' + scope: meta.class.c++ meta.block.c++ punctuation.section.block.end.c++ + pop: true + - include: data-structures-body + + data-structures-struct-definition: + - meta_scope: meta.struct.c++ + - include: data-structures-definition-common-begin + - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})' + scope: entity.name.struct.forward-decl.c++ + set: data-structures-struct-definition-after-identifier + - match: '(?={{path_lookahead}})' + set: + - meta_scope: meta.struct.c++ + - match: '{{identifier}}(?!\s*::)' + scope: entity.name.struct.c++ + set: data-structures-struct-definition-after-identifier + - include: identifiers + - match: '(?=[^\w\s])' + set: data-structures-struct-definition-after-identifier + - match: '(?=[:{])' + set: data-structures-struct-definition-after-identifier + - match: '(?=;)' + pop: true + + data-structures-struct-definition-after-identifier: + - meta_content_scope: meta.struct.c++ + - include: data-structures-definition-common-begin + # No matching of identifiers since they should all be macros at this point + - include: data-structures-definition-common-end + - match: '\{' + scope: meta.block.c++ punctuation.section.block.begin.c++ + set: + - meta_content_scope: meta.struct.c++ meta.block.c++ + - match: '\}' + scope: meta.struct.c++ meta.block.c++ punctuation.section.block.end.c++ + pop: true + - include: data-structures-body + + data-structures-enum-definition: + - meta_scope: meta.enum.c++ + - include: data-structures-definition-common-begin + - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})' + scope: entity.name.enum.forward-decl.c++ + set: data-structures-enum-definition-after-identifier + - match: '(?={{path_lookahead}})' + set: + - meta_scope: meta.enum.c++ + - match: '{{identifier}}(?!\s*::)' + scope: entity.name.enum.c++ + set: data-structures-enum-definition-after-identifier + - include: identifiers + - match: '(?=[^\w\s])' + set: data-structures-enum-definition-after-identifier + - match: '(?=[:{])' + set: data-structures-enum-definition-after-identifier + - match: '(?=;)' + pop: true + + data-structures-enum-definition-after-identifier: + - meta_content_scope: meta.enum.c++ + - include: data-structures-definition-common-begin + # No matching of identifiers since they should all be macros at this point + - include: data-structures-definition-common-end + - match: '\{' + scope: meta.block.c++ punctuation.section.block.begin.c++ + set: + - meta_content_scope: meta.enum.c++ meta.block.c++ + # Enums don't support methods so we have a simplified body + - match: '\}' + scope: meta.enum.c++ meta.block.c++ punctuation.section.block.end.c++ + pop: true + - include: statements-enum + + data-structures-union-definition: + - meta_scope: meta.union.c++ + - include: data-structures-definition-common-begin + - match: '{{identifier}}(?={{data_structures_forward_decl_lookahead}})' + scope: entity.name.union.forward-decl.c++ + set: data-structures-union-definition-after-identifier + - match: '(?={{path_lookahead}})' + set: + - meta_scope: meta.union.c++ + - match: '{{identifier}}(?!\s*::)' + scope: entity.name.union.c++ + set: data-structures-union-definition-after-identifier + - include: identifiers + - match: '(?=[^\w\s])' + set: data-structures-union-definition-after-identifier + - match: '(?=[{])' + set: data-structures-union-definition-after-identifier + - match: '(?=;)' + pop: true + + data-structures-union-definition-after-identifier: + - meta_content_scope: meta.union.c++ + - include: data-structures-definition-common-begin + # No matching of identifiers since they should all be macros at this point + # Unions don't support base classes + - include: angle-brackets + - match: '\{' + scope: meta.block.c++ punctuation.section.block.begin.c++ + set: + - meta_content_scope: meta.union.c++ meta.block.c++ + - match: '\}' + scope: meta.union.c++ meta.block.c++ punctuation.section.block.end.c++ + pop: true + - include: data-structures-body + - match: '(?=;)' + pop: true + + data-structures-concept-definition: + - meta_content_scope: meta.concept.c++ + - include: data-structures-definition-common-begin + - match: '({{identifier}})\s+(=)' + captures: + 1: entity.name.concept.c++ + 2: keyword.operator.assignment.c++ + set: + - meta_content_scope: meta.concept.c++ meta.constraint.c++ + - include: constraint + + data-structures-definition-common-begin: + - include: comments + - match: '(?=\b(?:{{before_tag}}|{{control_keywords}})\b)' + pop: true + - include: preprocessor-other + - include: modifiers-parens + - include: modifiers + - include: preprocessor-workaround-eat-macro-before-identifier + + data-structures-definition-common-end: + - include: angle-brackets + - match: \bfinal\b + scope: storage.modifier.c++ + - match: ':' + scope: punctuation.separator.c++ + push: + - include: comments + - include: preprocessor-other + - include: modifiers-parens + - include: modifiers + - match: '\b(virtual|{{visibility_modifiers}})\b' + scope: storage.modifier.c++ + - match: (?={{path_lookahead}}) + push: + - meta_scope: entity.other.inherited-class.c++ + - include: identifiers + - match: '' + pop: true + - include: angle-brackets + - match: ',' + scope: punctuation.separator.c++ + - match: (?=\{|;) + pop: true + - match: '(?=;)' + pop: true + + data-structures-body: + - include: preprocessor-data-structures + - match: '(?=\btemplate\b)' + push: + - include: template + - match: (?=\S) + set: data-structures-modifier + - include: using-namespace + - include: typedef + - include: using-alias + - match: \b({{visibility_modifiers}})\s*(:)(?!:) + captures: + 1: storage.modifier.c++ + 2: punctuation.section.class.c++ + - match: '^\s*(?=(?:~?\w+|::|\[\[{{attribute_body}}\]\]))' + push: data-structures-modifier + - include: expressions-minus-generic-type + + data-structures-modifier-friend: + - match: (?=;) + pop: true + - match: '\{' + scope: punctuation.section.block.begin.c++ + set: + - meta_scope: meta.block.c++ + - match: '\}' + scope: punctuation.section.block.end.c++ + pop: true + - include: statements + - include: expressions-minus-function-call + + data-structures-modifier: + - match: '\bfriend\b' + scope: storage.modifier.c++ + push: + - include: comments + - match: '\b({{before_tag}})\b' + scope: keyword.declaration.c++ + set: data-structures-modifier-friend + - match: '(?=\S)(?=[^;]+;)' + set: data-structures-modifier-friend + - match: '(?=\S)' + pop: true + - include: comments + - include: modifiers-parens + - include: modifiers + - match: '\bstatic_assert(?=\s*\()' + scope: meta.static-assert.c++ keyword.operator.word.c++ + push: + - match: '\(' + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_content_scope: meta.function-call.c++ meta.group.c++ + - match: '\)' + scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + # Destructor + - match: '(?:{{identifier}}\s*(::)\s*)?~{{identifier}}(?=\s*(\(|$))' + scope: meta.method.destructor.c++ entity.name.function.destructor.c++ + captures: + 1: punctuation.accessor.c++ + set: method-definition-params + # It's a macro, not a constructor if there is no type in the first param + - match: '({{identifier}})\s*(\()(?=\s*(?!void){{identifier}}\s*[),])' + captures: + 1: variable.function.c++ + 2: meta.group.c++ punctuation.section.group.begin.c++ + push: + - meta_scope: meta.function-call.c++ + - meta_content_scope: meta.group.c++ + - match: '\)' + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + # Constructor + - include: preprocessor-workaround-eat-macro-before-identifier + - match: '((?!{{before_tag}}|template){{identifier}})(?=\s*\()' + scope: meta.method.constructor.c++ entity.name.function.constructor.c++ + set: method-definition-params + # Long form constructor + - match: '({{identifier}}\s*(::)\s*{{identifier}})(?=\s*\()' + captures: + 1: meta.method.constructor.c++ entity.name.function.constructor.c++ + 2: punctuation.accessor.c++ + push: method-definition-params + - match: '(?=\S)' + set: data-structures-type + + data-structures-type: + - include: comments + - match: \*|& + scope: keyword.operator.c++ + # Cast methods + - match: '(operator)\s+({{identifier}})(?=\s*(\(|$))' + captures: + 1: keyword.control.c++ + 2: meta.method.c++ entity.name.function.c++ + set: method-definition-params + - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}}|operator)\b)' + pop: true + - match: '(?=\s)' + set: data-structures-maybe-method + # If a class/struct/enum followed by a name that is not a macro or declspec + # then this is likely a return type of a function. This is uncommon. + - match: |- + (?x: + ({{before_tag}}) + \s+ + (?= + (?![[:upper:][:digit:]_]+\b|__declspec|{{before_tag}}) + {{path_lookahead}} + (\s+{{identifier}}\s*\(|\s*[*&]) + ) + ) + captures: + 1: keyword.declaration.c++ + set: + - include: identifiers + - match: '' + set: data-structures-maybe-method + # The previous match handles return types of struct/enum/etc from a func, + # there this one exits the context to allow matching an actual struct/class + - match: '(?=\b({{before_tag}})\b)' + set: data-structures + - match: '(?=\b({{casts}})\b\s*<)' + pop: true + - match: '{{non_angle_brackets}}' + pop: true + - include: angle-brackets + - include: types + - include: variables + - include: constants + - include: identifiers + - match: (?=[&*]) + set: data-structures-maybe-method + - match: (?=\W) + pop: true + + data-structures-maybe-method: + - include: comments + # Consume pointer info, macros and any type info that was offset by macros + - match: \*|& + scope: keyword.operator.c++ + - match: '(?=\b({{control_keywords}}|{{operator_keywords}}|{{casts}}|{{memory_operators}}|{{other_keywords}})\b)' + pop: true + - match: '\b({{type_qualifier}})\b' + scope: storage.modifier.c++ + - match: '{{non_angle_brackets}}' + pop: true + - include: angle-brackets + - include: types + - include: modifiers-parens + - include: modifiers + # Operator overloading + - match: '{{operator_method_name}}(?=\s*(\(|$))' + scope: meta.method.c++ entity.name.function.c++ + set: method-definition-params + # Identifier that is not the function name - likely a macro or type + - match: '(?={{path_lookahead}}([ \t]+|[*&])(?!\s*(<|::|\()))' + push: + - include: identifiers + - match: '' + pop: true + # Real function definition + - match: '(?={{path_lookahead}}({{generic_lookahead}})\s*(\())' + set: [method-definition-params, data-structures-function-identifier-generic] + - match: '(?={{path_lookahead}}\s*(\())' + set: [method-definition-params, data-structures-function-identifier] + - match: '(?={{path_lookahead}}\s*::\s*$)' + set: [method-definition-params, data-structures-function-identifier] + - match: '(?=\S)' + pop: true + + data-structures-function-identifier-generic: + - include: angle-brackets + - match: '(?={{identifier}})' + push: + - meta_content_scope: entity.name.function.c++ + - include: identifiers + - match: '(?=<)' + pop: true + - match: '(?=\()' + pop: true + + data-structures-function-identifier: + - meta_content_scope: entity.name.function.c++ + - include: identifiers + - match: '(?=\S)' + pop: true + + method-definition-params: + - meta_content_scope: meta.method.c++ + - include: comments + - match: '(?=\()' + set: + - match: \( + scope: meta.method.parameters.c++ meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_content_scope: meta.method.parameters.c++ meta.group.c++ + - match : \) + scope: punctuation.section.group.end.c++ + set: method-definition-continue + - match: '\bvoid\b' + scope: storage.type.c++ + - match: '{{identifier}}(?=\s*(\[|,|\)|=))' + scope: variable.parameter.c++ + - match: '=' + scope: keyword.operator.assignment.c++ + push: + - match: '(?=,|\))' + pop: true + - include: expressions-minus-generic-type + - include: expressions-minus-generic-type + - match: '(?=\S)' + pop: true + + method-definition-continue: + - meta_content_scope: meta.method.c++ + - include: comments + - match: '(?=;)' + pop: true + - match: '->' + scope: punctuation.separator.c++ + set: method-definition-trailing-return + - include: function-specifiers + - include: constraint-requires + - match: '=' + scope: keyword.operator.assignment.c++ + - match: '&' + scope: keyword.operator.c++ + - match: \b0\b + scope: meta.number.integer.decimal.c++ constant.numeric.value.c++ + - match: \b(default|delete)\b + scope: storage.modifier.c++ + - match: '(?=:)' + set: + - match: ':' + scope: punctuation.separator.initializer-list.c++ + set: + - meta_scope: meta.method.constructor.initializer-list.c++ + - match: '{{identifier}}' + scope: variable.other.readwrite.member.c++ + push: + - match: \( + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_content_scope: meta.group.c++ + - match: \) + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - match: \{ + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: + - meta_content_scope: meta.group.c++ + - match: \} + scope: meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + - include: comments + - match: (?=\{|;) + set: method-definition-continue + - include: expressions + - match: '(?=\{)' + set: method-definition-body + - match: '(?=\S)' + pop: true + + method-definition-trailing-return: + - include: comments + - match: '(?=;)' + pop: true + - match: '(?=\{)' + set: method-definition-body + - include: function-specifiers + - include: function-trailing-return-type + + method-definition-body: + - meta_content_scope: meta.method.c++ meta.block.c++ + - match: '\{' + scope: punctuation.section.block.begin.c++ + set: + - meta_content_scope: meta.method.c++ meta.block.c++ + - match: '\}' + scope: meta.method.c++ meta.block.c++ punctuation.section.block.end.c++ + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else|endif)\b) + pop: true + - match: '(?=({{before_tag}})([^(;]+$|.*\{))' + push: data-structures + - include: statements + + ## Preprocessor for data-structures + + preprocessor-data-structures: + - include: preprocessor-rule-enabled-data-structures + - include: preprocessor-rule-disabled-data-structures + - include: preprocessor-practical-workarounds + + preprocessor-rule-disabled-data-structures: + - match: ^\s*((#if)\s+(0+))\b + captures: + 1: meta.preprocessor.c++ + 2: keyword.control.directive.conditional.if.c++ + 3: meta.number.integer.decimal.c++ constant.numeric.value.c++ + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.end.c++ + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.else.c++ + push: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: negated-block + - include: data-structures-body + - match: "" + push: + - meta_scope: comment.block.preprocessor.if-branch.c++ + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: scope:source.c#preprocessor-disabled + + preprocessor-rule-enabled-data-structures: + - match: ^\s*((#if)\s+(0*[1-9]+[\d]*))\b + captures: + 1: meta.preprocessor.c++ + 2: keyword.control.directive.conditional.if.c++ + 3: meta.number.integer.decimal.c++ constant.numeric.value.c++ + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.else.c++ + push: + - meta_content_scope: comment.block.preprocessor.else-branch.c++ + - match: (?=^\s*#\s*endif\b) + pop: true + - include: scope:source.c#preprocessor-disabled + - match: "" + push: + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: negated-block + - include: data-structures-body + + ## Preprocessor for global + + preprocessor-global: + - include: preprocessor-rule-enabled-global + - include: preprocessor-rule-disabled-global + - include: preprocessor-rule-other-global + + preprocessor-statements: + - include: preprocessor-rule-enabled-statements + - include: preprocessor-rule-disabled-statements + - include: preprocessor-rule-other-statements + + preprocessor-expressions: + - include: scope:source.c#incomplete-inc + - include: preprocessor-macro-define + - include: scope:source.c#pragma-mark + - include: preprocessor-other + + preprocessor-rule-disabled-global: + - match: ^\s*((#if)\s+(0+))\b + captures: + 1: meta.preprocessor.c++ + 2: keyword.control.directive.conditional.c++ + 3: meta.number.integer.decimal.c++ constant.numeric.value.c++ + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.else.c++ + push: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: preprocessor-global + - include: negated-block + - include: global + - match: "" + push: + - meta_scope: comment.block.preprocessor.if-branch.c++ + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: scope:source.c#preprocessor-disabled + + preprocessor-rule-enabled-global: + - match: ^\s*((#if)\s+(0*[1-9]+[\d]*))\b + captures: + 1: meta.preprocessor.c++ + 2: keyword.control.directive.conditional.if.c++ + 3: meta.number.integer.decimal.c++ constant.numeric.value.c++ + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.else.c++ + push: + - meta_content_scope: comment.block.preprocessor.else-branch.c++ + - match: (?=^\s*#\s*endif\b) + pop: true + - include: scope:source.c#preprocessor-disabled + - match: "" + push: + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: preprocessor-global + - include: negated-block + - include: global + + preprocessor-rule-other-global: + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: keyword.control.directive.conditional.if.c++ + push: + - meta_scope: meta.preprocessor.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c++ + # Enter a new scope where all elif/elifdef/elifndef/else branches have + # their contexts popped by a subsequent elif/elifdef/elifndef/else/endif. + # This ensures that preprocessor branches don't push multiple meta.block + # scopes on the stack, thus messing up the "global" context's detection + # of functions. + - match: $\n + set: preprocessor-if-branch-global + + # These gymnastics here ensure that we are properly handling scope even + # when the preprocessor is used to create different scope beginnings, such + # as a different if/while condition + preprocessor-if-branch-global: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-global + - match: \{ + scope: punctuation.section.block.begin.c++ + set: preprocessor-block-if-branch-global + - include: preprocessor-global + - include: negated-block + - include: global + + preprocessor-block-if-branch-global: + - meta_scope: meta.block.c++ + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + set: preprocessor-block-finish-global + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-global + - match: \} + scope: punctuation.section.block.end.c++ + set: preprocessor-if-branch-global + - include: statements + + preprocessor-block-finish-global: + - meta_scope: meta.block.c++ + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.if.c++ + set: preprocessor-block-finish-if-branch-global + - match: \} + scope: punctuation.section.block.end.c++ + pop: true + - include: statements + + preprocessor-block-finish-if-branch-global: + - match: ^\s*(#\s*endif)\b + captures: + 1: keyword.control.directive.conditional.endif.c++ + pop: true + - match: \} + scope: punctuation.section.block.end.c++ + set: preprocessor-if-branch-global + - include: statements + + preprocessor-elif-else-branch-global: + - match: (?=^\s*#\s*(endif)\b) + pop: true + - include: preprocessor-global + - include: negated-block + - include: global + + ## Preprocessor for statements + + preprocessor-rule-disabled-statements: + - match: ^\s*((#if)\s+(0+))\b + captures: + 1: meta.preprocessor.c++ + 2: keyword.control.directive.conditional.if.c++ + 3: meta.number.integer.decimal.c++ constant.numeric.value.c++ + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.else.c++ + push: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: negated-block + - include: statements + - match: "" + push: + - meta_scope: comment.block.preprocessor.if-branch.c++ + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: scope:source.c#preprocessor-disabled + + preprocessor-rule-enabled-statements: + - match: ^\s*((#if)\s+(0*[1-9]+[\d]*))\b + captures: + 1: meta.preprocessor.c++ + 2: keyword.control.directive.conditional.if.c++ + 3: meta.number.integer.decimal.c++ constant.numeric.value.c++ + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.else.c++ + push: + - meta_content_scope: comment.block.preprocessor.else-branch.c++ + - match: (?=^\s*#\s*endif\b) + pop: true + - include: scope:source.c#preprocessor-disabled + - match: "" + push: + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: negated-block + - include: statements + + preprocessor-rule-other-statements: + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: keyword.control.directive.conditional.if.c++ + push: + - meta_scope: meta.preprocessor.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c++ + # Enter a new scope where all elif/elifdef/elifndef/else branches have + # their contexts popped by a subsequent elif/elifdef/elifndef/else/endif. + # This ensures that preprocessor branches don't push multiple meta.block + # scopes on the stack, thus messing up the "global" context's detection + # of functions. + - match: $\n + set: preprocessor-if-branch-statements + + # These gymnastics here ensure that we are properly handling scope even + # when the preprocessor is used to create different scope beginnings, such + # as a different if/while condition + preprocessor-if-branch-statements: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-statements + - match: \{ + scope: punctuation.section.block.begin.c++ + set: preprocessor-block-if-branch-statements + - match: (?=(?!{{non_func_keywords}}){{path_lookahead}}\s*\() + set: preprocessor-if-branch-function-call + - include: negated-block + - include: statements + + preprocessor-if-branch-function-call: + - meta_content_scope: meta.function-call.c++ + - include: scope:source.c#c99 + - match: '(?:(::)\s*)?{{identifier}}\s*(::)\s*' + scope: variable.function.c++ + captures: + 1: punctuation.accessor.c++ + 2: punctuation.accessor.c++ + - match: '(?:(::)\s*)?{{identifier}}' + scope: variable.function.c++ + captures: + 1: punctuation.accessor.c++ + - match: '\(' + scope: meta.group.c++ punctuation.section.group.begin.c++ + set: preprocessor-if-branch-function-call-arguments + + preprocessor-if-branch-function-call-arguments: + - meta_content_scope: meta.function-call.c++ meta.group.c++ + - match : \) + scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++ + set: preprocessor-if-branch-statements + - match: ^\s*(#\s*(?:elif|elifdef|elifndef|else))\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.elseif.c++ + set: preprocessor-if-branch-statements + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + set: preprocessor-if-branch-function-call-arguments-finish + - include: expressions + + preprocessor-if-branch-function-call-arguments-finish: + - meta_content_scope: meta.function-call.c++ meta.group.c++ + - match: \) + scope: meta.function-call.c++ meta.group.c++ punctuation.section.group.end.c++ + pop: true + - include: expressions + + preprocessor-block-if-branch-statements: + - meta_scope: meta.block.c++ + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.endif.c++ + set: preprocessor-block-finish-statements + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-statements + - match: \} + scope: punctuation.section.block.end.c++ + set: preprocessor-if-branch-statements + - include: statements + + preprocessor-block-finish-statements: + - meta_scope: meta.block.c++ + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.if.c++ + set: preprocessor-block-finish-if-branch-statements + - match: \} + scope: punctuation.section.block.end.c++ + pop: true + - include: statements + + preprocessor-block-finish-if-branch-statements: + - match: ^\s*(#\s*endif)\b + captures: + 1: keyword.control.directive.conditional.endif.c++ + pop: true + - match: \} + scope: meta.block.c++ punctuation.section.block.end.c++ + set: preprocessor-if-branch-statements + - include: statements + + preprocessor-elif-else-branch-statements: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: negated-block + - include: statements + + ## Preprocessor other + + negated-block: + - match: '\}' + scope: punctuation.section.block.end.c++ + push: + - match: '\{' + scope: punctuation.section.block.begin.c++ + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else|endif)\b) + pop: true + - include: statements + + preprocessor-macro-define: + - match: ^\s*(\#\s*define)\b + captures: + 1: meta.preprocessor.macro.c++ keyword.control.directive.define.c++ + push: + - meta_content_scope: meta.preprocessor.macro.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-line-ending + - include: scope:source.c#preprocessor-comments + - match: '({{identifier}})(?=\()' + scope: entity.name.function.preprocessor.c++ + set: + - match: '\(' + scope: punctuation.section.group.begin.c++ + set: preprocessor-macro-params + - match: '{{identifier}}' + scope: entity.name.constant.preprocessor.c++ + set: preprocessor-macro-definition + + preprocessor-macro-params: + - meta_scope: meta.preprocessor.macro.parameters.c++ meta.group.c++ + - match: '{{identifier}}' + scope: variable.parameter.c++ + - match: \) + scope: punctuation.section.group.end.c++ + set: preprocessor-macro-definition + - match: ',' + scope: punctuation.separator.c++ + push: + - match: '{{identifier}}' + scope: variable.parameter.c++ + pop: true + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-comments + - match: '\.\.\.' + scope: keyword.operator.variadic.c++ + - match: '(?=\))' + pop: true + - match: (/\*).*(\*/) + scope: comment.block.c++ + captures: + 1: punctuation.definition.comment.c++ + 2: punctuation.definition.comment.c++ + - match: '\S+' + scope: invalid.illegal.unexpected-character.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-comments + - match: '\.\.\.' + scope: keyword.operator.variadic.c++ + - match: (/\*).*(\*/) + scope: comment.block.c++ + captures: + 1: punctuation.definition.comment.c++ + 2: punctuation.definition.comment.c++ + - match: $\n + scope: invalid.illegal.unexpected-end-of-line.c++ + + preprocessor-macro-definition: + - meta_content_scope: meta.preprocessor.macro.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-line-ending + - include: scope:source.c#preprocessor-comments + # Don't define blocks in define statements + - match: '\{' + scope: punctuation.section.block.begin.c++ + - match: '\}' + scope: punctuation.section.block.end.c++ + # Captures the namespace macro idiom + - match: '\b(namespace)\s+(?={{path_lookahead}}\s*\{)' + scope: meta.namespace.c++ + captures: + 1: keyword.control.c++ + push: + - meta_content_scope: meta.namespace.c++ entity.name.namespace.c++ + - include: identifiers + - match: '(?=\S)' + pop: true + - include: expressions + + preprocessor-practical-workarounds: + - include: preprocessor-convention-ignore-uppercase-ident-lines + - include: scope:source.c#preprocessor-convention-ignore-uppercase-calls-without-semicolon + + preprocessor-convention-ignore-uppercase-ident-lines: + - match: ^(\s*{{macro_identifier}})+\s*$ + scope: meta.assumed-macro.c++ + push: + # It's possible that we are dealing with a function return type on its own line, and the + # name of the function is on the subsequent line. + - match: '(?={{path_lookahead}}({{generic_lookahead}}({{path_lookahead}})?)\s*\()' + set: [function-definition-params, global-function-identifier-generic] + - match: '(?={{path_lookahead}}\s*\()' + set: [function-definition-params, global-function-identifier] + - match: ^ + pop: true + + preprocessor-other: + - match: ^\s*(#\s*(?:if|ifdef|ifndef|elif|elifdef|elifndef|else))\b + captures: + 1: keyword.control.directive.conditional.c++ + push: + - meta_scope: meta.preprocessor.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-line-ending + - include: scope:source.c#preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c++ + - match: ^\s*(#\s*(?:line|pragma|undef))\b + captures: + 1: keyword.control.directive.other.c++ + push: + - meta_scope: meta.preprocessor.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-line-ending + - include: scope:source.c#preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c++ + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c++ keyword.control.directive.conditional.endif.c++ + - match: ^\s*(#\s*(?:error|warning))\b + captures: + 1: keyword.control.directive.error.c++ + push: + - meta_scope: meta.preprocessor.diagnostic.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-line-ending + - include: scope:source.c#preprocessor-comments + - include: strings + - match: '\S+' + scope: string.unquoted.c++ + - match: ^\s*(#\s*(?:include|include_next|embed|import))\b + captures: + 1: keyword.control.directive.include.c++ + push: + - meta_scope: meta.preprocessor.include.c++ + - include: scope:source.c#preprocessor-line-continuation + - include: scope:source.c#preprocessor-line-ending + - include: scope:source.c#preprocessor-comments + - match: '"' + scope: punctuation.definition.string.begin.c++ + push: + - meta_scope: string.quoted.double.include.c++ + - match: '"' + scope: punctuation.definition.string.end.c++ + pop: true + - match: < + scope: punctuation.definition.string.begin.c++ + push: + - meta_scope: string.quoted.other.lt-gt.include.c++ + - match: '>' + scope: punctuation.definition.string.end.c++ + pop: true + - include: preprocessor-practical-workarounds
diff --git /dev/null b/syntax/C/C.sublime-syntax @@ -0,0 +1,1527 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: C +scope: source.c + +file_extensions: + - c + - h + +first_line_match: |- + (?xi: + ^ \s* // .*? -\*- .*? \bc\b(?![#+]) .*? -\*- # editorconfig + ) + +variables: + # number digits + bin_digit: '[01'']' + oct_digit: '[0-7'']' + dec_digit: '[\d'']' + hex_digit: '[\h'']' + + # number exponents + dec_exponent: '(?:[eE][-+]?{{dec_digit}}*)' + hex_exponent: '(?:[pP][-+]?{{dec_digit}}*)' + + # number suffixes + bin_suffix: '[2-9a-zA-Z_][[:alnum:]_]*' + oct_suffix: '[8-9g-zG-Z_][[:alnum:]_]*' + dec_suffix: '[a-zA-Z_][[:alnum:]_]*' + hex_suffix: '[g-zG-Z_][[:alnum:]_]*' + double_suffix: 'df|DF|dd|DD|dl|DL|[fFlL]' + integer_suffix: 'u?wb|[lL]{1,2}[uU]?|[uU][lL]{0,2}' + + identifier: \b[[:alpha:]_][[:alnum:]_]*\b # upper and lowercase + macro_identifier: \b[[:upper:]_][[:upper:][:digit:]_]{2,}\b # only uppercase, at least 3 chars + control_keywords: 'break|case|continue|default|do|else|for|goto|if|_Pragma|return|switch|while' + basic_types: 'asm|__asm__|auto|bool|_Bool|char|_Complex|double|float|_Imaginary|_Decimal(32|64|128)|int|long|short|signed|unsigned|void' + before_tag: 'struct|union|enum' + microsoft_types: '__int8|__int16|__int32|__int64' + windows_types: 'APIENTRY|ATOM|BOOL|BOOLEAN|BYTE|CALLBACK|CCHAR|CHAR|COLORREF|CONST|DWORD|DWORDLONG|DWORD_PTR|DWORD32|DWORD64|FLOAT|HACCEL|HALF_PTR|HANDLE|HBITMAP|HBRUSH|HCOLORSPACE|HCONV|HCONVLIST|HCURSOR|HDC|HDDEDATA|HDESK|HDROP|HDWP|HENHMETAFILE|HFILE|HFONT|HGDIOBJ|HGLOBAL|HHOOK|HICON|HINSTANCE|HKEY|HKL|HLOCAL|HMENU|HMETAFILE|HMODULE|HMONITOR|HPALETTE|HPEN|HRESULT|HRGN|HRSRC|HSZ|HWINSTA|HWND|INT|INT_PTR|INT8|INT16|INT32|INT64|LANGID|LCID|LCTYPE|LGRPID|LONG|LONGLONG|LONG_PTR|LONG32|LONG64|LPARAM|LPBOOL|LPBYTE|LPCOLORREF|LPCSTR|LPCTSTR|LPCVOID|LPCWSTR|LPDWORD|LPHANDLE|LPINT|LPLONG|LPSTR|LPTSTR|LPVOID|LPWORD|LPWSTR|LRESULT|PBOOL|PBOOLEAN|PBYTE|PCHAR|PCSTR|PCTSTR|PCWSTR|PDWORD|PDWORDLONG|PDWORD_PTR|PDWORD32|PDWORD64|PFLOAT|PHALF_PTR|PHANDLE|PHKEY|PINT|PINT_PTR|PINT8|PINT16|PINT32|PINT64|PLCID|PLONG|PLONGLONG|PLONG_PTR|PLONG32|PLONG64|POINTER_32|POINTER_64|POINTER_SIGNED|POINTER_UNSIGNED|PSHORT|PSIZE_T|PSSIZE_T|PSTR|PTBYTE|PTCHAR|PTSTR|PUCHAR|PUHALF_PTR|PUINT|PUINT_PTR|PUINT8|PUINT16|PUINT32|PUINT64|PULONG|PULONGLONG|PULONG_PTR|PULONG32|PULONG64|PUSHORT|PVOID|PWCHAR|PWORD|PWSTR|QWORD|SC_HANDLE|SC_LOCK|SERVICE_STATUS_HANDLE|SHORT|SIZE_T|SSIZE_T|TBYTE|TCHAR|UCHAR|UHALF_PTR|UINT|UINT_PTR|UINT8|UINT16|UINT32|UINT64|ULONG|ULONGLONG|ULONG_PTR|ULONG32|ULONG64|UNICODE_STRING|USHORT|USN|VOID|WCHAR|WINAPI|WORD|WPARAM' + complex: 'complex|imaginary' + fenv: 'fenv_t|fexcept_t' + setjmp: 'jmp_buf' + signal: 'sig_atomic_t' + stdarg: 'va_list' + stdatomic: 'atomic_(bool|char|schar|uchar|short|ushort|int|uint|long|ulong|llong|ullong|char8_t|char16_t|char32_t|wchar_t|int_least8_t|uint_least8_t|int_least16_t|uint_least16_t|int_least32_t|uint_least32_t|int_least64_t|uint_least64_t|int_fast8_t|uint_fast8_t|int_fast16_t|uint_fast16_t|int_fast32_t|uint_fast32_t|int_fast64_t|uint_fast64_t|intptr_t|uintptr_t|size_t|ptrdiff_t|intmax_t|uintmax_t|flag)|memory_order' + stdint: 'int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t' + stdio: 'FILE|fpos_t' + stdlib: 'div_t|ldiv_t|lldiv_t|imaxdiv_t' + stddef: 'size_t|ptrdiff_t|max_align_t|nullptr_t' + time: 'time_t|clock_t' + threads: 'thrd_t|thrd_start_t|mtx_t|cnd_t|tss_t|tss_dtor_t|once_flag' + wchar: 'wchar_t|wint_t|wctrans_t|wctype_t' + uchar: 'mbstate_t|char8_t|char16_t|char32_t' + declspec: '__declspec\(\s*\w+(?:\([^)]+\))?\s*\)' + storage_classes: 'static|extern|register|thread_local|_Thread_local|constexpr|{{declspec}}' + type_qualifier: 'const|volatile|_Atomic' + compiler_directive: 'inline|restrict|__restrict__|__restrict|_Noreturn|noreturn' + modifiers: '{{storage_classes}}|{{type_qualifier}}|{{compiler_directive}}' + non_func_keywords: 'if|for|switch|while|decltype|typeof|typeof_unqual|_Atomic|_BitInt|sizeof|alignof|_Alignof|alignas|_Alignas|static_assert|_Static_assert|__declspec|__attribute__' + # A single token inside a macro argument list: a non-paren character, or a + # balanced parenthesised group with one level of further nesting. Repeated, + # this matches macro arguments with up to two levels of nested parentheses + # (e.g. Unreal Engine's `USTRUCT(meta = (Abstract))`). + nested_parens: '(?:[^()]|\((?:[^()]|\([^()]*\))*\))' + + attribute_token: '({{identifier}}|{{identifier}}::{{identifier}}|{{identifier}}\(.*\)|{{identifier}}::{{identifier}}\(.*\))' + attribute_list: '({{attribute_token}}|({{attribute_token}},\s*)+{{attribute_token}})' + +contexts: + main: + - include: preprocessor-global + - include: global + + ############################################################################# + # Reusable contexts + # + # The follow contexts are currently constructed to be reused in the C++ + # syntax. They are specifically constructed to not push into sub-contexts, + # which ensures that C++ code isn't accidentally lexed as plain C. They also + # should not use the {{identifier}} variable since that is different for C++. + ############################################################################# + + comments: + - include: block-comments + - include: line-comments + - include: merge-conflict-markers + + block-comments: + - match: ^(/\*) =\s*(.*?)\s*= (\*/)$\n? + scope: comment.block.banner.c + captures: + 1: punctuation.definition.comment.begin.c + 2: meta.toc-list.banner.block.c + 3: punctuation.definition.comment.end.c + # empty block comments + - match: /\*\*+/ + scope: comment.block.empty.c punctuation.definition.comment.c + # documentation block comments + - match: (?:/\*!|/\*{2,}) + scope: punctuation.definition.comment.begin.c + push: block-comment-documentation-body + # normal block comments + - match: /\* + scope: punctuation.definition.comment.begin.c + push: block-comment-body + # stray block comment end + - match: \*+/(?!\*) + scope: invalid.illegal.stray-comment-end.c + + block-comment-documentation-body: + - meta_include_prototype: false + - meta_scope: comment.block.documentation.c + - match: \*+/ + scope: punctuation.definition.comment.end.c + pop: true + - match: ^\s*(\*)(?!\**/) + captures: + 1: punctuation.definition.comment.c + - include: merge-conflict-markers + + block-comment-body: + - meta_include_prototype: false + - meta_scope: comment.block.c + - match: \*/ + scope: punctuation.definition.comment.end.c + pop: true + - match: ^\s*(\*)(?!\**/) + captures: + 1: punctuation.definition.comment.c + - include: merge-conflict-markers + + line-comments: + - match: ^(//) =\s*(.*?)\s*=\s*$\n? + scope: comment.line.banner.c + captures: + 1: punctuation.definition.comment.c + 2: meta.toc-list.banner.line.c + - match: //(?:!|/(?!/)) + scope: punctuation.definition.comment.c + push: line-comment-documentation-body + - match: //+ + scope: punctuation.definition.comment.c + push: line-comment-body + + line-comment-body: + - meta_include_prototype: false + - meta_scope: comment.line.double-slash.c + - include: line-comment-end + + line-comment-documentation-body: + - meta_include_prototype: false + - meta_scope: comment.line.documentation.c + - include: line-comment-end + + line-comment-end: + - match: (?:(//+)\s*)?$\n? + captures: + 1: punctuation.definition.comment.c + pop: 1 + - match: (\\)$\n? + captures: + 1: punctuation.separator.continuation.c + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + + strings: + - match: '(L|u8|u|U)?(")' + captures: + 1: storage.type.string.c + 2: punctuation.definition.string.begin.c + push: + - meta_scope: string.quoted.double.c + - match: '"' + scope: punctuation.definition.string.end.c + pop: true + - include: string_escaped_char + - include: string_placeholder + - match: "(L|u8|u|U)?(')" + captures: + 1: storage.type.string.c + 2: punctuation.definition.string.begin.c + push: + - meta_scope: string.quoted.single.c + - match: "'" + scope: punctuation.definition.string.end.c + pop: true + - include: string_escaped_char + + string_escaped_char: + - match: '(\\)$\n' + captures: + 1: punctuation.separator.continuation.c + - match: \\(?:\\|[abefnrtv\'"?]|[0-3][0-9]{0,2}|[4-7][0-9]?|x[a-fA-F0-9]+|u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}) + scope: constant.character.escape.c + - match: \\. + scope: invalid.illegal.unknown-escape.c + + string_placeholder: + - match: |- + (?x)% + (\d+\$)? # field (argument #) + [#0\- +']* # flags + [,;:_]? # separator character (AltiVec) + ((-?\d+)|\*(-?\d+\$)?)? # minimum field width + (\.((-?\d+)|\*(-?\d+\$)?)?)? # precision + (hh|h|ll|l|j|t|z|q|L|H|D|DD|vh|vl|v|hv|hl|wf?[0-9]+)? # length modifier + (\[[^\]]+\]|[am]s|[diouxXbDOUeEfFgGaACcSspn%]) # conversion type + scope: constant.other.placeholder.c + + keywords: + - match: \bbreak\b + scope: keyword.control.flow.break.c + - match: \bcontinue\b + scope: keyword.control.flow.continue.c + - match: \bgoto\b + scope: keyword.control.flow.goto.c + - match: \breturn\b + scope: keyword.control.flow.return.c + - match: \b({{control_keywords}})\b + scope: keyword.control.c + - match: \b(sizeof|alignof|_Alignof|static_assert|_Static_assert)\b + scope: keyword.operator.word.c + + attributes: + - match: '\[\[(?={{attribute_list}}\]\])' + scope: punctuation.section.attribute.begin.c + push: + - meta_scope: meta.attribute.c + - match: '\b(deprecated|__deprecated__|fallthrough|__fallthrough__|nodiscard|__nodiscard__|maybe_unused|__maybe_unused__|noreturn|__noreturn__|unsequenced|__unsequenced__|reproducible|__reproducible__)\b' + scope: storage.modifier.c + - match: ',' + scope: punctuation.separator.c + - include: parens + - match: \]\] + scope: punctuation.section.attribute.end.c + pop: true + + modifiers: + - match: \b({{modifiers}})\b + scope: storage.modifier.c + - include: attributes + + variables: + - match: '\bg[A-Z]\w*\b' + scope: variable.other.readwrite.global.mac-classic.c + - match: '\bs[A-Z]\w*\b' + scope: variable.other.readwrite.static.mac-classic.c + + constants: + - match: \b(false|FALSE)\b + scope: constant.language.boolean.false.c + - match: \b(true|TRUE)\b + scope: constant.language.boolean.true.c + - match: \b(nullptr|NULL)\b + scope: constant.language.null.c + - match: \b__func__\b + scope: constant.language.c + - match: \b(__FILE__|__FUNCTION__|__LINE__)\b + scope: support.constant.c + # common C constant naming idiom -- kConstantVariable + - match: '\bk[A-Z]\w*\b' + scope: constant.other.variable.mac-classic.c + - match: \b(noErr|kNilOptions|kInvalidID|kVariableLengthArray)\b + scope: support.constant.mac-classic.c + + c99: + - match: \b(hypot(f|l)?|s(scanf|ystem|nprintf|ca(nf|lb(n(f|l)?|ln(f|l)?))|i(n(h(f|l)?|f|l)?|gn(al|bit))|tr(s(tr|pn)|nc(py|at|mp)|c(spn|hr|oll|py|at|mp)|to(imax|d|u(l(l)?|max)|k|f|l(d|l)?)|error|pbrk|ftime|len|rchr|xfrm)|printf|et(jmp|vbuf|locale|buf)|qrt(f|l)?|w(scanf|printf)|rand)|n(e(arbyint(f|l)?|xt(toward(f|l)?|after(f|l)?))|an(f|l)?)|c(s(in(h(f|l)?|f|l)?|qrt(f|l)?)|cos(h(f)?|f|l)?|imag(f|l)?|t(ime|an(h(f|l)?|f|l)?)|o(s(h(f|l)?|f|l)?|nj(f|l)?|pysign(f|l)?)|p(ow(f|l)?|roj(f|l)?)|e(il(f|l)?|xp(f|l)?)|l(o(ck|g(f|l)?)|earerr)|a(sin(h(f|l)?|f|l)?|cos(h(f|l)?|f|l)?|tan(h(f|l)?|f|l)?|lloc|rg(f|l)?|bs(f|l)?)|real(f|l)?|brt(f|l)?)|t(ime|o(upper|lower)|an(h(f|l)?|f|l)?|runc(f|l)?|gamma(f|l)?|mp(nam|file))|i(s(space|n(ormal|an)|cntrl|inf|digit|u(nordered|pper)|p(unct|rint)|finite|w(space|c(ntrl|type)|digit|upper|p(unct|rint)|lower|al(num|pha)|graph|xdigit|blank)|l(ower|ess(equal|greater)?)|al(num|pha)|gr(eater(equal)?|aph)|xdigit|blank)|logb(f|l)?|max(div|abs))|di(v|fftime)|_Exit|unget(c|wc)|p(ow(f|l)?|ut(s|c(har)?|wc(har)?)|error|rintf)|e(rf(c(f|l)?|f|l)?|x(it|p(2(f|l)?|f|l|m1(f|l)?)?))|v(s(scanf|nprintf|canf|printf|w(scanf|printf))|printf|f(scanf|printf|w(scanf|printf))|w(scanf|printf)|a_(start|copy|end|arg))|qsort|f(s(canf|e(tpos|ek))|close|tell|open|dim(f|l)?|p(classify|ut(s|c|w(s|c))|rintf)|e(holdexcept|set(e(nv|xceptflag)|round)|clearexcept|testexcept|of|updateenv|r(aiseexcept|ror)|get(e(nv|xceptflag)|round))|flush|w(scanf|ide|printf|rite)|loor(f|l)?|abs(f|l)?|get(s|c|pos|w(s|c))|re(open|e|ad|xp(f|l)?)|m(in(f|l)?|od(f|l)?|a(f|l|x(f|l)?)?))|l(d(iv|exp(f|l)?)|o(ngjmp|cal(time|econv)|g(1(p(f|l)?|0(f|l)?)|2(f|l)?|f|l|b(f|l)?)?)|abs|l(div|abs|r(int(f|l)?|ound(f|l)?))|r(int(f|l)?|ound(f|l)?)|gamma(f|l)?)|w(scanf|c(s(s(tr|pn)|nc(py|at|mp)|c(spn|hr|oll|py|at|mp)|to(imax|d|u(l(l)?|max)|k|f|l(d|l)?|mbs)|pbrk|ftime|len|r(chr|tombs)|xfrm)|to(b|mb)|rtomb)|printf|mem(set|c(hr|py|mp)|move))|a(s(sert|ctime|in(h(f|l)?|f|l)?)|cos(h(f|l)?|f|l)?|t(o(i|f|l(l)?)|exit|an(h(f|l)?|2(f|l)?|f|l)?)|b(s|ort))|g(et(s|c(har)?|env|wc(har)?)|mtime)|r(int(f|l)?|ound(f|l)?|e(name|alloc|wind|m(ove|quo(f|l)?|ainder(f|l)?))|a(nd|ise))|b(search|towc)|m(odf(f|l)?|em(set|c(hr|py|mp)|move)|ktime|alloc|b(s(init|towcs|rtowcs)|towc|len|r(towc|len))))\b + scope: support.function.C99.c + + types: + - match: \bstruct\b + scope: keyword.declaration.struct.c + - match: \benum\b + scope: keyword.declaration.enum.c + - match: \bunion\b + scope: keyword.declaration.union.c + - match: \b({{basic_types}})\b + scope: storage.type.c + - match: \b(u_char|u_short|u_int|u_long|ushort|uint|u_quad_t|quad_t|qaddr_t|caddr_t|daddr_t|dev_t|fixpt_t|blkcnt_t|blksize_t|gid_t|in_addr_t|in_port_t|ino_t|key_t|mode_t|nlink_t|id_t|pid_t|off_t|segsz_t|swblk_t|uid_t|id_t|ssize_t|useconds_t|suseconds_t)\b + scope: support.type.sys-types.c + - match: \b(pthread_attr_t|pthread_cond_t|pthread_condattr_t|pthread_mutex_t|pthread_mutexattr_t|pthread_once_t|pthread_rwlock_t|pthread_rwlockattr_t|pthread_t|pthread_key_t)\b + scope: support.type.pthread.c + - match: \b({{complex}})\b + scope: support.type.complex.c + - match: \b({{fenv}})\b + scope: support.type.fenv.c + - match: \b({{setjmp}})\b + scope: support.type.setjmp.c + - match: \b({{signal}})\b + scope: support.type.signal.c + - match: \b({{stdarg}})\b + scope: support.type.stdarg.c + - match: \b({{stdatomic}})\b + scope: support.type.stdatomic.c + - match: \b({{stdint}})\b + scope: support.type.stdint.c + - match: \b({{stdio}})\b + scope: support.type.stdio.c + - match: \b({{stdlib}})\b + scope: support.type.stdlib.c + - match: \b({{stddef}})\b + scope: support.type.stddef.c + - match: \b({{wchar}})\b + scope: support.type.wchar.c + - match: \b({{uchar}})\b + scope: support.type.uchar.c + - match: \b({{time}})\b + scope: support.type.time.c + - match: \b({{threads}})\b + scope: support.type.threads.c + - match: '\b({{microsoft_types}})\b' + scope: support.type.microsoft.c + - match: '\b({{windows_types}})\b' + scope: support.type.windows.c + - match: \b(AbsoluteTime|Boolean|Byte|ByteCount|ByteOffset|BytePtr|CompTimeValue|ConstLogicalAddress|ConstStrFileNameParam|ConstStringPtr|Duration|Fixed|FixedPtr|Float32|Float32Point|Float64|Float80|Float96|FourCharCode|Fract|FractPtr|Handle|ItemCount|LogicalAddress|OptionBits|OSErr|OSStatus|OSType|OSTypePtr|PhysicalAddress|ProcessSerialNumber|ProcessSerialNumberPtr|ProcHandle|Ptr|ResType|ResTypePtr|ShortFixed|ShortFixedPtr|SignedByte|SInt16|SInt32|SInt64|SInt8|Size|StrFileName|StringHandle|StringPtr|TimeBase|TimeRecord|TimeScale|TimeValue|TimeValue64|UInt16|UInt32|UInt64|UInt8|UniChar|UniCharCount|UniCharCountPtr|UniCharPtr|UnicodeScalarValue|UniversalProcHandle|UniversalProcPtr|UnsignedFixed|UnsignedFixedPtr|UnsignedWide|UTF16Char|UTF32Char|UTF8Char)\b + scope: support.type.mac-classic.c + - match: \b([A-Za-z0-9_]+_t)\b + scope: support.type.posix-reserved.c + - include: types-parens + + types-parens: + - match: '\b(typeof|__typeof|__typeof__|typeof_unqual|alignas|_Alignas|_Atomic|_BitInt)\b\s*(\()' + captures: + 1: keyword.declaration.type.c + 2: meta.group.c punctuation.section.group.begin.c + push: + - meta_content_scope: meta.group.c + - match: '\)' + scope: meta.group.c punctuation.section.group.end.c + pop: true + - include: expressions + + numbers: + # https://en.cppreference.com/w/c/language/floating_constant + + # decimal floats + - match: |- + (?x) + ( + \b{{dec_digit}}+ + (?: + # 1., 1.f, 1.L, 1.1, 1.1e1, 1.1e-1, 1.1f, 1.1e1f, 1.1e-1f, 1.1L, 1.1e1L, 1.1e-1L + (\.) (?: {{dec_digit}}+ | (?!\.) ) {{dec_exponent}}? + # 1.e1, 1.e-1, 1.e1f, 1.e-1f, 1.e1L, 1.e-1L + | {{dec_exponent}} + ) + # .1, .1e1, .1e-1, .1f, .1e1f, .1e-1f, .1L, .1e1L, .1e-1L + | (\.) {{dec_digit}}+ {{dec_exponent}}? + ) + (?: ({{double_suffix}}) | ({{dec_suffix}}) )? + scope: meta.number.float.decimal.c + captures: + 1: constant.numeric.value.c + 2: punctuation.separator.decimal.c + 3: punctuation.separator.decimal.c + 4: constant.numeric.suffix.c + 5: invalid.illegal.numeric.suffix.c + + # hexadecimal float (C99) + - match: |- + (?x) + \b(0[xX]) + ( + (?: + # 0xfp1, 0xf.p1, 0xfp1f, 0xf.p1f + {{hex_digit}}+ (\.)? + # 0x.fp1, 0xf.fp1, 0x.fp1f, 0xf.fp1f + | {{hex_digit}}* (\.) {{hex_digit}}+ + ) + {{hex_exponent}} + ) + (?: ({{double_suffix}}) | ({{dec_suffix}}) )? + scope: meta.number.float.hexadecimal.c + captures: + 1: constant.numeric.base.c + 2: constant.numeric.value.c + 3: punctuation.separator.decimal.c + 4: punctuation.separator.decimal.c + 5: constant.numeric.suffix.c + 6: invalid.illegal.numeric.suffix.c + + # https://en.cppreference.com/w/c/language/integer_constant + + # binary integer (C23) + - match: \b(0[bB])({{bin_digit}}*)(?:({{integer_suffix}})|({{bin_suffix}}))? + scope: meta.number.integer.binary.c + captures: + 1: constant.numeric.base.c + 2: constant.numeric.value.c + 3: constant.numeric.suffix.c + 4: invalid.illegal.numeric.suffix.c + + # hexadecimal integer + - match: \b(0[xX])({{hex_digit}}*)(?:({{integer_suffix}})|({{hex_suffix}}))? + scope: meta.number.integer.hexadecimal.c + captures: + 1: constant.numeric.base.c + 2: constant.numeric.value.c + 3: constant.numeric.suffix.c + 4: invalid.illegal.numeric.suffix.c + + # octal integer + - match: \b(0)({{oct_digit}}+)(?:({{integer_suffix}})|({{oct_suffix}}))? + scope: meta.number.integer.octal.c + captures: + 1: constant.numeric.base.c + 2: constant.numeric.value.c + 3: constant.numeric.suffix.c + 4: invalid.illegal.numeric.suffix.c + + # decimal integer + - match: \b({{dec_digit}}+)(?:({{integer_suffix}})|({{dec_suffix}}))? + scope: meta.number.integer.decimal.c + captures: + 1: constant.numeric.value.c + 2: constant.numeric.suffix.c + 3: invalid.illegal.numeric.suffix.c + + operators: + - match: (?:\+\+|--) + scope: keyword.operator.arithmetic.c + - match: '->' + scope: punctuation.accessor.c + - match: \+\=|-\=|\*\=|/\=|%\=|&\=|\|\=|\^\=|>>\=|<<\= + scope: keyword.operator.assignment.augmented.c + - match: <<|>>|&&|\|\| + scope: keyword.operator.arithmetic.c + - match: <\=|>\=|\=\=|<|>|\!\= + scope: keyword.operator.comparison.c + - match: \+|\-|/|%|\||\^|~|! + scope: keyword.operator.arithmetic.c + # These two operator can be both arithmetic and pointer/address related + - match: \*|& + scope: keyword.operator.c + - match: \= + scope: keyword.operator.assignment.c + # Negative lookahead prevents match :: when included in C++ + - match: '\?|:(?!:)' + scope: keyword.operator.ternary.c + - match: '\.\.\.' + scope: keyword.operator.variadic.c + + access-illegal: + - match: \.\.(?!\.) + scope: invalid.illegal.syntax.c + + access: + - match: '(\.)({{identifier}})(?!\s*\()' + captures: + 1: punctuation.accessor.c + 2: variable.other.member.c + - include: access-illegal + - match: \.(?!\.) + scope: punctuation.accessor.c + + label: + - match: '^\s*((?!default){{identifier}})(:)(?!:)' + captures: + 1: entity.name.label.c + 2: punctuation.separator.c + + preprocessor-disabled: + - match: ^\s*(#\s*if(n?def)?)\b + captures: + 1: meta.preprocessor.c + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c + pop: true + - include: preprocessor-disabled + - include: pragma-mark + - include: pragma-mark + + preprocessor-line-continuation: + - match: '(\\)$\n' + captures: + 1: punctuation.separator.continuation.c + - match: \\(\s+?)$ + captures: + 1: invalid.illegal.space-after-continuation.c + + preprocessor-line-ending: + - match: $\n + pop: true + + # Comment handling in preprocessor directives are complicated by the fact + # that a single-line comment will normally consume the newline to prevent + # completions from being presented to the user. Additionally, a multi-line + # comment without a line continuation ends at the newline. + preprocessor-comments: + - match: /\* + scope: punctuation.definition.comment.c + push: + - meta_scope: comment.block.c + - match: '\\$\n' + scope: punctuation.separator.continuation.c + - match: \*/ + scope: punctuation.definition.comment.c + pop: true + - match: // + scope: punctuation.definition.comment.c + push: + - meta_scope: comment.line.double-slash.c + - match: '(\\)$\n' + captures: + 1: punctuation.separator.continuation.c + pop: true + - match: (?=\n) + pop: true + + pragma-mark: + - match: ^\s*((#\s*pragma\s+mark)\s+(.*)) + scope: meta.section.c + captures: + 1: meta.preprocessor.c + 2: keyword.control.directive.pragma.c + 3: meta.toc-list.pragma-mark.c + + # Used by "inc" snippets to prevent double ##include + incomplete-inc: + - match: '^\s*(#i(nc?)?)\b\s*' + scope: meta.preprocessor.incomplete.c + + ############################################################################# + # The following are C-specific scopes that should not be reused. This is + # because they push into subcontexts and use variables that are C-specific. + ############################################################################# + + global: + - include: early-expressions + - match: '^\s*(?=\w+|\[\[{{attribute_list}}\]\])' + push: global-modifier + - include: late-expressions + + statements: + - include: preprocessor-statements + - include: label + - include: expressions + + expressions: + - include: early-expressions + - include: late-expressions + + early-expressions: + - include: preprocessor-expressions + - include: comments + - include: case-default + - include: typedef + - include: keywords-parens + - include: keywords + - include: numbers + - include: operators + - include: strings + - include: parens + - include: brackets + - include: block + - include: variables + - include: constants + - include: access + - match: ',' + scope: punctuation.separator.c + - match: '\)|\}' + scope: invalid.illegal.stray-bracket-end.c + + late-expressions: + - include: modifiers-parens + - include: modifiers + - include: types + - include: function-call + - match: ';' + scope: punctuation.terminator.c + + ## C-specific contexts + + global-modifier: + - include: comments + - include: modifiers-parens + - include: modifiers + - match: '(?=\S)' + set: global-type + + global-type: + - include: comments + - include: types-parens + - match: \* + scope: keyword.operator.c + - match: |- + (?x: + (struct) + \s+ + (?= + {{identifier}} + (\s+{{identifier}}(?!\s*[{=;])|\s*\*+) + ) + ) + captures: + 1: keyword.declaration.struct.c + set: global-maybe-function + - match: |- + (?x: + (enum) + \s+ + (?= + {{identifier}} + (\s+{{identifier}}(?!\s*[{=;])|\s*\*+) + ) + ) + captures: + 1: keyword.declaration.enum.c + set: global-maybe-function + - match: |- + (?x: + (union) + \s+ + (?= + {{identifier}} + (\s+{{identifier}}(?!\s*[{=;])|\s*\*+) + ) + ) + captures: + 1: keyword.declaration.union.c + set: global-maybe-function + # The previous match handles return types of struct/enum/etc from a func, + # there this one exits the context to allow matching an actual struct/union + - match: '(?=\b({{before_tag}})\b)' + set: data-structures + - match: '(?=\b({{control_keywords}})\b)' + pop: true + - match: '(?=\s)' + set: global-maybe-function + # Allow a macro call + - match: '({{identifier}})\s*(\()(?={{nested_parens}}+\))' + captures: + 1: variable.function.c + 2: meta.group.c punctuation.section.group.begin.c + push: + - meta_scope: meta.function-call.c + - meta_content_scope: meta.group.c + - match: '\)' + scope: meta.group.c punctuation.section.group.end.c + pop: true + - include: expressions + - match: (?={{identifier}}\s*\() + set: + - include: function-call + - match: '' + pop: true + - include: types + - match: '{{identifier}}' + - match: (?=\W) + pop: true + + global-maybe-function: + - include: comments + # Consume pointer info, macros and any type info that was offset by macros + - match: \* + scope: keyword.operator.c + - include: types + - include: modifiers-parens + - include: modifiers + # All uppercase identifier just before a newline is most likely a macro + - match: '[[:upper:][:digit:]_]+\s*$' + # Identifier that is not the function name - likely a macro + - match: '{{identifier}}(?!\s*(\(|$))' + # Real function definition + - match: '{{identifier}}(?=\s*(\(|$))' + scope: meta.function.c entity.name.function.c + set: function-definition-params + - match: '(?=\S)' + pop: true + + function-definition-params: + - meta_content_scope: meta.function.c + - include: comments + - match: '(?=\()' + set: + - match: \( + scope: meta.function.parameters.c meta.group.c punctuation.section.group.begin.c + set: + - meta_content_scope: meta.function.parameters.c meta.group.c + - match : \) + scope: punctuation.section.group.end.c + set: function-definition-continue + - include: modifiers + - include: types + - match: '{{identifier}}(?=\s*(\[|,|\)))' + scope: variable.parameter.c + - include: expressions + - include: preprocessor-line-continuation + - match: (?=\S) + pop: true + + function-definition-continue: + - meta_content_scope: meta.function.c + - include: comments + - match: '(?=;)' + pop: true + - match: \b(const|final|noexcept|override)\b + scope: storage.modifier.c + - match: '(?=\{)' + set: function-definition-body + - match: '(?=\S)' + pop: true + + function-definition-body: + - meta_content_scope: meta.function.c + - match: '\{' + scope: meta.block.c punctuation.section.block.begin.c + set: + - meta_content_scope: meta.function.c meta.block.c + - match: '\}' + scope: meta.function.c meta.block.c punctuation.section.block.end.c + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else|endif)\b) + pop: true + - match: '(?=({{before_tag}})([^(;]+$|.*\{))' + push: data-structures + - include: statements + + data-structures: + # Detect variable type definitions using struct/enum/union followed by a tag + - match: '\bstruct(?=\s+{{identifier}}\s+{{identifier}}\s*[=;\[])' + scope: keyword.declaration.struct.c + - match: '\benum(?=\s+{{identifier}}\s+{{identifier}}\s*[=;\[])' + scope: keyword.declaration.enum.c + - match: '\bunion(?=\s+{{identifier}}\s+{{identifier}}\s*[=;\[])' + scope: keyword.declaration.union.c + - match: '\bstruct\b' + scope: keyword.declaration.struct.c + set: data-structures-struct-definition + - match: '\benum\b' + scope: keyword.declaration.enum.c + set: data-structures-enum-definition + - match: '\bunion\b' + scope: keyword.declaration.union.c + set: data-structures-union-definition + - match: '(?=\S)' + pop: true + + data-structures-struct-definition: + - meta_scope: meta.struct.c + - include: data-structures-definition-common-begin + - include: data-structures-definition-common-macro + - match: '{{identifier}}(?=\s*;)' + scope: entity.name.struct.forward-decl.c + - match: '{{identifier}}' + scope: entity.name.struct.c + set: data-structures-struct-definition-after-name + - include: data-structures-struct-definition-block-start + - match: '(?=;)' + pop: true + + data-structures-struct-definition-after-name: + - meta_scope: meta.struct.c + - include: data-structures-definition-common-begin + - match: '(?=;)' + pop: true + - include: data-structures-struct-definition-block-start + + data-structures-struct-definition-block-start: + - match: '\{' + scope: meta.block.c punctuation.section.block.begin.c + set: + - meta_content_scope: meta.struct.c meta.block.c + - match: '\}' + scope: meta.struct.c meta.block.c punctuation.section.block.end.c + pop: true + - include: data-structures-body + + data-structures-enum-definition: + - meta_scope: meta.enum.c + - include: data-structures-definition-common-begin + - include: data-structures-definition-common-macro + - match: '{{identifier}}(?=\s*;)' + scope: entity.name.enum.forward-decl.c + - match: '{{identifier}}' + scope: entity.name.enum.c + set: data-structures-enum-definition-after-name + - include: data-structures-enum-definition-block-start + - match: '(?=;)' + pop: true + + data-structures-enum-definition-after-name: + - meta_scope: meta.enum.c + - include: data-structures-definition-common-begin + - match: '(?=;)' + pop: true + - include: data-structures-enum-definition-block-start + + data-structures-enum-definition-block-start: + - match: '\{' + scope: meta.block.c punctuation.section.block.begin.c + set: + - meta_content_scope: meta.enum.c meta.block.c + # Enums don't support methods so we have a simplified body + - match: '\}' + scope: meta.enum.c meta.block.c punctuation.section.block.end.c + pop: true + - include: data-structures-body-enum + + data-structures-union-definition: + - meta_scope: meta.union.c + - include: data-structures-definition-common-begin + - include: data-structures-definition-common-macro + - match: '{{identifier}}(?=\s*;)' + scope: entity.name.union.forward-decl.c + - match: '{{identifier}}' + scope: entity.name.union.c + set: data-structures-union-definition-after-name + - include: data-structures-union-definition-block-start + - match: '(?=;)' + pop: true + + data-structures-union-definition-after-name: + - meta_scope: meta.union.c + - include: data-structures-definition-common-begin + - match: '(?=;)' + pop: true + - include: data-structures-union-definition-block-start + + data-structures-union-definition-block-start: + - match: '\{' + scope: meta.block.c punctuation.section.block.begin.c + set: + - meta_content_scope: meta.union.c meta.block.c + - match: '\}' + scope: meta.union.c meta.block.c punctuation.section.block.end.c + pop: true + - include: data-structures-body + + data-structures-definition-common-begin: + - include: comments + - match: '(?=\b(?:{{before_tag}}|{{control_keywords}})\b)' + pop: true + - include: modifiers-parens + - include: modifiers + + data-structures-definition-common-macro: + # Handle macros so they aren't matched as the class name + - match: '\b[[:upper:][:digit:]_]+\b(?!\s*($|\{))' + + data-structures-definition-common-end: + - match: '(?=;)' + pop: true + + data-structures-body: + - include: preprocessor-data-structures + - match: '(?={{before_tag}})' + push: data-structures + - include: expressions + + data-structures-body-enum: + - include: comments + - include: preprocessor-data-structures + - match: '(?={{before_tag}})' + push: data-structures + - match: '{{identifier}}' + scope: entity.name.constant.c + push: constant-value + - match: ',' + scope: punctuation.separator.c + + constant-value: + - match: (?=[,;}]) + pop: true + - include: expressions + + block: + - match: '\{' + scope: punctuation.section.block.begin.c + push: + - meta_scope: meta.block.c + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else|endif)\b) + pop: true + - match: '\}' + scope: punctuation.section.block.end.c + pop: true + - include: statements + + parens: + - match: \( + scope: punctuation.section.group.begin.c + push: + - meta_scope: meta.group.c + - match: \) + scope: punctuation.section.group.end.c + pop: true + - include: expressions + + brackets: + - match: \[(?!\[{{attribute_list}}\]\]) + scope: punctuation.section.brackets.begin.c + push: + - meta_scope: meta.brackets.c + - match: \] + scope: punctuation.section.brackets.end.c + pop: true + - include: expressions + + case-default: + - match: '\b(default|case)\b' + scope: keyword.control.c + push: + - match: ':' + scope: punctuation.separator.c + pop: true + - include: expressions + + modifiers-parens: + - match: \b(__attribute__)\s*(\(\() + captures: + 1: storage.modifier.c + 2: meta.group.c punctuation.section.group.begin.c + push : + - meta_scope: meta.attribute.c + - meta_content_scope: meta.group.c + - include: parens + - include: strings + - match: \)\) + scope: meta.group.c punctuation.section.group.end.c + pop: true + - match: \b(__declspec)(\() + captures: + 1: storage.modifier.c + 2: meta.group.c punctuation.section.group.begin.c + push: + - meta_content_scope: meta.group.c + - match: '\)' + scope: meta.group.c punctuation.section.group.end.c + pop: true + - match: '\b(align|allocate|code_seg|deprecated|property|uuid)\b\s*(\()' + captures: + 1: storage.modifier.c + 2: meta.group.c punctuation.section.group.begin.c + push: + - meta_content_scope: meta.group.c + - match: '\)' + scope: meta.group.c punctuation.section.group.end.c + pop: true + - include: numbers + - include: strings + - match: \b(get|put)\b + scope: variable.parameter.c + - match: ',' + scope: punctuation.separator.c + - match: '=' + scope: keyword.operator.assignment.c + - match: '\b(appdomain|deprecated|dllimport|dllexport|jintrinsic|naked|noalias|noinline|noreturn|nothrow|novtable|process|restrict|safebuffers|selectany|thread)\b' + scope: constant.other.c + + keywords-parens: + - match: '\b(sizeof|alignof|_Alignof|static_assert|_Static_assert)\b\s*(\()' + captures: + 1: keyword.operator.word.c + 2: meta.group.c punctuation.section.group.begin.c + push: + - meta_content_scope: meta.group.c + - match: '\)' + scope: meta.group.c punctuation.section.group.end.c + pop: true + - include: expressions + + typedef: + - match: \btypedef\b + scope: keyword.declaration.type.c + push: + - match: ({{identifier}})?\s*(?=;) + captures: + 1: entity.name.type.typedef.c + pop: true + - match: '(?=\b({{before_tag}})\b)' + push: data-structures + - include: expressions + + function-call: + - match: (?={{identifier}}\s*\() + push: + - meta_content_scope: meta.function-call.c + - include: c99 + - match: '{{identifier}}' + scope: variable.function.c + - match: '\(' + scope: meta.group.c punctuation.section.group.begin.c + set: + - meta_content_scope: meta.function-call.c meta.group.c + - match : \) + scope: meta.function-call.c meta.group.c punctuation.section.group.end.c + pop: true + - include: expressions + + ## Preprocessor for data-structures + + preprocessor-data-structures: + - include: preprocessor-rule-enabled-data-structures + - include: preprocessor-rule-disabled-data-structures + + preprocessor-rule-disabled-data-structures: + - match: ^\s*((#if)\s+(0+))\b + captures: + 1: meta.preprocessor.c + 2: keyword.control.directive.conditional.if.c + 3: meta.number.integer.decimal.c constant.numeric.value.c + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.else.c + push: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: negated-block + - include: data-structures-body + - match: "" + push: + - meta_scope: comment.block.preprocessor.if-branch.c + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: preprocessor-disabled + + preprocessor-if-true: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.else.c + push: + - meta_content_scope: comment.block.preprocessor.else-branch.c + - match: (?=^\s*#\s*endif\b) + pop: true + - include: preprocessor-disabled + + preprocessor-rule-enabled-data-structures: + - match: ^\s*((#if)\s+(0*[1-9]+[\d]*))\b + captures: + 1: meta.preprocessor.c + 2: keyword.control.directive.conditional.if.c + 3: meta.number.integer.decimal.c constant.numeric.value.c + push: + - include: preprocessor-if-true + - match: "" + push: + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: negated-block + - include: data-structures-body + + ## Preprocessor for global + + preprocessor-global: + - include: preprocessor-rule-enabled-global + - include: preprocessor-rule-disabled-global + - include: preprocessor-rule-other-global + + preprocessor-statements: + - include: preprocessor-rule-enabled-statements + - include: preprocessor-rule-disabled-statements + - include: preprocessor-rule-other-statements + + preprocessor-expressions: + - include: incomplete-inc + - include: preprocessor-macro-define + - include: pragma-mark + - include: preprocessor-other + + preprocessor-rule-disabled-global: + - match: ^\s*((#if)\s+(0+))\b + captures: + 1: meta.preprocessor.c + 2: keyword.control.directive.conditional.if.c + 3: meta.number.integer.decimal.c constant.numeric.value.c + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.else.c + push: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: preprocessor-global + - include: negated-block + - include: global + - match: "" + push: + - meta_scope: comment.block.preprocessor.if-branch.c + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: preprocessor-disabled + + preprocessor-rule-enabled-global: + - match: ^\s*((#if)\s+(0*[1-9]+[\d]*))\b + captures: + 1: meta.preprocessor.c + 2: keyword.control.directive.conditional.if.c + 3: meta.number.integer.decimal.c constant.numeric.value.c + push: + - include: preprocessor-if-true + - match: "" + push: + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: preprocessor-global + - include: negated-block + - include: global + + preprocessor-rule-other-global: + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: keyword.control.directive.conditional.if.c + push: + - meta_scope: meta.preprocessor.c + - include: preprocessor-line-continuation + - include: preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c + # Enter a new scope where all elif/elifdef/elifndef/else branches have + # their contexts popped by a subsequent elif/elifdef/elifndef/else/endif. + # This ensures that preprocessor branches don't push multiple meta.block + # scopes on the stack, thus messing up the "global" context's detection + # of functions. + - match: $\n + set: preprocessor-if-branch-global + + # These gymnastics here ensure that we are properly handling scope even + # when the preprocessor is used to create different scope beginnings, such + # as a different if/while condition + preprocessor-if-branch-global: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-global + - match: \{ + scope: punctuation.section.block.begin.c + set: preprocessor-block-if-branch-global + - include: preprocessor-global + - include: negated-block + - include: global + + preprocessor-block-if-branch-global: + - meta_scope: meta.block.c + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + set: preprocessor-block-finish-global + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-global + - match: \} + scope: punctuation.section.block.end.c + set: preprocessor-if-branch-global + - include: statements + + preprocessor-block-finish-global: + - meta_scope: meta.block.c + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.if.c + set: preprocessor-block-finish-if-branch-global + - match: \} + scope: punctuation.section.block.end.c + pop: true + - include: statements + + preprocessor-block-finish-if-branch-global: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: \} + scope: punctuation.section.block.end.c + set: preprocessor-if-branch-global + - include: statements + + preprocessor-elif-else-branch-global: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: negated-block + - include: preprocessor-global + - include: global + + ## Preprocessor for statements + + preprocessor-rule-disabled-statements: + - match: ^\s*((#if)\s+(0+))\b + captures: + 1: meta.preprocessor.c + 2: keyword.control.directive.conditional.if.c + 3: meta.number.integer.decimal.c constant.numeric.value.c + push: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: ^\s*(#\s*else)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.else.c + push: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: negated-block + - include: statements + - match: "" + push: + - meta_scope: comment.block.preprocessor.if-branch.c + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: preprocessor-disabled + + preprocessor-rule-enabled-statements: + - match: ^\s*((#if)\s+(0*[1-9]+[\d]*))\b + captures: + 1: meta.preprocessor.c + 2: keyword.control.directive.conditional.if.c + 3: meta.number.integer.decimal.c constant.numeric.value.c + push: + - include: preprocessor-if-true + - match: "" + push: + - match: (?=^\s*#\s*(else|endif)\b) + pop: true + - include: negated-block + - include: statements + + preprocessor-rule-other-statements: + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: keyword.control.directive.conditional.if.c + push: + - meta_scope: meta.preprocessor.c + - include: preprocessor-line-continuation + - include: preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c + # Enter a new scope where all elif/elifdef/elifndef/else branches have + # their contexts popped by a subsequent elif/elifdef/elifndef/else/endif. + # This ensures that preprocessor branches don't push multiple meta.block + # scopes on the stack, thus messing up the "global" context's detection + # of functions. + - match: $\n + set: preprocessor-if-branch-statements + + # These gymnastics here ensure that we are properly handling scope even + # when the preprocessor is used to create different scope beginnings, such + # as a different if/while condition + preprocessor-if-branch-statements: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-statements + - match: \{ + scope: punctuation.section.block.begin.c + set: preprocessor-block-if-branch-statements + - match: (?=(?!{{non_func_keywords}}){{identifier}}\s*\() + set: preprocessor-if-branch-function-call + - include: negated-block + - include: statements + + preprocessor-if-branch-function-call: + - meta_content_scope: meta.function-call.c + - include: c99 + - match: '{{identifier}}' + scope: variable.function.c + - match: '\(' + scope: meta.group.c punctuation.section.group.begin.c + set: preprocessor-if-branch-function-call-arguments + + preprocessor-if-branch-function-call-arguments: + - meta_content_scope: meta.function-call.c meta.group.c + - match : \) + scope: meta.function-call.c meta.group.c punctuation.section.group.end.c + set: preprocessor-if-branch-statements + - match: ^\s*(#\s*(?:elif|elifdef|elifndef|else))\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.elseif.c + set: preprocessor-if-branch-statements + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + set: preprocessor-if-branch-function-call-arguments-finish + - include: expressions + + preprocessor-if-branch-function-call-arguments-finish: + - meta_content_scope: meta.function-call.c meta.group.c + - match: \) + scope: meta.function-call.c meta.group.c punctuation.section.group.end.c + pop: true + - include: expressions + + preprocessor-block-if-branch-statements: + - meta_scope: meta.block.c + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + set: preprocessor-block-finish-statements + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else)\b) + push: preprocessor-elif-else-branch-statements + - match: \} + scope: punctuation.section.block.end.c + set: preprocessor-if-branch-statements + - include: statements + + preprocessor-block-finish-statements: + - meta_scope: meta.block.c + - match: ^\s*(#\s*(?:if|ifdef|ifndef))\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.if.c + set: preprocessor-block-finish-if-branch-statements + - match: \} + scope: punctuation.section.block.end.c + pop: true + - include: statements + + preprocessor-block-finish-if-branch-statements: + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + pop: true + - match: \} + scope: punctuation.section.block.end.c + set: preprocessor-if-branch-statements + - include: statements + + preprocessor-elif-else-branch-statements: + - match: (?=^\s*#\s*endif\b) + pop: true + - include: negated-block + - include: statements + + ## Preprocessor other + + negated-block: + - match: '\}' + scope: punctuation.section.block.end.c + push: + - match: '\{' + scope: punctuation.section.block.begin.c + pop: true + - match: (?=^\s*#\s*(elif|elifdef|elifndef|else|endif)\b) + pop: true + - include: statements + + preprocessor-macro-define: + - match: ^\s*(#\s*define)\b + captures: + 1: meta.preprocessor.macro.c keyword.control.directive.define.c + push: + - meta_content_scope: meta.preprocessor.macro.c + - include: preprocessor-line-continuation + - include: preprocessor-line-ending + - include: preprocessor-comments + - match: '({{identifier}})(?=\()' + scope: entity.name.function.preprocessor.c + set: + - match: '\(' + scope: punctuation.section.group.begin.c + set: preprocessor-macro-params + - match: '{{identifier}}' + scope: entity.name.constant.preprocessor.c + set: preprocessor-macro-definition + + preprocessor-macro-params: + - meta_scope: meta.preprocessor.macro.parameters.c meta.group.c + - match: '{{identifier}}' + scope: variable.parameter.c + - match: \) + scope: punctuation.section.group.end.c + set: preprocessor-macro-definition + - match: ',' + scope: punctuation.separator.c + push: + - match: '{{identifier}}' + scope: variable.parameter.c + pop: true + - include: preprocessor-line-continuation + - include: preprocessor-comments + - match: '\.\.\.' + scope: keyword.operator.variadic.c + - match: '(?=\))' + pop: true + - match: (/\*).*(\*/) + scope: comment.block.c + captures: + 1: punctuation.definition.comment.c + 2: punctuation.definition.comment.c + - match: '\S+' + scope: invalid.illegal.unexpected-character.c + - include: preprocessor-line-continuation + - include: preprocessor-comments + - match: '\.\.\.' + scope: keyword.operator.variadic.c + - match: (/\*).*(\*/) + scope: comment.block.c + captures: + 1: punctuation.definition.comment.c + 2: punctuation.definition.comment.c + - match: $\n + scope: invalid.illegal.unexpected-end-of-line.c + + preprocessor-macro-definition: + - meta_content_scope: meta.preprocessor.macro.c + - include: preprocessor-line-continuation + - include: preprocessor-line-ending + - include: preprocessor-comments + # Don't define blocks in define statements + - match: '\{' + scope: punctuation.section.block.begin.c + - match: '\}' + scope: punctuation.section.block.end.c + - include: expressions + + preprocessor-practical-workarounds: + - include: preprocessor-convention-ignore-uppercase-ident-lines + - include: preprocessor-convention-ignore-uppercase-calls-without-semicolon + + preprocessor-convention-ignore-uppercase-ident-lines: + - match: ^(\s*{{macro_identifier}})+\s*$ + scope: meta.assumed-macro.c + push: + # It's possible that we are dealing with a function return type on its own line, and the + # name of the function is on the subsequent line. + - match: \s*({{identifier}})(?=\s*\() + captures: + 1: meta.function.c entity.name.function.c + set: function-definition-params + - match: ^ + pop: true + + + preprocessor-convention-ignore-uppercase-calls-without-semicolon: + - match: ^\s*({{macro_identifier}})\s*(\()(?={{nested_parens}}*\)\s*$) + captures: + 1: variable.function.assumed-macro.c + 2: punctuation.section.group.begin.c + push: + - meta_scope: meta.assumed-macro.c + - match: \) + scope: punctuation.section.group.end.c + pop: true + - include: expressions + + preprocessor-other: + - match: ^\s*(#\s*(?:if|ifdef|ifndef|elif|elifdef|elifndef|else))\b + captures: + 1: keyword.control.directive.conditional.elseif.c + push: + - meta_scope: meta.preprocessor.c + - include: preprocessor-line-continuation + - include: preprocessor-line-ending + - include: preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c + - match: ^\s*(#\s*(?:line|pragma|undef))\b + captures: + 1: keyword.control.directive.other.c + push: + - meta_scope: meta.preprocessor.c + - include: preprocessor-line-continuation + - include: preprocessor-line-ending + - include: preprocessor-comments + - match: \bdefined\b + scope: keyword.control.c + - match: ^\s*(#\s*endif)\b + captures: + 1: meta.preprocessor.c keyword.control.directive.conditional.endif.c + - match: ^\s*(#\s*(?:error|warning))\b + captures: + 1: keyword.control.directive.error.c + push: + - meta_scope: meta.preprocessor.diagnostic.c + - include: preprocessor-line-continuation + - include: preprocessor-line-ending + - include: preprocessor-comments + - include: strings + - match: '\S+' + scope: string.unquoted.c + - match: ^\s*(#\s*(?:include|include_next|embed|import))\b + captures: + 1: keyword.control.directive.include.c + push: + - meta_scope: meta.preprocessor.include.c + - include: preprocessor-line-continuation + - include: preprocessor-line-ending + - include: preprocessor-comments + - match: '"' + scope: punctuation.definition.string.begin.c + push: + - meta_scope: string.quoted.double.include.c + - match: '"' + scope: punctuation.definition.string.end.c + pop: true + - match: < + scope: punctuation.definition.string.begin.c + push: + - meta_scope: string.quoted.other.lt-gt.include.c + - match: ">" + scope: punctuation.definition.string.end.c + pop: true + - include: preprocessor-practical-workarounds
diff --git /dev/null b/syntax/Erlang/Erlang.sublime-syntax @@ -0,0 +1,2254 @@ +%YAML 1.2 +--- +# https://www.erlang.org/doc/reference_manual +# https://www.sublimetext.com/docs/syntax.html +name: Erlang +scope: source.erlang +version: 2 + +file_extensions: + - erl + - hrl + - escript + +hidden_file_extensions: + - Emakefile + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* \%+ .*? -\*- .*? \berlang\b .*? -\*- # editorconfig + ) + +############################################################################### + +variables: + shebang_language: \b(?:erlang|escript)\b + + # https://www.erlang.org/doc/reference_manual/data_types.html#atom + # an atom starts with lowercase alphanumeric + atom_unquoted: '[a-z]{{ident_char}}*' + + # https://www.erlang.org/doc/reference_manual/expressions.html#variables + # a variable starts with uppercase alphanumeric or underscore + variable: '[_A-Z]{{ident_char}}*' + + # an identifier can contain lowercase, uppercase, digits, underscore and @ + ident_char: '[_A-Za-z\d@]' + # the character which identifies the end of an identifier + # Note: need the character as embedded positive lookaheads don't work + ident_break_char: '[^{{ident_char}}]' + # end of identifier lookahead + # Note: avoid negative lookahead as it is 6-8% slower + ident_break: (?={{ident_break_char}}) + # a quoted identifier with possibly escaped single quote + # preceded by an arbitrary number of escaped backslashes + ident_quoted: \'((?:\\\\)*\\\'|[^''])*\' + # an identifier can be an atom or a variable + ident_unquoted: '[_A-Za-z]{{ident_char}}*' + # all characters not being used to indicate a context change + illegal_ident: '[^\s,:.;''(){}\[\]%=|/]+' + # quoted/unquoted/macro identifier + ident: \?{,2}(?:{{ident_unquoted}}|{{ident_quoted}}) + + # https://www.erlang.org/doc/reference_manual/macros.html#predefined-macros + erlang_macros: |- + (?x: + MODULE|FUNCTION_NAME|FUNCTION_ARITY|MODULE_STRING| + FILE|LINE|MACHINE|OTP_RELEASE + ){{ident_break}} + + # https://www.erlang.org/doc/man/erlang.html#exports + erlang_functions: |- + (?x: + abs|adler32|adler32_combine|append_element|apply|atom_to_binary|atom_to_list| + binary_part|binary_to_atom|binary_to_existing_atom|binary_to_float| + binary_to_integer|binary_to_list|binary_to_term|bit_size|bitstring_to_list| + bump_reductions|byte_size|cancel_timer|ceil|check_old_code|check_process_code| + convert_time_unit|crc32|crc32_combine|date|decode_packet|delete_element| + delete_module|demonitor|disconnect_node|display|dist_ctrl_get_data| + dist_ctrl_get_data_notification|dist_ctrl_input_handler|dist_ctrl_put_data| + element|erase|error|exit|external_size|float|float_to_binary|float_to_list| + floor|fun_info|fun_to_list|function_exported|garbage_collect|get|get_cookie| + get_keys|get_stacktrace|group_leader|halt|hd|hibernate|insert_element| + integer_to_binary|integer_to_list|iolist_size|iolist_to_binary| + iolist_to_iovec|is_alive|is_atom|is_binary|is_bitstring|is_boolean|is_builtin| + is_float|is_function|is_integer|is_list|is_map|is_map_key|is_number|is_pid| + is_port|is_process_alive|is_record|is_reference|is_tuple|length|link| + list_to_atom|list_to_binary|list_to_bitstring|list_to_existing_atom| + list_to_float|list_to_integer|list_to_pid|list_to_port|list_to_ref| + list_to_tuple|load_module|load_nif|loaded|localtime| + localtime_to_universaltime|make_ref|make_tuple|map_get|map_size| + match_spec_test|max|md5|md5_final|md5_init|md5_update|memory|min| + module_loaded|monitor|monitor_node|monotonic_time|nif_error|node|nodes|now| + open_port|phash|phash2|pid_to_list|port_call|port_close|port_command| + port_connect|port_control|port_info|port_to_list|ports|pre_loaded| + process_display|process_flag|process_info|processes|purge_module|put|raise| + read_timer|ref_to_list|register|registered|resume_process|round|self|send| + send_after|send_nosuspend|set_cookie|setelement|size|spawn|spawn_link| + spawn_monitor|spawn_opt|split_binary|start_timer|statistics|suspend_process| + system_flag|system_info|system_monitor|system_profile|system_time| + term_to_binary|throw|time|time_offset|timestamp|tl|trace|trace_delivered| + trace_info|trace_pattern|trunc|tuple_size|tuple_to_list|unique_integer| + universaltime|universaltime_to_localtime|unlink|unregister|whereis|yield + ){{ident_break}} + + erlang_types: |- + (?x: + # builtin data types + # https://www.erlang.org/doc/reference_manual/typespec.html#the-erlang-type-language + any|arity|atom|binary|bitstring|boolean|byte|char|float|fun|function| + identifier|integer|iodata|iolist|list|map|maybe_improper_list|mfa|module|nil| + no_return|node|none|non_neg_integer|neg_integer|pos_integer|nonempty_list| + nonempty_maybe_improper_list|nonempty_improper_list| + nonempty_maybe_improper_list|nonempty_string| + number|pid|port|record|reference|string|term|timeout|tuple| + + # erlang library + # https://www.erlang.org/doc/man/erlang.html#data-types + dist_handle|ext_binary|iovec|message_queue_data|nif_resource| + deprecated_time_unit|timeout|timestamp|time_unit + ){{ident_break}} + + support_namespaces: |- + (?x: + # builtin namespace + erlang| + + # erlang otp libraries + # https://github.com/erlang/otp + asn1|common_test|compiler|crypto|debugger|dialyzer|diameter|edoc|eldap| + erl_(docgen|interface)|et|eunit|ftp|hipe|inets|jinterface|kernel| + megaco|mnesia|observer|odbc|os_mon|parsetools|public_key|reltool| + runtime_tools|sasl|snmp|ssh|ssl|stdlib|syntax_tools|tftp|tools|wx|xmerl + ){{ident_break}} + +############################################################################### + +contexts: + + main: + - meta_include_prototype: false + - match: '' + push: [statements, shebang] + + prototype: + - include: comments + + statements: + - include: preproc-control + - include: preproc-undef + - include: preproc-define + - include: preproc-export + - include: preproc-import + - include: preproc-include + - include: preproc-module + - include: preproc-record + - include: preproc-spec + - include: preproc-type + - include: preproc-attribute + - include: function + - include: illegal-stray + # fallback incase preprocessor or function didn't match + - match: (?=\S) + push: + - include: eol-pop + - include: terminator-clause + - include: separator-clauses + - include: separator-expressions + - include: expressions + + terms: + - include: constant + - include: keyword + - include: operator + - include: character + - include: macro + - include: number + - include: record + - include: string + - include: operator-unary + - include: variable-anonymous + - include: atom + + common: + - include: map-of-expressions + - include: expr-control + - include: expr-try + - include: expr-fun + - include: function-call + - include: terms + + expressions-nested: + - include: binary + - include: group-of-expressions + - include: list-of-expressions + - include: tuple-of-expressions + + expressions: + - include: expressions-nested + - include: namespace + - include: common + - include: variable-other + + function-parameter-nested: + - include: binary-function-parameter + - include: group-of-function-parameters + - include: list-of-function-parameters + - include: tuple-of-function-parameters + + function-parameter: + - include: parameters-end-pop + - include: function-parameter-nested + - include: namespace + - include: common + - include: variable-parameter + + type-common: + - include: illegal-type-keyword + - include: map-of-types + - include: separator-type + - include: separator-union + - include: type-namespace + - include: type-call + + type-expressions: + - include: binary + - include: group-of-types + - include: list-of-types + - include: tuple-of-types + - include: type-common + - include: terms + - include: variable-other + + type-parameter-nested: + - include: binary-type-parameter + - include: group-of-type-parameters + - include: list-of-type-parameters + - include: tuple-of-type-parameters + - include: type-common + + type-parameter: + - include: parameters-end-pop + - include: type-parameter-nested + - include: terms + - include: variable-parameter + +###[ COMMENTS ]############################################################### + + comments: + - match: \%+ + scope: punctuation.definition.comment.erlang + push: comment-body + - include: merge-conflict-markers + + comment-body: + - meta_include_prototype: false + - meta_scope: comment.line.percentage.erlang + - match: \n + pop: 1 + + shebang: + - meta_include_prototype: false + - match: ^\s*(\#!) + captures: + 1: punctuation.definition.comment.shell + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if the syntax is embedded. + pop: 1 + + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.shell + - match: '{{shebang_language}}' + scope: constant.language.shebang.erlang + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ PREPROCESSOR CONTROL ]################################################### + + preproc-control: + # https://www.erlang.org/doc/reference_manual/macros.html#flow-control-in-macros + # Note: + # The `-` is scoped as `punctuation.definition` because: + # 1. directives are most likely one-liners (with exceptions!) + # 2. the hyphen is compared to the hash-tag in C/C++ preprocessors + # 3. the `.` is meant to share the scope `punctuation.terminator.clause` + # with clauses/functions as it has the same meaning. + - match: (-)\s*(ifdef|ifndef){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.conditional.erlang + push: [preproc-control-meta, preproc-control-definitions] + - match: (-)\s*(if|elif){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.conditional.erlang + push: [preproc-control-meta, preproc-control-expressions] + - match: (-)\s*(else|endif){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.conditional.erlang + push: preproc-control-meta + + preproc-control-meta: + - meta_scope: meta.preprocessor.conditional.erlang + - include: preproc-expect-end + + preproc-control-definitions: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-control-definitions-end + - constant-other-macro + - include: preproc-stray-arguments-end + + preproc-control-definitions-end: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.conditional.arguments.erlang + - include: expect-arguments-end + + preproc-control-expressions: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.conditional.arguments.erlang + - include: arguments-common + - include: expressions + - include: preproc-stray-arguments-end + +###[ PREPROCESSOR UNDEF ]##################################################### + + preproc-undef: + - match: (-)\s*(undef){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.undef.erlang + push: + - preproc-undef-end + - preproc-undef-arguments + + preproc-undef-end: + - meta_scope: meta.preprocessor.undef.erlang + - include: preproc-expect-end + + preproc-undef-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-undef-arguments-end + - entity-name-macro + - include: preproc-stray-arguments-end + + preproc-undef-arguments-end: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.undef.arguments.erlang + - include: expect-arguments-end + +###[ PREPROCESSOR DEFINE ]#################################################### + + preproc-define: + # https://www.erlang.org/doc/reference_manual/macros.html#defining-and-using-macros + - match: (-)\s*(define){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.define.erlang + push: + - preproc-define-end + - preproc-define-arguments + + preproc-define-end: + - meta_scope: meta.preprocessor.define.erlang + - include: preproc-expect-end + + preproc-define-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-define-arguments-body + - expect-arguments-separator + - preproc-define-arguments-parameters + - entity-name-macro + - include: preproc-stray-arguments-end + + preproc-define-arguments-parameters: + - meta_content_scope: meta.macro.identifier.erlang + - match: \( + scope: punctuation.section.parameters.begin.erlang + set: + - meta_scope: meta.macro.parameters.erlang + - include: parameters-common + - include: function-parameter + - include: else-pop + + preproc-define-arguments-body: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.define.arguments.erlang + - include: separator-clauses + - include: separator-expressions + - include: separator-union + - include: expressions + - include: arguments-end + +###[ PREPROCESSOR EXPORT ]#################################################### + + preproc-export: + # https://www.erlang.org/doc/reference_manual/modules.html#pre-defined-module-attributes + - match: (-)\s*(export(_type)?){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.export.erlang + push: + - preproc-export-end + - preproc-export-arguments + + preproc-export-end: + - meta_scope: meta.preprocessor.export.erlang + - include: preproc-expect-end + + preproc-export-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-export-arguments-end + - preproc-expect-references + - include: preproc-stray-arguments-end + + preproc-export-arguments-end: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.export.arguments.erlang + - include: expect-arguments-end + + preproc-expect-references: + - match: \[ + scope: punctuation.section.sequence.begin.erlang + set: + - meta_scope: meta.sequence.list.erlang + - include: list-common + - include: namespace + - include: reference + - match: (?=[.)]) + pop: 1 + - match: \S + scope: invalid.illegal.expect-list.erlang + +###[ PREPROCESSOR IMPORT ]#################################################### + + preproc-import: + # https://www.erlang.org/doc/reference_manual/modules.html#pre-defined-module-attributes + - match: (-)\s*(import){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.import.erlang + push: + - preproc-import-end + - preproc-import-arguments + + preproc-import-end: + - meta_scope: meta.preprocessor.import.erlang + - include: preproc-expect-end + + preproc-import-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-import-arguments-end + - preproc-expect-references + - expect-arguments-separator + - entity-name-module + - include: preproc-stray-arguments-end + + preproc-import-arguments-end: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.import.arguments.erlang + - include: expect-arguments-end + +###[ PREPROCESSOR INCLUDE ]################################################### + + preproc-include: + # https://www.erlang.org/doc/reference_manual/macros.html#file-inclusion + - match: (-)\s*(include(_lib)?){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.include.erlang + push: + - preproc-include-end + - preproc-include-arguments + + preproc-include-end: + - meta_scope: meta.preprocessor.include.erlang + - include: preproc-expect-end + + preproc-include-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-include-arguments-end + - preproc-include-path + - include: preproc-stray-arguments-end + + preproc-include-arguments-end: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.include.arguments.erlang + - include: expect-arguments-end + + preproc-include-path: + - match: \" + scope: punctuation.definition.string.begin.erlang + set: [string-body, string-maybe-env] + - include: else-pop + +###[ PREPROCESSOR MODULE ]#################################################### + + preproc-module: + # https://www.erlang.org/doc/reference_manual/modules.html#module-syntax + - match: (-)\s*(module){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.namespace.erlang + push: + - preproc-module-end + - preproc-module-arguments + + preproc-module-end: + - meta_scope: meta.preprocessor.namespace.erlang + - include: preproc-expect-end + + preproc-module-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-module-arguments-end + - entity-name-module + - include: preproc-stray-arguments-end + + preproc-module-arguments-end: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.namespace.arguments.erlang + - include: expect-arguments-end + +###[ PREPROCESSOR ATTRIBUTE ]################################################# + + preproc-attribute: + - match: -(?=\s*{{ident}}) + scope: punctuation.definition.keyword.erlang + push: + - preproc-attribute-end + - preproc-attribute-arguments + - preproc-attribute-keyword + + preproc-attribute-end: + - meta_scope: meta.preprocessor.attribute.erlang + - include: preproc-expect-end + + preproc-attribute-keyword: + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang keyword.control.directive.attribute.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang keyword.control.directive.attribute.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + + preproc-attribute-arguments: + # ordinary directive `-name( ... ).` + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.attribute.arguments.erlang + - include: arguments-common + - include: preproc-attribute-argument + # spec/type like directive `-attribute ... .` + - match: (?=\S) + set: + - include: separator-expressions + - include: expressions + - include: clause-end-pop + - include: eol-pop + + preproc-attribute-argument: + # https://www.erlang.org/doc/reference_manual/expressions.html#parenthesized-expressions + - match: \( + scope: punctuation.section.group.begin.erlang + push: + - meta_scope: meta.group.erlang + - include: group-common + - include: preproc-attribute-argument + # https://www.erlang.org/doc/reference_manual/data_types.html#list + - match: \[ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.list.erlang + - include: list-common + - include: preproc-attribute-argument + # https://www.erlang.org/doc/reference_manual/data_types.html#tuple + - match: \{ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.tuple.erlang + - include: tuple-common + - include: preproc-attribute-argument + - include: binary + - include: namespace + - include: reference + - include: common + - include: variable-other + +###[ PREPROCESSOR RECORD ]#################################################### + + preproc-record: + # https://www.erlang.org/doc/reference_manual/modules.html#record-definitions + - match: (-)\s*(record){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.record.erlang + push: + - preproc-record-end + - preproc-record-arguments + + preproc-record-end: + - meta_scope: meta.preprocessor.record.erlang + - include: preproc-expect-end + + preproc-record-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - preproc-record-arguments-end + - record-fields-declaration + - expect-arguments-separator + - record-name + - entity-name-record + - include: preproc-stray-arguments-end + + preproc-record-arguments-end: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.record.arguments.erlang + - include: expect-arguments-end + +###[ PREPROCESSOR SPEC ]###################################################### + + preproc-spec: + # https://www.erlang.org/doc/reference_manual/typespec.html#specifications-for-functions + - match: (-)\s*(callback|spec){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.spec.erlang + push: + - meta_scope: meta.preprocessor.spec.erlang + - include: terminator-clause-pop + - include: separator-clauses + # NOTE: function name is optional for all but the first clauses + - match: (?={{ident}}\s*:[^:]) + push: + - preproc-spec-return + - preproc-spec-parameters + - preproc-spec-path + - entity-name-function + - namespace-accessor + - namespace-qualifier + - match: (?=\S) + push: + - preproc-spec-return + - preproc-spec-parameters + - preproc-spec-name + - entity-name-function + + preproc-spec-name: + - meta_scope: meta.preprocessor.spec.name.erlang + - include: else-pop + + preproc-spec-path: + - meta_scope: meta.preprocessor.spec.name.erlang meta.path.erlang + - include: else-pop + + preproc-spec-parameters: + - match: \( + scope: punctuation.section.parameters.begin.erlang + set: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.spec.parameters.erlang + - include: parameters-common + - include: type-parameter + - include: else-pop + + preproc-spec-return: + - match: -> + scope: + meta.preprocessor.spec.erlang + punctuation.separator.parameters-return-type.erlang + set: + - clear_scopes: 1 + - meta_content_scope: meta.preprocessor.spec.return-type.erlang + - include: preproc-spec-guards + - include: separator-expressions + - include: type-expressions + - include: preproc-spec-guards + - include: illegal-group + - match: '{{illegal_ident}}|\S' + scope: invalid.illegal.expect-separator.erlang + + preproc-spec-guards: + - match: (?=when{{ident_break_char}}) + set: + - match: when + scope: keyword.control.conditional.when.erlang + set: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.spec.guards.erlang + - include: separator-expressions + - include: type-expressions + - include: clause-end-pop + - include: clause-end-pop + +###[ PREPROCESSOR TYPE ]###################################################### + + preproc-type: + # https://www.erlang.org/doc/reference_manual/typespec.html#typespec-of-user-defined-types + - match: (-)\s*(opaque|type){{ident_break}} + captures: + 1: punctuation.definition.keyword.erlang + 2: keyword.control.directive.type.erlang + push: + - preproc-type-end + - preproc-type-name + + preproc-type-end: + - meta_scope: meta.preprocessor.type.erlang + - include: preproc-expect-end + + preproc-type-name: + - match: (?=\S) + set: + - preproc-type-body + - preproc-type-parameters + - entity-name-type + + preproc-type-parameters: + - meta_content_scope: meta.preprocessor.type.name.erlang + - match: \( + scope: punctuation.section.parameters.begin.erlang + set: + - clear_scopes: 1 + - meta_scope: meta.preprocessor.type.parameters.erlang + - include: parameters-common + - include: type-parameter + - include: else-pop + + preproc-type-body: + - match: '::' + scope: punctuation.separator.type-head-body.erlang + set: + - include: type-expressions + - include: clause-end-pop + - include: clause-end-pop + # anything else is invalid + - include: illegal-group + - match: '{{illegal_ident}}|\S' + scope: invalid.illegal.expect-separator.erlang + +###[ PREPROCESSOR PROTOTYPES ]################################################ + + preproc-stray-arguments-end: + - match: \) + scope: invalid.illegal.stray-arguments-end.erlang + pop: 1 + - include: eol-pop + - include: else-pop + + preproc-expect-end: + - include: terminator-clause-pop + - match: \n + scope: invalid.illegal.expect-terminator.erlang + pop: 1 + - match: '[^\s.]+' + scope: invalid.illegal.expect-terminator.erlang + +###[ CONTROL EXPRESSION ]##################################################### + + expr-control: + # https://www.erlang.org/doc/reference_manual/expressions.html#if + - match: if{{ident_break}} + scope: keyword.control.conditional.if.erlang + push: + - meta_scope: meta.if.erlang + - include: expr-control-conditional-end + - include: expr-control-body + # https://www.erlang.org/doc/reference_manual/expressions.html#case + - match: case{{ident_break}} + scope: keyword.control.conditional.case.erlang + push: + - meta_scope: meta.case.erlang + - include: expr-control-conditional-end + - include: expr-control-body + # https://www.erlang.org/doc/reference_manual/expressions.html#maybe + - match: maybe{{ident_break}} + scope: keyword.control.conditional.maybe.erlang + push: + - meta_scope: meta.maybe.erlang + - match: \?= + scope: keyword.operator.logical.erlang + - include: expr-control-conditional-end + - include: expr-control-body + # https://www.erlang.org/doc/reference_manual/expressions.html#receive + - match: receive{{ident_break}} + scope: keyword.control.flow.receive.erlang + push: + - meta_scope: meta.receive.erlang + - include: expr-control-flow-end + - include: expr-control-body + # https://www.erlang.org/doc/reference_manual/expressions.html#block-expressions + - match: begin{{ident_break}} + scope: keyword.control.flow.begin.erlang + push: + - meta_scope: meta.block.erlang + - include: expr-control-flow-end + - include: expr-control-body + # https://www.erlang.org/doc/reference_manual/expressions.html#guard-sequences + - match: when{{ident_break}} + scope: keyword.control.conditional.when.erlang + push: + - match: (?=->|\.|(end|after|catch){{ident_break_char}}) + pop: 1 + - include: expr-control-body + - match: -> + scope: punctuation.separator.clause-head-body.erlang + + expr-control-body: + - include: separator-clauses + - include: separator-expressions + - include: expressions + + expr-control-conditional-end: + - match: end{{ident_break}}|(?=\.) + scope: keyword.control.conditional.end.erlang + pop: 1 + + expr-control-flow-end: + - match: end{{ident_break}}|(?=\.) + scope: keyword.control.flow.end.erlang + pop: 1 + +###[ TRY-CATCH EXPRESSION ]################################################### + + expr-try: + # https://www.erlang.org/doc/reference_manual/expressions.html#try + - match: try{{ident_break}} + scope: keyword.control.exception.try.erlang + push: + - meta_scope: meta.exception.try.erlang + - match: end{{ident_break}}|(?=\.) + scope: keyword.control.exception.end.erlang + pop: 1 + - match: catch{{ident_break}} + scope: keyword.control.exception.catch.erlang + push: + - clear_scopes: 1 + - meta_scope: meta.exception.catch.erlang + - match: (?=\.|(end|after){{ident_break_char}}) + pop: 1 + - match: -> + scope: punctuation.separator.clause-head-body.erlang + push: + - match: (?=[.;]|(end|after|catch){{ident_break_char}}) + pop: 1 + - include: separator-expressions + - include: expressions + # Don't match namespaces in exception patterns + - match: ':' + scope: punctuation.separator.patterns.erlang + - include: separator-clauses + - include: expressions-nested + - include: common + - include: variable-other + - match: after{{ident_break}} + scope: keyword.control.exception.after.erlang + push: + - clear_scopes: 1 + - meta_scope: meta.exception.after.erlang + - match: (?=\.|(end|after|catch){{ident_break_char}}) + pop: 1 + - include: expr-control-body + - include: expr-control-body + +###[ FUN EXPRESSION ]######################################################### + + expr-fun: + # https://www.erlang.org/doc/reference_manual/expressions.html#fun-expressions + - match: fun{{ident_break}} + scope: keyword.declaration.function.erlang + push: + - expr-fun-meta + - expr-fun-type-decider + + expr-fun-meta: + - meta_scope: meta.fun.erlang + - include: immediately-pop + + expr-fun-type-decider: + # function reference (e.g.: FuncName = fun module:name/arity) + # keyword `fun` followed by a `function-declaration` but without `end`. + - include: namespace-pop + - include: reference-pop + # function expression (e.g.: FuncName = fun(arg) ... end) + - match: (?=\S) + set: expr-fun-anonymous-clauses + + expr-fun-anonymous-clauses: + - match: end{{ident_break}}|(?=\.) + scope: keyword.declaration.end.erlang + pop: 1 + - include: separator-clauses + - match: (?=\S) + push: + - expr-fun-body + - expr-fun-parameters + - expr-fun-name-meta + - expr-fun-name + + expr-fun-name: + - include: variable-other-pop + - include: macro-pop + - match: '{{illegal_ident}}' + scope: invalid.illegal.expect-variable.erlang + pop: 1 + - include: else-pop + + expr-fun-name-meta: + - clear_scopes: 1 + - meta_scope: meta.fun.identifier.erlang + - include: else-pop + + expr-fun-parameters: + - match: \( + scope: punctuation.section.parameters.begin.erlang + set: + - clear_scopes: 1 + - meta_scope: meta.fun.parameters.erlang + - include: parameters-common + - include: function-parameter + - include: else-pop + + expr-fun-body: + - match: (?=[.;]|end{{ident_break_char}}) + pop: 1 + - include: separator-expressions + - include: expressions + +###[ FUNCTION DEFINITION ]#################################################### + + function: + # https://www.erlang.org/doc/reference_manual/functions.html#function-declaration-syntax + # Function names can be (un-)quoted atoms or nested (un-)quoted macros + # which can contain escape sequences as ordinary strings. + # Example: ?'fu % na\'me' (arguments) + - match: (?={{ident}}\s*\() + push: [function-body, function-parameters, entity-name-function] + + function-parameters: + - meta_content_scope: meta.function.identifier.erlang + - match: \( + scope: punctuation.section.parameters.begin.erlang + set: + - meta_scope: meta.function.parameters.erlang + - include: parameters-common + - include: function-parameter + - include: else-pop + + function-body: + - match: '' + set: + - meta_scope: meta.function.erlang + - match: \. + scope: punctuation.terminator.clause.erlang + pop: 1 + - match: ';' + scope: punctuation.separator.clauses.erlang + pop: 1 + - include: separator-expressions + - include: expressions + +###[ FUNCTION CALL ]########################################################## + + function-call: + - match: (?={{ident}}\s*\() + push: [function-call-arguments, function-call-name, variable-function] + + function-call-pop: + - match: (?={{ident}}\s*\() + set: [function-call-arguments, function-call-path, variable-function] + + function-call-name: + - meta_scope: meta.function-call.identifier.erlang + - include: else-pop + + function-call-path: + - meta_scope: meta.path.erlang meta.function-call.identifier.erlang + - include: else-pop + + function-call-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - meta_scope: meta.function-call.arguments.erlang + - include: arguments-common + - include: expressions + - include: else-pop + +###[ TYPE CALL ]############################################################## + + type-call: + # https://www.erlang.org/doc/reference_manual/typespec.html + # A function type looks like: + # fun() %% any function + # fun((...) -> Type) %% any arity, returning Type + # fun(() -> Type) + # fun((TList) -> Type) + - match: fun{{ident_break}} + scope: support.type.erlang + push: [type-call-fun-arguments, type-call-name] + # other type definition + - match: (?={{ident}}\s*\() + push: [type-call-other-arguments, type-call-name, storage-type] + + type-call-pop: + - match: fun{{ident_break}} + scope: support.type.erlang + set: [type-call-fun-arguments, type-call-path] + - match: (?={{ident}}\s*\() + set: [type-call-other-arguments, type-call-path, storage-type] + + type-call-name: + - meta_scope: meta.type-call.identifier.erlang + - include: else-pop + + type-call-path: + - meta_scope: meta.path.erlang meta.type-call.identifier.erlang + - include: else-pop + + type-call-fun-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - type-call-fun-arguments-end + - type-call-fun-return-type + - type-call-fun-parameters + - include: else-pop + + type-call-fun-arguments-end: + - meta_scope: meta.type-call.arguments.erlang + - include: expect-arguments-end + + type-call-fun-parameters: + - match: \( + scope: punctuation.section.parameters.begin.erlang + set: + - meta_scope: meta.fun.parameters.erlang + - include: variadic-operators + - include: parameters-common + - include: type-parameter + - include: else-pop + + type-call-fun-return-type: + - match: -> + scope: punctuation.separator.parameters-return-type.erlang + set: + - meta_content_scope: meta.fun.return-type.erlang + - match: (?=[.;)]) + pop: 1 + - include: type-expressions + - include: else-pop + + type-call-other-arguments: + - match: \( + scope: punctuation.section.arguments.begin.erlang + set: + - meta_scope: meta.type-call.arguments.erlang + - include: arguments-common + - include: type-expressions + - include: else-pop + +###[ GROUPS ]################################################################# + + group-of-expressions: + # https://www.erlang.org/doc/reference_manual/expressions.html#parenthesized-expressions + - match: \( + scope: punctuation.section.group.begin.erlang + push: + - meta_scope: meta.group.erlang + - include: group-common + - include: expressions + + group-of-function-parameters: + # https://www.erlang.org/doc/reference_manual/expressions.html#parenthesized-expressions + - match: \( + scope: punctuation.section.group.begin.erlang + push: + - meta_scope: meta.group.erlang + - include: group-common + - include: function-parameter + + group-of-types: + # https://www.erlang.org/doc/reference_manual/expressions.html#parenthesized-expressions + - match: \( + scope: punctuation.section.group.begin.erlang + push: + - meta_scope: meta.group.erlang + - include: group-common + - include: type-expressions + + group-of-type-parameters: + # https://www.erlang.org/doc/reference_manual/expressions.html#parenthesized-expressions + - match: \( + scope: punctuation.section.group.begin.erlang + push: + - meta_scope: meta.group.erlang + - include: group-common + - include: type-parameter + + group-common: + - match: \) + scope: punctuation.section.group.end.erlang + pop: 1 + - include: clause-end-or-stray + +###[ LISTS ]################################################################## + + list-of-expressions: + # https://www.erlang.org/doc/reference_manual/data_types.html#list + - match: \[ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.list.erlang + - include: list-common + - include: expressions + + list-of-function-parameters: + # https://www.erlang.org/doc/reference_manual/data_types.html#list + - match: \[ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.list.erlang + - include: list-common + - include: function-parameter + + list-of-types: + # https://www.erlang.org/doc/reference_manual/data_types.html#list + - match: \[ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.list.erlang + - include: variadic-operators + - include: list-common + - include: type-expressions + + list-of-type-parameters: + # https://www.erlang.org/doc/reference_manual/data_types.html#list + - match: \[ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.list.erlang + - include: variadic-operators + - include: list-common + - include: type-parameter + + list-common: + - match: \] + scope: punctuation.section.sequence.end.erlang + pop: 1 + - include: operator-comprehension + - include: separator-sequence + - include: separator-union + - include: clause-end-or-stray + +###[ MAPS ]################################################################### + + map-of-expressions: + # https://www.erlang.org/doc/reference_manual/data_types.html#map + # https://www.erlang.org/doc/reference_manual/expressions.html#map-expressions + - match: '#{' + scope: meta.mapping.erlang punctuation.section.mapping.begin.erlang + push: + - include: map-common + # filter + - match: \|\| + scope: meta.mapping.erlang keyword.operator.comprehension.erlang + push: + - meta_content_scope: meta.mapping.filter.erlang + - include: expressions + - include: value-end-pop + # value + - match: =>|\:= + scope: meta.mapping.erlang punctuation.separator.key-value.erlang + push: + - meta_content_scope: meta.mapping.value.erlang + - match: (?=\|\|) + pop: 1 + - include: expressions + - include: value-end-pop + # key + - match: ',?' + scope: meta.mapping.erlang punctuation.separator.sequence.erlang + push: + - meta_content_scope: meta.mapping.key.erlang + - match: (?==>|\:=|\|\|) + pop: 1 + - include: expressions + - include: value-end-pop + - include: map-separator + + map-of-types: + # https://www.erlang.org/doc/reference_manual/data_types.html#map + # https://www.erlang.org/doc/reference_manual/expressions.html#map-expressions + - match: '#{' + scope: meta.mapping.erlang punctuation.section.mapping.begin.erlang + push: + - include: map-common + # filter + - match: \|\| + scope: meta.mapping.erlang keyword.operator.comprehension.erlang + push: + - meta_content_scope: meta.mapping.filter.erlang + - include: type-expressions + - include: value-end-pop + # value + - match: =>|\:= + scope: meta.mapping.erlang punctuation.separator.key-value.erlang + push: + - meta_content_scope: meta.mapping.value.erlang + - match: (?=\|\|) + pop: 1 + - include: type-expressions + - include: value-end-pop + # key + - match: ',?' + scope: meta.mapping.erlang punctuation.separator.sequence.erlang + push: + - meta_content_scope: meta.mapping.key.erlang + - match: (?==>|\:=|\|\|) + pop: 1 + - include: type-expressions + - include: value-end-pop + - include: map-separator + + map-separator: + - match: =>|\:= + scope: punctuation.separator.key-value.erlang + + map-common: + - match: \} + scope: meta.mapping.erlang punctuation.section.mapping.end.erlang + pop: 1 + - include: clause-end-or-stray + +###[ RECORDS ]################################################################ + + record: + # https://www.erlang.org/doc/reference_manual/records.html + - match: \#(?={{ident}}) + scope: punctuation.definition.record.erlang + push: [record-fields, record-name, variable-other-record] + # records may look like normal variables in macro definitions + - match: '{{variable}}(?=\.{{ident}})' + scope: meta.record.identifier.erlang variable.other.readwrite.erlang + push: record-fields + + record-name: + - meta_scope: meta.record.identifier.erlang + - include: else-pop + + variable-other-record: + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang storage.type.record.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang storage.type.record.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + + record-fields: + - include: record-field-access + - include: record-fields-declaration + + record-field-access: + - match: \. + scope: meta.record.erlang punctuation.accessor.dot.erlang + set: + - record-field-access-meta + - record-field-access-name + + record-field-access-meta: + - meta_content_scope: meta.record.field.erlang + - include: immediately-pop + + record-field-access-name: + - include: variable-other-field + - include: eol-pop + + record-fields-declaration: + - match: \{ + scope: punctuation.section.fields.begin.erlang + set: record-fields-declaration-common + - include: else-pop + + record-fields-declaration-common: + - meta_scope: meta.record.fields.erlang + - match: \} + scope: punctuation.section.fields.end.erlang + pop: 1 + - include: clause-end-or-stray + # field value + - match: = + scope: meta.field.erlang keyword.operator.assignment.erlang + push: record-field-value + # field type + - match: '::' + scope: meta.field.erlang punctuation.separator.variable-type.erlang + push: record-field-type + # field identifier + - match: ',?' + scope: punctuation.separator.expressions.erlang + push: + - record-field-identifier-meta + - record-field-identifier + + record-field-identifier-meta: + - meta_content_scope: meta.field.identifier.erlang + - include: immediately-pop + + record-field-identifier: + - include: variable-anonymous-pop + - include: variable-other-field + + record-field-type: + - meta_content_scope: meta.field.type.erlang + - include: type-expressions + - include: value-end-pop + + record-field-value: + - meta_content_scope: meta.field.value.erlang + - match: (?=::) + pop: 1 + - include: expressions + - include: value-end-pop + + variable-other-field: + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang variable.other.member.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang variable.other.member.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + +###[ TUPLES ]################################################################# + + tuple-of-expressions: + # https://www.erlang.org/doc/reference_manual/data_types.html#tuple + - match: \{ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.tuple.erlang + - include: tuple-common + - include: expressions + + tuple-of-function-parameters: + # https://www.erlang.org/doc/reference_manual/data_types.html#tuple + - match: \{ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.tuple.erlang + - include: tuple-common + - include: function-parameter + + tuple-of-types: + # https://www.erlang.org/doc/reference_manual/data_types.html#tuple + - match: \{ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.tuple.erlang + - include: variadic-operators + - include: tuple-common + - include: type-expressions + + tuple-of-type-parameters: + # https://www.erlang.org/doc/reference_manual/data_types.html#tuple + - match: \{ + scope: punctuation.section.sequence.begin.erlang + push: + - meta_scope: meta.sequence.tuple.erlang + - include: variadic-operators + - include: tuple-common + - include: type-parameter + + tuple-common: + - match: \} + scope: punctuation.section.sequence.end.erlang + pop: 1 + - include: operator-comprehension + - include: separator-sequence + - include: clause-end-or-stray + +###[ KEYWORDS ]############################################################### + + constant: + # https://www.erlang.org/doc/reference_manual/data_types.html#boolean + - match: false{{ident_break}} + scope: constant.language.boolean.false.erlang + - match: true{{ident_break}} + scope: constant.language.boolean.true.erlang + # https://www.erlang.org/doc/reference_manual/errors.html#exceptions + - match: (error|exit|ok|throw){{ident_break}} + scope: constant.language.exception.type.erlang + - match: (badarg|badarith|badmatch|function_clause|case_clause|if_clause|try_clause|undef|badfun|badarity|timeout_value|noproc|nocatch|system_limit){{ident_break}} + scope: constant.language.exception.reason.erlang + # https://www.erlang.org/doc/reference_manual/records.html#defining-records + - match: (none|undefined){{ident_break}} + scope: constant.language.undefined.erlang + # https://www.erlang.org/doc/man/erlang.html#data-types + - match: (off_heap|on_heap){{ident_break}} + scope: constant.language.message-queue-data.erlang + - match: ((milli|micro|nano)?second|native|perf_counter|infinity){{ident_break}} + scope: constant.language.time.erlang + - match: ((milli|micro|nano)_)?seconds{{ident_break}} + scope: constant.language.time.erlang invalid.deprecated.erlang + + keyword: + # keywords which are not otherwise matched already and don't need fallbacks + - match: catch{{ident_break}} + scope: keyword.control.exception.erlang + - match: (after|cond|end|let|of){{ident_break}} + scope: keyword.control.flow.erlang + + illegal-type-keyword: + # The following keywords are not part of the type/spec language and must + # not be used as types/constants as they are part of the reserved words. + # https://www.erlang.org/doc/reference_manual/introduction.html#reserved-words + - match: (after|andalso|begin|case|catch|cond|end|if|let|of|orelse|receive|try|when){{ident_break}} + scope: invalid.illegal.keyword.erlang + +###[ NAMESPACE ]############################################################## + + namespace: + - match: (?={{ident}}\s*:[^:=]) + push: [namespace-member, namespace-accessor, namespace-qualifier] + + namespace-pop: + - match: (?={{ident}}\s*:[^:=]) + set: [namespace-member, namespace-accessor, namespace-qualifier] + + type-namespace: + - match: (?={{ident}}\s*:[^:=]) + push: [type-namespace-member, namespace-accessor, namespace-qualifier] + + namespace-member: + - meta_scope: meta.path.erlang + - include: function-call-pop + - match: (?=\S)|$ + set: [namespace-meta, namespace-member-other] + + type-namespace-member: + - meta_scope: meta.path.erlang + - include: type-call-pop + - match: (?=\S)|$ + set: [namespace-meta, namespace-member-other] + + namespace-meta: + - meta_scope: meta.path.erlang + - include: immediately-pop + + namespace-member-other: + - include: reference-pop + - include: constant + - include: atom-pop + - include: macro-pop + - include: variable-other-pop + - include: immediately-pop + + namespace-accessor: + - match: ':' + scope: punctuation.accessor.double-colon.erlang + pop: 1 + + namespace-qualifier: + - match: '{{support_namespaces}}' + scope: meta.atom.erlang support.namespace.erlang + pop: 1 + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang variable.namespace.erlang + pop: 1 + - include: variable-other-pop + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang variable.namespace.erlang + - include: atom-quoted-common + - include: macro-pop + +###[ REFERENCE ]############################################################## + + reference: + - match: (?={{ident}}\s*/) + push: [reference-arity, variable-function] + + reference-pop: + - match: (?={{ident}}\s*/) + set: [reference-arity, variable-function] + + reference-arity: + - meta_content_scope: meta.reference.function.name.erlang + - match: / + scope: meta.reference.function.erlang punctuation.separator.reference.erlang + set: + - reference-arity-meta + - reference-arity-body + - include: else-pop + + reference-arity-meta: + - meta_content_scope: meta.reference.function.arity.erlang + - include: immediately-pop + + reference-arity-body: + - match: \d+ + scope: meta.number.integer.decimal.erlang constant.numeric.value.erlang + pop: 1 + - include: variable-anonymous-pop + - include: variable-other-pop + - include: macro-pop + - match: '{{illegal_ident}}' + scope: invalid.illegal.expect-integer.erlang + pop: 1 + - include: else-pop + +###[ VARIABLE ]############################################################### + + variable-anonymous: + - match: _{{ident_break}} + scope: variable.language.anonymous.erlang + + variable-anonymous-pop: + - match: _{{ident_break}} + scope: variable.language.anonymous.erlang + pop: 1 + + variable-other: + - match: '{{variable}}' + scope: variable.other.readwrite.erlang + + variable-other-pop: + - match: '{{variable}}' + scope: variable.other.readwrite.erlang + pop: 1 + + variable-parameter: + - match: '{{variable}}' + scope: variable.parameter.erlang + +###[ IDENTIFIERS ]############################################################ + + atom: + # https://www.erlang.org/doc/reference_manual/data_types.html#atom + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang constant.other.symbol.erlang + - match: \' + scope: punctuation.definition.atom.begin.erlang + push: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang constant.other.symbol.erlang + - include: atom-quoted-common + + atom-pop: + # https://www.erlang.org/doc/reference_manual/data_types.html#atom + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang constant.other.symbol.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang constant.other.symbol.erlang + - include: atom-quoted-common + + entity-name-function: + # function name must be an atom + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang entity.name.function.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang entity.name.function.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + + entity-name-macro: + - match: '{{ident_unquoted}}' + scope: meta.atom.erlang entity.name.constant.macro.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang entity.name.constant.macro.erlang + - include: atom-quoted-common + - include: macro-pop + - include: ident-expect-end + + entity-name-module: + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang entity.name.namespace.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang entity.name.namespace.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + + entity-name-record: + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang entity.name.record.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang entity.name.record.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + + entity-name-type: + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang entity.name.type.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang entity.name.type.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + + constant-other-macro: + - match: '{{ident_unquoted}}' + scope: meta.atom.erlang constant.other.macro.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang constant.other.macro.erlang + - include: atom-quoted-common + - include: ident-expect-end + + storage-type: + - match: '{{erlang_types}}' + scope: meta.atom.erlang support.type.erlang + pop: 1 + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang storage.type.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang storage.type.erlang + - include: atom-quoted-common + - include: macro-pop + - include: atom-expect-end + + variable-function: + - match: '{{erlang_functions}}' + scope: meta.atom.erlang support.function.erlang + pop: 1 + - match: '{{atom_unquoted}}' + scope: meta.atom.erlang variable.function.erlang + pop: 1 + - match: \' + scope: punctuation.definition.atom.begin.erlang + set: + - meta_include_prototype: false + - meta_scope: meta.atom.erlang variable.function.erlang + - include: atom-quoted-common + - include: variable-other-pop + - include: macro-pop + - include: ident-expect-end + + atom-quoted-common: + - match: \' + scope: punctuation.definition.atom.end.erlang + pop: 1 + - match: (?=\\) + push: escape + + atom-expect-end: + - match: '{{illegal_ident}}' + scope: invalid.illegal.expect-atom.erlang + pop: 1 + - include: else-pop + + ident-expect-end: + - match: '{{illegal_ident}}' + scope: invalid.illegal.expect-identifier.erlang + pop: 1 + - include: else-pop + +###[ ATOMIC DATA TYPES ]###################################################### + + binary: + # https://www.erlang.org/doc/reference_manual/data_types.html#bit-strings-and-binaries + # https://www.erlang.org/doc/reference_manual/expressions.html#bit_syntax + - match: << + scope: punctuation.definition.sequence.begin.erlang + push: + - meta_scope: meta.sequence.binary.erlang + - include: binary-common + - include: expressions-nested + - include: common + - include: variable-other + + binary-function-parameter: + # https://www.erlang.org/doc/reference_manual/data_types.html#bit-strings-and-binaries + # https://www.erlang.org/doc/reference_manual/expressions.html#bit_syntax + - match: << + scope: punctuation.definition.sequence.begin.erlang + push: + - meta_scope: meta.sequence.binary.erlang + - include: binary-common + - include: function-parameter-nested + - include: common + - include: variable-parameter + + binary-type-parameter: + # https://www.erlang.org/doc/reference_manual/data_types.html#bit-strings-and-binaries + # https://www.erlang.org/doc/reference_manual/expressions.html#bit_syntax + - match: << + scope: punctuation.definition.sequence.begin.erlang + push: + - meta_scope: meta.sequence.binary.erlang + - include: binary-common + - include: type-parameter-nested + - include: terms + - include: variable-parameter + + binary-common: + - match: '>>' + scope: punctuation.definition.sequence.end.erlang + pop: 1 + - match: ':' + scope: punctuation.separator.value-size.erlang + - match: / + scope: punctuation.separator.value-type.erlang + push: + - match: (?=>>|[.,;]) + pop: 1 + - match: '-' + scope: punctuation.separator.type-specifiers.erlang + - match: ':' + scope: punctuation.separator.unit-value.erlang + - match: (integer|float|binary|bytes|bitstring|bits|utf8|utf16|utf32){{ident_break}} + scope: storage.type.erlang + - match: (signed|unsigned){{ident_break}} + scope: storage.modifier.signedness.erlang + - match: (big|little|native){{ident_break}} + scope: storage.modifier.endianness.erlang + - match: unit{{ident_break}} + scope: storage.modifier.unit.erlang + - include: number + - include: macro + - include: operator-comprehension + - include: separator-sequence + - include: clause-end-pop + + character: + - match: \$ + scope: constant.character.erlang punctuation.definition.character.erlang + push: + - meta_include_prototype: false + - include: escape + - match: . + scope: constant.character.erlang + pop: 1 + + escape: + # https://www.erlang.org/doc/reference_manual/data_types.html#escape-sequences + - match: (\\)[bdefnrstv\\''"$~] + scope: constant.character.escape.erlang + captures: + 1: punctuation.definition.escape.erlang + pop: 1 + # Character with octal representation + - match: (\\)[0-7]{1,3} + scope: constant.character.escape.erlang + captures: + 1: punctuation.definition.escape.erlang + pop: 1 + # Character with hexadecimal representation + - match: (\\x)\h{2} + scope: constant.character.escape.erlang + captures: + 1: punctuation.definition.escape.erlang + pop: 1 + - match: \\x\{ + scope: punctuation.definition.escape.begin.erlang + set: + - meta_scope: constant.character.escape.erlang + - include: clause-end-pop + - match: \}|$ + scope: punctuation.definition.escape.end.erlang + pop: 1 + - match: \H + scope: invalid.illegal.hex.erlang + - match: (\\x)\S{2} + scope: constant.character.escape.erlang invalid.illegal.escape.erlang + captures: + 1: punctuation.definition.escape.erlang + pop: 1 + # Control A to control Z and Control [, ] seen in default libs + - match: (\\\^)[A-Za-z\[\]] + scope: constant.character.escape.erlang + captures: + 1: punctuation.definition.escape.erlang + pop: 1 + - match: (\\\^?).? + scope: constant.character.escape.erlang invalid.illegal.escape.erlang + captures: + 1: punctuation.definition.escape.erlang + pop: 1 + + macro: + # https://www.erlang.org/doc/reference_manual/macros.html#predefined-macros + - match: (\?{1,2}){{erlang_macros}} + scope: constant.language.macro.erlang + captures: + 1: punctuation.definition.macro.erlang + # https://www.erlang.org/doc/reference_manual/macros.html#defining-and-using-macros + - match: \?{1,2} + scope: + constant.other.macro.erlang + punctuation.definition.macro.erlang + push: constant-other-macro + + macro-pop: + # predefined macro + - match: (\?{1,2}){{erlang_macros}} + scope: constant.language.macro.erlang + captures: + 1: punctuation.definition.macro.erlang + pop: 1 + # user defined macro + - match: \?{1,2} + scope: + constant.other.macro.erlang + punctuation.definition.macro.erlang + set: constant-other-macro + + number: + # https://www.erlang.org/doc/reference_manual/data_types.html#number + - match: \d[\d_]*(\.)[\d_]+([eE][-+]?[\d_]+)?\b + scope: meta.number.float.decimal.erlang constant.numeric.value.erlang + captures: + 1: punctuation.separator.decimal.erlang + - match: (2\#)([0-1_]+)\b + scope: meta.number.integer.binary.erlang + captures: + 1: constant.numeric.base.erlang + 2: constant.numeric.value.erlang + - match: (8\#)([0-7_]+)\b + scope: meta.number.integer.octal.erlang + captures: + 1: constant.numeric.base.erlang + 2: constant.numeric.value.erlang + - match: (10\#)([0-9_]+)\b + scope: meta.number.integer.decimal.erlang + captures: + 1: constant.numeric.base.erlang + 2: constant.numeric.value.erlang + - match: (16\#)([\da-fA-F_]+)\b + scope: meta.number.integer.hexadecimal.erlang + captures: + 1: constant.numeric.base.erlang + 2: constant.numeric.value.erlang + - match: |- + (?x: + (3\#)([0-2_]+) + | (4\#)([0-3_]+) + | (5\#)([0-4_]+) + | (6\#)([0-5_]+) + | (7\#)([0-6_]+) + | (9\#)([0-8_]+) + | (11\#)([\daA_]+) + | (12\#)([\da-bA-B_]+) + | (13\#)([\da-cA-C_]+) + | (14\#)([\da-dA-D_]+) + | (15\#)([\da-eA-E_]+) + | (17\#)([\da-gA-G_]+) + | (18\#)([\da-hA-H_]+) + | (19\#)([\da-iA-I_]+) + | (20\#)([\da-jA-J_]+) + | (21\#)([\da-kA-K_]+) + | (22\#)([\da-lA-L_]+) + | (23\#)([\da-mA-M_]+) + | (24\#)([\da-nA-N_]+) + | (25\#)([\da-oA-O_]+) + | (26\#)([\da-pA-P_]+) + | (27\#)([\da-qA-Q_]+) + | (28\#)([\da-rA-R_]+) + | (29\#)([\da-sA-S_]+) + | (30\#)([\da-tA-T_]+) + | (31\#)([\da-uA-U_]+) + | (32\#)([\da-vA-V_]+) + | (33\#)([\da-wA-W_]+) + | (34\#)([\da-xA-X_]+) + | (35\#)([\da-yA-Y_]+) + | (36\#)([\da-zA-Z_]+) + )\b + scope: meta.number.integer.other.erlang + captures: + 1: constant.numeric.base.erlang + 2: constant.numeric.value.erlang + 3: constant.numeric.base.erlang + 4: constant.numeric.value.erlang + 5: constant.numeric.base.erlang + 6: constant.numeric.value.erlang + 7: constant.numeric.base.erlang + 8: constant.numeric.value.erlang + 9: constant.numeric.base.erlang + 10: constant.numeric.value.erlang + 11: constant.numeric.base.erlang + 12: constant.numeric.value.erlang + 13: constant.numeric.base.erlang + 14: constant.numeric.value.erlang + 15: constant.numeric.base.erlang + 16: constant.numeric.value.erlang + 17: constant.numeric.base.erlang + 18: constant.numeric.value.erlang + 19: constant.numeric.base.erlang + 20: constant.numeric.value.erlang + 21: constant.numeric.base.erlang + 22: constant.numeric.value.erlang + 23: constant.numeric.base.erlang + 24: constant.numeric.value.erlang + 25: constant.numeric.base.erlang + 26: constant.numeric.value.erlang + 27: constant.numeric.base.erlang + 28: constant.numeric.value.erlang + 29: constant.numeric.base.erlang + 30: constant.numeric.value.erlang + 31: constant.numeric.base.erlang + 32: constant.numeric.value.erlang + 33: constant.numeric.base.erlang + 34: constant.numeric.value.erlang + 35: constant.numeric.base.erlang + 36: constant.numeric.value.erlang + 37: constant.numeric.base.erlang + 38: constant.numeric.value.erlang + 39: constant.numeric.base.erlang + 40: constant.numeric.value.erlang + 41: constant.numeric.base.erlang + 42: constant.numeric.value.erlang + 43: constant.numeric.base.erlang + 44: constant.numeric.value.erlang + 45: constant.numeric.base.erlang + 46: constant.numeric.value.erlang + 47: constant.numeric.base.erlang + 48: constant.numeric.value.erlang + 49: constant.numeric.base.erlang + 50: constant.numeric.value.erlang + 51: constant.numeric.base.erlang + 52: constant.numeric.value.erlang + 53: constant.numeric.base.erlang + 54: constant.numeric.value.erlang + 55: constant.numeric.base.erlang + 56: constant.numeric.value.erlang + 57: constant.numeric.base.erlang + 58: constant.numeric.value.erlang + 59: constant.numeric.base.erlang + 60: constant.numeric.value.erlang + 61: constant.numeric.base.erlang + 62: constant.numeric.value.erlang + - match: \d+\#\S+ + scope: invalid.illegal.integer.erlang + - match: \d[\d_]*\b + scope: meta.number.integer.decimal.erlang constant.numeric.value.erlang + - match: \d\w+ + scope: invalid.illegal.integer.erlang + + string: + # https://www.erlang.org/doc/reference_manual/data_types.html#string + - match: \" + scope: punctuation.definition.string.begin.erlang + push: string-body + + string-body: + - meta_include_prototype: false + - meta_scope: string.quoted.double.erlang + - match: \" + scope: punctuation.definition.string.end.erlang + pop: 1 + - match: (?=\\) + push: escape + # https://www.erlang.org/doc/man/io.html + # The general format of a control sequence is ~F.P.PadModC. + - match: |- + (?x: + (~) + (?: (\-?\*) | (\-?\d+) )? # F - field width + (?: + (\.) (?: (\*) | (\d+) )? # P - precision + (?: (\.) (.) )? # Pad - padding character + )? + ([lt]{0,2}) # Mod - control modifier + ([~cfegswpWPBX#bx\+ni]) # C - control sequence + ) + captures: + 1: constant.other.placeholder.erlang punctuation.definition.placeholder.erlang + 2: constant.other.placeholder.width.asterisk.erlang + 3: constant.other.placeholder.width.integer.erlang + 4: constant.other.placeholder.precision.erlang punctuation.separator.placeholder.erlang + 5: constant.other.placeholder.precision.asterisk.erlang + 6: constant.other.placeholder.precision.integer.erlang + 7: constant.other.placeholder.separator.erlang punctuation.separator.placeholder.erlang + 8: constant.other.placeholder.padding.character.erlang + 9: constant.other.placeholder.control.modifier.erlang + 10: constant.other.placeholder.control.character.erlang + + string-maybe-env: + - match: (\$){{ident_unquoted}} + scope: variable.language.environment.erlang + captures: + 1: punctuation.definition.variable.erlang + pop: 1 + - include: else-pop + +###[ OPERATORS ]############################################################## + + variadic-operators: + - match: \.{3} + scope: keyword.operator.variadic.erlang + + operator-comprehension: + - match: \|\| + scope: keyword.operator.comprehension.erlang + + operator-unary: + # https://www.erlang.org/doc/reference_manual/expressions.html#list-comprehensions + - match: <=|<- + scope: keyword.operator.generator.erlang + # https://www.erlang.org/doc/reference_manual/expressions.html#term-comparisons + - match: =/=|=:=|/=|==|=<|>=|=!|>|< + scope: keyword.operator.comparison.erlang + # https://www.erlang.org/doc/reference_manual/expressions.html#list-operations + - match: \+\+|-- + scope: keyword.operator.lists.erlang + # https://www.erlang.org/doc/reference_manual/expressions.html#arithmetic-expressions + - match: '[-+*/]' + scope: keyword.operator.arithmetic.erlang + - match: '[=!]' + scope: keyword.operator.assignment.erlang + + operator: + # https://www.erlang.org/doc/reference_manual/expressions.html#arithmetic-expressions + - match: (div|rem){{ident_break}} + scope: keyword.operator.arithmetic.erlang + - match: (band|bor|bxor|bnot|bsl|bsr){{ident_break}} + scope: keyword.operator.bitwise.erlang + # https://www.erlang.org/doc/reference_manual/expressions.html#boolean-expressions + # https://www.erlang.org/doc/reference_manual/expressions.html#short-circuit-expressions + - match: (and|or|xor|not|andalso|orelse){{ident_break}} + scope: keyword.operator.logical.erlang + +###[ SEPARATORS ]############################################################# + + separator-clauses: + - match: ';' + scope: punctuation.separator.clauses.erlang + + separator-expressions: + - match: ',' + scope: punctuation.separator.expressions.erlang + + separator-sequence: + - match: ',' + scope: punctuation.separator.sequence.erlang + + separator-type: + - match: \.\. + scope: punctuation.separator.range.erlang + - match: '::' + scope: punctuation.separator.variable-type.erlang + + separator-union: + - match: \| + scope: punctuation.separator.sequence.erlang + + terminator-clause: + - match: \. + scope: punctuation.terminator.clause.erlang + + terminator-clause-pop: + - match: \. + scope: punctuation.terminator.clause.erlang + pop: 1 + +###[ ARGUMENTS ]############################################################## + + arguments-common: + - include: arguments-end + - match: ',' + scope: punctuation.separator.arguments.erlang + + arguments-end: + - match: \) + scope: punctuation.section.arguments.end.erlang + pop: 1 + - include: clause-end-or-stray + + expect-arguments-end: + - include: arguments-end + - include: illegal-group + - match: \S + scope: invalid.illegal.expect-arguments-end.erlang + + expect-arguments-separator: + - match: ',' + scope: punctuation.separator.arguments.erlang + pop: 1 + - match: \s+(?!,) + scope: invalid.illegal.expect-separator.erlang + pop: 1 + - include: else-pop + +###[ CONTEXT POP OFFS ]####################################################### + + parameters-common: + - match: \) + scope: punctuation.section.parameters.end.erlang + pop: 1 + - match: ',' + scope: punctuation.separator.parameters.erlang + - include: clause-end-or-stray + + parameters-end-pop: + # bailout from parameter lists if guard or clause body starts + - match: (?=->|when{{ident_break_char}}) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + eol-pop: + - match: $ + pop: 1 + + else-pop: + - match: (?=\S) + pop: 1 + + clause-end-pop: + - match: (?=[.;]) + pop: 1 + + clause-end-or-stray: + - include: clause-end-pop + - include: illegal-stray + + value-end-pop: + # a `value body` ends with + # - the end of a clause (`;` or `.`) + # - the end of a clause body (`end`, `after`, `catch`) + # - the end of a section (`)`, `]`, `}`) + # - an separator (`,`, `:`) + - match: (?=->|[,:.;)}\]]|(end|after|catch){{ident_break_char}}) + pop: 1 + +###[ ILLEGALS ]############################################################### + + illegal-group: + # Note: To try to prevent breaking highlighting it is important to keep + # parens/brackets/braces in balance if the opening bracket is not + # expected at its current position and marked illegal. + - match: \( + push: + - meta_scope: invalid.illegal.unexpected-group.erlang + - match: \) + pop: 1 + - include: illegal-group-body + - match: \[ + push: + - meta_scope: invalid.illegal.unexpected-list.erlang + - match: \] + pop: 1 + - include: illegal-group-body + - match: \#?\{ + push: + - meta_scope: invalid.illegal.unexpected-tuple.erlang + - match: \} + pop: 1 + - include: illegal-group-body + + illegal-group-body: + # consume numbers to prevent matching decimal separator as clause-end + - match: \d+\.\d*|\.\d+ + - include: clause-end-pop + - match: \( + push: + - match: \) + pop: 1 + - include: illegal-group-body + - match: \[ + push: + - match: \] + pop: 1 + - include: illegal-group-body + - match: \#?\{ + push: + - match: \} + pop: 1 + - include: illegal-group-body + + illegal-stray: + - match: '[)\]}]' + scope: invalid.illegal.stray.erlang
diff --git /dev/null b/syntax/Gap/Gap.sublime-syntax @@ -0,0 +1,73 @@ +%YAML 1.2 +--- +# Based on: https://github.com/ThGroth/sublimeGapSyntax +name: gap +file_extensions: [g, gi, gd] +scope: source.gap + +contexts: + main: + - include: comment + - include: keyword + - include: support + - include: function-definition + - include: string + - include: loop + - include: list + + comment: + - match: '(#).*\n?' + scope: comment.line.number-sign.gap + + keyword: + - match: '->' + scope: keyword.control.gap + - match: '\b(?:if|then|else|elif|fi|for|in|do|od|end|continue|while|until|return|Error)\b' + scope: keyword.control.gap + - match: '(?<![-/])\b(?:local)\b' + scope: storage.modifier.gap + - match: '(?<![-/])\b(?:Assert|Info|IsBound|QUIT|TryNextMethod|Unbind|mod|quit|rec)\b' + scope: keyword.control.gap + - match: '<=?|>=?|=' + scope: keyword.control.gap + - match: '\b(?:and|or|not)\b' + scope: keyword.control.gap + + support: + - match: '(?<![-/])\b(?:DeclareOperation|DeclareGlobalFunction|DeclareGlobalVariable|DeclareAttribute|DeclareProperty|DeclareCategory|DeclareFilter|DeclareRepresentation|DeclareInfoClass|DeclareCategoryCollections|DeclareSynonym)' + scope: support.function.declare.gap + - match: '(?<![-/])\b(?:InstallMethod|InstallOtherMethod|NewType|Objectify|NewFamily|InstallTrueMethod|InstallGlobalFunction|ObjectifyWithAttributes|BindGlobal|BIND_GLOBAL|InstallValue)' + scope: support.function.install.gap + + function-definition: + - match: ':=' + scope: keyword.operator.assign.gap + - match: '\bfunction\b' + scope: storage.type.function.gap + + loop: + - match: '\b(while|until)\b' + scope: keyword.control.gap + - match: '\b(od)\b' + scope: keyword.control.gap + - match: '\b(if)\b' + scope: keyword.control.gap + - match: '\b(fi)\b' + scope: keyword.control.gap + + list: + - match: ';|&&|&|\|\|' + scope: keyword.operator.list.gap + + string: + # double-quoted strings (no multiline) + - match: '"(?:\\\\.|[^"\\\\])*"' + scope: string.quoted.double.gap + # your tmLanguage also highlighted escape sequences; keep a fallback + - match: '\\.' + scope: constant.character.escape.gap + # if the tool/scopes need opening quote tokens too, keep these as well + - match: "'" + scope: punctuation.definition.string.begin.gap + - match: '"' + scope: punctuation.definition.string.begin.gap
diff --git /dev/null b/syntax/Go/Go.sublime-syntax @@ -0,0 +1,1654 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html + +# The structure and lexicon of this syntax reflects the Go spec: +# https://golang.org/ref/spec + +# The following is a simplified model of Sublime Text's syntax engine, reverse- +# engineered through experience. This model uses assertive language for brevity, +# but does not reflect the real implementation and should not be taken +# literally. Still, it helps a LOT, and is necessary for understanding this +# syntax. +# +# The engine has a stack of rulesets. The topmost frame is the current ruleset: +# +# rulesets: +# # current +# - [ +# {match: '...', scope: '...'}, +# {match: '...', scope: '...'}, +# {match: '...', scope: '...'}, +# ], +# # other +# - [...] +# +# The engine appears to use three nested loops: (1) lines, (2) character +# positions, and (3) rules. +# +# First, the engine loops through lines. On each line, it loops through char +# positions. On each char position, it loops through rules. It also loops +# through rules on at least two special "positions" that don't correspond to a +# character: start of line and end of line. +# +# For each rule, the engine runs its regex against the remainder of the line, +# which may also start with ^ or consist entirely of $. Note that older syntax +# engine(s) supported multiline regexes, but this has been deprecated for +# performance reasons. +# +# Each rule may "consume" 0 to N characters, optionally assigning scopes. In +# addition, the rule may modify the rule stack with `push / pop / set`. +# Consuming characters advances the character loop. Consuming characters OR +# modifying the rule stack also resets the RULE loop; the engine will continue +# from the next character and the FIRST rule in the then-current ruleset. +# +# Rules that consume ZERO characters and DON'T modify the stack also DON'T reset +# the rule loop. We must be mindful of this behavior. Regexes for such rules +# typically look like this: (?=\S) or $. If they did reset the rule loop, it +# would cause an infinite loop in the engine. +# +# Another potential gotcha: the engine will loop through the rules at the end of +# each line, where there aren't any characters to match. The only matches are $ +# or its derivatives such as (?=$). Rules intended to work across multiple +# lines, for example to trim whitespace and comments, may be unexpectedly +# interrupted by sibling rules with $. + +name: Go +scope: source.go +version: 2 + +file_extensions: + - go + +variables: + # https://golang.org/ref/spec#Keywords + # These are the only words that can't be used as identifiers. + keyword: \b(?:break|case|chan|const|continue|default|defer|else|fallthrough|for|func|go|goto|if|import|interface|map|package|range|return|select|struct|switch|type|var)\b + + # https://golang.org/ref/spec#Predeclared_identifiers + predeclared_type: \b(?:any|bool|byte|comparable|complex64|complex128|error|float32|float64|int|int8|int16|int32|int64|rune|string|uint|uint8|uint16|uint32|uint64|uintptr)\b + + # https://golang.org/ref/spec#Predeclared_identifiers + predeclared_func: \b(?:append|cap|close|complex|copy|delete|imag|len|make|new|panic|print|println|real|recover)\b + + ident_anon: \b_\b + + # Note: this matches ALL valid identifiers, including predeclared constants, + # functions and types. + ident: (?!{{keyword}}){{keyword_or_ident}} + + keyword_or_ident: \b[[:alpha:]_][[:alnum:]_]*\b + + # Heuristic to scope types, assuming they start with upper case + type_ident: \b[[:upper:]_][[:alnum:]_]*\b + + # Sublime normalizes newlines from `\r\n` and `\r` into `\n`. Sublime's syntax + # engine uses regexps line-by-line, so `$` is often equivalent to `\n`. For + # semantic accuracy, we should use `\n` when possible. However, the last line + # in a file may end with `$` INSTEAD of `\n`, so we must try both. + newline: (?:\n|$) + + # Directive comment key. + directive: \b[[:alpha:]_-][[:alnum:]_-]*\b + + # Single-line general comment. + inline_comment: /[*](?:[^*]|[*](?!/))*[*]/ + + # Whitespace and general comments on a single line. + # This should only be used for lookahead, not for capturing / scoping. + noise: (?:\s|{{inline_comment}})* + + dec_exponent: (?:[eE][-+]??{{dec_digits}}) + hex_exponent: (?:[pP][-+]??{{dec_digits}}) + + # Matches a digit with any number of numeric separators, while + # not allowing a numeric separator as the last or first character. + dec_digits: (?:\d+(?:_\d+)*) + + # Hexadecimal counterpart to dec_digits. + hex_digits: (?:_?\h+(?:_\h+)*) + + # Octal counterpart to dec_digits. + oct_digits: (?:_?[0-7]+(?:_[0-7]+)*) + + # Binary counterpart to dec_digits. + bin_digits: (?:_?[01]+(?:_[01]+)*) + + # Should be used only for lookahead. Syntactically ambiguous with many other + # uses of square brackets. Should be used ONLY in contexts where the use of + # brackets is unambiguous. + # + # Known defect: fails to recognize multiline type argument lists. + # We should convert from lookahead to branching. + type_argument_list: |- + (?x: + \[ (?: + {{noise}} + | \[ (?: + {{noise}} + | \[ (?: + {{noise}} + | \[ (?: + {{noise}} + | \[ (?: + {{noise}} + | \[ (?: + {{noise}} + | [^\[\]] + )* \] + | [^\[\]] + )* \] + | [^\[\]] + )* \] + | [^\[\]] + )* \] + | [^\[\]] + )* \] + | [^\[\]] + )* \] + ) + + iface_entry_delim: (?://|;|\}|{{newline}}) + struct_entry_delim: (?:"|`|{{iface_entry_delim}}) + struct_embed_argument_list: '{{type_argument_list}}{{noise}}{{struct_entry_delim}}' + + operator_char: '[!%&*+/:<=>^|-]' + operator_break: (?!{{operator_char}}) + + # Tokens that may signify the beginning of a type. Should be used only for + # lookahead, and only in contexts where this is unambiguous with other + # expressions. Doesn't include `*` because inside brackets, it would be + # ambiguous with multiplication, which may be used for array size. + type_begin: (?:~|\[|{{keyword_or_ident}}) + +contexts: + prototype: + - include: match-comments + + main: + - include: match-any + + match-any: + - include: match-tokens + + # https://golang.org/ref/spec#Comments + match-comments: + - include: match-comment-line + - include: match-comment-general + - include: merge-conflict-markers + + pop-line-annotation: + - meta_scope: comment.line.double-slash.go + - meta_content_scope: meta.annotation.parameters.go + - include: pop-on-eol + + match-comment-line: + - match: // + scope: punctuation.definition.comment.go + push: pop-comment-line-normal + + pop-comment-line-normal: + - meta_scope: comment.line.double-slash.go + - include: pop-on-eol + + match-comment-general: + - match: /\* + scope: punctuation.definition.comment.begin.go + push: pop-comment-general + + pop-comment-general: + - meta_scope: comment.block.go + - match: \*/ + scope: punctuation.definition.comment.end.go + pop: 1 + # Indentation, followed by exactly one space, followed by *. + # This enables support for javadoc comments, while avoiding false + # positives in non-javadoc comments that use "*" as simple list bullets. + - match: ^(?:\t|[ ]{2}|[ ]{4}|[ ]{8})*[ ](\*)(?!/) + captures: + 1: punctuation.definition.comment.go + - include: merge-conflict-markers + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + + # https://golang.org/ref/spec#Tokens + # + # Nominally, this should include `match-call-or-type-conversion`; instead, + # it's specified in `match-parens` to ensure proper ordering. + match-tokens: + - include: match-keywords + - include: match-identifiers + - include: match-literals + - include: match-operators + - include: match-punctuation + + # https://golang.org/ref/spec#Keywords + match-keywords: + - include: match-keyword-break + - include: match-keyword-case + - include: match-keyword-chan + - include: match-keyword-const + - include: match-keyword-continue + - include: match-keyword-default + - include: match-keyword-defer + - include: match-keyword-else + - include: match-keyword-fallthrough + - include: match-keyword-for + - include: match-keyword-func + - include: match-keyword-go + - include: match-keyword-goto + - include: match-keyword-if + - include: match-keyword-import + - include: match-keyword-interface + - include: match-keyword-map + - include: match-keyword-package + - include: match-keyword-range + - include: match-keyword-return + - include: match-keyword-select + - include: match-keyword-struct + - include: match-keyword-switch + - include: match-keyword-type + - include: match-keyword-var + + # See `match-selector` for field scoping. + match-identifiers: + - include: match-predeclared-constants + - include: match-call-or-type-conversion + - include: match-short-variable-declarations + - include: match-identifier-anon + - match: '{{ident}}' + scope: variable.other.go + + # https://golang.org/ref/spec#Predeclared_identifiers + # + # In Go, the predeclared constants are not keywords, and can be redefined. In + # many places such as variable declarations, types, function names, etc, we + # allow them to be scoped the same way as other identifiers. This "constant" + # rule should be used in places that are "left over". Detecting redefinition + # would be ideal, but is beyond the scope of this syntax engine; we simply + # expect it to be very rare. + match-predeclared-constants: + - match: \bfalse\b + scope: constant.language.boolean.false.go + - match: \btrue\b + scope: constant.language.boolean.true.go + - match: \bnil\b + scope: constant.language.null.go + + # Reference: https://golang.org/ref/spec#Predeclared_identifiers + # + # Note: in Go, calls and type conversions are syntactically identical. + # Detecting type conversions and scoping them as types is beyond the + # capabilities of this syntax engine. + # + # # Notes on built-in functions + # + # Most built-in functions don't need special syntactic support. We scope them + # for the benefit of the users who prefer to distinguish them from + # user-defined identifiers. Two exceptions are `make` and `new`, where the + # first argument is scoped as a type, matching the special-case support in + # the compiler. When built-ins are redefined, this leads to incorrect + # scoping; like with constants, we expect such redefinition to be very rare. + # + # Note that we limit this detection to plain function calls, ignoring method + # calls and other identifier occurrences. The language currently allows + # built-in functions ONLY in a function call position. This helps minimize + # false positives. + # + # # Notes on built-in types + # + # Unlike type conversions involving a user-defined type, type conversions + # involving built-in types could be scoped purely as types rather than + # function calls, hoping that they haven't been redefined as functions. + # However, we stick to `variable.function.go` to make the treatment of + # built-ins purely additive, allowing the user to opt out. + match-call-or-type-conversion: + - include: match-identifier-anon + - match: \b(?:make|new)\b(?=(?:{{noise}}\))*{{noise}}\() + scope: variable.function.go support.function.builtin.go + push: pop-arguments-starting-with-type + - match: '{{predeclared_type}}(?=(?:{{noise}}\))*{{noise}}\()' + scope: variable.function.go support.type.builtin.go + - match: '{{predeclared_func}}(?=(?:{{noise}}\))*{{noise}}\()' + scope: variable.function.go support.function.builtin.go + - match: '{{ident}}(?=(?:{{noise}}\))*(?:{{noise}}{{type_argument_list}})?{{noise}}\()' + scope: variable.function.go + push: pop-type-argument-list + - match: '{{ident}}(?=(?:{{noise}}\))*{{noise}}\()' + scope: variable.function.go + + # Note: this currently doesn't work across multiple lines. + match-short-variable-declarations: + - match: (?={{ident}}(?:{{noise}},{{noise}}{{ident}})*{{noise}}:=) + push: + - include: match-identifier-anon + - match: '{{ident}}' + scope: variable.other.readwrite.declaration.go + - include: match-comma + - include: pop-before-nonblank + + match-identifier-anon: + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + + pop-identifier-anon: + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + pop: 1 + + # https://golang.org/ref/spec#Operators_and_punctuation + # + # Note: pipe "|" is not always bitwise. In type unions + # it should be scoped differently. + match-operators: + - match: '<<=|>>=|&\^=|&=|\^=|\|=|%=|\+=|-=|\*=|/=|\+\+|--' + scope: keyword.operator.assignment.augmented.go + - match: '<-|:=' + scope: keyword.operator.assignment.go + - match: '&\^|<<|>>' + scope: keyword.operator.bitwise.go + - match: '==|!=|<=|>=|<|>' + scope: keyword.operator.comparison.go + - match: '=' + scope: keyword.operator.assignment.go + - match: '&&|\|\||!' + scope: keyword.operator.logical.go + - match: '[|^]' + scope: keyword.operator.bitwise.go + - match: '[-+/%]' + scope: keyword.operator.arithmetic.go + - match: '[*&~]' + scope: keyword.operator.go + + # Special characters that in some contexts may precede a type. + # Not all of them are allowed in all contexts. + # Bundling them together simplifies our syntax implementation. + match-type-operators: + - include: match-star + - include: match-union-pipe + + match-star: + - match: \*{{operator_break}} + scope: keyword.operator.go + + match-union-pipe: + - match: \|{{operator_break}} + scope: keyword.operator.go + + # https://golang.org/ref/spec#Operators_and_punctuation + match-punctuation: + - include: match-comma + - include: match-ellipsis + - include: match-colon + - include: match-semicolon + - include: match-selector + - include: match-parens + - include: match-brackets + - include: match-braces + + match-comma: + - match: \, + scope: punctuation.separator.go + + match-ellipsis: + - match: \.\.\. + scope: keyword.operator.variadic.go + + match-colon: + - match: ':' + scope: punctuation.separator.go + + match-semicolon: + - match: ; + scope: punctuation.terminator.go + + match-selector: + - match: \. + scope: punctuation.accessor.dot.go + push: pop-selector + + pop-selector: + - match: '{{ident_anon}}(?!{{noise}}\()' + scope: variable.language.anonymous.go + pop: 1 + - match: '{{ident}}(?!{{noise}}{{type_argument_list}}?\()' + scope: variable.other.member.go + pop: 1 + - match: \( + scope: punctuation.section.parens.begin.go + set: pop-type-assertion + - include: pop-before-nonblank + + pop-type-assertion: + - include: pop-on-paren-end + - include: match-type + + match-parens: + - match: \( + scope: punctuation.section.parens.begin.go + push: pop-parens-inner + - match: \) + scope: invalid.illegal.go + + pop-parens-inner: + - include: pop-on-paren-end + - include: match-any + + match-brackets: + - match: \[ + scope: punctuation.section.brackets.begin.go + push: [pop-after-brackets, pop-brackets-inner] + - match: \] + scope: invalid.illegal.go + + pop-brackets-inner: + - match: '' + pop: 1 + branch_point: point-brackets-inner + branch: + - pop-brackets-inner-type-parameter-list + - pop-brackets-inner-any + + pop-brackets-inner-type-parameter-list: + - match: (?={{ident}}{{noise}}(?:,|{{type_begin}})) + set: pop-type-parameter-list-inner + - match: (?=\S) + fail: point-brackets-inner + + pop-brackets-inner-any: + - include: pop-on-bracket-end + - include: match-any + + pop-after-brackets: + - include: pop-before-terminator + - include: pop-type-identifier + + # TODO: consider detecting composite literals. In principle, it should allow + # us to drop the erroneous "meta.block" from composite literals, detect field + # names, and also detect labeled statements by disambiguating them from field + # names. + # + # For future reference: + # + # https://golang.org/ref/spec#Composite_literals + # https://golang.org/ref/spec#Labeled_statements + match-braces: + - match: \{ + scope: punctuation.section.braces.begin.go + push: [meta-block, pop-braces-inner] + - match: \} + scope: invalid.illegal.go + + pop-braces-inner: + - include: pop-on-brace-end + - include: match-any + + match-literals: + - include: match-imaginary + - include: match-floats + - include: match-integers + - include: match-runes + - include: match-strings + + match-imaginary: + # Decimal imaginary numbers + - match: '({{dec_digits}}(?:(\.){{dec_digits}}?)?{{dec_exponent}}?)(i)' + scope: meta.number.imaginary.decimal.go + captures: + 1: constant.numeric.value.go + 2: punctuation.separator.decimal.go + 3: constant.numeric.suffix.go + # Hexadecimal imaginary numbers + - match: (0[xX])({{hex_digits}}?(?:(\.){{hex_digits}}?)?{{hex_exponent}}?)(i) + scope: meta.number.imaginary.hexadecimal.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + 3: punctuation.separator.decimal.go + 4: constant.numeric.suffix.go + # Octal imaginary numbers + - match: (0[oO])({{oct_digits}})(i) + scope: meta.number.imaginary.octal.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + 3: constant.numeric.suffix.go + # Binary imaginary numbers + - match: (0[bB])({{bin_digits}})(i) + scope: meta.number.imaginary.binary.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + 3: constant.numeric.suffix.go + + match-floats: + # Decimal float literal + - match: |- + (?x: + # 1.1, 1., 1.1e1, 1.e1 + {{dec_digits}}(\.){{dec_digits}}?{{dec_exponent}}? + # 1e1 + | {{dec_digits}}{{dec_exponent}} + # .1, .1e1 + | (\.){{dec_digits}}{{dec_exponent}}? + ) + scope: meta.number.float.decimal.go constant.numeric.value.go + captures: + 1: punctuation.separator.decimal.go + 2: punctuation.separator.decimal.go + # Hexadecimal float literal + - match: (0[xX])({{hex_digits}}?(?:(\.){{hex_digits}}?)?{{hex_exponent}}) + scope: meta.number.float.hexadecimal.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + 3: punctuation.separator.decimal.go + + match-integers: + - include: match-octal-integer + - include: match-hex-integer + - include: match-binary-integer + - include: match-decimal-integer + + match-octal-integer: + - match: (0)({{oct_digits}})(?=\D) + scope: meta.number.integer.octal.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + - match: 0[0-7]*[8-9]+ + scope: invalid.illegal.go + - match: (0[oO])({{oct_digits}}) + scope: meta.number.integer.octal.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + + match-hex-integer: + - match: (0[xX])({{hex_digits}}) + scope: meta.number.integer.hexadecimal.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + + match-binary-integer: + - match: (0[bB])({{bin_digits}}) + scope: meta.number.integer.binary.go + captures: + 1: constant.numeric.base.go + 2: constant.numeric.value.go + + match-decimal-integer: + - match: '({{dec_digits}})' + scope: meta.number.integer.decimal.go constant.numeric.value.go + + # https://golang.org/ref/spec#Rune_literals + match-runes: + # Note: Scope constants as `string` to prevent ST' bracket matching from + # failing in case the character contains '{', '}', '[', ']', etc. + - match: |- + (?x) + (\') + (?: (\\[0-7]{1,3}) | (\\x\h{2}) | (\\u\h{4}) | (\\U\h{8}) | (\\[\\'abfnrtv]) | (\\.) | ([^']*) ) + (\') + scope: meta.string.go string.quoted.single.go + captures: + 1: punctuation.definition.string.begin.go + 2: constant.character.escape.octal.go + 3: constant.character.escape.hex.go + 4: constant.character.escape.unicode.16bit.go + 5: constant.character.escape.unicode.32bit.go + 6: constant.character.escape.go + 7: invalid.illegal.escape.go + 8: constant.character.literal.go + 9: punctuation.definition.string.end.go + + match-strings: + - include: match-raw-string + - include: match-interpreted-string + + match-raw-string: + - match: \` + scope: punctuation.definition.string.begin.go + push: match-raw-string-inner + + match-raw-string-inner: + - meta_include_prototype: false + - meta_scope: meta.string.go string.quoted.backtick.go + - match: \` + scope: punctuation.definition.string.end.go + pop: 1 + - include: match-raw-string-content + + match-raw-string-content: + # Note: used by language injection comment syntaxes + - include: match-placeholders + - include: match-string-templates + + match-raw-text-content: + # Note: used by language injection comment syntaxes + - include: match-placeholders + - include: match-text-templates + + match-interpreted-string: + - match: \" + scope: punctuation.definition.string.begin.go + push: match-interpreted-string-inner + + match-interpreted-string-inner: + - meta_include_prototype: false + - meta_scope: meta.string.go string.quoted.double.go + - match: \" + scope: punctuation.definition.string.end.go + pop: 1 + - include: match-interpreted-string-content + + match-interpreted-string-content: + - include: match-escaped-chars + - include: match-placeholders + - include: match-string-templates + + match-escaped-chars: + - match: \\[0-7]{1,3} + scope: constant.character.escape.octal.go + - match: \\x\h{2} + scope: constant.character.escape.hex.go + - match: \\u\h{4} + scope: constant.character.escape.unicode.16bit.go + - match: \\U\h{8} + scope: constant.character.escape.unicode.32bit.go + - match: \\. + scope: constant.character.escape.go + + # https://godoc.org/fmt + # + # Tries to match known patterns without being too specific. We want to avoid + # false positives in non-fmt strings that just happen to contain %, but don't + # want too much coupling with the current version of fmt. + match-placeholders: + - match: \%% + scope: constant.character.escape.go + - match: |- + (?x) + \% + # flags + [-+#0 ]* + # width + (?: \d+ | (?:\[\d+\])? \* )? + # precision + (?: \. (?: \d+ | (?:\[\d+\])? \* )? )? + # maybe indexed verb + (?:\[\d+\])? [bcdeEfFgGoOpqsTtUvwxX] + scope: constant.other.placeholder.go + + match-block-string-templates: + # This context is used for interpolation within quoted or unquoted multiline strings. + # Doesn't check for closing `}}` as it might be located on a sub-sequent line. + # It clears the `string` scope of the owning context. + # Note: used by YAML (Go).sublime-syntax + - match: ({{)(-?) + captures: + 1: punctuation.section.interpolation.begin.go + 2: keyword.operator.template.trim.left.go + push: + - pop-now-clear-scope + - match-template-inner + - match-template-function + - match-template-keyword + + match-string-templates: + # This context is used for interpolation within quoted or unquoted strings. + # Matches only if closing `}}` is found on same line to avoid false positives. + # It clears the `string` scope of the owning context. + - match: ({{)(-?)(?=.*?}}) + captures: + 1: punctuation.section.interpolation.begin.go + 2: keyword.operator.template.trim.left.go + push: + - pop-now-clear-scope + - match-template-inner + - match-template-function + - match-template-keyword + + match-text-templates: + # This context is used for interpolation in text or normal content. + # It does not clear scopes of the owning context. + - match: ({{)(-?) + captures: + 1: punctuation.section.interpolation.begin.go + 2: keyword.operator.template.trim.left.go + push: + - match-template-inner + - match-template-function + - match-template-keyword + + match-template-inner: + - meta_scope: meta.interpolation.go + - meta_content_scope: source.go.template + - match: (-?)(}}) + captures: + 1: keyword.operator.template.trim.right.go + 2: punctuation.section.interpolation.end.go + pop: 1 + - include: match-template-expressions + + match-template-function: + - include: match-template-builtin-function + - match: '{{keyword_or_ident}}(?=\s+[^-:=|)}])' # requires arguments + scope: variable.function.go + pop: 1 + - match: (?=\.) + set: match-template-members + - include: pop-before-nonblank + + match-template-builtin-function: + # https://pkg.go.dev/text/template#hdr-Functions + - match: (?:and|call|html|index|slice|js|len|not|or|print|printf|println|urlquery|eq|ne|lt|le|gt|ge)\b + scope: support.function.builtin.go + pop: 1 + + match-template-members: + - match: (\.)({{keyword_or_ident}})(?=\s+[^-:=|)}]) # requires arguments + captures: + 1: punctuation.accessor.dot.go + 2: variable.function.method.go + pop: 1 + - include: match-template-attributes + - include: pop-now + + match-template-keyword: + - match: (?:block|define|end|template|with)\b + scope: keyword.control.context.go + pop: 1 + - match: if\b + scope: keyword.control.conditional.if.go + pop: 1 + - match: else\s+if\b + scope: keyword.control.conditional.elseif.go + pop: 1 + - match: else\b + scope: keyword.control.conditional.else.go + pop: 1 + - match: range\b + scope: keyword.control.loop.range.go + pop: 1 + - match: break\b + scope: keyword.control.flow.break.go + pop: 1 + - match: continue\b + scope: keyword.control.flow.continue.go + pop: 1 + - include: pop-before-nonblank + + match-template-expressions: + - include: match-template-groups + - include: match-template-operators + - include: match-template-pipes + - include: match-template-attributes + - include: match-template-variables + - include: match-comma + - include: match-literals + - include: match-predeclared-constants + + match-template-groups: + - match: \( + scope: punctuation.section.group.begin.go + push: + - match-template-group-body + - match-template-function + + match-template-group-body: + - meta_scope: meta.group.go + - match: \) + scope: punctuation.section.group.end.go + pop: 1 + - include: pop-before-brace-end + - include: match-template-expressions + + match-template-operators: + - match: \:?= + scope: keyword.operator.assignment.go + push: match-template-function + + match-template-pipes: + # https://pkg.go.dev/text/template#hdr-Pipelines + - match: \| + scope: keyword.operator.assignment.pipe.go + push: match-template-function-after-pipe + + match-template-function-after-pipe: + - include: match-template-builtin-function + - match: '{{keyword_or_ident}}(?!\.)' + scope: variable.function.go + pop: 1 + - match: (?=\.) + set: match-template-members-after-pipe + - include: pop-before-nonblank + + match-template-members-after-pipe: + - match: (\.)({{keyword_or_ident}})(?!\.) + captures: + 1: punctuation.accessor.dot.go + 2: variable.function.method.go + pop: 1 + - include: match-template-attributes + - include: pop-now + + match-template-attributes: + - match: (\.)({{keyword_or_ident}}) + captures: + 1: punctuation.accessor.dot.go + 2: variable.other.member.go + + match-template-variables: + - match: (\$){{keyword_or_ident}} + scope: variable.other.template.go + captures: + 1: punctuation.definition.variable.go + - match: '[.$]' + scope: variable.language.template.go + + match-keyword-break: + - match: \bbreak\b + scope: keyword.control.flow.break.go + + match-keyword-case: + - match: \bcase\b + scope: keyword.control.conditional.case.go + push: match-case-value + + match-case-value: + - match: ':' + scope: punctuation.separator.case-statement.go + pop: true + - match: '{{predeclared_type}}' + scope: support.type.go + - match: (?=;) + pop: 1 + - include: match-any + + match-keyword-chan: + - match: (?=\bchan\b) + push: pop-chan + + match-keyword-const: + - match: \bconst\b + scope: keyword.declaration.const.go + push: + - match: \( + scope: punctuation.section.parens.begin.go + set: + - include: pop-on-paren-end + + - match: '{{ident_anon}}(?={{noise}},)' + scope: variable.language.anonymous.go + + - match: '{{ident}}(?={{noise}},)' + scope: variable.other.constant.declaration.go + + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + push: pop-const-type-and-or-assignment + + - match: '{{ident}}' + scope: variable.other.constant.declaration.go + push: pop-const-type-and-or-assignment + + - include: match-any + + - include: match-comma + + - match: '{{ident_anon}}(?={{noise}},)' + scope: variable.language.anonymous.go + + - match: '{{ident}}(?={{noise}},)' + scope: variable.other.constant.declaration.go + + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + set: pop-const-type-and-or-assignment + + - match: '{{ident}}' + scope: variable.other.constant.declaration.go + set: pop-const-type-and-or-assignment + + - include: pop-before-nonblank + + match-keyword-continue: + - match: \bcontinue\b + scope: keyword.control.flow.continue.go + + match-keyword-default: + - match: \b(default)\b(:)? + captures: + 1: keyword.control.conditional.default.go + 2: punctuation.separator.case-statement.go + + match-keyword-defer: + - match: \bdefer\b + scope: keyword.control.go + + match-keyword-else: + - match: \belse\b + scope: keyword.control.go + + match-keyword-fallthrough: + - match: \bfallthrough\b + scope: keyword.control.go + + match-keyword-for: + - match: \bfor\b + scope: keyword.control.go + + match-keyword-func: + - match: \bfunc\b + scope: keyword.declaration.function.go + push: [meta-function-declaration, pop-func] + + pop-func: + # Known false positive: + # + # func(param Type[TypeArg]) Name[Type] {} + # + # In this example, the anonymous function is incorrectly scoped as a method, + # where `Name` is scoped as method name rather than type. TODO avoid. + # A proper implementation may involve complicated branching. + - match: (?=\([^()]*\){{noise}}{{ident}}{{noise}}[\[\(]) + set: [pop-func-signature, pop-func-method-receiver] + - include: pop-func-signature + + match-keyword-go: + - match: \bgo\b + scope: keyword.control.go + + match-keyword-goto: + - match: \bgoto\b + scope: keyword.control.flow.goto.go + + match-keyword-if: + - match: \bif\b + scope: keyword.control.conditional.if.go + + match-keyword-import: + - match: \bimport\b + scope: keyword.other.import.go + + match-keyword-interface: + - match: (?=\binterface\b) + push: pop-interface + + match-keyword-map: + - match: (?=\bmap\b) + push: pop-map + + match-keyword-package: + - match: \bpackage\b + scope: keyword.declaration.namespace.go + push: [meta-namespace, pop-package-name] + + pop-package-name: + - match: '{{ident}}' + scope: entity.name.namespace.go + pop: 1 + - include: pop-before-nonblank + + match-keyword-range: + - match: \brange\b + scope: keyword.other.go + + match-keyword-return: + - match: \breturn\b + scope: keyword.control.go + + match-keyword-select: + - match: \bselect\b + scope: keyword.control.go + + match-keyword-struct: + - match: (?=\bstruct\b) + push: pop-struct + + match-keyword-switch: + - match: \bswitch\b + scope: keyword.control.conditional.switch.go + + match-keyword-type: + - match: \btype\b + scope: keyword.declaration.type.go + push: pop-type-declaration-or-list + + pop-type-declaration-or-list: + - match: \( + scope: punctuation.section.parens.begin.go + set: pop-type-declaration-list + - include: pop-type-declaration + + pop-type-declaration-list: + - include: pop-on-paren-end + - match: (?={{ident}}) + push: pop-type-declaration + - include: match-any + + pop-type-declaration: + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + set: pop-type-spec + + - match: '{{ident}}' + scope: entity.name.type.go + set: pop-type-spec + + - include: pop-before-nonblank + + match-keyword-var: + - match: \bvar\b + scope: keyword.declaration.var.go + push: + - match: \( + scope: punctuation.section.parens.begin.go + set: + - include: pop-on-paren-end + + - match: '{{ident_anon}}(?={{noise}},)' + scope: variable.language.anonymous.go + + - match: '{{ident}}(?={{noise}},)' + scope: variable.other.readwrite.declaration.go + + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + push: pop-var-type-and-or-assignment + + - match: '{{ident}}' + scope: variable.other.readwrite.declaration.go + push: pop-var-type-and-or-assignment + + - include: match-any + + - include: match-comma + + - match: '{{ident_anon}}(?={{noise}},)' + scope: variable.language.anonymous.go + + - match: '{{ident}}(?={{noise}},)' + scope: variable.other.readwrite.declaration.go + + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + set: pop-var-type-and-or-assignment + + - match: '{{ident}}' + scope: variable.other.readwrite.declaration.go + set: pop-var-type-and-or-assignment + + - include: pop-before-nonblank + + pop-func-method-receiver: + - match: \( + scope: punctuation.section.parens.begin.go + set: pop-func-method-receiver-inner + - include: pop-before-nonblank + + pop-func-method-receiver-inner: + - include: pop-on-paren-end + - include: match-type-operators + - include: match-namespace + + # The lookahead is too special-case. TODO improve. + - match: '{{ident_anon}}(?={{noise}}(?:\*|{{ident}}))' + scope: variable.language.anonymous.go + - match: '{{ident}}(?={{noise}}(?:\*|{{ident}}))' + scope: variable.parameter.go + + - match: '{{ident}}' + scope: storage.type.go + push: pop-type-parameter-list-simple + + - include: match-any + + pop-func-signature: + - match: (?=\S) + set: [pop-func-parameter-and-return-lists, pop-type-parameter-list, pop-func-name] + + pop-func-name: + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + pop: 1 + + - match: '{{ident}}' + scope: entity.name.function.go + pop: 1 + + - include: pop-before-nonblank + + pop-func-parameter-and-return-lists: + - match: (?=\() + set: [pop-func-return-signature, pop-func-parameter-list] + - include: pop-before-nonblank + + pop-func-return-signature: + - include: pop-before-terminator + - match: (?=\() + set: pop-func-parameter-list + - include: pop-type + + # https://golang.org/ref/spec#Function_types + # + # Go has two parameter syntaxes: unnamed and named. + # + # Unnamed: + # + # (typ) + # (typ, typ) + # (typ, typ, ...typ) + # + # Named: + # + # (a typ) + # (a, b typ) + # (a, b ...typ) + # (a typ, b typ) + # (a, b typ, c ...typ) + # + # The modes are distinct: either all named, or all unnamed. + # + # Gotchas: + # + # * Parameters can span multiple lines. + # * A type can span multiple lines (anonymous struct, interface, etc.). + # * Parameter groups AND parameter names are comma-separated. + # * `chan type` is a type that looks like an identifier followed by a type. + # + # The current implementation is imperfect: when a group of comma-separated + # parameters spans multiple lines, we incorrectly assume "unnamed" mode. + # However, a "perfect" implementation requires multiline lookahead or + # branching. The current approach works for most real code. + pop-func-parameter-list: + - match: \( + scope: punctuation.section.parens.begin.go + set: + - match: | + (?x) + (?= + (?:{{noise}}{{ident}}{{noise}},{{noise}})* + {{ident}}{{noise}}(?:\.\.\.|[^\s/,).]) + ) + set: pop-parameter-list-named + - match: (?=\S) + set: pop-parameter-list-unnamed + - include: pop-before-nonblank + + pop-parameter-list-named: + - include: pop-on-paren-end + - include: match-keywords + - include: match-comma + - include: match-ellipsis + + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + push: pop-parameter-type + + - match: '{{type_ident}}' + scope: storage.type.go + push: pop-type-argument-list + + - match: '{{ident}}' + scope: variable.parameter.go + push: pop-parameter-type + + pop-parameter-type: + - match: (?=\)|,) + pop: 1 + - include: match-ellipsis + - include: pop-type + + pop-parameter-list-unnamed: + - include: pop-on-paren-end + - include: match-comma + - include: match-ellipsis + - include: match-keywords + - include: match-type + + # At the time of writing, this is the only part of Go that uses "untyped" + # syntax for parameters, similar to function definitions in dynamic languages + # or closure definitions in typed languages such as Java lambdas. + # + # Note: this should not be confused with `pop-type-parameter-list` that + # uses "typed" syntax. + pop-type-parameter-list-simple: + - match: \[ + scope: punctuation.section.brackets.begin.go + set: pop-type-parameter-list-simple-inner + - include: pop-before-nonblank + + pop-type-parameter-list-simple-inner: + - include: pop-on-bracket-end + - include: match-identifier-anon + - match: '{{ident}}' + scope: variable.parameter.type.go + - include: match-any + + # Note: this should not be confused with `pop-type-parameter-list-simple` or + # `pop-type-argument-list`. + pop-type-parameter-list: + - match: \[ + scope: punctuation.section.brackets.begin.go + set: pop-type-parameter-list-inner + - include: pop-before-nonblank + + # Unlike value parameter lists that have both named and anonymous modes, + # type parameter lists have only the named mode. Parameter names must exist. + pop-type-parameter-list-inner: + - include: pop-on-bracket-end + - match: '{{ident_anon}}(?={{noise}},)' + scope: variable.language.anonymous.go + - match: '{{ident}}(?={{noise}},)' + scope: variable.parameter.type.go + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + push: pop-type + - match: '{{ident}}' + scope: variable.parameter.type.go + push: pop-type + - include: match-any + + # Note: this should not be confused with `pop-type-parameter-list`. + pop-type-argument-list: + - include: pop-before-terminator + - match: \[ + scope: punctuation.section.brackets.begin.go + set: pop-type-argument-list-inner + - include: pop-before-nonblank + + pop-type-argument-list-inner: + - include: pop-on-bracket-end + - include: match-identifier-anon + - match: '{{ident}}' + scope: variable.other.type.go + - include: match-any + + pop-now-clear-scope: + - clear_scopes: 1 + - meta_include_prototype: false + - include: pop-now + + pop-now: + - match: '' + pop: 1 + + pop-before-nonblank: + - match: (?=\S) + pop: 1 + + pop-before-semicolon: + - match: (?=;) + pop: 1 + + pop-before-newline: + - match: (?={{newline}}) + pop: 1 + + pop-before-terminator: + - include: pop-before-semicolon + - include: pop-before-newline + + pop-before-paren-end: + - match: (?=\)) + pop: 1 + + pop-on-paren-end: + - match: \) + scope: punctuation.section.parens.end.go + pop: 1 + + pop-before-bracket-end: + - match: (?=\]) + pop: 1 + + pop-on-bracket-end: + - match: \] + scope: punctuation.section.brackets.end.go + pop: 1 + + pop-on-brace-end: + - match: \} + scope: punctuation.section.braces.end.go + pop: 1 + + pop-before-brace-end: + - match: (?=\}) + pop: 1 + + match-type: + - match: (?=\S) + push: [pop-after-type, pop-type-single] + + pop-type: + - match: (?=\S) + set: [pop-after-type, pop-type-single] + + pop-type-single: + # Note: Go allows wrapping types in an arbitrary number of parens. + - match: \( + scope: punctuation.section.parens.begin.go + push: [pop-type-nested-in-parens, pop-type] + + # Note: Go allows multiple levels of slices + - match: \[ + scope: punctuation.section.brackets.begin.go + push: pop-brackets-inner + + - include: match-type-operators + - include: match-operators + + - include: pop-chan + - include: pop-interface + - include: pop-map + - include: pop-struct + + - match: \bfunc\b + scope: keyword.declaration.function.go + set: pop-func-parameter-and-return-lists + + - match: \btype\b + scope: keyword.operator.type.go + + # Note: must be the last one as it pops unconditionally + - include: pop-type-identifier + + pop-after-type: + - match: \|{{operator_break}} + scope: keyword.operator.go + set: pop-type + - include: pop-before-newline + - include: pop-before-nonblank + + pop-type-nested-in-parens: + # The implementation is fairly similar. Parameter lists allow some + # additional tokens, which shouldn't occur here. + - include: pop-parameter-list-unnamed + + pop-struct: + - match: \bstruct\b + scope: keyword.declaration.struct.go + set: pop-struct-block + + pop-struct-block: + - match: \{ + scope: punctuation.section.braces.begin.go + set: [meta-type, pop-struct-block-inner] + - include: pop-before-nonblank + + pop-struct-block-inner: + - include: pop-on-brace-end + - include: match-keywords + - include: match-type-operators + - include: match-namespace + + - match: '{{ident_anon}}(?={{noise}}{{struct_embed_argument_list}})' + scope: variable.language.anonymous.go + push: pop-type-argument-list + + - match: '{{ident}}(?={{noise}}{{struct_embed_argument_list}})' + scope: entity.other.inherited-class.go + push: pop-type-argument-list + + - match: '{{predeclared_type}}(?={{noise}}{{struct_entry_delim}})' + scope: entity.other.inherited-class.go support.type.builtin.go + + - include: match-identifier-anon + + - match: '{{ident}}(?={{noise}}{{struct_entry_delim}})' + scope: entity.other.inherited-class.go + + - match: '{{ident}}' + scope: variable.other.member.declaration.go + push: pop-struct-field-meta + + - include: match-struct-tag-annotation + - include: match-semicolon + - include: match-comma + - include: match-operators + + match-struct-tag-annotation: + - match: '`' + scope: punctuation.definition.annotation.begin.go + push: match-struct-tag-annotation-inner + + match-struct-tag-annotation-inner: + - meta_include_prototype: false + - meta_scope: meta.annotation.go + - match: '`' + scope: punctuation.definition.annotation.end.go + pop: 1 + - match: (\w+)(:) + captures: + 1: meta.annotation.identifier.go variable.annotation.go + 2: meta.annotation.go punctuation.separator.key-value.go + push: match-struct-tag-annotation-value + - match: (\w+)(?=[\s`]) + scope: meta.annotation.identifier.go variable.annotation.go + push: pop-now-clear-scope + + match-struct-tag-annotation-value: + - clear_scopes: 1 + - match: '"' + scope: punctuation.definition.string.begin.go + push: match-struct-tag-annotation-value-inner + - include: pop-now + + match-struct-tag-annotation-value-inner: + - meta_include_prototype: false + - meta_scope: meta.annotation.parameters.go string.quoted.double.go + - include: match-interpreted-string-inner + - match: ',' + scope: punctuation.separator.sequence.go + + pop-struct-field-meta: + - include: pop-before-brace-end + - include: pop-before-terminator + - include: pop-type + + pop-interface: + - match: \binterface\b + scope: keyword.declaration.interface.go + set: [meta-type, pop-interface-block] + + pop-interface-block: + - match: \{ + scope: punctuation.section.braces.begin.go + set: pop-interface-inner + - include: pop-before-nonblank + + # Ideally we would scope embedded interfaces as `entity.other.inherited-class` + # rather than `storage.type`. Prior to Go 1.18 and type unions, it was + # possible to detect embedding unambiguously. With the advent of unions, + # embeddings are syntactically indistinguishable from single-element unions. + pop-interface-inner: + - include: pop-on-brace-end + - include: match-keywords + - include: match-namespace + - include: match-type-operators + + - match: '{{ident}}(?={{noise}}\()' + scope: entity.name.function.go + push: pop-func-parameter-and-return-lists + + - match: '{{predeclared_type}}' + scope: storage.type.go support.type.builtin.go + + - match: '{{ident}}' + scope: storage.type.go + + - include: match-any + + pop-map: + # Note: newlines between `map` and `[` are ok, but newlines after `]` + # terminate the type. + - match: \bmap\b + scope: keyword.declaration.map.go + set: [meta-type, pop-map-brackets] + + pop-map-brackets: + - match: \[ + scope: punctuation.section.brackets.begin.go + set: pop-map-brackets-inner + - include: pop-before-nonblank + + pop-map-brackets-inner: + - match: \] + scope: punctuation.section.brackets.end.go + set: pop-type + - include: match-type + + # Note: newlines between `chan`, subsequent arrow, and subsequent type, are + # perfectly ok. + pop-chan: + - match: \bchan\b + scope: keyword.declaration.chan.go + set: pop-type + + pop-type-identifier: + - include: match-namespace + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + set: pop-type-argument-list + - match: '{{predeclared_type}}' + scope: storage.type.go support.type.builtin.go + set: pop-type-argument-list + - match: '{{ident}}' + scope: storage.type.go + set: pop-type-argument-list + - include: pop-before-nonblank + + pop-type-spec: + - include: pop-before-terminator + # Newlines after `=` are ok. + - match: = + scope: keyword.operator.assignment.go + set: pop-type + - include: pop-type + + pop-const-type-and-or-assignment: + - include: pop-before-terminator + - match: = + scope: keyword.operator.assignment.go + set: pop-const-expressions + - match: (?=\S) + set: [pop-const-assignment-or-terminate, pop-type] + + pop-const-assignment-or-terminate: + - include: pop-before-terminator + - match: = + scope: keyword.operator.assignment.go + set: pop-const-expressions + - include: pop-before-nonblank + + # Note: this doesn't support multiline expressions. + # + # Note on `iota`. See https://golang.org/ref/spec#Iota. `iota` is a regular + # identifier that happens to be predeclared in constant initialization + # expressions, but not anywhere else. Just like `true|false|nil`, you can + # redefine it. Doing so in the root scope makes the magic constant unavailable + # for the entire package. + pop-const-expressions: + - include: pop-before-semicolon + - match: (?=\S) + set: + - include: pop-before-terminator + - match: \biota\b + scope: constant.language.go + - include: match-any + + pop-var-type-and-or-assignment: + - include: pop-before-terminator + - match: = + scope: keyword.operator.assignment.go + set: pop-var-expressions + - match: (?=\S) + set: [pop-var-assignment-or-terminate, pop-type] + + pop-var-assignment-or-terminate: + - include: pop-before-terminator + - match: = + scope: keyword.operator.assignment.go + set: pop-var-expressions + - include: pop-before-nonblank + + # Note: this doesn't support multiline expressions. + pop-var-expressions: + - include: pop-before-semicolon + - match: (?=\S) + set: + - include: pop-before-terminator + - include: match-any + + pop-member: + - match: '{{ident_anon}}' + scope: variable.language.anonymous.go + pop: 1 + + - match: '{{ident}}' + scope: variable.other.member.go + pop: 1 + + pop-arguments-starting-with-type: + # Go allows functions and types to be wrapped in an arbitrary number of + # parens. These are not part of the call. + - match: \( + scope: punctuation.section.parens.begin.go + set: [pop-inside-parens, pop-type] + - include: pop-before-nonblank + + # Including the newline allows the scope to visually stretch to the right, + # and ensures that functionality that relies on comment scoping, such as + # contextual hotkeys, works properly at EOL while typing a comment. + pop-on-eol: + - match: '{{newline}}' + pop: 1 + + pop-inside-parens: + - include: pop-on-paren-end + - include: match-any + + match-namespace: + - match: '({{ident}})\s*(\.)' + captures: + 1: variable.other.go + 2: punctuation.accessor.dot.go + + meta-function-declaration: + - meta_include_prototype: false + - meta_scope: meta.function.declaration.go + - include: pop-now + + meta-block: + - meta_include_prototype: false + - meta_scope: meta.block.go + - include: pop-now + + meta-type: + - meta_include_prototype: false + - meta_scope: meta.type.go + - include: pop-now + + meta-namespace: + - meta_include_prototype: false + - meta_scope: meta.namespace.go + - include: pop-now
diff --git /dev/null b/syntax/Haskell/Haskell.sublime-syntax @@ -0,0 +1,1715 @@ +%YAML 1.2 +--- +# https://ghc.gitlab.haskell.org/ghc/doc/users_guide +# https://www.haskell.org/onlinereport/haskell2010 +# https://www.sublimetext.com/docs/syntax.html +name: Haskell +scope: source.haskell +version: 2 + +file_extensions: + - hs + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* -- .*? -\*- .*? \bhaskell\b .*? -\*- # editorconfig + ) + +############################################################################### + +variables: + shebang_language: \b(?:cabal|runhaskell|stack)\b + + # 2.2 Lexical Program Structure + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-160002.2 + special: '[(),;\[\]`{}]' + symbol: '[\p{S}\p{P}&&[^_"''{{special}}]]' + ascii_symbol: '[!#$%&β+./<=>?@\\\^|\-~:]' + unicode_symbol: '[[:punct:]&&[^:ascii:]]' + + # 2.3 Comments + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-170002.3 + no_comment_ahead: '(?!{{comment_begin}})' + comment_ahead: '(?={{comment_begin}})' + comment_begin: '--+(?:{{comment_first_char}}|$)' + comment_first_char: '[\s\w"''{{special}}]' + + # 2.4 Identifiers and Operators + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-180002.4 + id: (?:(?!{{reserved_id}})[\w']*(#)*) + con_id: (?:[[:upper:]][\w']*(#)*) + var_id: (?:(?!{{reserved_id}})[[:lower:]_][\w']*(#)*) + reserved_id: |- + (?x: + _ | case | class | data | default | deriving | do | else | family | forall + | foreign | if | import | in | infix | infixl | infixr | instance | let | mdo + | module | newtype | of | proc | rec | signature | then | type | via | where + ){{break}} + break: (?![\w'#]) + + # GHC 6.9.5 Numeric underscores + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/numeric_underscores.html + bin_digit: '[01_]' + dec_digit: '[\d_]' + hex_digit: '[\h_]' + oct_digit: '[0-7_]' + dec_exponent: (?:[eE][-+]?\d+) + hex_exponent: (?:[pP][-+]?\d+) + + # In case this regex seems overly general, note that Haskell permits + # the definition of new operators which can be nearly any string + # of punctuation characters, such as $%^&*. + operator_symbol: (?:{{symbol}}+) + operator_parens: (?:{{no_comment_ahead}}{{operator_symbol}}) + + operator_double_colon: (?:::|β·) + operator_big_arrow: (?:=>|β) + operator_left_arrow: (?:<-|β) + operator_right_arrow: (?:->|β) + + consym: (?:[:]{{varsym}}) + varsym: (?:[{{symbol}}&&[^:]]{{symbol}}*) + + # 2.6 Character and String Literals + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-200002.6 + escape_chars: |- + (?x: + NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | HT | LF | VT | FF + | CR | SO | SI | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN | EM + | SUB | ESC | FS | GS | RS | US | SP | DEL + | [abfnrtv\\\"'\&] + ) + escape_sequence: |- + (?x: + (\\{{escape_chars}}) # Escapes + | (\\[0-9]+) # Decimal Escapes + | (\\o[0-7]+) # Octal Escapes + | (\\x[0-9A-Fa-f]+) # Hexadecimal Escapes + | (\^[A-Z@\[\]\\\^_]) # Control Chars + ) + + # GHC 6.20 Pragmas + pragma_directives: |- + (?x: + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html + LANGUAGE | OPTIONS | OPTIONS_GHC | OPTIONS_HADDOCK | INCLUDE | WARNING + | DEPRECATED | MINIMAL | INLINE | NOINLINE | INLINABLE | CONLIKE | LINE + | COLUMN | RULES | SPECIALIZE | UNPACK | NOUNPACK | SOURCE | COMPLETE + | OVERLAPPING | OVERLAPPABLE | OVERLAPS | INCOHERENT | CTYPE + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/profiling.html + | CORE | GENERATED | SCC + ){{break}} + + # https://wiki.haskell.org/Language_extensions + # https://github.com/JustusAdam/language-haskell + pragma_deprecated_constants: |- + (?:No)?(?x: + AutoDeriveTypeable | DatatypeContexts | DoRec | IncoherentInstances + | MonadFailDesugaring | MonoPatBinds | NullaryTypeClasses + | OverlappingInstances | PatternSignatures | RecordPuns | RelaxedPolyRec + ){{break}} + + # https://wiki.haskell.org/Language_extensions + # https://github.com/JustusAdam/language-haskell + pragma_extension_constants: |- + (?:No)?(?x: + AllowAmbiguousTypes | AlternativeLayoutRule + | AlternativeLayoutRuleTransitional | Arrows | BangPatterns | BinaryLiterals + | CApiFFI | CPP | CUSKs | ConstrainedClassMethods | ConstraintKinds + | DataKinds | DefaultSignatures | DeriveAnyClass | DeriveDataTypeable + | DeriveFoldable | DeriveFunctor | DeriveGeneric | DeriveLift + | DeriveTraversable | DerivingStrategies | DerivingVia + | DisambiguateRecordFields | DoAndIfThenElse | BlockArguments + | DuplicateRecordFields | EmptyCase | EmptyDataDecls | EmptyDataDeriving + | ExistentialQuantification | ExplicitForAll | ExplicitNamespaces + | ExtendedDefaultRules | FlexibleContexts | FlexibleInstances + | ForeignFunctionInterface | FunctionalDependencies | GADTSyntax | GADTs + | GHCForeignImportPrim | Generali(?:s | z)edNewtypeDeriving | ImplicitParams + | ImplicitPrelude | ImportQualifiedPost | ImpredicativeTypes + | TypeFamilyDependencies | InstanceSigs | ApplicativeDo | InterruptibleFFI + | JavaScriptFFI | KindSignatures | LambdaCase | LexicalNegation + | LiberalTypeSynonyms | LinearTypes | MagicHash | MonadComprehensions + | MonoLocalBinds | MonomorphismRestriction | MultiParamTypeClasses + | MultiWayIf | NumericUnderscores | NPlusKPatterns | NamedFieldPuns + | NamedWildCards | NegativeLiterals | HexFloatLiterals + | NondecreasingIndentation | NumDecimals | OverloadedLabels | OverloadedLists + | OverloadedStrings | PackageImports | ParallelArrays | ParallelListComp + | PartialTypeSignatures | PatternGuards | PatternSynonyms | PolyKinds + | PolymorphicComponents | QuantifiedConstraints | PostfixOperators + | QualifiedDo | QuasiQuotes | Rank2Types | RankNTypes | RebindableSyntax + | RecordWildCards | RecursiveDo | RelaxedLayout | RoleAnnotations | Safe + | ScopedTypeVariables | StandaloneDeriving | StarIsType | StaticPointers + | Strict | StrictData | TemplateHaskell | TemplateHaskellQuotes + | StandaloneKindSignatures | TraditionalRecordSyntax | TransformListComp + | Trustworthy | TupleSections | TypeApplications | TypeInType | TypeFamilies + | TypeOperators | TypeSynonymInstances | UnboxedTuples | UnboxedSums + | UndecidableInstances | UndecidableSuperClasses | UnicodeSyntax + | UnliftedFFITypes | UnliftedNewtypes | Unsafe | ViewPatterns + | Haskell98 | Haskell2010 + ){{break}} + + prelude_classes: |- + (?x: + # 9 Standard Prelude + Applicative | Bifoldable | Bifunctor | Bitraversable | Bits | Bounded + | Coercible | Enum | Eq | Floating | Foldable | Fractional | Functor | Integral + | IsString | Ix | Monad | Monoid | Num | Ord | Read | Real | RealFloat + | RealFrac | Semigroup | Show | Traversable | Typeable + ){{break}} + + prelude_constants: |- + (?x: Just | Left | Nothing | Right | True | False | LT | EQ | GT ){{break}} + + prelude_types: |- + (?x: + # 9 Standard Prelude + # https://hackage.haskell.org/package/base-4.16.0.0 + Bool | Char | Complex | Constraint | Double | Dynamic | Either | FilePath + | Float | Integer | IO | IOError | IOException | IORef | Maybe | Ordering | Proxy + | Ratio | Rational | ReadS | ShowS | STRef | String | Type | Unique | Version | Void + # 24 Foreign + # https://www.haskell.org/onlinereport/haskell2010/haskellch24.html#x32-26200024 + | Int | Int8 | Int16 | Int32 | Int64 | Word | Word8 | Word16 | Word32 | Word64 + | Ptr | FunPtr | StablePtr + ){{break}} + + prelude_functions: |- + (?x: + abs | acos | acosh | all | and | any | appendFile | asTypeOf | asin + | asinh | atan | atan2 | atanh | break | ceiling | compare | concat + | concatMap | const | cos | cosh | curry | cycle | decodeFloat | div + | divMod | drop | dropWhile | either | elem | encodeFloat | enumFrom + | enumFromThen | enumFromThenTo | enumFromTo | error | errorWithoutStackTrace + | even | exp | exponent | fail | filter | flip | floatDigits | floatRadix + | floatRange | floor | fmap | foldMap | foldl | foldl1 | foldr | foldr1 + | fromEnum | fromInteger | fromIntegral | fromRational | fst | gcd | getChar + | getContents | getLine | head | id | init | interact | ioError + | isDenormalized | isIEEE | isInfinite | isNaN | isNegativeZero | iterate + | last | lcm | length | lex | lines | log | logBase | lookup | map | mapM + | mapM_ | mappend | max | maxBound | maximum | maybe | mconcat | mempty + | min | minBound | minimum | mod | negate | not | notElem | null | odd | or + | pi | pred | print | product | properFraction | pure | putChar + | putStr | putStrLn | quot | quotRem | read | readFile | readIO | readList + | readLn | readParen | reads | readsPrec | realToFrac | recip | rem | repeat + | replicate | return | reverse | round | scaleFloat | scanl | scanl1 | scanr + | scanr1 | seq | sequence | sequenceA | sequence_ | show | showChar + | showList | showParen | showString | shows | showsPrec | significand + | signum | sin | sinh | snd | span | splitAt | sqrt | subtract | succ | sum + | tail | take | takeWhile | tan | tanh | toEnum | toInteger | toRational + | traverse | truncate | uncurry | undefined | unlines | until | unwords + | unzip | unzip3 | userError | words | writeFile | zip | zip3 | zipWith + | zipWith3 + ){{break}} + + unboxed_types: |- + (?x: + # GHC 6.2.2 The magic hash + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/magic_hash.html + Addr | Array | Char | Double | Float | Int | Word + # GHC 6.17.2.1 Unlifted FFI Types + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/ffi.html + | ArrayArray | ByteArray | SmallArray | StablePtr + | Mutable (?: ArrayArray | ByteArray | SmallArray) + )(#){{break}} + +############################################################################### + +contexts: + prototype: + - include: comments + - include: preprocessor-pragmas + - include: preprocessor-directives + + main: + - meta_include_prototype: false + - match: '' + push: [haskell, shebang] + + haskell: + - include: modules + - include: declarations + - include: statements + - include: expressions + + declarations: + - include: classes + - include: instances + - include: datas + - include: foreigns + - include: imports + - include: newtypes + - include: types + - include: functions + + statements: + - include: blocks + - include: defaults + - include: deriving + - include: statement-terminators + + expressions: + - include: literal-chars + - include: literal-strings + - include: literal-numbers + - include: type-forall + - include: operators + - include: brackets + - include: parens + - include: keywords + - include: ident-anonymous + - include: ident-namespaces + - include: ident-builtin-functions + - include: ident-builtin-constants + - include: ident-types + - include: ident-variables + +###[ COMMENTS ]################################################################ + + comments: + # 2.3 Comments + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-170002.3 + - include: line-comments + - include: block-comments + - include: merge-conflict-markers + + block-comments: + - match: \{-(?!#) + scope: punctuation.definition.comment.begin.haskell + push: block-comment-body + + block-comment-body: + - meta_include_prototype: false + - meta_scope: comment.block.haskell + - match: -\} + scope: punctuation.definition.comment.end.haskell + pop: 1 + - match: \{-# + push: block-comment-nested-body + - include: block-comments + + block-comment-nested-body: + - meta_include_prototype: false + - match: -\} + pop: 1 + - include: block-comments + + line-comments: + - match: (--+)(?:{{comment_first_char}}.*)?$\n? + scope: comment.line.double-dash.haskell + captures: + 1: punctuation.definition.comment.haskell + + shebang: + - match: ^\s*(\#!) + captures: + 1: punctuation.definition.comment.haskell + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if Haskell is embedded. + pop: 1 + + shebang-body: + - meta_scope: comment.line.shebang.haskell + - match: '{{shebang_language}}' + scope: constant.language.shebang.haskell + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ PREPROCESSOR ]############################################################ + + preprocessor-directives: + # In addition to Haskell's "native" syntax, + # GHC permits the C preprocessor to be run on a source file. + - match: ^\s*((#)\s*\w+) + scope: meta.preprocessor.c + captures: + 1: keyword.control.directive.other.c + 2: punctuation.definition.preprocessor.c + + preprocessor-pragmas: + # GHC 6.20 Pragmas + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/pragmas.html + - match: \{-# + scope: punctuation.section.preprocessor.begin.haskell + push: preprocessor-pragma-body + + preprocessor-pragma-body: + - meta_include_prototype: false + - meta_scope: meta.preprocessor.pragma.directive.haskell + - include: comments + # known directives + - match: LANGUAGE{{break}} + scope: keyword.control.directive.language.haskell + set: preprocessor-pragma-language-value + - match: (?:OPTIONS|OPTIONS_GHC|OPTIONS_HADDOCK){{break}} + scope: keyword.control.directive.options.haskell + set: preprocessor-pragma-options-value + - match: (?:COMPLETE|INLINE|INLINABLE|MINIMAL|NOINLINE){{break}} + scope: + meta.preprocessor.pragma.directive.haskell + keyword.control.directive.builtin.haskell + embed: preprocessor-pragma-signature-value + pop: 1 + escape: '#-\}' + escape_captures: + 0: meta.preprocessor.pragma.value.haskell + punctuation.section.preprocessor.end.haskell + - match: (SPECIALIZE)(?:\s+(?:(INLINE|NOINLINE)|(instance)))?{{break}} + scope: meta.preprocessor.pragma.directive.haskell + captures: + 1: keyword.control.directive.builtin.haskell + 2: keyword.control.directive.builtin.haskell + 3: keyword.declaration.instance.haskell + embed: preprocessor-pragma-signature-value + pop: 1 + escape: '#-\}' + escape_captures: + 0: meta.preprocessor.pragma.value.haskell + punctuation.section.preprocessor.end.haskell + - match: '{{pragma_directives}}' + scope: keyword.control.directive.builtin.haskell + set: preprocessor-pragma-other-value + # maybe incomplete directive + # maintain meta scope to support completions + - match: \p{Lu}+|(?=\S) + set: preprocessor-pragma-other-value + + preprocessor-pragma-language-value: + - meta_include_prototype: false + - meta_content_scope: meta.preprocessor.pragma.value.language.haskell + - include: preprocessor-pragma-common + - match: '{{pragma_extension_constants}}' + scope: constant.language.extension.haskell + - match: '{{pragma_deprecated_constants}}' + scope: constant.language.extension.haskell invalid.deprecated.haskell + + preprocessor-pragma-options-value: + - meta_include_prototype: false + - meta_content_scope: meta.preprocessor.pragma.value.options.haskell + - include: preprocessor-pragma-common + - match: (-*)[-\w]+ + scope: constant.other.pragma.haskell + captures: + 1: punctuation.definition.constant.haskell + + preprocessor-pragma-signature-value: + - meta_include_prototype: false + - meta_content_scope: meta.preprocessor.pragma.value.signature.haskell + - include: comments + - include: sequence-separators + - include: functions + - include: type-expressions + + preprocessor-pragma-other-value: + - meta_include_prototype: false + - meta_content_scope: meta.preprocessor.pragma.value.other.haskell + - include: preprocessor-pragma-common + - include: literal-numbers + - include: literal-strings + + preprocessor-pragma-common: + - match: '#-\}' + scope: + meta.preprocessor.pragma.value.haskell + punctuation.section.preprocessor.end.haskell + pop: 1 + - include: comments + - include: sequence-separators + +###[ MODULE DECLARATIONS ]##################################################### + + modules: + # 5.1 Module Structure + # https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-990005.1 + - match: module{{break}} + scope: + meta.declaration.module.haskell + keyword.declaration.namespace.haskell + push: + - module-where + - module-export + - module-name + # https://wiki.haskell.org/Module_signature + - match: signature{{break}} + scope: + meta.declaration.signature.haskell + keyword.declaration.namespace.haskell + push: + - signature-where + - module-export + - module-name + + module-name: + - include: ident-namespaces + - include: ident-module + - include: else-pop + + module-export: + - match: \( + scope: punctuation.section.sequence.begin.haskell + set: module-export-body + - include: else-pop + + module-export-body: + - meta_scope: meta.sequence.tuple.haskell + - include: tuple-end + - include: range-tuples + - include: prefix-parens-operators + - include: sequence-separators + - include: ident-namespaces + - match: \( + scope: punctuation.section.sequence.begin.haskell + push: module-export-body + - match: module{{break}} + scope: keyword.declaration.namespace.haskell + # class / constructor / data / module / type + - match: '{{con_id}}' + scope: entity.name.export.haskell + captures: + 1: storage.modifier.unboxed.haskell + # function / pattern / variable + - match: '{{var_id}}' + scope: entity.name.export.haskell + captures: + 1: storage.modifier.unboxed.haskell + - include: else-pop + + signature-where: + - meta_content_scope: meta.declaration.signature.haskell + - include: module-where + + module-where: + - meta_content_scope: meta.declaration.module.haskell + - match: where{{break}} + scope: keyword.control.context.haskell + set: module-block + - include: else-pop + + module-block: + # The module body may be wrapped into braces, which still needs to be + # handled as top-level block containing top-level declarations. + - match: \{ + scope: punctuation.section.block.begin.haskell + set: module-block-body + - include: else-pop + + module-block-body: + - meta_scope: meta.block.haskell + - include: block-end + - include: declarations + - include: statements + - include: expressions + +###[ IMPORT DECLARATIONS ]##################################################### + + imports: + # 5.3 Import Declarations + # https://www.haskell.org/onlinereport/haskell2010/haskellch5.html#x11-1010005.3 + # GHC 6.18.3 Safe Imports + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/safe_haskell.html#safe-imports + - match: import{{break}} + scope: meta.import.haskell keyword.declaration.import.haskell + push: + - import-filter + - import-hiding + - import-alias + - import-name + - import-modifier + - import-modifier + + import-modifier: + - match: (?:qualified|safe){{break}} + scope: storage.modifier.import.haskell + pop: 1 + - include: else-pop + + import-name: + - include: ident-namespaces + - include: ident-import + - include: else-pop + + import-alias: + - meta_content_scope: meta.import.module.haskell + - match: as{{break}} + scope: keyword.declaration.import.as.haskell + set: import-alias-name + - include: else-pop + + import-alias-name: + - meta_scope: meta.import.alias.haskell + - include: import-name + + import-hiding: + - match: hiding{{break}} + scope: storage.modifier.import.haskell + pop: 1 + - include: else-pop + + import-filter: + - match: \( + scope: punctuation.section.sequence.begin.haskell + set: import-filter-body + - include: else-pop + + import-filter-body: + - meta_scope: meta.import.filter.haskell meta.sequence.tuple.haskell + - include: import-tuple-body + + import-tuple-body: + - meta_scope: meta.sequence.tuple.haskell + - include: tuple-end + - include: range-tuples + - include: prefix-parens-operators + - include: sequence-separators + - match: \( + scope: punctuation.section.sequence.begin.haskell + push: import-tuple-body + - match: \. + scope: invalid.illegal.accessor.haskell + - match: module{{break}} + scope: invalid.illegal.unexpected-keyword.haskell + - match: newtype{{break}} + scope: keyword.declaration.newtype.haskell + - match: type{{break}} + scope: keyword.declaration.type.haskell + # class / constructor / data / module / type + - match: '{{con_id}}' + scope: entity.name.import.haskell + captures: + 1: storage.modifier.unboxed.haskell + # function / pattern / variable + - match: '{{var_id}}' + scope: entity.name.import.haskell + captures: + 1: storage.modifier.unboxed.haskell + - include: else-pop + +###[ FOREIGN DECLARATIONS ]#################################################### + + foreigns: + # 8.4 Foreign Declarations + # https://www.haskell.org/onlinereport/haskell2010/haskellch8.html#x15-1490008 + # GHC 6.17 Foreign function interface (FFI) + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/ffi.html + - match: foreign{{break}} + scope: storage.modifier.foreign.haskell + branch_point: foreign + branch: + - foreign-import + - foreign-export + + foreign-import: + # 8.4.3 Import Declarations + - meta_scope: meta.declaration.foreign.import.haskell + - match: export{{break}} + fail: foreign + - match: import{{break}} + scope: keyword.declaration.import.haskell + - match: (?:interruptible|unsafe|safe){{break}} + scope: storage.modifier.import.haskell + - include: foreign-common + + foreign-export: + # 8.4.4 Export Declarations + - meta_scope: meta.declaration.foreign.export.haskell + - match: export{{break}} + scope: keyword.declaration.export.haskell + - match: (?:interruptible|unsafe|safe){{break}} + scope: invalid.illegal.unexpected-keyword.haskell + - include: foreign-common + + foreign-common: + - include: literal-strings + - include: prefix-parens-operators + - match: (?:capi|ccall|cplusplus|dotnet|jvm|stdcall){{break}} + scope: constant.language.convention.haskell + - match: '{{var_id}}' + scope: entity.name.function.haskell + captures: + 1: storage.modifier.unboxed.haskell + - include: else-pop + +###[ CLASS DECLARATIONS ]###################################################### + + classes: + # 4.3.1 Class Declarations + # https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-750004.3 + - match: class{{break}} + scope: + meta.declaration.class.haskell + keyword.declaration.class.haskell + branch_point: class-declaration + branch: + - class-signature + - class-context + + class-context: + - meta_content_scope: meta.declaration.class.context.haskell + - match: '{{operator_big_arrow}}' + scope: + meta.declaration.class.haskell + punctuation.separator.type.context.haskell + set: + - class-maybe-args + - class-name + - include: expressions + + class-signature: + - meta_include_prototype: false + - match: '' + set: + - class-expect-args + - class-name + + class-name: + - include: ident-namespaces + - match: '{{con_id}}' + scope: entity.name.class.haskell + captures: + 1: storage.modifier.unboxed.haskell + pop: 1 + - include: else-pop + + class-expect-args: + - meta_content_scope: meta.declaration.class.haskell + - match: (?={{operator_big_arrow}}) + fail: class-declaration + - include: class-type + + class-maybe-args: + - meta_content_scope: meta.declaration.class.haskell + - include: class-type + + class-type: + - match: where{{break}} + scope: keyword.control.context.haskell + set: class-block + - include: declaration-type + + class-block: + - match: \{ + scope: punctuation.section.block.begin.haskell + set: class-block-body + - include: else-pop + + class-block-body: + - meta_scope: meta.block.haskell + - include: block-end + - include: functions + - include: statements + - include: expressions + +###[ INSTANCE DECLARATIONS ]################################################### + + instances: + # 4.3.2 Instance Declarations + # https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-750004.3 + - match: instance{{break}} + scope: + meta.declaration.instance.haskell + keyword.declaration.instance.haskell + branch_point: instance-declaration + branch: + - instance-signature + - instance-context + + instance-context: + - meta_content_scope: meta.declaration.instance.context.haskell + - match: '{{operator_big_arrow}}' + scope: + meta.declaration.instance.haskell + punctuation.separator.type.context.haskell + set: instance-maybe-type + - include: expressions + + instance-signature: + - meta_content_scope: meta.declaration.instance.haskell + - match: (?={{operator_big_arrow}}) + fail: instance-declaration + - include: class-type + + instance-maybe-type: + - meta_content_scope: meta.declaration.instance.haskell + - include: class-type + +###[ DATA DECLARATIONS ]####################################################### + + datas: + # 4.2.1 Algebraic Datatype Declarations + # https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-680004.2 + - match: (data)(?:\s+(family|instance))?{{break}} + scope: meta.declaration.data.haskell + captures: + 1: keyword.declaration.data.haskell + 2: storage.modifier.family.haskell + branch_point: data-declaration + branch: + - data-signature + - data-context + + data-context: + # A data declaration with optional `context` expression being present. + - meta_content_scope: meta.declaration.data.context.haskell + - match: '{{operator_big_arrow}}' + scope: punctuation.separator.type.context.haskell + set: + - data-maybe-constructors + - type-name + - include: expressions + + data-signature: + # A data declaration without optional `context` expression being present. + # That's the more common use case and thus matched first. + - meta_include_prototype: false + - match: '' + set: + - data-expect-constructors + - type-name + + data-expect-constructors: + - meta_scope: meta.declaration.data.haskell + - match: (?={{operator_big_arrow}}) + fail: data-declaration + - include: data-maybe-constructors + + data-maybe-constructors: + - meta_scope: meta.declaration.data.haskell + - match: = + scope: keyword.operator.haskell + set: + - constructors + - constructor-or-type + - include: declaration-type + +###[ CONSTRUCTOR DECLARATIONS ]################################################ + + constructors: + - meta_content_scope: meta.declaration.data.haskell + - match: \| + scope: punctuation.separator.sequence.haskell + push: constructor-or-type + - include: declaration-type + + constructor-or-type: + - match: (?={{con_id}}) + pop: 1 + branch_point: constructor-or-type + branch: + - constructor + - ident-type + - include: else-pop + + constructor: + # Data constructors without arguments are also called constants. + # Thus all data constructors are scoped as constant. + - match: '{{con_id}}' + scope: entity.name.constant.haskell + set: constructor-parameters + + constructor-parameters: + - match: \{ + scope: punctuation.section.block.begin.haskell + set: record-body + - match: (?=\S) + set: constructor-body + + constructor-body: + - include: declaration-end + - include: type-lists + - include: type-parens + - include: ident-namespaces + - include: ident-types + - include: ident-variables + - match: \! + scope: keyword.operator.haskell + # terminated by + # - statement terminator + # - constructor separator + # - record block + # - any (key)word + - match: (?=[|{\w]) + pop: 1 + - match: (?=\S) + fail: constructor-or-type + +###[ DEFAULT DECLARATIONS ]#################################################### + + defaults: + # 4.3.4 Ambiguous Types, and Defaults for Overloaded Numeric Operations + # https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-750004.3 + - match: default{{break}} + scope: storage.modifier.haskell + push: + - default-meta + - default-body + + default-meta: + - meta_include_prototype: false + - meta_scope: meta.declaration.default.haskell + - include: immediately-pop + + default-body: + - match: \( + scope: punctuation.section.sequence.begin.haskell + set: type-tuple-body + - include: else-pop + +###[ DERIVING DECLARATIONS ]################################################### + + deriving: + # 4.3.3 Derived Instances + # https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-750004.3 + - match: (?:deriving|via){{break}} + scope: storage.modifier.haskell + push: + - deriving-meta + - deriving-begin + + deriving-meta: + - meta_include_prototype: false + - meta_scope: meta.declaration.deriving.haskell + - include: immediately-pop + + deriving-begin: + - match: \( + scope: punctuation.section.sequence.begin.haskell + set: deriving-tuple-body + - match: (?=\S) + set: deriving-body + + deriving-body: + - include: ident-namespaces + - include: ident-type + - include: else-pop + + deriving-tuple-body: + - meta_scope: meta.sequence.tuple.haskell + - include: tuple-end + - include: sequence-separators + - include: ident-namespaces + - include: ident-types + - include: else-pop + +###[ FUNCTION DECLARATIONS ]################################################### + + functions: + - match: (?={{var_id}}|\(\s*{{operator_parens}}\s*\)) + branch_point: functions + branch: + - variable-name + - function-name + + function-name: + - meta_content_scope: meta.function.identifier.haskell + - match: '{{operator_double_colon}}' + scope: punctuation.separator.type.haskell + pop: 1 + - match: '{{var_id}}' + scope: entity.name.function.haskell + captures: + 1: storage.modifier.unboxed.haskell + - include: prefix-parens-operators + - include: sequence-separators + + variable-name: + - match: (\()\s*({{operator_parens}})\s*(\)) + scope: meta.prefix.haskell + captures: + 1: punctuation.definition.prefix.begin.haskell + 2: keyword.operator.haskell + 3: punctuation.definition.prefix.end.haskell + push: variable-name-end + - match: '{{prelude_functions}}' + scope: support.function.prelude.haskell + push: variable-name-end + - match: _\b + scope: variable.language.anonymous.haskell + captures: + 1: storage.modifier.unboxed.haskell + push: variable-name-end + - match: '{{var_id}}' + scope: variable.other.haskell + captures: + 1: storage.modifier.unboxed.haskell + push: variable-name-end + - include: sequence-separators + - include: else-pop + + variable-name-end: + - match: (?={{operator_double_colon}}) + fail: functions + - match: (?=,) + pop: 1 + - match: (?=\S) + pop: 2 + +###[ NEWTYPE DECLARATIONS ]#################################################### + + newtypes: + - match: newtype{{break}} + scope: + meta.declaration.newtype.haskell + keyword.declaration.newtype.haskell + branch_point: newtype-declaration + branch: + - newtype-signature + - newtype-context + + newtype-context: + - meta_content_scope: meta.declaration.newtype.context.haskell + - match: '{{operator_big_arrow}}' + scope: punctuation.separator.type.context.haskell + set: + - newtype-maybe-args + - type-name + - include: expressions + + newtype-signature: + - meta_include_prototype: false + - match: '' + set: + - newtype-expect-args + - type-name + + newtype-expect-args: + - meta_scope: meta.declaration.newtype.haskell + - match: (?={{operator_big_arrow}}) + fail: newtype-declaration + - include: declaration-type + + newtype-maybe-args: + - meta_scope: meta.declaration.newtype.haskell + - include: declaration-type + +###[ TYPE DECLARATIONS ]####################################################### + + types: + # https://wiki.haskell.org/GHC/Type_families + - match: (type)(?:\s+(family))?{{break}} + scope: meta.declaration.type.haskell + captures: + 1: keyword.declaration.type.haskell + 2: storage.modifier.family.haskell + branch_point: type-declaration + branch: + - type-signature + - type-context + + type-context: + - meta_content_scope: meta.declaration.type.context.haskell + - match: '{{operator_big_arrow}}' + scope: punctuation.separator.type.context.haskell + set: + - type-maybe-args + - type-name + - include: expressions + + type-signature: + - meta_include_prototype: false + - match: '' + set: + - type-expect-args + - type-name + + type-name: + - include: ident-namespaces + - match: '{{con_id}}' + scope: entity.name.type.haskell + captures: + 1: storage.modifier.unboxed.haskell + pop: 1 + - include: else-pop + + type-expect-args: + - meta_scope: meta.declaration.type.haskell + - match: (?={{operator_big_arrow}}) + fail: type-declaration + - include: declaration-type + + type-maybe-args: + - meta_scope: meta.declaration.type.haskell + - include: declaration-type + +###[ DECLARATION TYPE EXPRESSIONS ]############################################ + + declaration-type: + - include: declaration-end + - include: right-arrow-operators + - include: infix-quoted-operators + - include: infix-operators + - include: type-lists + - include: type-parens + - include: type-forall + - include: ident-anonymous + - include: ident-namespaces + - include: ident-types + - include: ident-variables + - match: \S + scope: invalid.illegal.haskell + + declaration-end: + - match: (?=;|=(?!{{symbol}})|{{operator_double_colon}}|{{operator_left_arrow}}|{{reserved_id}}) + pop: 1 + # pop context if beginning of a line looks like a function declaration or assignment expression + - match: ^(?=\s*{{var_id}}) + branch_point: declaration-type-end + branch: + - declaration-type-variable + - immediately-pop2 + + declaration-type-variable: + - match: '{{var_id}}' + scope: variable.other.haskell + captures: + 1: storage.modifier.unboxed.haskell + set: declaration-type-variable-after + + declaration-type-variable-after: + - match: (?=,|=(?!{{symbol}})|{{operator_double_colon}}|{{operator_left_arrow}}) + fail: declaration-type-end + - include: ident-anonymous + - include: ident-namespaces + - include: ident-types + - include: ident-variables + - include: else-pop + +###[ TYPE EXPRESSIONS ]######################################################## + + type-expressions: + - include: big-arrow-operators + - include: right-arrow-operators + - include: type-lists + - include: type-parens + - include: type-forall + - include: ident-anonymous + - include: ident-namespaces + - include: ident-types + - include: ident-variables + + type-forall: + - match: forall{{break}}|β(?!{{symbol}}) + scope: keyword.control.forall.haskell + push: type-forall-body + + type-forall-body: + # Note: This is the only situation a dot is allowed within type expressions. + - match: \. + scope: punctuation.separator.sequence.haskell + pop: 1 + - include: ident-anonymous + - include: ident-variables + - include: else-pop + + type-lists: + - include: empty-lists + - match: \[ + scope: punctuation.section.sequence.begin.haskell + push: type-list-body + + type-list-body: + - meta_scope: meta.sequence.list.haskell + - include: list-end + - include: sequence-separators + - include: type-expressions + - include: else-pop + + type-parens: + # 4.1.3 Syntax of Class Assertions and Contexts + # https://www.haskell.org/onlinereport/haskell2010/haskellch4.html#x10-630004.1 + - include: empty-tuples + - include: prefix-parens-operators + - match: (?=\() + branch_point: type-parens + branch: + - type-group + - type-tuple + + type-group: + - match: \( + scope: punctuation.section.group.begin.haskell + set: type-group-body + + type-group-body: + - meta_scope: meta.group.haskell + - match: ',|:(?!{{symbol}})' + fail: type-parens + - include: group-end + - include: type-expressions + - include: else-pop + + type-tuple: + - match: \( + scope: punctuation.section.sequence.begin.haskell + set: type-tuple-body + + type-tuple-body: + - meta_scope: meta.sequence.tuple.haskell + - include: tuple-end + - include: sequence-separators + - include: type-expressions + - include: else-pop + +###[ BRACES ]################################################################## + + blocks: + # 2.7 Layout + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-210002.7 + - match: \{ + scope: punctuation.section.block.begin.haskell + push: block-body + + block-end: + - match: \} + scope: punctuation.section.block.end.haskell + pop: 1 + + block-body: + - meta_scope: meta.block.haskell + - include: block-end + - include: statements + - include: expressions + - include: else-pop + + records: + - match: \{ + scope: punctuation.section.block.begin.haskell + push: record-body + + record-body: + - meta_scope: meta.block.haskell + - include: block-end + - include: expressions + - include: else-pop + +###[ BRACKETS ]################################################################ + + brackets: + - include: hsx-quotes + - include: typed-quotes + - include: overloaded-quotes + - include: empty-lists + - match: (?=\[) + branch_point: list-or-quasiquote + branch: + - list + - quasi-quote + + empty-lists: + - match: (\[)(\]) + captures: + 0: meta.sequence.list.empty.haskell + 1: punctuation.section.sequence.begin.haskell + 2: punctuation.section.sequence.end.haskell + + list: + # 3.7 Lists + # https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-340003.7 + - match: \[ + scope: punctuation.section.sequence.begin.haskell + set: list-body + + list-body: + - meta_scope: meta.sequence.list.haskell + - include: list-fail + - include: list-end + - include: list-keywords + - include: records + - include: expressions + - include: else-pop + + list-end: + - match: \] + scope: punctuation.section.sequence.end.haskell + pop: 1 + + list-fail: + - match: \|\] + fail: list-or-quasiquote + + list-keywords: + # 6.2.7. Generalised (SQL-like) List Comprehensions + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/generalised_list_comprehensions.html + - match: (?:group|by|using){{break}} + scope: keyword.control.list.haskell + + quasi-quote: + # https://wiki.haskell.org/Quasiquotation + - match: \[ + scope: meta.quoted.quasi.haskell punctuation.section.quoted.begin.haskell + set: quasi-quote-name + + quasi-quote-name: + - meta_content_scope: meta.quoted.quasi.haskell + - match: \| + scope: meta.quoted.quasi.haskell punctuation.section.quoted.haskell + set: quasi-quote-body + - match: '[\w'']+' + scope: variable.function.quasi-quoter.haskell + - include: quasi-quote-end + + quasi-quote-body: + - meta_content_scope: meta.quoted.quasi.haskell meta.string.haskell string.unquoted.haskell + - include: quasi-quote-end + + quasi-quote-end: + - match: \|\] + scope: meta.quoted.quasi.haskell punctuation.section.quoted.end.haskell + pop: 1 + + hsx-quotes: + - match: (\[)(hsx)(\|) + scope: meta.quoted.quasi.haskell + captures: + 1: punctuation.section.quoted.begin.haskell + 2: variable.function.quasi-quoter.haskell + 3: punctuation.section.quoted.haskell + embed: scope:text.html.embedded.haskell + embed_scope: meta.quoted.quasi.haskell text.html.embedded.haskell + escape: \|\] + escape_captures: + 0: meta.quoted.quasi.haskell punctuation.section.quoted.end.haskell + + overloaded-quotes: + # https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0246-overloaded-bracket.rst + - match: \[\| + scope: punctuation.section.quoted.begin.haskell + push: overloaded-quote-body + + overloaded-quote-body: + - meta_scope: meta.quoted.overloaded.haskell + - match: \|\] + scope: punctuation.section.quoted.end.haskell + pop: 1 + - include: expressions + + typed-quotes: + # https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0246-overloaded-bracket.rst + - match: \[\|\|(?!\]) + scope: punctuation.section.quoted.begin.haskell + push: typed-quote-body + + typed-quote-body: + - meta_scope: meta.quoted.typed.haskell + - match: \|\|\] + scope: punctuation.section.quoted.end.haskell + pop: 1 + - include: expressions + +###[ PARENTHESES ]############################################################# + + parens: + # 3.8 Tuples + # https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-360003.8 + - include: empty-tuples + - include: unboxed-tuples + - include: prefix-parens-operators + - match: (?=\() + branch_point: parens + branch: + - group + - tuple + + group: + - match: \( + scope: punctuation.section.group.begin.haskell + set: group-body + + group-end: + - match: \) + scope: punctuation.section.group.end.haskell + pop: 1 + + group-body: + - meta_scope: meta.group.haskell + - match: ',|:(?!{{symbol}})' + fail: parens + - include: group-end + - include: records + - include: expressions + - include: else-pop + + tuple: + - match: \( + scope: punctuation.section.sequence.begin.haskell + set: tuple-body + + tuple-end: + - match: \) + scope: punctuation.section.sequence.end.haskell + pop: 1 + + tuple-body: + - meta_scope: meta.sequence.tuple.haskell + - include: tuple-end + - include: records + - include: expressions + - include: else-pop + + empty-tuples: + # 6.1.5 Unit Data Type + # https://www.haskell.org/onlinereport/haskell2010/haskellch6.html#x13-1200006.1.5 + - match: (\()(\)) + scope: meta.sequence.tuple.empty.haskell + captures: + 1: punctuation.section.sequence.begin.haskell + 2: punctuation.section.sequence.end.haskell + + range-tuples: + - match: (\()\s*(\.\.)\s*(\)) + scope: meta.sequence.tuple.haskell + captures: + 1: punctuation.section.sequence.begin.haskell + 2: keyword.operator.haskell + 3: punctuation.section.sequence.end.haskell + + unboxed-tuples: + # GHC 6.16.3 Unboxed tuples + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/primitives.html#unboxed-tuples + - match: (\()(#) + captures: + 1: punctuation.section.sequence.begin.haskell + 2: storage.modifier.unboxed.haskell + push: unboxed-tuple-body + + unboxed-tuple-body: + - meta_scope: meta.sequence.tuple.haskell + - match: (#)(\)) + captures: + 1: storage.modifier.unboxed.haskell + 2: punctuation.section.sequence.end.haskell + pop: 1 + - include: records + - include: expressions + - include: else-pop + +###[ IDENTIFIERS ]############################################################# + + ident-anonymous: + - match: _\b + scope: variable.language.anonymous.haskell + captures: + 1: storage.modifier.unboxed.haskell + + ident-builtin-constants: + # Data constructors without arguments are also called constants. + # Thus all data constructors are scoped as constant. + - match: '{{prelude_constants}}' + scope: support.constant.prelude.haskell + + ident-builtin-functions: + - match: '{{prelude_functions}}' + scope: support.function.prelude.haskell + + ident-namespaces: + - match: ({{con_id}})(\.) + captures: + 1: variable.namespace.haskell + 2: storage.modifier.haskell + 3: punctuation.accessor.dot.haskell + + ident-module: + - match: '{{con_id}}' + scope: entity.name.namespace.haskell + captures: + 1: storage.modifier.unboxed.haskell + pop: 1 + + ident-import: + - match: '{{con_id}}' + scope: variable.namespace.haskell + captures: + 1: storage.modifier.unboxed.haskell + pop: 1 + + ident-types: + - include: ident-builtin-types + - include: ident-user-types + + ident-builtin-types: + # Prelude Class Types + - match: '{{prelude_classes}}' + scope: support.class.prelude.haskell + # Prelude Data Types + - match: '{{prelude_types}}' + scope: support.type.prelude.haskell + # Unboxed Data Types + - match: '{{unboxed_types}}' + scope: support.type.unboxed.haskell + captures: + 1: storage.modifier.unboxed.haskell + + ident-user-types: + - match: '{{con_id}}' + scope: storage.type.haskell + captures: + 1: storage.modifier.unboxed.haskell + + ident-type: + - include: ident-builtin-type + - include: ident-user-type + + ident-builtin-type: + # Prelude Class Types + - match: '{{prelude_classes}}' + scope: support.class.prelude.haskell + pop: 1 + # Prelude Data Types + - match: '{{prelude_types}}' + scope: support.type.prelude.haskell + pop: 1 + # Unboxed Data Types + - match: '{{unboxed_types}}' + scope: support.type.unboxed.haskell + captures: + 1: storage.modifier.unboxed.haskell + pop: 1 + + ident-user-type: + - match: '{{con_id}}' + scope: storage.type.haskell + captures: + 1: storage.modifier.unboxed.haskell + pop: 1 + + ident-variables: + - match: '{{var_id}}' + scope: variable.other.haskell + captures: + 1: storage.modifier.unboxed.haskell + +###[ LITERALS ]################################################################ + + literal-numbers: + # 2.5 Decimal floating point literals + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-190002.5 + - match: (\d{{dec_digit}}*(?:(\.){{dec_digit}}+{{dec_exponent}}?|{{dec_exponent}}))(#*) + scope: meta.number.float.decimal.haskell + captures: + 1: constant.numeric.value.haskell + 2: punctuation.separator.decimal.haskell + 3: constant.numeric.suffix.haskell + # GHC 6.9.3 Hexadecimal floating point literals + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/hex_float_literals.html + - match: (0[xX])({{hex_digit}}+(\.){{hex_digit}}+{{hex_exponent}}?)(#*) + scope: meta.number.float.hexadecimal.haskell + captures: + 1: constant.numeric.base.haskell + 2: constant.numeric.value.haskell + 3: punctuation.separator.decimal.haskell + 4: constant.numeric.suffix.haskell + # GHC 6.9.2 Binary integer literals + # https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/binary_literals.html + - match: (0[bB])({{bin_digit}}+)(#*) + scope: meta.number.integer.binary.haskell + captures: + 1: constant.numeric.base.haskell + 2: constant.numeric.value.haskell + 3: constant.numeric.suffix.haskell + # 2.5 Numeric Literals + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-190002.5 + - match: (0[oO])({{oct_digit}}+)(#*) + scope: meta.number.integer.octal.haskell + captures: + 1: constant.numeric.base.haskell + 2: constant.numeric.value.haskell + 3: constant.numeric.suffix.haskell + - match: (0[xX])({{hex_digit}}+)(#*) + scope: meta.number.integer.hexadecimal.haskell + captures: + 1: constant.numeric.base.haskell + 2: constant.numeric.value.haskell + 3: constant.numeric.suffix.haskell + - match: (\d{{dec_digit}}*)(#*) + scope: meta.number.integer.decimal.haskell + captures: + 1: constant.numeric.value.haskell + 2: constant.numeric.suffix.haskell + + literal-chars: + # 2.6 Character and String Literals + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-200002.6 + - match: (')(?:([ [\S&&[^\\'']]])|{{escape_sequence}})?(?:(')(#*)|{{comment_ahead}}) + scope: meta.string.haskell string.quoted.single.haskell + captures: + 1: punctuation.definition.string.begin.haskell + 2: constant.character.literal.haskell + 3: constant.character.escape.haskell + 4: constant.character.escape.decimal.haskell + 5: constant.character.escape.octal.haskell + 6: constant.character.escape.hexadecimal.haskell + 7: constant.character.escape.control.haskell + 8: punctuation.definition.string.end.haskell + 9: storage.modifier.unboxed.haskell + + literal-strings: + # 2.6 Character and String Literals + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-200002.6 + - match: \" + scope: punctuation.definition.string.begin.haskell + push: literal-string-body + + literal-string-body: + - meta_include_prototype: false + - meta_scope: meta.string.haskell string.quoted.double.haskell + - match: (\")(#*)|$ + captures: + 1: punctuation.definition.string.end.haskell + 2: storage.modifier.unboxed.haskell + pop: 1 + - match: '{{escape_sequence}}' + captures: + 1: constant.character.escape.haskell + 2: constant.character.escape.decimal.haskell + 3: constant.character.escape.octal.haskell + 4: constant.character.escape.hexadecimal.haskell + 5: constant.character.escape.control.haskell + - match: (\\)\s*$ + captures: + 1: punctuation.definition.continuation.begin.haskell + push: literal-string-continuation + + literal-string-continuation: + - clear_scopes: 2 + - meta_scope: meta.string.continuation.haskell + - meta_include_prototype: false + - match: \\ + scope: punctuation.definition.continuation.end.haskell + pop: 1 + - match: \" + scope: invalid.illegal.expect-continuation-end.haskell + pop: 2 + - match: \S + scope: invalid.illegal.expect-continuation-end.haskell + pop: 1 + +###[ KEYWORDS AND OPERATORS ]################################################## + + keywords: + - match: (?:mdo|do|in|rec|where){{break}} + scope: keyword.control.context.haskell + - match: (?:case|of){{break}} + scope: keyword.control.conditional.select.haskell # the construct is commonly called "select" + - match: if{{break}} + scope: keyword.control.conditional.if.haskell + - match: then{{break}} + scope: keyword.control.conditional.then.haskell + - match: else{{break}} + scope: keyword.control.conditional.else.haskell + - match: let{{break}} + scope: keyword.declaration.variable.haskell + - match: proc{{break}} + scope: keyword.declaration.function.haskell + # 4.4.2 Fixity Declarations + - match: infix[lr]?{{break}} + scope: keyword.declaration.fixity.haskell + + operators: + - include: sequence-separators + - include: big-arrow-operators + - include: left-arrow-operators + - include: right-arrow-operators + - include: prefix-parens-operators + - include: infix-quoted-operators + - include: infix-operators + + big-arrow-operators: + - match: '{{operator_big_arrow}}' + scope: punctuation.separator.type.context.haskell + + left-arrow-operators: + - match: '{{operator_left_arrow}}' + scope: keyword.operator.arrow.haskell + + right-arrow-operators: + - match: '{{operator_right_arrow}}' + scope: keyword.operator.arrow.haskell + + prefix-parens-operators: + - match: (\()\s*({{operator_parens}})\s*(\)) + scope: meta.prefix.haskell + captures: + 1: punctuation.definition.prefix.begin.haskell + 2: keyword.operator.haskell + 3: punctuation.definition.prefix.end.haskell + + infix-operators: + # Match all not otherwise matched single quotes as promotion operator + # Note: Found in real world code but not in specs so far. + - match: \' + scope: keyword.operator.haskell + - match: '{{operator_double_colon}}' + scope: punctuation.separator.type.haskell + - match: '{{operator_symbol}}' + scope: keyword.operator.haskell + + infix-quoted-operators: + - match: (?=\`) + branch_point: infix-quoted-operators + branch: + - infix-quoted-operators-begin + - immediately-pop + + infix-quoted-operators-begin: + - match: (\`)\s* + captures: + 1: punctuation.definition.infix.begin.haskell + set: infix-quoted-operators-body + + infix-quoted-operators-body: + - meta_scope: meta.infix.haskell + - match: \s*(\`) + captures: + 1: punctuation.definition.infix.end.haskell + pop: 1 + - include: ident-namespaces + - match: '{{id}}' + scope: keyword.operator.function.infix.haskell + captures: + 1: storage.modifier.unboxed.haskell + - match: '' + fail: infix-quoted-operators + + statement-terminators: + # Depending on layout, semicolon may be needed to terminate statements. + # https://www.haskell.org/onlinereport/haskell2010/haskellch2.html#x7-210002.7 + - match: ';' + scope: punctuation.terminator.statement.haskell + + sequence-separators: + - match: ',|\|(?!\|)' + scope: punctuation.separator.sequence.haskell + +###[ PROTOTYPES ]############################################################## + + else-pop: + - match: (?=\S) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + immediately-pop2: + - match: '' + pop: 2 +
diff --git /dev/null b/syntax/INI/INI.sublime-syntax @@ -0,0 +1,221 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/syntax.html +# https://en.wikipedia.org/wiki/INI_file +name: INI +scope: source.ini + +file_extensions: + - ini + - dosini + - conf + +variables: + separator: '[=:]' + +contexts: + + main: + - include: comment + - include: section + - include: mapping + + comment: + - match: ; + scope: punctuation.definition.comment.ini + push: + - meta_scope: comment.line.semicolon.ini + - match: \n + pop: true + - match: \# + scope: punctuation.definition.comment.ini + push: + - meta_scope: comment.line.number-sign.ini + - match: \n + pop: true + + section: + - match: ^\s*(\[) + captures: + 1: punctuation.definition.section.begin.ini + push: + - meta_scope: meta.section.ini + - match: \-? + scope: keyword.operator.arithmetic.ini + set: section-name + + section-name: + - meta_content_scope: meta.section.ini entity.name.section.ini + - match: (\])(\s*$)? + scope: meta.section.ini + captures: + 1: punctuation.definition.section.end.ini + 2: meta.whitespace.newline.ini + pop: true + - match: \. + scope: punctuation.separator.namespace.ini + - match: \\ + scope: punctuation.separator.backslash.ini + - match: ':' + scope: punctuation.separator.colon.ini + - include: eol-pop + + mapping: + - match: (?=\S) + push: + - meta_content_scope: meta.mapping.key.ini + - match: (?=\s*{{separator}}) + set: + - mapping-value + - mapping-separator + - match: (\[)(\d+)(\]) + captures: + 1: punctuation.section.brackets.begin.ini + 2: meta.number.integer.decimal.ini constant.numeric.value.ini + 3: punctuation.section.brackets.end.ini + - match: \, + scope: punctuation.separator.sequence.ini + - include: string + - include: eol-pop + + mapping-separator: + - match: '{{separator}}' + scope: punctuation.separator.key-value.ini + pop: true + + mapping-value: + - meta_content_scope: meta.mapping.ini + - match: \-(?=\s*($|#)) + scope: meta.mapping.value.ini keyword.operator.arithmetic.ini + pop: true + - match: (?=\S) + set: + - mapping-value-meta + - maybe-value-firstline + - match: \n + set: + - mapping-value-meta + - maybe-value-multiline + + mapping-value-meta: + - meta_scope: meta.mapping.value.ini + - match: '' + pop: true + + maybe-value-firstline: + - match: (,)\s*$\n? + captures: + 1: punctuation.separator.sequence.ini + set: maybe-value-multiline + - include: constant + - include: number + - include: string + - include: eol-pop + + maybe-value-multiline: + - include: comment + - match: ^(?=\S) + pop: true + - match: (?=.+{{separator}}) + pop: true + - match: (,)\s*$\n? + captures: + 1: punctuation.separator.sequence.ini + - include: constant + - include: number + - include: string + + constant: + - match: \b(?i:true)\b + scope: constant.language.boolean.true.ini + - match: \b(?i:false)\b + scope: constant.language.boolean.false.ini + - match: \bdword\b + scope: storage.type.dword.ini + set: + - match: ':' + scope: punctuation.separator.colon.ini + set: + - include: hex-number + - include: eol-pop + - match: \S + scope: invalid.illegal.ini + - include: eol-pop + - match: \S + scope: invalid.illegal.ini + - match: \b(hex\b(?:\([01234578ab]\))?) + scope: storage.type.hex.ini + set: + - match: ':' + scope: punctuation.separator.colon.ini + set: + - include: hex-number + - include: eol-pop + - match: \, + scope: punctuation.separator.sequence.ini + - match: (\\)\s*$ + captures: + 1: punctuation.separator.continuation.line.ini + push: + - include: comment + - match: (?=\S) + pop: true + - match: ^\s+ + - match: \S + scope: invalid.illegal.ini + - match: '[^()01234578ab\s]' + scope: invalid.illegal.ini + + hex-number: + - match: \b\h+\b + scope: meta.number.integer.hexadecimal.ini constant.numeric.value.ini + + number: + - match: '([-+])?\b(\d*(\.)\d+(?:(?:E|e)[-+]?\d+)?)(F|f)?\b' + scope: meta.number.float.decimal.ini + captures: + 1: keyword.operator.arithmetic.ini + 2: constant.numeric.value.ini + 3: punctuation.separator.decimal.ini + 4: constant.numeric.suffix.ini + - match: '([-+])?\b(\d+)\b' + scope: meta.number.integer.decimal.ini + captures: + 1: keyword.operator.arithmetic.ini + 2: constant.numeric.value.ini + + string: + - match: \" + scope: punctuation.definition.string.begin.ini + push: + - meta_scope: string.quoted.double.ini + - include: character-escape + - match: \" + scope: punctuation.definition.string.end.ini + pop: true + - match: \n + pop: true + - match: \' + scope: punctuation.definition.string.begin.ini + push: + - meta_scope: string.quoted.single.ini + - include: character-escape + - match: \' + scope: punctuation.definition.string.end.ini + pop: true + - match: \n + pop: true + - match: (?=\S) + push: + - meta_content_scope: string.unquoted.ini + - include: character-escape + - match: (?=[\s=:,\[]) + pop: true + + character-escape: + - match: \\(?:[^*\s\w]|[abnrt0]|x\h{4}) + scope: constant.character.escape.ini + + eol-pop: + - match: $|(?=\s+#) + pop: true
diff --git /dev/null b/syntax/Java/Java.sublime-syntax @@ -0,0 +1,3483 @@ +%YAML 1.2 +--- +# https://www.sublimetext.com/docs/syntax.html +# https://docs.oracle.com/javase/specs/jls/se13/html/index.html +name: Java +scope: source.java +version: 2 + +file_extensions: + - java + +first_line_match: |- + (?x: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* // .*? -\*- .*? \bjava\b .*? -\*- # editorconfig + ) + +############################################################################### + +variables: + shebang_language: \b(?:bsh|java)\b + + # Reserved keywords + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.9 + reserved_words: |- + (?x: + {{keywords}} + | {{storage_types}} + | {{storage_modifiers}} + | {{constants}} + | {{variables}} + ) + keywords: |- + (?x: + {{declaration_keywords}} + | {{control_keywords}} + | {{operator_keywords}} + | {{illegal_keywords}} + ) + declaration_keywords: |- + (?x: class | enum | @?interface | var | void | extends | implements | import | package ) + control_keywords: |- + (?x: assert | break | case | catch | continue | default | do | else | finally | for + | if | return | switch | synchronized | throw | throws | try | while | yield ) + operator_keywords: |- + (?x: new | instanceof ) + illegal_keywords: |- + (?x: const | goto ) + + # Storage Modifiers + # excludes `default`, `synchronized` keywords + storage_modifiers: |- + (?x: public | protected | private | abstract | final | native | sealed | static | strictfp | transient | volatile ) + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.1.1 + class_modifier: |- + (?x: public | protected | private | abstract | final | sealed | static | strictfp ) + class_no_modifier: |- + (?x: default | native | synchronized | transient | volatile ) + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.8 + constructor_modifier: |- + (?x: public | protected | private ) + constructor_no_modifier: |- + (?x: abstract | default | final | native | sealed | static | strictfp | synchronized | transient | volatile ) + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.3.1 + field_modifier: |- + (?x: public | protected | private | final | static | transient | volatile ) + field_no_modifier: |- + (?x: abstract | default | native | sealed | strictfp | synchronized ) + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-9.1.1 + interface_modifier: |- + (?x: public | protected | private | abstract | sealed | static | strictfp ) + interface_no_modifier: |- + (?x: default | final | native | synchronized | transient | volatile ) + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.4.3 + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.4 + method_modifier: |- + (?x: public | protected | private | abstract | default | final | native | static | strictfp | synchronized ) + method_no_modifier: |- + (?x: sealed | transient | volatile ) + + # Storage Types + storage_types: |- + (?x: boolean | byte | char | short | int | float | long | double ) + + # Literals + constants: |- + (?x: false | null | true ) + variables: |- + (?x: _ | super | this ) + + # Identifiers + break: (?!{{id_char}}) + + identifier: (?!{{reserved_words}}[^{{id_char}}]){{id}} + + id: (?:{{id_first_char}}{{id_char}}*) + id_first_char: '[\p{L}_$]' + id_char: '[\p{L}\p{N}_$]' + + classcase_id: (?:\p{Lu}{{id_char}}*) + lowercase_id: (?:[_$]*\p{Ll}[\p{Ll}\p{N}_$]*{{break}}) + uppercase_id: (?:[_$]*\p{Lu}[\p{Lu}\p{N}_$]*{{break}}) + + # digits + bin_digit: '[01_]' + oct_digit: '[0-7_]' + dec_digit: '[\d_]' + hex_digit: '[\h_]' + dec_exponent: '[eE][-+]?{{dec_digit}}*' + hex_exponent: '[pP][-+]?{{dec_digit}}*' + float_suffix: '[dDfF]{{break}}' + int_suffix: '[lL]{{break}}' + + escape_octal: \\[0-3]?[0-7]{1,2} + escape_other: \\[btnfr"'\\] + escape_unicode: \\u+\h{4} + + # accessor but no variadic operator + single_dot: \.(?!\.) + +############################################################################### + +contexts: + main: + - meta_include_prototype: false + - match: '' + push: [java, shebang] + + java: + - include: import + - include: module + - include: package + - include: declarations + - include: statements + - include: else-expressions + + statements: + - include: member-statements + - include: synchronized-statements + + member-statements: + - include: punctuation-terminator-semicolon + - include: blocks + - include: stray-group + - include: flow-control-statements + - include: if-else-statements + - include: switch-case-statements + - include: do-while-statements + - include: for-statements + - include: try-catch-statements + - include: labeled-statements + + expressions: + - include: instantiations + - include: lambdas + - include: constant-expressions + + constant-expressions: + - include: groups + - include: literals + - include: punctuations + - include: operators + - include: type-comparisons + - include: primitive-maybe-class-literals + - include: var-types + - include: array-modifiers + - include: storage-modifiers + - include: object-types + - include: variables + +###[ COMMENTS ]################################################################ + + comments: + - include: line-comments + - include: block-comments + - include: merge-conflict-markers + + block-comments: + # empty block comments + - match: /\*\*+/ + scope: comment.block.empty.java punctuation.definition.comment.java + # documentation block comments + - match: /\*\*+ + scope: + comment.block.documentation.java + punctuation.definition.comment.begin.java + embed: Packages/Java/Embeddings/JavaDoc.sublime-syntax#javadoc + embed_scope: comment.block.documentation.java + escape: \*+/ + escape_captures: + 0: comment.block.documentation.java + punctuation.definition.comment.end.java + # normal block comments + - match: /\* + scope: punctuation.definition.comment.begin.java + push: block-comment-body + + block-comment-body: + - meta_include_prototype: false + - meta_scope: comment.block.java + - match: \*+/ + scope: punctuation.definition.comment.end.java + pop: 1 + - match: ^\s*(\*)(?![*/]) + scope: punctuation.definition.comment.java + - include: merge-conflict-markers + + line-comments: + - match: //+ + scope: punctuation.definition.comment.java + push: line-comment-body + + line-comment-body: + - meta_include_prototype: false + - meta_scope: comment.line.double-slash.java + - match: (//+)?\n + captures: + 1: punctuation.definition.comment.java + pop: 1 + + shebang: + - meta_include_prototype: false + - match: ^\s*(\#!) + captures: + 1: punctuation.definition.comment.java + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if Erlang is embedded. + pop: 1 + + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.java + - match: '{{shebang_language}}' + scope: constant.language.shebang.java + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ ANNOTATIONS ]############################################################# + + annotations: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.7 + - match: \@(?!interface{{break}}) + scope: punctuation.definition.annotation.java + branch_point: annotation-identifier + branch: + - annotation-unqualified-identifier + - annotation-qualified-identifier + + annotation-unqualified-identifier: + - meta_scope: meta.annotation.identifier.java + - match: '{{identifier}}' + scope: variable.annotation.java + branch_point: annotation-unqualified-parameters + branch: + - annotation-unqualified-parameters + - immediately-pop2 + - include: else-pop + + annotation-unqualified-parameters: + - match: \( + scope: punctuation.section.group.begin.java + pop: 2 + push: annotation-parameters-body + # fail: looks like a qualified annotation + - match: (?={{single_dot}}) + fail: annotation-identifier + # fail: truncate meta scope immediately + - match: (?=\S) + fail: annotation-unqualified-parameters + + annotation-qualified-identifier: + - meta_include_prototype: false + - meta_scope: meta.annotation.identifier.java meta.path.java + - match: '' + branch_point: annotation-qualified-identifier + branch: + - annotation-qualified-identifier-path + - annotation-qualified-identifier-name + + annotation-qualified-identifier-path: + - match: '{{identifier}}' + scope: variable.namespace.java + set: annotation-qualified-identifier-accessor + - include: else-pop2 + + annotation-qualified-identifier-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: annotation-qualified-identifier + + annotation-qualified-identifier-name: + - match: '{{identifier}}' + scope: + meta.annotation.identifier.java meta.path.java + variable.annotation.java + pop: 2 + branch_point: annotation-qualified-parameters + branch: + - annotation-qualified-parameters + - immediately-pop + - include: else-pop2 + + annotation-qualified-parameters: + - meta_content_scope: meta.annotation.identifier.java + - match: \( + scope: punctuation.section.group.begin.java + set: annotation-parameters-body + - match: (?=\S) + fail: annotation-qualified-parameters + + annotation-parameters-body: + - meta_scope: meta.annotation.parameters.java meta.group.java + - include: group-end + - match: (?={{id_first_char}}) + branch_point: annotation-parameter + branch: + - annotation-parameter + - expression + - include: variable-initializers + + annotation-parameter: + - match: '{{identifier}}' + scope: variable.parameter.java + set: annotation-parameter-assignment + - match: '' + fail: annotation-parameter + + annotation-parameter-assignment: + - match: = + scope: keyword.operator.assignment.java + set: variable-initializer + - match: (?=\S) + fail: annotation-parameter + +###[ DECLARATIONS ]############################################################ + + declarations: + # As per specification separate declarations for globals, members, and + # locals are needed, as each of them supports only a subset of declaration + # statements: + # - globals: class, enum, interface + # - members: class, enum, interface, constructor, field, method + # - locals: class, variables + # - try/for: variables + # + # Member declarations need to be handled differently as constructors look + # exactly like function calls. The other two scopes (global, local) are + # merged here to maintain syntax highlighting whenever possible. That's + # needed for `incomplete code` scenarios or if contexts are lost due to + # embedding Java into JSP. + - include: annotations + - match: (?=@interface{{break}}) + push: interface-keyword + - match: (?=[{{id_first_char}}<]) + branch_point: declarations + branch: + - declaration-maybe-class + - declaration-maybe-enum + - declaration-maybe-interface + - declaration-maybe-variable + - declaration-maybe-method + + declaration-else-fail: + - match: (?=\S) + fail: declarations + + declaration-maybe-class: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.1 + - meta_scope: meta.class.java + - include: class-keyword + - include: record-keyword + - include: class-modifiers + - include: declaration-else-fail + + declaration-maybe-enum: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.9 + # Note: Local enum declarations are not valid, + # but may help maintaining highlighting in incomplete code. + - meta_scope: meta.enum.java + - include: enum-keyword + - include: class-modifiers + - include: declaration-else-fail + + declaration-maybe-interface: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.1 + # Note: Local interface declarations are not valid, + # but may help maintaining highlighting in incomplete code. + - meta_scope: meta.interface.java + - include: interface-keyword + - include: interface-modifiers + - include: declaration-else-fail + + declaration-maybe-method: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.4 + - meta_include_prototype: false + - match: '' + set: + - method-block + - method-attributes + - method-array-modifiers + - declaration-method-signature + - method-modifier + + declaration-method-signature: + - include: method-void-signature + - match: (?=\S) + set: + - declaration-method-expect-parameters + - declaration-method-expect-identifier + - method-result-modifier + - method-result-type + + declaration-method-expect-identifier: + - include: method-identifier + - include: declaration-else-fail + + declaration-method-expect-parameters: + - meta_content_scope: meta.function.identifier.java + - include: method-parameters + - include: declaration-else-fail + + declaration-maybe-variable: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.4 + - meta_include_prototype: false + - match: '' + set: + - variable-declaration-list + - variable-declaration-value-assignment + - variable-declaration-expect-identifier + - variable-declaration-type-modifier + - variable-declaration-type + +###[ PACKAGE DECLARATIONS ]#################################################### + + package: + - match: package{{break}} + scope: keyword.declaration.namespace.package.java + push: + - meta_scope: meta.namespace.package.java + - match: (?=\S) + set: package-identifier + + package-identifier: + - meta_include_prototype: false + - meta_content_scope: meta.namespace.package.identifier.java + - include: entity-package + - include: immediately-pop + +###[ MODULE DECLARATIONS ]##################################################### + + module: + - match: (?:(open)\s+)?(module){{break}} + captures: + 1: storage.modifier.java + 2: keyword.declaration.namespace.module.java + push: + - meta_scope: meta.namespace.module.java + - match: (?=\S) + set: + - module-block + - module-identifier + + module-identifier: + - meta_include_prototype: false + - include: entity-module + - include: immediately-pop + + module-block: + - meta_content_scope: meta.namespace.module.identifier.java + - match: \{ + scope: punctuation.section.block.begin.java + set: module-block-body + - include: else-pop + + module-block-body: + - meta_scope: meta.namespace.module.java meta.block.java + - include: block-end + - include: punctuation-terminator-semicolon + - match: exports{{break}} + scope: keyword.other.module.exports.java + push: + - module-exports-meta + - module-exports-or-opens-body + - match: opens{{break}} + scope: keyword.other.module.opens.java + push: + - module-opens-meta + - module-exports-or-opens-body + - match: requires{{break}} + scope: keyword.other.module.requires.java + push: module-requires-body + - match: uses{{break}} + scope: keyword.other.module.uses.java + push: + - module-uses-meta + - module-provides-or-uses-body + - match: provides{{break}} + scope: keyword.other.module.provides.java + push: + - module-provides-meta + - module-provides-or-uses-body + + module-exports-meta: + - meta_include_prototype: false + - meta_scope: meta.exports.java + - include: immediately-pop + + module-opens-meta: + - meta_include_prototype: false + - meta_scope: meta.opens.java + - include: immediately-pop + + module-exports-or-opens-body: + - include: module-statement-terminator + - match: to{{break}} + scope: keyword.other.module.to.java + set: + - include: module-statement-terminator + - include: punctuation-separator-comma + - include: entity-module + - include: entity-package + + module-requires-body: + - meta_scope: meta.requires.java + - match: transitive{{break}} + scope: keyword.other.module.transitive.java + - include: module-statement-terminator + - include: entity-module + + module-uses-meta: + - meta_include_prototype: false + - meta_scope: meta.uses.java + - include: immediately-pop + + module-provides-meta: + - meta_include_prototype: false + - meta_scope: meta.provides.java + - include: immediately-pop + + module-provides-or-uses-body: + - include: module-statement-terminator + - match: with{{break}} + scope: keyword.other.module.with.java + set: + - include: module-statement-terminator + - include: punctuation-separator-comma + - include: entity-class + - include: entity-class + + module-statement-terminator: + - match: (?=[;}]|(?:exports|opens|requires|provides|uses|{{reserved_words}}){{break}}) + pop: 1 + +###[ IMPORT DECLARATIONS ]##################################################### + + import: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-7.html#jls-7.5 + - match: import{{break}} + scope: keyword.declaration.import.java + push: + - import-meta + - import-modifier + + import-meta: + - meta_include_prototype: false + - meta_scope: meta.import.java + - include: immediately-pop + + import-modifier: + - match: module{{break}} + scope: keyword.declaration.module.java + set: import-module + - match: static{{break}} + scope: storage.modifier.java + set: import-static + - match: (?=\S) + set: type-import + + import-module: + - include: entity-module + - include: else-pop + + import-static: + - match: (?=\S) + set: static-import + + import-wildcard: + - match: \* + scope: constant.other.wildcard.asterisk.java + pop: 2 + set: import-expect-terminator + + import-expect-terminator: + - match: (?=\s*;|{{reserved_words}}{{break}}) + pop: 1 + - match: \S + scope: invalid.illegal.expect-semicolon.java + +###[ CLASS DECLARATIONS ]###################################################### + + class-keyword: + - match: class{{break}} + scope: keyword.declaration.class.java + set: + - class-block + - class-extends + - class-name-meta + - maybe-type-parameter + - class-name + + class-modifiers: + - match: '{{class_modifier}}{{break}}' + scope: storage.modifier.java + - match: '{{class_no_modifier}}{{break}}' + scope: invalid.illegal.unexpected-keyword.java + - include: annotations + + class-name: + - match: '{{identifier}}' + scope: entity.name.class.java + pop: 1 + - include: else-pop + + class-name-meta: + - meta_content_scope: meta.class.identifier.java + - include: else-pop + + class-extends: + - match: extends{{break}} + scope: storage.modifier.extends.java + push: + - class-extends-object-type-list + - inherited-object-type + - match: implements{{break}} + scope: storage.modifier.implements.java + push: + - class-implements-object-type-list + - inherited-object-type + - match: permits{{break}} + scope: storage.modifier.permits.java + push: + - class-permits-object-type-list + - inherited-object-type + - include: else-pop + + class-extends-object-type-list: + - meta_scope: meta.class.extends.java + - include: inherited-object-type-list + - include: else-pop + + class-implements-object-type-list: + - meta_scope: meta.class.implements.java + - include: inherited-object-type-list + - include: else-pop + + class-permits-object-type-list: + - meta_scope: meta.class.permits.java + - include: inherited-object-type-list + - include: else-pop + + class-block: + - match: \{ + scope: punctuation.section.block.begin.java + set: class-block-body + - include: else-pop + + class-block-body: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.1.6 + - meta_scope: meta.class.java meta.block.java + - include: block-end + - include: member-declarations + - include: member-statements + - include: else-expressions + +###[ ENUM DECLARATIONS ]####################################################### + + enum-keyword: + - match: enum{{break}} + scope: keyword.declaration.enum.java + set: + - enum-block + - enum-extends + - enum-name-meta + - maybe-illegal-type-parameter + - enum-name + + enum-name: + - match: '{{identifier}}' + scope: entity.name.enum.java + pop: 1 + - include: else-pop + + enum-name-meta: + - meta_content_scope: meta.enum.identifier.java + - include: else-pop + + enum-extends: + - match: extends{{break}} + scope: invalid.illegal.unexpected-keyword.java + push: + - enum-extends-object-type-list + - inherited-object-type + - match: implements{{break}} + scope: storage.modifier.implements.java + push: + - enum-implements-object-type-list + - inherited-object-type + - match: permits{{break}} + scope: invalid.illegal.unexpected-keyword.java + push: + - enum-permits-object-type-list + - inherited-object-type + - include: else-pop + + enum-extends-object-type-list: + - meta_scope: meta.enum.extends.java + - include: inherited-object-type-list + - include: else-pop + + enum-implements-object-type-list: + - meta_scope: meta.enum.implements.java + - include: inherited-object-type-list + - include: else-pop + + enum-permits-object-type-list: + - meta_scope: meta.enum.permits.java + - include: inherited-object-type-list + - include: else-pop + + enum-block: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.9.1 + - match: \{ + scope: punctuation.section.block.begin.java + set: + - enum-block-body + - enum-constants-list + - include: else-pop + + enum-block-body: + - meta_scope: meta.enum.java meta.block.java + - include: class-block-body + + enum-constants-list: + - meta_content_scope: meta.sequence.constants.java + - match: '{{identifier}}' + scope: meta.constant.identifier.java entity.name.constant.java + push: enum-constant-arguments + - include: punctuation-separator-comma + - include: annotation-else-pop + + enum-constant-arguments: + - meta_content_scope: meta.constant.identifier.java + - match: \( + scope: punctuation.section.group.begin.java + set: + - enum-constant-block + - enum-constant-arguments-body + - include: enum-constant-block + + enum-constant-arguments-body: + - clear_scopes: 1 + - meta_scope: meta.constant.arguments.java meta.group.java + - include: group-body + + enum-constant-block: + - meta_content_scope: meta.constant.java + - match: \{ + scope: punctuation.section.block.begin.java + set: enum-constant-block-body + - include: else-pop + + enum-constant-block-body: + - meta_scope: meta.constant.java meta.block.java + - include: class-block-body + +###[ INTERFACE DECLARATIONS ]################################################## + + interface-keyword: + - meta_scope: meta.interface.java + - match: (@?)interface{{break}} + scope: keyword.declaration.interface.java + set: + - interface-block + - interface-extends + - interface-name-meta + - maybe-type-parameter + - interface-name + + interface-modifiers: + - match: '{{interface_modifier}}{{break}}' + scope: storage.modifier.java + - match: '{{interface_no_modifier}}{{break}}' + scope: invalid.illegal.unexpected-keyword.java + - include: annotations + + interface-name: + - match: '{{identifier}}' + scope: entity.name.interface.java + pop: 1 + - include: else-pop + + interface-name-meta: + - meta_content_scope: meta.interface.identifier.java + - include: else-pop + + interface-extends: + - match: extends{{break}} + scope: storage.modifier.extends.java + push: + - interface-extends-object-type-list + - inherited-object-type + - match: implements{{break}} + scope: invalid.illegal.unexpected-keyword.java + push: + - interface-implements-object-type-list + - inherited-object-type + - match: permits{{break}} + scope: storage.modifier.permits.java + push: + - interface-permits-object-type-list + - inherited-object-type + - include: else-pop + + interface-extends-object-type-list: + - meta_scope: meta.interface.extends.java + - include: inherited-object-type-list + - include: else-pop + + interface-implements-object-type-list: + - meta_scope: meta.interface.implements.java + - include: inherited-object-type-list + - include: else-pop + + interface-permits-object-type-list: + - meta_scope: meta.interface.permits.java + - include: inherited-object-type-list + - include: else-pop + + interface-block: + - match: \{ + scope: punctuation.section.block.begin.java + set: interface-block-body + - include: else-pop + + interface-block-body: + - meta_scope: meta.interface.java meta.block.java + - include: class-block-body + +###[ RECORD DECLARATIONS ]##################################################### + + member-record-keyword: + # https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-8.10 + - match: record{{break}} + scope: keyword.declaration.record.java + set: + - member-record-block + - record-extends + - record-parameters + - maybe-type-parameter + - class-name + + member-record-block: + - match: \{ + scope: punctuation.section.block.begin.java + set: class-block-body + - include: member-else-fail + + record-keyword: + # https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-8.10 + - match: record{{break}} + scope: keyword.declaration.record.java + set: + - record-block + - record-extends + - record-parameters + - maybe-type-parameter + - class-name + + record-parameters: + - meta_content_scope: meta.class.identifier.java + - match: \( + scope: punctuation.section.group.begin.java + set: + - record-parameter-body + - parameter-maybe-identifier + - parameter-maybe-variadic + - maybe-array-modifiers + - parameter-type + - include: else-pop + + record-parameter-body: + - meta_scope: meta.class.parameters.java meta.group.java + - match: \) + scope: punctuation.section.group.end.java + set: + - meta_content_scope: meta.class.java + - include: else-pop + - include: method-parameters-body + + record-extends: + - match: extends{{break}} + scope: invalid.illegal.unexpected-keyword.java + push: + - class-extends-object-type-list + - inherited-object-type + - match: implements{{break}} + scope: storage.modifier.implements.java + push: + - class-implements-object-type-list + - inherited-object-type + - match: permits{{break}} + scope: invalid.illegal.unexpected-keyword.java + push: + - class-permits-object-type-list + - inherited-object-type + - include: else-pop + + record-block: + - match: \{ + scope: punctuation.section.block.begin.java + set: class-block-body + - include: declaration-else-fail + +###[ MEMBER DECLARATIONS ]##################################################### + + member-declarations: + - include: annotations + - match: (?=@interface{{break}}) + push: interface-keyword + - match: (?=[{{id_first_char}}<]) + branch_point: class-members + branch: + - member-maybe-constructor + - member-maybe-class + - member-maybe-enum + - member-maybe-interface + - member-maybe-method + - member-maybe-field + + member-else-fail: + - match: (?=\S) + fail: class-members + + member-reserved-fail: + - match: (?={{reserved_words}}{{break}}) + fail: class-members + + member-maybe-class: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.1 + - meta_scope: meta.class.java + - include: class-keyword + - include: member-record-keyword + - include: class-modifiers + - include: member-else-fail + + member-maybe-enum: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.9 + - meta_scope: meta.enum.java + - include: enum-keyword + - include: class-modifiers + - include: member-else-fail + + member-maybe-interface: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.1 + - meta_scope: meta.interface.java + - include: interface-keyword + - include: interface-modifiers + - include: member-else-fail + + member-maybe-field: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.3 + - meta_include_prototype: false + - match: '' + set: + - field-identifier-list + - field-value-assignment + - field-identifier + - field-type-modifier + - field-type + - field-modifier + + member-maybe-constructor: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.8 + - meta_include_prototype: false + - match: '' + set: + - method-block + - method-attributes + - method-array-modifiers + - method-expect-parameters + - constructor-name + - method-modifier + + member-maybe-method: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.4 + - meta_include_prototype: false + - match: '' + set: + - method-block + - method-attributes + - method-array-modifiers + - method-signature + - method-modifier + +###[ FIELD DECLARATIONS ]###################################################### + + field-modifier: + - clear_scopes: 1 + - meta_scope: meta.field.modifier.java + - match: '{{field_modifier}}{{break}}' + scope: storage.modifier.java + - match: '{{field_no_modifier}}{{break}}' + scope: invalid.illegal.unexpected-keyword.java + - include: type-parameters + - include: annotation-else-pop + + field-type: + - include: primitive-type + - include: object-type + - include: illegal-var-type + - include: member-else-fail + + field-type-modifier: + - clear_scopes: 1 + - meta_scope: meta.field.type.java + - match: (?=[{(]|{{declaration_keywords}}{{break}}) + fail: class-members + - include: maybe-only-array-modifiers + + field-identifier-list: + - match: ',' + scope: + meta.field.java + punctuation.separator.comma.java + push: + - field-value-assignment + - field-identifier + - include: else-pop + + field-identifier: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-VariableDeclaratorId + - match: '{{uppercase_id}}' + scope: entity.name.constant.java + pop: 1 + - match: '{{identifier}}' + scope: variable.other.member.java + pop: 1 + - match: '{{variables}}{{break}}' + scope: invalid.illegal.identifier.java + pop: 1 + - include: else-pop + + field-value-assignment: + - meta_content_scope: meta.field.identifier.java + - match: = + scope: + meta.field.java + keyword.operator.assignment.java + set: field-value-initializer + - include: maybe-only-array-modifiers + + field-value-initializer: + - meta_content_scope: meta.field.value.java + - include: variable-initializer + +###[ METHOD DECLARATIONS ]##################################################### + + constructor-name: + - include: member-reserved-fail + - match: '{{id}}' + scope: entity.name.function.constructor.java + pop: 1 + - include: else-pop + + method-modifier: + - meta_scope: meta.function.modifier.java + - match: '{{method_modifier}}{{break}}' + scope: storage.modifier.java + - match: '{{method_no_modifier}}{{break}}' + scope: invalid.illegal.unexpected-keyword.java + - include: type-parameters + - include: annotation-else-pop + + method-signature: + - include: method-void-signature + - include: method-result-signature + + method-void-signature: + # void indicates a method for sure + - match: (?=void{{break}}) + set: + - method-maybe-parameters + - method-maybe-identifier + - method-result-modifier + - method-void-type + + method-void-type: + - match: void + scope: storage.type.void.java + pop: 1 + + method-result-signature: + # a method only if parameter list found + - match: (?=\S) + set: + - method-expect-parameters + - method-expect-identifier + - method-result-modifier + - method-result-type + + method-result-type: + - include: primitive-type + - include: object-type + - include: illegal-var-type + - include: else-pop + + method-result-modifier: + - clear_scopes: 1 + - meta_scope: meta.function.return-type.java + - include: maybe-array-modifiers + + method-expect-identifier: + - include: method-identifier + - include: member-else-fail + + method-maybe-identifier: + - include: method-identifier + - include: else-pop + + method-identifier: + - match: '{{identifier}}' + scope: entity.name.function.java + pop: 1 + + method-expect-parameters: + - meta_content_scope: meta.function.identifier.java + - include: method-parameters + - match: (?=\{) + pop: 1 + - include: member-else-fail + + method-maybe-parameters: + - meta_content_scope: meta.function.identifier.java + - include: method-parameters + - include: else-pop + + method-parameters: + - match: \( + scope: punctuation.section.group.begin.java + set: + - method-parameters-body + - receiver-or-parameter + + method-parameters-body: + - meta_scope: meta.function.parameters.java meta.group.java + - include: group-end + - match: ',' + scope: punctuation.separator.comma.java + push: + - parameter-maybe-identifier + - parameter-maybe-variadic + - maybe-array-modifiers + - parameter-type + - include: expression-terminator + + method-array-modifiers: + - meta_include_prototype: false + - match: '' + set: method-array-modifiers-content + + method-array-modifiers-content: + - meta_scope: meta.function.java + - include: maybe-array-modifiers + + method-attributes: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.4.6 + - match: throws{{break}} + scope: storage.modifier.throws.java + set: + - method-throws-body + - maybe-illegal-array-modifiers + - expect-object-type + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-9.html#jls-9.6.2 + - match: default{{break}} + scope: storage.modifier.default.java + set: method-default-body + - include: else-pop + + method-default-body: + - meta_scope: meta.function.default.java + - include: variable-initializer + + method-throws-body: + - meta_scope: meta.function.throws.java + - match: ',' + scope: punctuation.separator.comma.java + push: + - maybe-illegal-array-modifiers + - expect-object-type + - include: else-pop + + method-block: + - match: \{ + scope: punctuation.section.block.begin.java + set: method-block-body + - include: else-pop + + method-block-body: + - meta_scope: meta.function.java meta.block.java + - include: block-body + +###[ VARIABLE DECLARATIONS ]################################################### + + variable-declaration-type: + - include: primitive-type + - include: var-type + - include: object-type + - include: final-modifiers + - include: annotations + - include: illegal-storage-modifiers + - include: else-pop + + variable-declaration-type-modifier: + - clear_scopes: 1 + - meta_scope: meta.declaration.type.java + - include: maybe-only-array-modifiers + + variable-declaration-list: + - match: ',' + scope: + meta.declaration.java + punctuation.separator.comma.java + push: + - variable-declaration-value-assignment + - variable-declaration-maybe-identifier + - include: else-pop + + variable-declaration-expect-identifier: + - include: variable-declaration-identifier + - include: declaration-else-fail + + variable-declaration-maybe-identifier: + - include: variable-declaration-identifier + - include: else-pop + + variable-declaration-identifier: + - match: _{{break}} + scope: variable.language.anonymous.java + pop: 1 + - match: '{{uppercase_id}}' + scope: constant.other.java + pop: 1 + - match: '{{identifier}}' + scope: variable.other.java + pop: 1 + + variable-declaration-value-assignment: + - meta_content_scope: meta.declaration.identifier.java + - match: = + scope: + meta.declaration.java + keyword.operator.assignment.java + set: variable-declaration-value-initializer + # found parentheses after identifier, appears to be a method declaration + - match: (?=\() + fail: declarations + - include: maybe-only-array-modifiers + + variable-declaration-value-initializer: + - meta_content_scope: meta.declaration.value.java + - include: variable-initializer + +###[ VARIABLE DECLARATIONS OR ASSIGNMENTS ]#################################### + + variable-declarations-or-assignments: + # A subset of `declarations` to optimize performance in contexts which need + # to distinguish between variable declaration and variable assignment only. + - match: (?=[{{id_first_char}}@<]) + branch_point: variable-declarations-or-assignments + branch: + - variable-maybe-declaration + - variable-maybe-assignment + + variable-maybe-assignment: + - meta_include_prototype: false + - match: '' + set: + - variable-declaration-value-assignment + - variable-maybe-modifier + - variable-declaration-identifier + + variable-maybe-modifier: + - meta_content_scope: meta.variable.identifier.java + - include: maybe-only-array-modifiers + + variable-maybe-declaration: + - meta_include_prototype: false + - match: '' + set: + - variable-declaration-list + - variable-declaration-value-assignment + - variable-expect-identifier + - variable-declaration-type-modifier + - variable-declaration-type + + variable-expect-identifier: + - include: variable-declaration-identifier + - match: (?=\S) + fail: variable-declarations-or-assignments + +###[ IF ELSE STATEMENTS ]###################################################### + + if-else-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.9 + - match: if{{break}} + scope: keyword.control.conditional.if.java + push: + - if-meta + - block-or-expression + - maybe-group + - match: else{{break}} + scope: keyword.control.conditional.else.java + push: + - else-meta + - block-or-expression + + if-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.conditional.if.java + - include: immediately-pop + + else-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.conditional.else.java + - include: immediately-pop + +###[ SWITCH CASE STATEMENTS ]################################################## + + switch-case-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.11 + - match: case{{break}} + scope: keyword.control.conditional.case.java + push: case-label + - match: default{{break}} + scope: keyword.control.conditional.default.java + push: case-default-end + - match: switch{{break}} + scope: keyword.control.conditional.switch.java + push: + - switch-meta + - block-or-expression + - maybe-group + + switch-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.conditional.switch.java + - include: immediately-pop + + case-default-end: + - meta_scope: meta.statement.conditional.default.java + - match: ':|->' + scope: punctuation.separator.expressions.java + pop: 1 + - include: else-pop + + case-label: + - meta_include_prototype: false + - meta_scope: meta.statement.conditional.case.java + - match: (?=\S) + branch_point: case-label + branch: + - case-label-constant + - case-label-pattern + - case-label-expression + + case-label-constant: + - meta_include_prototype: false + - match: '' + set: + - case-label-constant-end + - case-label-constant-identifier + + case-label-constant-identifier: + - include: literal-constant + - include: constant + - include: annotations + - include: case-label-fail + + case-label-constant-end: + - clear_scopes: 1 + - meta_content_scope: meta.statement.conditional.case.label.java + - include: case-label-end + - include: case-label-fail + + case-label-pattern: + - meta_include_prototype: false + - match: '' + set: + - case-label-pattern-end + - case-label-pattern-identifier + - type-pattern-type + + case-label-pattern-identifier: + # prevent `when` from being scoped variable or constant + - match: (?=when{{break}}) + pop: 1 + - include: variable-declaration-maybe-identifier + + case-label-pattern-end: + - clear_scopes: 1 + - meta_content_scope: meta.statement.conditional.case.label.java + - match: when{{break}} + scope: meta.statement.conditional.case.label.java keyword.control.conditional.when.java + pop: 1 + push: case-label-expression + - include: case-label-end + - include: case-label-fail + + case-label-expression: + - clear_scopes: 1 + - meta_content_scope: meta.statement.conditional.case.label.java + - include: case-label-end + - include: constant-expressions + + case-label-end: + - match: ',' + scope: meta.statement.conditional.case.java punctuation.separator.comma.java + pop: 1 + - match: ':|->' + scope: meta.statement.conditional.case.java punctuation.separator.expressions.java + pop: 2 + - match: (?=[;{}]|(?:{{keywords}}|{{storage_modifiers}}){{break}}) + pop: 2 + + case-label-fail: + - match: (?=\S) + fail: case-label + +###[ DO WHILE STATEMENTS ]##################################################### + + do-while-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.12 + - match: while{{break}} + scope: keyword.control.loop.while.java + push: + - while-meta + - block-or-expression + - maybe-group + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.13 + - match: do{{break}} + scope: keyword.control.loop.do-while.java + push: + - do-meta + - block-or-expression + + do-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.loop.do-while.java + - include: immediately-pop + + while-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.loop.while.java + - include: immediately-pop + +###[ FOR LOOP STATEMENTS ]##################################################### + + for-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.14 + - match: for{{break}} + scope: keyword.control.loop.for.java + push: + - for-meta + - block-or-expression + - for-parameters + + for-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.loop.for.java + - include: immediately-pop + + for-parameters: + - match: \( + scope: punctuation.section.group.begin.java + set: + - for-parameters-update + - for-parameters-init + - include: else-pop + + for-parameters-init: + # enhanced for statement + - match: ':' + scope: keyword.operator.assignment.java + pop: 1 + # basic for statement + - match: ';' + scope: punctuation.terminator.java + set: for-parameters-condition + - include: variable-declarations-or-assignments + - include: expressions + - include: expression-terminator + + for-parameters-condition: + - include: punctuation-terminator-semicolon-pop + - include: expressions + - include: expression-terminator + + for-parameters-update: + - meta_scope: meta.group.java + - include: group-end + - include: expressions + - match: ; + scope: invalid.illegal.stray.java + - include: expression-terminator + +###[ FLOW CONTROL STATEMENTS ]################################################# + + labeled-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.7 + - match: ({{identifier}})(:)(?!:) + captures: + 1: entity.name.label.java + 2: punctuation.separator.colon.java + + flow-control-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.10 + - match: assert{{break}} + scope: keyword.control.flow.assert.java + push: assert-statement-body + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.15 + - match: break{{break}} + scope: keyword.control.flow.break.java + push: + - break-statement-end + - variable-label + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.16 + - match: continue{{break}} + scope: keyword.control.flow.continue.java + push: + - continue-statement-end + - variable-label + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.17 + - match: return{{break}} + scope: keyword.control.flow.return.java + push: return-statement-body + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.18 + - match: throw{{break}} + scope: keyword.control.flow.throw.java + push: throw-statement-body + # https://docs.oracle.com/javase/specs/jls/se16/html/jls-14.html#jls-14.21 + - match: yield{{break}} + scope: keyword.control.flow.yield.java + push: yield-statement-body + + assert-statement-body: + - meta_scope: meta.statement.conditional.assertion.java + - match: ':' + scope: punctuation.separator.expressions.java + - include: expression + + break-statement-end: + - meta_scope: meta.statement.flow.break.java + - include: expect-expression-terminator + + continue-statement-end: + - meta_scope: meta.statement.flow.continue.java + - include: expect-expression-terminator + + return-statement-body: + - meta_scope: meta.statement.flow.return.java + - include: expression + + throw-statement-body: + - meta_scope: meta.statement.flow.throw.java + - include: expression + + yield-statement-body: + - meta_scope: meta.statement.flow.yield.java + - include: expression + + variable-label: + - match: '{{identifier}}' + scope: variable.label.java + pop: 1 + - include: else-pop + +###[ SYNCHRONIZED STATEMENTS ]################################################# + + synchronized-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.19 + - match: synchronized{{break}} + scope: keyword.control.flow.synchronized.java + push: + - synchronized-meta + - block-or-expression + - maybe-group + + synchronized-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.flow.synchronized.java + - include: immediately-pop + +###[ TRY CATCH STATEMENTS ]#################################################### + + try-catch-statements: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.20 + - match: catch{{break}} + scope: keyword.control.exception.catch.java + push: + - catch-meta + - block-or-expression + - catch-parameters + - match: finally{{break}} + scope: keyword.control.exception.finally.java + push: + - finally-meta + - block-or-expression + - match: try{{break}} + scope: keyword.control.exception.try.java + push: + - try-meta + - block-or-expression + - try-parameters + + catch-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.exception.catch.java + - include: immediately-pop + + catch-parameters: + - match: \( + scope: punctuation.section.group.begin.java + set: + - catch-parameters-end + - maybe-illegal-array-modifiers + - catch-parameter-identifier + - maybe-illegal-array-modifiers + - catch-parameter-type + - include: else-pop + + catch-parameter-type: + - include: final-modifiers + - include: illegal-storage-modifiers + - include: expect-object-type + + catch-parameter-identifier: + - match: \| + scope: punctuation.separator.pipe.java + push: + - maybe-illegal-array-modifiers + - catch-parameter-type + - match: _{{break}} + scope: variable.language.anonymous.java + pop: 1 + - match: '{{identifier}}' + scope: variable.other.java + pop: 1 + - match: '{{variables}}{{break}}' + scope: invalid.illegal.identifier.java + pop: 1 + - include: else-pop + + catch-parameters-end: + - meta_scope: meta.group.java + - include: group-end + - match: '[^\s\)]+' + scope: invalid.illegal.unexpected-token.java + + finally-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.exception.finally.java + - include: immediately-pop + + try-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.exception.try.java + - include: immediately-pop + + try-parameters: + - match: \( + scope: punctuation.section.group.begin.java + set: try-parameters-body + - include: else-pop + + try-parameters-body: + - meta_scope: meta.group.java + - include: group-end + - include: variable-declarations-or-assignments + - include: punctuation-terminator-semicolon + - include: expressions + - include: expression-terminator + +###[ EXPRESSIONS ]############################################################# + + else-expressions: + - match: (?=\S) + push: expression + + else-expression: + - match: (?=\S) + set: expression + + expression: + - include: expression-terminator + - include: expressions + + expression-terminator: + - match: |- + (?x)(?= + [;)\]{}] | + ( {{control_keywords}} + | {{declaration_keywords}} + | {{storage_modifiers}} + | {{storage_types}} + ){{break}} + ) + pop: 1 + + expect-expression-terminator: + - include: expression-terminator + - match: \S + scope: invalid.illegal.expect-terminator.java + +###[ INSTANTIATION EXPRESSIONS ]############################################### + + instantiations: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.9 + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.10 + - match: new{{break}} + scope: keyword.other.storage.new.java + push: + - instantiation-meta + - instantiation-arguments + - instantiation-type + - maybe-type-argument + - include: annotations + + instantiation-meta: + - meta_include_prototype: false + - meta_scope: meta.instantiation.java + - include: immediately-pop + + instantiation-type: + - include: primitive-type + - include: object-type + - include: annotations + - include: illegal-storage-modifiers + - include: illegal-unexpected-keywords + - include: else-pop + + instantiation-arguments: + - meta_content_scope: meta.function-call.identifier.java + - match: \( + scope: punctuation.section.group.begin.java + set: + - class-block + - method-call-arguments-body + - include: array-dimensions + - include: else-pop + + array-dimensions: + - match: \[ + scope: punctuation.section.brackets.begin.java + set: array-dimension-body + - include: array-initializer + - include: annotations + + array-dimension-body: + - meta_scope: meta.brackets.java + - match: \] + scope: punctuation.section.brackets.end.java + set: + - include: array-dimensions + - include: else-pop + - include: expressions + - include: expression-terminator + +###[ INITIALIZATION EXPRESSIONS ]############################################## + + variable-initializers: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.3 + - include: array-initializers + - include: ternary-initializers + - include: expressions + + variable-initializer: + - match: (?=,) + pop: 1 + - include: array-initializers + - include: ternary-initializers + - include: expression + + array-initializers: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-10.html#jls-10.6 + - match: \{ + scope: punctuation.section.braces.begin.java + push: array-initializer-body + + array-initializer: + - match: \{ + scope: punctuation.section.braces.begin.java + set: array-initializer-body + + array-initializer-body: + - meta_scope: meta.braces.java + - match: \} + scope: punctuation.section.braces.end.java + pop: 1 + - include: variable-initializers + + ternary-initializers: + - match: \? + scope: keyword.operator.ternary.java + push: ternary-initializer-body + + ternary-initializer-body: + - include: operator-ternary-colon + - include: variable-initializer + +###[ BLOCKS ]################################################################## + + block-or-expression: + - include: block + - include: else-expression + + blocks: + - match: \{ + scope: punctuation.section.block.begin.java + push: block-body + - include: stray-braces + + block: + - match: \{ + scope: punctuation.section.block.begin.java + set: block-body + + block-end: + - match: \} + scope: punctuation.section.block.end.java + pop: 1 + + block-body: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-14.html#jls-14.2 + - meta_scope: meta.block.java + - include: block-end + - include: declarations + - include: statements + - include: else-expressions + +###[ GROUPS ]################################################################## + + groups: + - match: \( + scope: punctuation.section.group.begin.java + branch_point: groups + branch: + - cast-expression-group + - expression-group + - lambda-parameter-group + + group-else-fail: + - match: (?=\S) + fail: groups + + maybe-group: + - match: \( + scope: punctuation.section.group.begin.java + set: group-body + - include: else-pop + + group-body: + - meta_scope: meta.group.java + - include: group-end + - include: expressions + - include: expression-terminator + + group-end: + - match: \) + scope: punctuation.section.group.end.java + pop: 1 + +###[ CAST EXPRESSION GROUPS ]################################################## + + cast-expression-group: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.16 + - meta_scope: meta.cast.java meta.group.java + - meta_include_prototype: false + - match: '' + set: + - cast-expression-group-body + - maybe-only-array-modifiers + - cast-expression-type + + cast-expression-group-body: + - meta_scope: meta.cast.java meta.group.java + - match: \) + scope: punctuation.section.group.end.java + set: cast-expression-group-end + - include: additional-bounds + - include: group-else-fail + + cast-expression-group-end: + # cast expressions may be followed by: + # - `!` : unary operator + # - `~` : unary operator + # - `(` : cast, lambda or group expression + # - literal : variable, type or method + - match: (?=[{{id_first_char}}!~(]) + pop: 1 + - include: group-else-fail + + cast-expression-type: + - include: primitive-type + - include: object-type + - include: illegal-var-type + - include: annotations + - include: maybe-type-argument + +###[ EXPRESSION GROUPS ]####################################################### + + expression-group: + - meta_scope: meta.group.java + - match: \) + scope: punctuation.section.group.end.java + set: expression-group-end + - include: expressions + - include: expression-terminator + + expression-group-end: + # looks like a lambda + - match: (?=->) + fail: groups + - include: else-pop + +###[ LAMBDA PARAMETER GROUPS ]################################################# + + lambda-parameter-group: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.27 + - meta_scope: meta.function.anonymous.parameters.java meta.group.java + - match: \) + scope: punctuation.section.group.end.java + set: lambda-meta + - match: (?=[{{id_first_char}}<]) + branch_point: lambda-parameter-declaration + branch: + - lambda-parameter-declaration + - parameter-identifier + - include: annotations + - include: punctuation-separator-comma + - include: expect-expression-terminator + + lambda-parameter-declaration: + - meta_include_prototype: false + - match: '' + set: + - lambda-parameter-declaration-identifier + - parameter-maybe-variadic + - maybe-array-modifiers + - variable-declaration-type + + lambda-parameter-declaration-identifier: + - include: parameter-identifier + - match: (?=\S) + fail: lambda-parameter-declaration + + lambdas: + - match: -> + scope: + meta.function.anonymous.java + keyword.declaration.function.arrow.java + push: + - lambda-meta + - block-or-expression + + lambda-meta: + - meta_content_scope: meta.function.anonymous.java + - include: else-pop + +###[ RECEIVER OR FORMAL PARAMETERS ]########################################### + + receiver-or-parameter: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.4 + # The first parameter of a method or constructor declaration may be a + # receiver parameter which represents the object to invoke the method for. + - match: (?=[{{id_first_char}}<]) + branch_point: receiver-or-parameter + branch: + - receiver + - parameter + - include: annotation-else-pop + + receiver: + - meta_include_prototype: false + - match: '' + pop: 1 + set: + - receiver-identifier + - receiver-type + + receiver-type: + # A 'receiver-type' is basically an 'object-type' whose 'namespace' part + # is skipped as it is expected to be declared in the same source file due + # to receiver args being valid only for nested class' methods. + - match: (?={{reserved_words}}{{break}}) + fail: receiver-or-parameter + - match: (?=\S) + branch_point: receiver-type + branch: + - receiver-unqualified-type + - receiver-qualified-type + + receiver-unqualified-type: + - match: '{{identifier}}' + scope: support.class.java + push: + - receiver-unqualified-type-end + - maybe-array-modifiers + - maybe-type-argument + - include: else-pop2 + + receiver-unqualified-type-end: + - match: (?={{id_first_char}}) + pop: 3 + - match: (?={{single_dot}}) + fail: receiver-type + - match: (?=\S) + fail: receiver-or-parameter + + receiver-qualified-type: + - meta_scope: meta.path.java + - match: '{{identifier}}' + scope: support.class.java + push: + - receiver-qualified-type-end + - qualified-object-type-arguments + - include: annotation-else-pop2 + + receiver-qualified-type-end: + - match: \s*({{single_dot}}) + captures: + 1: punctuation.accessor.dot.java + pop: 1 + # consume comments + - match: \s*(?=/[/*]) + # Maintain meta.path boundaries at the end of the type. + - match: (?=\s*\S) + pop: 3 + + receiver-identifier: + - match: (?=\S) + branch_point: receiver-identifier + branch: + - receiver-unqualified-identifier + - receiver-qualified-identifier + + receiver-unqualified-identifier: + - match: this{{break}} + scope: variable.parameter.this.java + push: receiver-identifier-end + - match: '{{identifier}}' + scope: variable.parameter.java + set: receiver-unqualified-identifier-end + - include: annotation-else-pop2 + + receiver-unqualified-identifier-end: + - match: (?={{single_dot}}) + fail: receiver-identifier + - match: (?=\S) + fail: receiver-or-parameter + + receiver-qualified-identifier: + - meta_include_prototype: false + - match: '' + branch_point: receiver-qualified-identifier + branch: + - receiver-qualified-identifier-path + - receiver-qualified-identifier-name + + receiver-qualified-identifier-path: + - meta_scope: meta.path.java + - match: '{{id}}' + scope: support.class.java + push: + - receiver-qualified-identifier-accessor + - maybe-type-argument + - include: annotation-else-pop3 + + receiver-qualified-identifier-accessor: + - include: punctuation-accessor-dot-pop2 + - match: (?=\S) + fail: receiver-qualified-identifier + + receiver-qualified-identifier-name: + - meta_scope: meta.path.java + - match: this{{break}} + scope: variable.parameter.this.java + set: receiver-identifier-end + - match: '{{identifier}}' + scope: invalid.illegal.identifier.java + set: receiver-identifier-end + - include: annotation-else-pop3 + + receiver-identifier-end: + - include: illegal-array-modifiers + - include: illegal-members + - include: annotation-else-pop3 + + parameter: + - meta_include_prototype: false + - match: '' + pop: 1 + set: + - parameter-maybe-identifier + - parameter-maybe-variadic + - maybe-array-modifiers + - parameter-type + + parameter-type: + - include: final-modifiers + - include: illegal-storage-modifiers + - include: primitive-type + - include: illegal-var-type + - include: maybe-object-type + + parameter-maybe-variadic: + - match: \.\.\. + scope: keyword.operator.variadic.java + pop: 1 + - include: annotation-else-pop + + parameter-maybe-identifier: + - include: parameter-identifier + - include: else-pop + + parameter-identifier: + - match: _{{break}} + scope: variable.language.anonymous.java + pop: 1 + - match: '{{identifier}}' + scope: variable.parameter.java + set: maybe-only-array-modifiers + - match: '{{variables}}{{break}}' + scope: invalid.illegal.identifier.java + set: maybe-only-array-modifiers + +###[ TYPE PATTERNS ]########################################################### + + type-comparisons: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.20.2 + - match: instanceof{{break}} + scope: keyword.other.storage.instanceof.java + push: + - type-comparison-meta + - type-pattern + + type-comparison-meta: + - meta_include_prototype: false + - meta_scope: meta.instanceof.java + - include: immediately-pop + + type-pattern: + # https://openjdk.org/jeps/405 + - match: \( + scope: punctuation.section.group.begin.java + set: + - type-pattern-group-end + - type-pattern + - match: (?=\S) + set: + - variable-declaration-maybe-identifier + - type-pattern-type + + type-pattern-group-end: + - meta_scope: meta.group.java + - match: \) + scope: punctuation.section.group.end.java + pop: 1 + - include: else-pop + + type-pattern-type: + - include: primitive-maybe-class-literal + - include: var-type + - match: (?={{identifier}}) + set: + - record-structure-pattern + - maybe-only-array-modifiers + - object-type + - include: annotations + - include: maybe-type-argument + + record-structure-pattern: + - match: \( + scope: punctuation.section.group.begin.java + set: + - record-structure-pattern-body + - type-pattern + - include: else-pop + + record-structure-pattern-body: + - meta_scope: meta.group.java + - match: \) + scope: punctuation.section.group.end.java + pop: 1 + - match: ',' + scope: punctuation.separator.comma.java + push: type-pattern + - include: expression-terminator + +###[ VARIABLES ]############################################################### + + variables: + # Note: + # 1) `variable-other` must be the first branch to scope the very last + # identifier before eof or end of embedded section as ordinary variable. + # 2) `variable-qualifier` scopes identifiers not followed by ClassCaseIds + # as ordinary variables. Found no easy enough solution by only using + # `variable-other` and `variable-namespace`. + - match: (?={{id_first_char}}) + branch_point: variables + branch: + - variable-other + - variable-namespace + - variable-qualifier + - method-call-identifier + - lambda-parameter + - include: variable-item-access + + method-call-identifier: + - meta_include_prototype: false + - match: _{{break}} + scope: + meta.function-call.identifier.java + variable.language.anonymous.java + set: method-call-arguments + - match: '{{id}}' + scope: + meta.function-call.identifier.java + variable.function.java + set: method-call-arguments + - include: immediately-pop + + method-call-arguments: + - meta_content_scope: meta.function-call.identifier.java + - match: \( + scope: punctuation.section.group.begin.java + set: method-call-arguments-body + - match: (?=\S) + fail: variables + + method-call-arguments-body: + - meta_scope: meta.function-call.arguments.java meta.group.java + - include: group-body + + lambda-parameter: + - meta_include_prototype: false + - match: _{{break}} + scope: + meta.function.anonymous.parameters.java + variable.language.anonymous.java + set: lambda-parameter-end + - match: '{{id}}' + scope: + meta.function.anonymous.parameters.java + variable.parameter.java + set: lambda-parameter-end + - include: immediately-pop + + lambda-parameter-end: + - meta_content_scope: meta.function.anonymous.java + - include: else-pop + + variable-namespace: + - match: _{{break}} + fail: variables + - match: '{{lowercase_id}}' + scope: variable.namespace.java + push: variable-namespace-accessor + - match: '' + fail: variables + + variable-namespace-accessor: + - meta_scope: meta.path.java + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + set: + - match: '{{classcase_id}}' + scope: support.class.java + set: + - variable-namespace-meta + - maybe-object-type-child + - maybe-array-modifiers + - maybe-type-argument + - include: else-pop + - match: (?=\S) + fail: variables + + variable-namespace-meta: + - meta_include_prototype: false + - meta_scope: meta.path.java + - include: immediately-pop2 + + variable-other: + - meta_include_prototype: false + - match: _{{break}} + scope: + meta.variable.identifier.java + variable.language.anonymous.java + set: variable-other-end + - match: '{{id}}' + scope: + meta.variable.identifier.java + variable.other.java + set: variable-other-end + - include: immediately-pop + + variable-other-end: + - meta_content_scope: meta.variable.identifier.java + - match: \s*(\.|\(|->) + fail: variables + - include: variable-item-access-end + + variable-qualifier: + - meta_include_prototype: false + - match: _{{break}} + fail: variables + - match: '{{id}}' + scope: + meta.variable.identifier.java + variable.other.java + set: variable-qualifier-end + - include: immediately-pop + + variable-qualifier-end: + - meta_content_scope: meta.variable.identifier.java + - match: \s*(\(|->) + fail: variables + - include: variable-item-access-end + + variable-item-access: + - match: \[ + scope: punctuation.section.brackets.begin.java + push: variable-item-access-body + + variable-item-access-body: + - meta_scope: meta.variable.item-access.java meta.brackets.java + - match: \] + scope: punctuation.section.brackets.end.java + set: variable-item-access-end + - include: expressions + - include: expression-terminator + + variable-item-access-end: + - meta_content_scope: meta.variable.item-access.java + - match: \s*(?=\[|/[/*]) + - match: (?=\s*\S) + pop: 1 + + variable-language-class: + - match: class{{break}} + scope: variable.language.class.java + pop: 1 + + maybe-function-reference: + - match: new{{break}} + scope: keyword.other.storage.new.java + pop: 1 + - match: '{{identifier}}' + scope: variable.function.reference.java + pop: 1 + - include: else-pop + +###[ LITERALS ]################################################################ + + literals: + - include: literal-chars + - include: literal-strings + - include: literal-numbers + - include: literal-constants + - include: literal-variables + + literal-variables: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.9 + - match: super{{break}} + scope: variable.language.super.java + - match: this{{break}} + scope: variable.language.this.java + + literal-constants: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10.3 + - match: false{{break}} + scope: constant.language.boolean.false.java + - match: true{{break}} + scope: constant.language.boolean.true.java + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10.7 + - match: null{{break}} + scope: constant.language.null.java + + literal-constant: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10.3 + - match: false{{break}} + scope: constant.language.boolean.false.java + pop: 1 + - match: true{{break}} + scope: constant.language.boolean.true.java + pop: 1 + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10.7 + - match: null{{break}} + scope: constant.language.null.java + pop: 1 + + literal-numbers: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10 + # hexadecimal floats + - match: |- + (?x) + # 0x1., 0x1.1, 0x1.1p1, 0x1.1p-1, 0x1.p1, 0x1.p-1 | 0x1p1 | 0x.1, 0x.1p1, 0x.1p-1 + (0[xX]) ( {{hex_digit}}* (?: ({{single_dot}}) {{hex_digit}}* (?:{{hex_exponent}})? | {{hex_exponent}} ) ) ({{float_suffix}})? + scope: meta.number.float.hexadecimal.java + captures: + 1: constant.numeric.base.java + 2: constant.numeric.value.java + 3: punctuation.separator.decimal.java + 4: constant.numeric.suffix.java + # decimal floats + - match: |- + (?x) + ([0-9]{{dec_digit}}*) + (?: + # 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1, 1.d, 1.1d, 1.1e1d, 1.1e-1d, 1.e1d, 1.e-1d + ( ({{single_dot}}) {{dec_digit}}* (?:{{dec_exponent}})? ) ({{float_suffix}})? + # 1e1 1e1d + | ({{dec_exponent}}) ({{float_suffix}})? + # 1d + | ({{float_suffix}}) + ) + | ( ({{single_dot}}) {{dec_digit}}+ (?:{{dec_exponent}})? ) ({{float_suffix}})? + scope: meta.number.float.decimal.java + captures: + 1: constant.numeric.value.java + 2: constant.numeric.value.java + 3: punctuation.separator.decimal.java + 4: constant.numeric.suffix.java + 5: constant.numeric.value.java + 6: constant.numeric.suffix.java + 7: constant.numeric.suffix.java + 8: constant.numeric.value.java + 9: punctuation.separator.decimal.java + 10: constant.numeric.suffix.java + # binary integers + - match: (0[bB])({{bin_digit}}*)({{int_suffix}})? + scope: meta.number.integer.binary.java + captures: + 1: constant.numeric.base.java + 2: constant.numeric.value.java + 3: constant.numeric.suffix.java + # hexadecimal integers + - match: (0[xX])({{hex_digit}}*)({{int_suffix}})? + scope: meta.number.integer.hexadecimal.java + captures: + 1: constant.numeric.base.java + 2: constant.numeric.value.java + 3: constant.numeric.suffix.java + # octal integers + - match: (0)({{oct_digit}}+)({{int_suffix}}|(?![\d_])) + scope: meta.number.integer.octal.java + captures: + 1: constant.numeric.base.java + 2: constant.numeric.value.java + 3: constant.numeric.suffix.java + # decimal integers + - match: ((0_*)?[1-9]{{dec_digit}}*|0(?![\d_]))({{int_suffix}})? + scope: meta.number.integer.decimal.java + captures: + 1: constant.numeric.value.java + 2: invalid.illegal.numeric.java + 3: constant.numeric.suffix.java + + literal-chars: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10.4 + - match: (')(?:({{escape_unicode}})|({{escape_octal}})|({{escape_other}})|([^']))(') + scope: meta.string.java string.quoted.single.java + captures: + 1: punctuation.definition.string.begin.java + 2: constant.character.escape.unicode.java + 3: constant.character.escape.octal.java + 4: constant.character.escape.other.java + 5: constant.character.literal.java + 6: punctuation.definition.string.end.java + + literal-strings: + - include: literal-double-quoted-textblocks + - include: literal-double-quoted-strings + - include: literal-single-quoted-strings + + literal-single-quoted-strings: + # Java doesn't support single quoted strings, but Groovy does. + - match: (')[^']+(') + scope: invalid.illegal.not-a-char.java + + literal-double-quoted-strings: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10.5 + - match: \" + scope: punctuation.definition.string.begin.java + push: literal-double-quoted-string-body + + literal-double-quoted-string-body: + - meta_include_prototype: false + - meta_scope: meta.string.java string.quoted.double.java + - match: \" + scope: punctuation.definition.string.end.java + pop: 1 + - include: illegal-newline + - include: merge-conflict-markers + - include: literal-string-escapes + + literal-double-quoted-textblocks: + # https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-3.10.6 + - match: (\"{3})\s*(.*)$ + captures: + 1: punctuation.definition.string.begin.java + 2: invalid.illegal.unexpected-content.java + push: literal-double-quoted-textblock-body + + literal-double-quoted-textblock-body: + - meta_include_prototype: false + - meta_scope: meta.string.java string.quoted.triple.java + - match: \"{3} + scope: punctuation.definition.string.end.java + pop: 1 + - include: merge-conflict-markers + - include: literal-string-escapes + + literal-string-escapes: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.3 + - match: '{{escape_unicode}}' + scope: constant.character.escape.unicode.java + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.10.6 + - match: '{{escape_octal}}' + scope: constant.character.escape.octal.java + - match: '{{escape_other}}' + scope: constant.character.escape.other.java + +###[ OPERATORS ]############################################################### + + operators: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.12 + - match: (<<|>>>?|[-+*/%|&\^])= + scope: keyword.operator.assignment.augmented.java + - match: '<<|>>>?' + scope: keyword.operator.bitwise.java + - match: '==|!=|<=|>=|<>|<|>' + scope: keyword.operator.comparison.java + - match: '=' + scope: keyword.operator.assignment.java + push: variable-initializer + - match: '\+\+?|\-\-?|[*/%]' + scope: keyword.operator.arithmetic.java + - match: '!|&&|\|\|' + scope: keyword.operator.logical.java + - match: '[~|&\^]' + scope: keyword.operator.bitwise.java + - match: '\?' + scope: keyword.operator.ternary.java + push: ternary-expression + + operator-ternary-colon: + - match: ':' + scope: keyword.operator.ternary.java + pop: 1 + + ternary-expression: + - include: operator-ternary-colon + - include: expression + +###[ PUNCTUATION ]############################################################# + + punctuations: + - match: '::' + scope: punctuation.accessor.double-colon.java + push: + - maybe-function-reference + - maybe-type-argument + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + push: + - include: variable-language-class + - include: maybe-type-argument + - include: punctuation-separator-comma + + punctuation-accessor-dot: + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + + punctuation-accessor-dot-pop: + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + pop: 1 + + punctuation-accessor-dot-pop2: + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + pop: 2 + + punctuation-separator-comma: + - match: ',' + scope: punctuation.separator.comma.java + + punctuation-terminator-semicolon: + - match: ; + scope: punctuation.terminator.java + + punctuation-terminator-semicolon-pop: + - match: ; + scope: punctuation.terminator.java + pop: 1 + +###[ CONSTANT ]################################################################ + + constant: + - match: (?={{identifier}}) + branch_point: constant + branch: + - unqualified-constant + - qualified-constant + + unqualified-constant: + - meta_include_prototype: false + - match: '{{id}}' + scope: constant.other.java + set: unqualified-constant-end + - include: immediately-pop2 + + unqualified-constant-end: + - match: (?={{single_dot}}) + fail: constant + - include: else-pop2 + + qualified-constant: + - meta_include_prototype: false + - meta_content_scope: meta.path.java + - match: '' + branch_point: qualified-constant + branch: + - qualified-constant-package + - qualified-constant-class-or-name + + qualified-constant-package: + - match: '{{lowercase_id}}' + scope: variable.namespace.java + set: qualified-constant-package-accessor + - include: annotations + - match: (?=\S) + fail: qualified-constant + + qualified-constant-package-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: qualified-constant + + qualified-constant-class-or-name: + - meta_include_prototype: false + - match: '' + pop: 1 + branch_point: qualified-constant-class-or-name + branch: + - qualified-constant-class + - qualified-constant-name + + qualified-constant-class: + - match: '{{identifier}}' + scope: support.class.java + set: + - qualified-constant-class-accessor + - maybe-type-argument + - include: annotation-else-pop3 + + qualified-constant-class-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: qualified-constant-class-or-name + + qualified-constant-name: + - match: '{{identifier}}' + scope: constant.other.java + pop: 3 + - include: annotation-else-pop3 + +###[ STATIC IMPORT ]########################################################### + + static-import: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-7.html#jls-7.5.3 + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-7.html#jls-7.5.4 + - meta_include_prototype: false + - meta_content_scope: meta.path.java + - match: '' + branch_point: static-import + branch: + - static-import-package + - static-import-class-or-name + + static-import-package: + - match: '{{lowercase_id}}' + scope: variable.namespace.java + set: static-import-package-accessor + - include: annotations + - match: (?=\S) + fail: static-import + + static-import-package-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: static-import + + static-import-class-or-name: + - meta_include_prototype: false + - match: '' + pop: 1 + branch_point: static-import-class-or-name + branch: + - static-import-class + - static-import-name + + static-import-class: + - match: '{{identifier}}' + scope: support.class.java + set: + - static-import-class-accessor + - maybe-type-argument + - include: import-wildcard + - include: annotation-else-pop2 + + static-import-class-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: static-import-class-or-name + + static-import-name: + - match: '{{uppercase_id}}' + scope: entity.name.constant.java + pop: 2 + - match: '{{identifier}}' + scope: entity.name.import.java + pop: 2 + - include: annotation-else-pop2 + +###[ TYPE IMPORT ]############################################################# + + type-import: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-7.html#jls-7.5.1 + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-7.html#jls-7.5.2 + - meta_include_prototype: false + - meta_content_scope: meta.path.java + - match: '' + branch_point: type-import + branch: + - type-import-package + - type-import-class-or-name + + type-import-package: + - match: '{{lowercase_id}}' + scope: variable.namespace.java + set: type-import-package-accessor + - include: annotations + - match: (?=\S) + fail: type-import + + type-import-package-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: type-import + + type-import-class-or-name: + - meta_include_prototype: false + - match: '' + pop: 1 + branch_point: type-import-class-or-name + branch: + - type-import-class + - type-import-name + + type-import-class: + - match: '{{identifier}}' + scope: support.class.java + set: + - type-import-class-accessor + - maybe-type-argument + - include: import-wildcard + - include: annotation-else-pop2 + + type-import-class-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: type-import-class-or-name + + type-import-name: + - match: '{{identifier}}' + scope: entity.name.class.java + pop: 2 + - include: annotation-else-pop2 + +###[ ENTITY CLASS ]############################################################ + + entity-class: + - match: (?={{identifier}}) + branch_point: entity-class + branch: + - entity-class-qualified-identifier + - entity-class-unqualified-identifier + + entity-class-qualified-identifier: + - match: '{{id}}' + scope: variable.namespace.java + set: + - meta_scope: meta.path.java + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + set: + - meta_include_prototype: false + - meta_content_scope: meta.path.java + - match: '' + branch_point: entity-class-path + branch: + - entity-class-qualifier + - entity-class-identifier + - match: (?=\S) + fail: entity-class + + entity-class-qualifier: + - match: '{{identifier}}' + scope: variable.namespace.java + set: + - entity-class-accessor + - maybe-type-argument + - include: else-pop2 + + entity-class-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: entity-class-path + + entity-class-identifier: + - match: '{{identifier}}' + scope: entity.name.class.java + set: + - immediately-pop2 + - maybe-type-argument + - include: else-pop2 + + entity-class-unqualified-identifier: + - match: '{{id}}' + scope: entity.name.class.java + set: maybe-type-argument + +###[ ENTITY MODULE ]########################################################### + + entity-module: + - match: (?={{identifier}}) + branch_point: entity-module + branch: + - entity-module-qualified-identifier + - entity-module-unqualified-identifier + + entity-module-qualified-identifier: + - match: '{{id}}' + scope: variable.namespace.java + set: + - meta_scope: meta.path.java + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + set: + - meta_include_prototype: false + - meta_content_scope: meta.path.java + - match: '' + branch_point: entity-module-path + branch: + - entity-module-qualifier + - entity-module-identifier + - match: (?=\S) + fail: entity-module + + entity-module-qualifier: + - match: '{{identifier}}' + scope: variable.namespace.java + set: entity-module-accessor + - include: else-pop2 + + entity-module-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: entity-module-path + + entity-module-identifier: + - match: '{{identifier}}' + scope: entity.name.namespace.module.java + pop: 2 + - include: else-pop2 + + entity-module-unqualified-identifier: + - match: '{{id}}' + scope: entity.name.namespace.module.java + pop: 1 + +###[ ENTITY PACKAGE ]########################################################## + + entity-package: + - match: (?={{identifier}}) + branch_point: entity-package + branch: + - entity-package-qualified-identifier + - entity-package-unqualified-identifier + + entity-package-qualified-identifier: + - match: '{{id}}' + scope: variable.namespace.java + set: + - meta_scope: meta.path.java + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + set: + - meta_include_prototype: false + - meta_content_scope: meta.path.java + - match: '' + branch_point: entity-package-path + branch: + - entity-package-qualifier + - entity-package-identifier + - match: (?=\S) + fail: entity-package + + entity-package-qualifier: + - match: '{{identifier}}' + scope: variable.namespace.java + set: entity-package-accessor + - include: else-pop2 + + entity-package-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: entity-package-path + + entity-package-identifier: + - match: '{{identifier}}' + scope: entity.name.namespace.package.java + pop: 2 + - include: else-pop2 + + entity-package-unqualified-identifier: + - match: '{{id}}' + scope: entity.name.namespace.package.java + pop: 1 + +###[ OBJECT TYPES ]############################################################ + + object-types: + # Popular JDK classes, generic type variable + - match: (?:UUID|UR[LI]|\p{Lu}){{break}} + scope: support.class.java + push: + - maybe-object-type-child + - maybe-array-modifiers + - maybe-type-argument + # Uppercase constants + - match: '{{uppercase_id}}' + scope: constant.other.java + # Classes + - match: '{{classcase_id}}' + scope: support.class.java + push: + - maybe-object-type-child + - maybe-array-modifiers + - maybe-type-argument + + maybe-object-type-child: + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + set: object-types-child-identifier + - include: else-pop + + object-types-child-identifier: + - include: variable-language-class + - match: '{{uppercase_id}}' + scope: constant.other.java + pop: 1 + - match: '{{classcase_id}}' + scope: support.class.java + set: + - maybe-object-type-child + - maybe-array-modifiers + - maybe-type-argument + - include: annotation-else-pop + +###[ OBJECT TYPE ]############################################################# + + expect-object-type: + - include: object-type + - include: annotations + - include: illegal-unexpected-reserved + - include: else-pop + + maybe-object-type: + - include: object-type + - include: annotation-else-pop + + object-type: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-4.html#jls-4.3 + - match: (?={{identifier}}) + branch_point: object-type + branch: + - unqualified-object-type + - qualified-object-type + + unqualified-object-type: + - match: '{{id}}' + scope: support.class.java + push: + - unqualified-object-type-end + - maybe-type-argument + + unqualified-object-type-end: + - match: (?={{single_dot}}) + fail: object-type + - include: else-pop3 + + qualified-object-type: + - meta_include_prototype: false + - meta_scope: meta.path.java + - match: '' + branch_point: qualified-object-type + branch: + - qualified-object-type-package + - qualified-object-type-class + + qualified-object-type-package: + - match: '{{lowercase_id}}' + scope: variable.namespace.java + set: qualified-object-type-accessor + - include: annotations + - match: (?=\S) + fail: qualified-object-type + + qualified-object-type-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: qualified-object-type + + qualified-object-type-class: + - match: '{{identifier}}' + scope: support.class.java + push: + - qualified-object-type-end + - qualified-object-type-arguments + - include: annotation-else-pop3 + + qualified-object-type-arguments: + - match: (?=\s*<) + set: maybe-type-argument + - match: (?=\s*\S) + pop: 1 + + qualified-object-type-end: + - match: \s*({{single_dot}}) + captures: + 1: punctuation.accessor.dot.java + pop: 1 + - match: (?=\s*\S) + pop: 4 + +###[ REFERENCE TYPE ]########################################################## + + maybe-additional-bounds: + - include: additional-bounds + - include: else-pop + + additional-bounds: + - match: '&' + scope: keyword.operator.logical.java + push: maybe-reference-type + + maybe-reference-type: + - include: reference-type + - include: annotation-else-pop + + reference-type: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-4.html#jls-4.3 + - match: (?={{storage_types}}{{break}}) + branch_point: primitive-array-type + branch: + - reference-type-array + - reference-type-illegal + - match: (?={{id_first_char}}) + set: + - maybe-array-modifiers + - maybe-object-type + + reference-type-array: + # note: simplified pattern as primitive types consist of ascii chars only + - match: '[A-Za-z]+' + scope: storage.type.primitive.java + set: reference-type-array-item-access + + reference-type-array-item-access: + - match: (?=\[) + pop: 1 + set: maybe-array-modifiers + - include: annotations + - match: (?=\S) + fail: primitive-array-type + + reference-type-illegal: + # note: simplified pattern as primitive types consist of ascii chars only + - match: '[A-Za-z]+' + scope: invalid.illegal.unexpected-keyword.java + pop: 2 + +###[ INHERITED TYPE REFERENCES ]############################################### + + # Used in class-level 'extends' and 'implements' + inherited-object-type-list: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.1.4 + - match: ',' + scope: punctuation.separator.comma.java + push: inherited-object-type + + inherited-object-type: + - match: (?={{identifier}}) + branch_point: inherited-object-type + branch: + - unqualified-inherited-object-type + - qualified-inherited-object-type + - include: annotation-else-pop + + unqualified-inherited-object-type: + - match: '{{id}}' + scope: entity.other.inherited-class.java + push: + - unqualified-inherited-object-type-end + - maybe-type-argument + + unqualified-inherited-object-type-end: + - match: (?={{single_dot}}) + fail: inherited-object-type + - include: illegal-array-modifiers + - include: annotation-else-pop3 + + qualified-inherited-object-type: + - meta_include_prototype: false + - meta_scope: meta.path.java + - match: '' + branch_point: qualified-inherited-object-type + branch: + - qualified-inherited-object-type-package + - qualified-inherited-object-type-class + + qualified-inherited-object-type-package: + - match: '{{lowercase_id}}' + scope: variable.namespace.java + set: qualified-inherited-object-type-accessor + - include: annotations + - match: (?=\S) + fail: qualified-inherited-object-type + + qualified-inherited-object-type-accessor: + - include: punctuation-accessor-dot-pop + - match: (?=\S) + fail: qualified-inherited-object-type + + qualified-inherited-object-type-class: + - match: '{{identifier}}' + scope: entity.other.inherited-class.java + push: + - qualified-object-type-end + - qualified-object-type-arguments + - include: annotation-else-pop3 + +###[ TYPE ARGUMENTS ]########################################################## + + maybe-type-argument: + - include: type-argument + - include: else-pop + + type-argument: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-4.html#jls-4.5.1 + - match: <> + scope: + meta.generic.java + punctuation.definition.generic.diamond.java + pop: 1 + - match: < + scope: punctuation.definition.generic.begin.java + set: + - type-argument-body + - type-argument-reference + + type-argument-body: + - meta_scope: meta.generic.java + - match: ',' + scope: punctuation.separator.comma.java + push: type-argument-reference + - include: type-parameter-end + + type-argument-reference: + - match: \? + scope: constant.other.wildcard.questionmark.java + set: type-argument-bounds + - include: maybe-reference-type + + type-argument-bounds: + - match: extends{{break}} + scope: storage.modifier.extends.java + set: + - maybe-additional-bounds + - maybe-reference-type + - match: super{{break}} + scope: keyword.declaration.super.java + set: maybe-reference-type + - include: else-pop + +###[ TYPE PARAMETERS ]######################################################### + + maybe-type-parameter: + - include: type-parameter + - include: else-pop + + type-parameters: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.1.2 + - match: < + scope: punctuation.definition.generic.begin.java + push: + - type-parameter-body + - type-parameter-bounds + - type-parameter-reference + + type-parameter: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-8.html#jls-8.1.2 + - match: < + scope: punctuation.definition.generic.begin.java + set: + - type-parameter-body + - type-parameter-bounds + - type-parameter-reference + + type-parameter-body: + - meta_scope: meta.generic.declaration.java + - match: ',' + scope: punctuation.separator.comma.java + push: + - type-parameter-bounds + - type-parameter-reference + - include: type-parameter-end + + type-parameter-reference: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-4.html#jls-4.4 + - match: '{{identifier}}' + scope: variable.parameter.type.java + pop: 1 + - match: \?|{{storage_types}}{{break}} + scope: invalid.illegal.unexpected-keyword.java + pop: 1 + - include: annotation-else-pop + + type-parameter-bounds: + - match: extends{{break}} + scope: storage.modifier.extends.java + set: + - maybe-additional-bounds + - maybe-reference-type + - match: super{{break}} + scope: invalid.illegal.unexpected-keyword.java + set: maybe-reference-type + - include: else-pop + + type-parameter-end: + - match: '>' + scope: punctuation.definition.generic.end.java + pop: 1 + - match: extends{{break}} + scope: invalid.illegal.unexpected-keyword.java + push: + - maybe-additional-bounds + - maybe-reference-type + - match: super{{break}} + scope: invalid.illegal.unexpected-keyword.java + push: maybe-reference-type + - include: annotation-else-pop + +###[ PRIMITIVE TYPES ]######################################################### + + primitive-maybe-class-literals: + - match: '{{storage_types}}{{break}}' + scope: storage.type.primitive.java + push: maybe-only-class-literal + + primitive-maybe-class-literal: + - match: '{{storage_types}}{{break}}' + scope: storage.type.primitive.java + set: maybe-only-class-literal + + maybe-only-class-literal: + # https://docs.oracle.com/javase/specs/jls/se13/html/jls-15.html#jls-15.8.2 + - match: '{{single_dot}}' + scope: punctuation.accessor.dot.java + set: maybe-class-literal + - include: array-modifiers + - include: annotation-else-pop + + maybe-class-literal: + - match: class{{break}} + scope: variable.language.class.java + pop: 1 + - match: '{{id}}' + scope: invalid.illegal.unexpected-member.java + set: maybe-only-class-literal + - include: else-pop + + primitive-type: + - match: '{{storage_types}}{{break}}' + scope: storage.type.primitive.java + pop: 1 + + var-types: + - match: var{{break}} + scope: storage.type.variant.java + push: maybe-illegal-array-modifiers + + var-type: + - match: var{{break}} + scope: storage.type.variant.java + set: maybe-illegal-array-modifiers + + maybe-array-modifiers: + - include: array-modifiers + - include: annotation-else-pop + + maybe-only-array-modifiers: + - include: array-modifiers + - include: illegal-members + - include: annotation-else-pop + + array-modifiers: + - match: \[\s*\] + scope: storage.modifier.array.java + + final-modifiers: + - match: final{{break}} + scope: storage.modifier.java + + storage-modifiers: + - match: '{{storage_modifiers}}{{break}}' + scope: storage.modifier.java + +###[ PROTOTYPES ]############################################################## + + prototype: + - include: comments + - include: illegal-keywords + + annotation-else-pop: + - include: annotations + - include: else-pop + + annotation-else-pop2: + - include: annotations + - include: else-pop2 + + annotation-else-pop3: + - include: annotations + - include: else-pop3 + + else-pop: + - match: (?=\S) + pop: 1 + + else-pop2: + - match: (?=\S) + pop: 2 + + else-pop3: + - match: (?=\S) + pop: 3 + + immediately-pop: + - match: '' + pop: 1 + + immediately-pop2: + - match: '' + pop: 2 + + immediately-pop3: + - match: '' + pop: 3 + +###[ ILLEGALS ]################################################################ + + maybe-illegal-array-modifiers: + - include: illegal-array-modifiers + - include: annotation-else-pop + + illegal-array-modifiers: + - match: \[\s*\] + scope: invalid.illegal.unexpected-modifier.java + + illegal-keywords: + - match: '{{illegal_keywords}}{{break}}' + scope: invalid.illegal.keyword.java + + illegal-unexpected-keywords: + - match: '{{keywords}}{{break}}' + scope: invalid.illegal.unexpected-keyword.java + + illegal-unexpected-reserved: + - match: '{{reserved_words}}' + scope: invalid.illegal.unexpected-keyword.java + pop: 1 + + illegal-members: + - match: '{{single_dot}}' + scope: invalid.illegal.unexpected-accessor.java + push: + - maybe-illegal-array-modifiers + - maybe-illegal-member + + maybe-illegal-member: + - match: '{{id}}' + scope: invalid.illegal.unexpected-member.java + pop: 1 + - include: else-pop + + illegal-newline: + - match: \n + scope: invalid.illegal.unexpected-newline.java + pop: 1 + + illegal-storage-modifiers: + - match: '{{storage_modifiers}}{{break}}' + scope: invalid.illegal.unexpected-keyword.java + + maybe-illegal-type-parameter: + - match: \< + set: illegal-type-parameter-body + - include: else-pop + + illegal-type-parameter-body: + - meta_scope: invalid.illegal.unexpected-type-parameters.java + - match: \< + push: + - match: \> + pop: 1 + - match: \> + pop: 1 + + illegal-var-type: + - match: var{{break}} + scope: invalid.illegal.unexpected-keyword.java + pop: 1 + + stray-braces: + - match: \} + scope: invalid.illegal.stray.java + + stray-group: + - match: \) + scope: invalid.illegal.stray.java
diff --git /dev/null b/syntax/JavaScript/JavaScript.sublime-syntax @@ -0,0 +1,2812 @@ +%YAML 1.2 +--- +# Derived from JavaScript Next: https://github.com/Benvie/JavaScriptNext.tmLanguage +name: JavaScript +scope: source.js +version: 2 + +file_extensions: + - js + - mjs + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* // .*? -\*- .*? \b(?:js|javascript)\b .*? -\*- # editorconfig + ) + +variables: + shebang_language: \b(?:node|js|bun|osascript\s+-l\s+JavaScript)\b + + bin_digit: '[01_]' + oct_digit: '[0-7_]' + dec_digit: '[0-9_]' + hex_digit: '[\h_]' + dec_integer: (?:0|[1-9]{{dec_digit}}*) + dec_exponent: '[Ee](?:[-+]|(?![-+])){{dec_digit}}*' + + identifier_escape: (?:\\u(?:\h{4}|\{\h+\})) + identifier_start: (?:[_$\p{L}\p{Nl}]|{{identifier_escape}}) + identifier_part: (?:[_$\p{L}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]|{{identifier_escape}}) + identifier_break: (?!{{identifier_part}}) + + identifier_name: (?:{{identifier_start}}{{identifier_part}}*{{identifier_break}}) + constant_identifier: (?:[[:upper:]]{{identifier_part}}*{{identifier_break}}) + dollar_only_identifier: (?:\${{identifier_break}}) + dollar_identifier: '(?:(\$){{identifier_part}}*{{identifier_break}})' + + block_comment_contents: (?:(?:[^*]|\*(?!/))*) + block_comment: (?:/\*{{block_comment_contents}}\*/) + nothing: (?:(?:\s|{{block_comment}})*) + line_ending_ahead: (?={{nothing}}(?:/\*{{block_comment_contents}}|//.*)?$) + + # https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar + reserved_word: |- + (?x: + # standard mode + break + | case + | catch + | class + | const + | continue + | debugger + | default + | delete + | do + | else + | export + | extends + | false + | finally + | for + | function + | if + | import + | in + | instanceof + | new + | null + | return + | super + | switch + | this + | throw + | true + | try + | typeof + | var + | void + | while + | with + # strict mode + # | let # currently allowed as variable + | static + | yield + # async code + | await + # future reserved words + | enum + | implements + | interface + | package + | private + | protected + | public + ){{identifier_break}} + + non_reserved_identifier: (?:(?!{{reserved_word}}){{identifier_name}}) + + possible_arrow_function_begin: (?:\(|{{identifier_start}}) + either_func_lookahead: (?:{{func_lookahead}}|{{arrow_func_lookahead}}) + binding_pattern_lookahead: (?:{{identifier_name}}|\[|\{) + left_expression_end_lookahead: (?!\s*[.\[\(]) + + dot_accessor: (?:\??\.) + + property_name: >- + (?x: + {{identifier_name}} + | [0-9]+ + | '(?:[^\\']|\\.)*' + | "(?:[^\\"]|\\.)*" + | \[ .* \] + ) + + class_element_name: |- + (?x: + {{property_name}} + | \#{{identifier_name}} + ) + + modifier: (?:(?:static|accessor){{identifier_break}}) + + # Newline not permitted between `async` and `function`. + func_lookahead: |- + (?x: + (?:async{{identifier_break}}{{nothing}})? + function{{identifier_break}} + ) + + arrow_func_lookahead: |- + (?x: + (?:async\s*)? + (?: + {{identifier_name}} + | \( ( [^()] | \( [^()]* \) )* \) + ) + \s* + => + ) + + function_call_after_lookahead: (?=\s*(?:\?\.\s*)?\() + + function_assignment_lookahead: |- + (?x:(?= + \s* = \s* + {{either_func_lookahead}} + )) + + # '@' followed by a pattern like \S but excluding literal '*' and '@'. + jsdoc_block_tag: \@[^\n\t\f\v *@]+ + + leading_wspace: (?:^\s*) + trailing_wspace: (?:\s*$\n?) + + tagged_template_quote_begin: \` + tagged_template_quote_end: \` + tagged_template_quote_escape: '{{no_escape_behind}}{{tagged_template_quote_end}}' + no_escape_behind: (?<![^\\]\\)(?<![\\]{3}) + +contexts: + main: + - meta_include_prototype: false # don't match comments before shebang + - match: '' + push: [script, shebang] + + script: + - match: '\)|\}|\]' + scope: invalid.illegal.stray-bracket-end.js + # Don't pop or embedding could break. + + - include: statements + + prototype: + - include: comments + + comments: + - include: line-comments + - include: block-comments + - include: merge-conflict-markers + + block-comments: + # empty block comments + - match: /\*\*+/ + scope: comment.block.empty.js punctuation.definition.comment.js + # documentation block comments + - match: /\*\*+ + scope: punctuation.definition.comment.begin.js + push: + - jsdoc-comment-body + - jsdoc-block-tag + # normal block comments (not looking like tagged template string "decorator") + # note: required as comments are included via `prototype` and we don't want + # to exclude prototypes from `expression-begin` context as it might break inherited syntaxes. + - match: /\*(?!\s*{{identifier_name}}\s*\*/\s*`) + scope: punctuation.definition.comment.begin.js + push: block-comment-body + + block-comment-end: + - match: \*+/ + scope: punctuation.definition.comment.end.js + pop: 1 + + block-comment-body: + - meta_include_prototype: false + - meta_scope: comment.block.js + - include: block-comment-end + - match: ^\s*(\*)(?!/) + captures: + 1: punctuation.definition.comment.js + - include: merge-conflict-markers + + jsdoc-comment-body: + - meta_include_prototype: false + - meta_scope: comment.block.documentation.js + - include: block-comment-end + # JSDoc "block" tags (i.e. @param) are only accepted at the beginning of the documentation + # line so directly after the '/**' or after the '*' marker on the next lines. + - match: ^\s*(\*)(?!/) + captures: + 1: punctuation.definition.comment.js + push: jsdoc-block-tag + - include: merge-conflict-markers + + jsdoc-block-tag: + - match: '{{jsdoc_block_tag}}' + scope: entity.other.attribute-name.documentation.js + pop: 1 + - match: (?=\S)|$ + pop: 1 + + line-comments: + - match: /{4,} + scope: punctuation.definition.comment.js + push: line-comment-other-body + - match: /{3} + scope: punctuation.definition.comment.js + push: line-comment-triple-slash-body + - match: /{2} + scope: punctuation.definition.comment.js + push: line-comment-double-slash-body + + line-comment-end: + - match: (//+)?\n + captures: + 1: punctuation.definition.comment.js + pop: 1 + + line-comment-double-slash-body: + - meta_include_prototype: false + - meta_scope: comment.line.double-slash.js + - include: line-comment-end + + line-comment-triple-slash-body: + - meta_include_prototype: false + - meta_scope: comment.line.triple-slash.js + - include: line-comment-end + + line-comment-other-body: + - meta_include_prototype: false + - meta_scope: comment.line.other.js + - include: line-comment-end + + shebang: + - meta_include_prototype: false + - match: ^\s*(\#!) + captures: + 1: punctuation.definition.comment.js + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if the syntax is embedded. + pop: 1 + + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.js + - match: '{{shebang_language}}' + scope: constant.language.shebang.js + - match: $\n? + pop: 1 + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + + else-pop: + - match: (?=\S) + pop: 1 + + else-pop-2: + - match: (?=\S) + pop: 2 + + immediately-pop: + - meta_include_prototype: false + - match: '' + pop: 1 + + immediately-pop-2: + - meta_include_prototype: false + - match: '' + pop: 2 + + comma-separator: + - match: ',' + scope: punctuation.separator.comma.js + + import-statement-or-import-meta: + - match: (?=import{{identifier_break}}) + branch_point: import-statement + branch: + - import-statement + - expression-statement + + import-statement: + - match: import{{identifier_break}} + scope: keyword.control.import-export.js + set: + - import-meta + - expect-semicolon + - import-export-assert + - import-string-or-items + - import-check-branch + + import-check-branch: + - match: (?=[.(]) # Recovery for import expressions + fail: import-statement + - include: else-pop + + import-meta: + - meta_include_prototype: false + - meta_scope: meta.import.js + - include: immediately-pop + + import-export-alias: + - match: as{{identifier_break}} + scope: keyword.control.import-export.js + set: import-export-name + - include: else-pop + + import-export-name: + - match: default{{identifier_break}} + scope: keyword.control.import-export.js + pop: 1 + - match: '{{identifier_name}}' + scope: variable.other.readwrite.js + pop: 1 + - include: literal-string + - include: else-pop + + import-export-from: + - match: 'from{{identifier_break}}' + scope: keyword.control.import-export.js + set: import-export-from-name + - include: else-pop + + import-export-from-name: + - include: literal-string + - include: else-pop + + import-string-or-items: + - include: literal-string + - match: (?=\S) + set: + - import-export-from + - import-list + - import-export-item + + import-list: + - match: ',' + scope: punctuation.separator.comma.js + push: import-export-item + - include: else-pop + + import-export-item: + - match: '\{' + scope: punctuation.section.block.begin.js + set: import-export-brace + - match: '{{non_reserved_identifier}}' + scope: variable.other.readwrite.js + pop: 1 + - match: '\*' + scope: constant.other.wildcard.asterisk.js + set: import-export-alias + - include: else-pop + + import-export-brace: + - meta_scope: meta.block.js + - include: comma-separator + - match: '\}' + scope: punctuation.section.block.end.js + pop: 1 + - match: (?={{identifier_start}}|'|") + push: + - import-export-alias + - import-export-name + - match: '\*' + scope: constant.other.wildcard.asterisk.js + push: import-export-alias + - include: else-pop + + import-export-assert: + - match: (?:assert|with){{identifier_break}} + scope: keyword.control.import-export.js + set: import-export-object + - include: else-pop + + import-export-object: + - include: object-literal + - include: else-pop + + export-statement: + - match: export{{identifier_break}} + scope: keyword.control.import-export.js + set: + - export-meta + - export-body + + export-meta: + - meta_include_prototype: false + - meta_scope: meta.export.js + - include: immediately-pop + + export-body: + - include: declaration + + - match: default{{identifier_break}} + scope: keyword.control.import-export.js + set: export-default + + - match: (?=\S) + set: + - expect-semicolon + - import-export-assert + - import-export-from + - import-export-item + + export-default: + - include: declaration + - include: expression-statement + + statements: + - match: '\)|\}|\]' + scope: invalid.illegal.stray-bracket-end.js + pop: 1 + + - match: (?=\S) + push: statement + + statement: + - match: \; + scope: punctuation.terminator.statement.empty.js + pop: 1 + + - include: declaration + - include: import-statement-or-import-meta + - include: export-statement + - include: conditional + - include: block + - include: label + + - match: break{{identifier_break}} + scope: keyword.control.flow.break.js + set: + - expect-semicolon + - expect-label + + - match: continue{{identifier_break}} + scope: keyword.control.flow.continue.js + set: + - expect-semicolon + - expect-label + + - match: debugger{{identifier_break}} + scope: keyword.control.flow.debugger.js + set: expect-semicolon + + - match: return{{identifier_break}} + scope: keyword.control.flow.return.js + set: restricted-production + + - match: throw{{identifier_break}} + scope: keyword.control.flow.throw.js + set: restricted-production + + - include: decorator + + - include: expression-statement + + declaration: + - include: variable-declaration + - include: using-declaration + - include: class + - include: regular-function + + expect-semicolon: + - match: \; + scope: punctuation.terminator.statement.js + pop: 1 + - include: else-pop + + expect-label: + - meta_include_prototype: false + - match: '(?={{nothing}}{{identifier_name}})' + set: + - match: '{{non_reserved_identifier}}' + scope: variable.label.js + pop: 1 + - match: '{{identifier_name}}' + scope: invalid.illegal.identifier.js variable.label.js + pop: 1 + - include: else-pop + - include: immediately-pop + + block: + - match: '\{' + scope: punctuation.section.block.begin.js + set: + - meta_scope: meta.block.js + - match: '\}' + scope: punctuation.section.block.end.js + pop: 1 + - include: statements + + variable-binding-pattern: + - include: variable-binding-name + - include: variable-binding-array-destructuring + - include: variable-binding-object-destructuring + - include: else-pop + + variable-binding-name: + - match: (?={{non_reserved_identifier}}) + set: + - - meta_scope: meta.binding.name.js + - include: immediately-pop + - literal-variable + + variable-binding-array-destructuring: + - match: '\[' + scope: punctuation.section.sequence.begin.js + set: + - meta_scope: meta.binding.destructuring.sequence.js + - match: '\]' + scope: punctuation.section.sequence.end.js + pop: 1 + - include: variable-binding-spread + - include: variable-binding-list + + variable-binding-object-destructuring: + - match: '\{' + scope: punctuation.section.mapping.begin.js + set: + - meta_scope: meta.binding.destructuring.mapping.js + - match: '\}' + scope: punctuation.section.mapping.end.js + pop: 1 + - include: variable-binding-spread + - match: (?={{identifier_start}}|\[|'|") + push: + - initializer + - variable-binding-object-alias + - object-literal-meta-key + - variable-binding-object-key + - include: comma-separator + + variable-binding-object-alias: + - match: ':' + scope: punctuation.separator.key-value.js + set: variable-binding-pattern + - include: else-pop + + variable-binding-object-key: + - match: '{{identifier_name}}(?=\s*:)' + pop: 1 + - include: literal-string + - include: computed-property-name + - include: variable-binding-name + - include: else-pop + + variable-binding-spread: + - match: '\.\.\.' + scope: keyword.operator.spread.js + push: variable-binding-pattern + + variable-binding-list: + - include: comma-separator + - match: (?={{binding_pattern_lookahead}}) + push: + - initializer + - variable-binding-pattern + - include: else-pop + + variable-binding-top: + - match: (?={{binding_pattern_lookahead}}) + set: + - initializer + - variable-binding-pattern + - include: else-pop + + variable-binding-list-top: + - match: ',' + scope: punctuation.separator.comma.js + push: variable-binding-top + - include: else-pop + + variable-declaration: + - match: (?:const|let|var){{identifier_break}} + scope: keyword.declaration.js + set: + - expect-semicolon + - variable-binding-list-top + - variable-binding-top + + using-declaration: + - include: plain-using-declaration + + - match: (?=await{{identifier_break}}) + branch_point: await-using-declaration + branch: + - await-using-declaration + - expression-statement + pop: 1 + + plain-using-declaration: + - match: using{{identifier_break}}(?={{nothing}}{{non_reserved_identifier}}) + scope: keyword.declaration.js + set: + - expect-semicolon + - variable-binding-list-top + - variable-binding-top + + await-using-declaration: + - match: await{{identifier_break}} + scope: keyword.declaration.js + set: + - include: using-declaration + - match: (?=\S) + fail: await-using-declaration + + function-parameter-binding-pattern: + - include: function-parameter-binding-name + - include: function-parameter-binding-array-destructuring + - include: function-parameter-binding-object-destructuring + - include: else-pop + + function-parameter-binding-name: + - match: '{{dollar_identifier}}' + scope: meta.binding.name.js variable.parameter.function.js + captures: + 1: punctuation.dollar.js + - match: '{{non_reserved_identifier}}' + scope: meta.binding.name.js variable.parameter.function.js + - match: '{{identifier_name}}' + scope: invalid.illegal.identifier.js meta.binding.name.js variable.parameter.function.js + + function-parameter-binding-array-destructuring: + - match: '\[' + scope: punctuation.section.sequence.begin.js + set: + - meta_scope: meta.binding.destructuring.sequence.js + - match: '\]' + scope: punctuation.section.sequence.end.js + pop: 1 + - include: function-parameter-binding-list + + function-parameter-binding-object-destructuring: + - match: '\{' + scope: punctuation.section.mapping.begin.js + set: + - meta_scope: meta.binding.destructuring.mapping.js + - match: ',' + scope: punctuation.separator.parameter.function.js + - match: '\}' + scope: punctuation.section.mapping.end.js + pop: 1 + - include: function-parameter-binding-spread + - match: (?={{identifier_start}}|\[|'|") + push: + - initializer + - function-parameter-binding-object-alias + - object-literal-meta-key + - function-parameter-binding-object-key + + function-parameter-binding-object-alias: + - match: ':' + scope: punctuation.separator.key-value.js + set: function-parameter-binding-pattern + - include: else-pop + + function-parameter-binding-object-key: + - match: '{{identifier_name}}(?=\s*:)' + pop: 1 + - include: literal-string + - include: computed-property-name + - include: function-parameter-binding-name + - include: else-pop + + function-parameter-binding-spread: + - match: '\.\.\.' + scope: keyword.operator.spread.js + push: function-parameter + + function-parameter-binding-list: + - match: ',' + scope: punctuation.separator.parameter.function.js + - include: function-parameter-binding-spread + - match: (?={{binding_pattern_lookahead}}) + push: function-parameter + - include: else-pop + + function-parameter: + - match: '' + set: + - initializer + - function-parameter-binding-pattern + + initializer: + - match: '=' + scope: keyword.operator.assignment.js + set: expression-no-comma + - include: else-pop + + expression-statement: + - match: (?=\S) + set: + - expect-semicolon + - expression-statement-end + - expression-begin + + expression-statement-end: + - match: '{{line_ending_ahead}}' + branch_point: expression-statement-continuation + branch: + - expression-statement-continuation + - expression-statement-pop + - include: expression-end + + expression-statement-continuation: + - match: (?=\+\+|--) + fail: expression-statement-continuation + - match: |- + (?x) + (?= + != + | [-+*/%><=&|^\[(;,.:?] + | (?:in|instanceof){{identifier_break}} + ) + pop: 1 + - match: (?=\S) + fail: expression-statement-continuation + + expression-statement-pop: + # Consume only comments (ignore patterns from inheriting syntaxes) and + # pop `expression-statement-end` at the same text point the previous branch + # fails at in order to prevent ST's syntax engine to lock up. + # see: https://github.com/sublimehq/sublime_text/issues/5853 + - meta_include_prototype: false + - include: comments + - include: else-pop-2 + + restricted-production: + - meta_include_prototype: false + - match: '{{line_ending_ahead}}' + pop: 1 + - match: '' + set: expression-statement + + expect-case-colon: + - match: ':' + scope: punctuation.separator.js + pop: 1 + - include: else-pop + + conditional: + - match: switch{{identifier_break}} + scope: keyword.control.conditional.switch.js + set: + - switch-meta + - switch-block + - expect-parenthesized-expression + + - match: do{{identifier_break}} + scope: keyword.control.loop.do-while.js + set: + - do-while-meta + - do-while-condition + - statement + + - match: for{{identifier_break}} + scope: keyword.control.loop.for.js + set: + - for-meta + - block-scope + - for-condition + - for-await + + - match: while{{identifier_break}} + scope: keyword.control.loop.while.js + set: + - while-meta + - block-scope + - expect-parenthesized-expression + + - match: with{{identifier_break}} + scope: keyword.control.import.with.js + set: + - with-meta + - block-scope + - expect-parenthesized-expression + + - match: if{{identifier_break}} + scope: keyword.control.conditional.if.js + set: + - conditional-meta + - statement + - expect-parenthesized-expression + + - match: else\s+if{{identifier_break}} + scope: keyword.control.conditional.elseif.js + set: + - conditional-meta + - statement + - expect-parenthesized-expression + + - match: else{{identifier_break}} + scope: keyword.control.conditional.else.js + set: + - conditional-meta + - statement + + - match: try{{identifier_break}} + scope: keyword.control.exception.try.js + set: + - try-meta + - block-scope + + - match: finally{{identifier_break}} + scope: keyword.control.exception.finally.js + set: + - finally-meta + - block-scope + + - match: catch{{identifier_break}} + scope: keyword.control.exception.catch.js + set: + - catch-meta + - block-scope + - catch-binding + + expect-parenthesized-expression: + - include: parenthesized-expression + - include: else-pop + + switch-meta: + - meta_include_prototype: false + - meta_scope: meta.switch.js + - include: immediately-pop + + do-while-meta: + - meta_include_prototype: false + - meta_scope: meta.do-while.js + - include: immediately-pop + + for-meta: + - meta_include_prototype: false + - meta_scope: meta.for.js + - include: immediately-pop + + while-meta: + - meta_include_prototype: false + - meta_scope: meta.while.js + - include: immediately-pop + + with-meta: + - meta_include_prototype: false + - meta_scope: meta.with.js + - include: immediately-pop + + conditional-meta: + - meta_include_prototype: false + - meta_scope: meta.conditional.js + - include: immediately-pop + + try-meta: + - meta_include_prototype: false + - meta_scope: meta.try.js + - include: immediately-pop + + finally-meta: + - meta_include_prototype: false + - meta_scope: meta.finally.js + - include: immediately-pop + + catch-meta: + - meta_include_prototype: false + - meta_scope: meta.catch.js + - include: immediately-pop + + for-await: + - match: await{{identifier_break}} + scope: keyword.control.flow.await.js + pop: 1 + - include: else-pop + + for-condition: + - match: \( + scope: punctuation.section.group.begin.js + branch_point: for-in-of + branch: + - for-in-of + - for-oldstyle + pop: 1 + - include: else-pop + + for-condition-end: + - meta_scope: meta.group.js + - match: \) + scope: punctuation.section.group.end.js + pop: 1 + - match: ; + scope: invalid.illegal.unexpected-token.js + - include: expressions + + for-in-of: + - meta_include_prototype: false + - meta_scope: meta.group.js + - match: '' + set: + - for-condition-end + - for-in-of-word + - for-in-of-declaration + + for-in-of-declaration: + - match: (?:const|let|var){{identifier_break}} + scope: keyword.declaration.js + set: for-in-of-binding + + - match: |- + (?x: + (?! # [lookahead β using of] + using{{identifier_break}}{{nothing}} + of{{identifier_break}} + ) + (?= # await [no LineTerminator here] using [no LineTerminator here] ForBinding + (?:await{{identifier_break}}{{nothing}})? + using{{identifier_break}}{{nothing}} + {{non_reserved_identifier}} + ) + ) + scope: keyword.declaration.js + set: + - match: await{{identifier_break}} + scope: keyword.declaration.js + - match: using{{identifier_break}} + scope: keyword.declaration.js + set: for-in-of-binding + + - match: (?=\S) + set: + - left-expression-end + - expression-begin + + for-in-of-binding: + - include: variable-binding-name + - include: variable-binding-array-destructuring + - include: variable-binding-object-destructuring + - match: (?=\S) + fail: for-in-of + + for-in-of-word: + - match: in{{identifier_break}} + scope: keyword.control.loop.in.js + pop: 1 + - match: of{{identifier_break}} + scope: keyword.control.loop.of.js + pop: 1 + - match: (?=\S) + fail: for-in-of + + for-oldstyle: + - meta_include_prototype: false + - meta_scope: meta.group.js + - match: '' + set: + - for-condition-end + - for-oldstyle-separator + - expression + - for-oldstyle-separator + - for-oldstyle-declaration + + for-oldstyle-declaration: + - match: (?:const|let|var){{identifier_break}} + scope: keyword.declaration.js + set: + - variable-binding-list-top + - variable-binding-top + - include: expression + + for-oldstyle-separator: + - match: ; + scope: punctuation.separator.expression.js + pop: 1 + - include: else-pop + + block-scope: + - include: block + - include: else-pop + + block-meta: + - meta_include_prototype: false + - meta_scope: meta.block.js + - include: immediately-pop + + switch-block: + - match: '\{' + scope: punctuation.section.block.begin.js + set: switch-block-contents + - include: else-pop + + switch-block-contents: + - meta_scope: meta.block.js + + - match: '\}' + scope: punctuation.section.block.end.js + pop: 1 + + - match: case{{identifier_break}} + scope: keyword.control.conditional.case.js + push: + - expect-case-colon + - expression + + - match: default{{identifier_break}} + scope: keyword.control.conditional.default.js + push: + - expect-case-colon + + - include: statements + + do-while-condition: + - match: while{{identifier_break}} + scope: keyword.control.loop.while.js + set: parenthesized-expression + - include: else-pop + + catch-binding: + - match: \( + scope: punctuation.section.group.begin.js + set: + - catch-binding-end + - variable-binding-pattern + - include: else-pop + + catch-binding-end: + - meta_scope: meta.group.js + - match: \) + scope: punctuation.section.group.end.js + pop: 1 + + decorator: + - match: '@' + scope: punctuation.definition.annotation.js + push: + - decorator-meta + - decorator-expression-end + - decorator-expression-begin + + decorator-meta: + - meta_include_prototype: false + - meta_scope: meta.annotation.js + - include: immediately-pop + + decorator-name: + - match: '{{identifier_name}}(?!\s*[.\(`])' + scope: variable.annotation.js + pop: 1 + + decorator-expression-end: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + push: + - include: decorator-name + - include: object-property + + - include: literal-string-templates + + - match: (?={{function_call_after_lookahead}}) + push: function-call-arguments + + - match: '{{line_ending_ahead}}' + branch_point: decorator-expression-continuation + branch: + - decorator-expression-continuation + - decorator-expression-pop + + - include: else-pop + + decorator-expression-continuation: + - match: (?=[.`(]) + pop: 1 + - match: (?=\S) + fail: decorator-expression-continuation + + decorator-expression-pop: + # Consume only comments (ignore patterns from inheriting syntaxes) + # and clear `meta.annotation` scope so it looks like the comment not being + # part of the annotation anymore. + # Pop `decorator-expression-end` at the same text point the previous branch + # fails at in order to prevent ST's syntax engine to lock up. + # see: https://github.com/sublimehq/sublime_text/issues/5853 + - clear_scopes: 1 + - meta_include_prototype: false + - include: comments + - include: else-pop-2 + + decorator-expression-begin: + - include: decorator-name + - include: parenthesized-expression + - include: expression-begin + + expressions: + - match: (?=\S) + push: [ expression-end, expression-begin ] + + expression: + - meta_include_prototype: false + - match: (?=\S) + set: [ expression-end, expression-begin ] + + expression-list: + - include: expression-break + - include: comma-separator + - include: expressions-no-comma + + expressions-no-comma: + - match: (?=\S) + push: [ expression-end-no-comma, expression-begin ] + + expression-no-comma: + - meta_include_prototype: false + - match: (?=\S) + set: [ expression-end-no-comma, expression-begin ] + + expression-break: + - match: (?=[;})\]]) + pop: 1 + + left-expression-end: + - include: expression-break + + - include: literal-string-templates + + - match: '{{function_call_after_lookahead}}' + push: function-call-arguments + + - include: property-access + + - include: else-pop + + expression-end: + - include: postfix-operators + - include: binary-operators + - include: ternary-operator + + - include: left-expression-end + + expression-end-no-comma: + - match: (?=,) + pop: 1 + - include: expression-end + + expression-end-no-in: + - match: (?=in{{identifier_break}}) + pop: 1 + - include: expression-end + + expression-begin: + - include: expression-break + + - include: yield-expression + - include: await-expression + + - include: literal-string-template + - include: literal-string + - include: regexp-complete + - include: instantiation + - include: literal-number + - include: prefix-operators + - include: import-meta-expression + + - include: class + - include: special-name + + - include: regular-function + + - match: (?={{reserved_word}}) + pop: 1 + + - match: (?={{identifier_name}}{{function_assignment_lookahead}}) + set: + - function-name-meta + - literal-variable + + - include: object-literal + + # Newline not allowed between `async` and parameters. + - match: (?=async{{identifier_break}}{{nothing}}{{possible_arrow_function_begin}}) + pop: 1 + branch_point: async-arrow-function + branch: + - async-arrow-function + - literal-variable + + - match: (?={{possible_arrow_function_begin}}) + pop: 1 + branch_point: arrow-function + branch: + - branch-possible-arrow-function + - arrow-function-declaration + + - include: array-literal + + - include: literal-private-variable + + - include: else-pop + + async-arrow-function: + - match: async{{identifier_break}} + scope: keyword.declaration.async.js + set: + - function-meta + - arrow-function-expect-body + - arrow-function-expect-arrow-or-fail-async + - arrow-function-expect-parameters + + arrow-function-expect-arrow-or-fail-async: + - match: '=>' + scope: keyword.declaration.function.arrow.js + pop: 1 + - match: (?=\S) + fail: async-arrow-function + + branch-possible-arrow-function: + - meta_include_prototype: false + - match: (?=\() + set: + - detect-arrow + - parenthesized-expression + - match: '' + set: + - detect-arrow + - literal-variable + + detect-arrow: + - match: (?==>) + fail: arrow-function + - include: else-pop + + literal-string: + - include: literal-double-quoted-string + - include: literal-single-quoted-string + + literal-double-quoted-string: + - match: \" + scope: punctuation.definition.string.begin.js + set: literal-double-quoted-string-content + + literal-double-quoted-string-content: + - meta_include_prototype: false + - meta_scope: meta.string.js string.quoted.double.js + - match: \" + scope: punctuation.definition.string.end.js + pop: 1 + - match: \n + scope: invalid.illegal.newline.js + pop: 1 + - include: string-content + + literal-single-quoted-string: + - match: \' + scope: punctuation.definition.string.begin.js + set: literal-single-quoted-string-content + + literal-single-quoted-string-content: + - meta_include_prototype: false + - meta_scope: meta.string.js string.quoted.single.js + - match: \' + scope: punctuation.definition.string.end.js + pop: 1 + - match: \n + scope: invalid.illegal.newline.js + pop: 1 + - include: string-content + + literal-string-templates: + - match: (?=(?:(?:/\*\s*{{identifier_name}}\s*\*/|{{non_reserved_identifier}})\s*)?{{tagged_template_quote_begin}}) + push: literal-string-template-begin + + literal-string-template: + - match: (?=(?:(?:/\*\s*{{identifier_name}}\s*\*/|{{non_reserved_identifier}})\s*)?{{tagged_template_quote_begin}}) + set: literal-string-template-begin + + literal-string-template-begin: + - meta_include_prototype: false + # Notes: + # Consume trailing whitespace after opening punctuation + # and leading whitespace in front of closing punctuation + # to maintain JavaScript indentation rules until embedded + # code really begins/ends. It's required for embedded code + # to be indented using global JavaScript indentation rules. + - include: literal-string-template-css + - include: literal-string-template-html + - include: literal-string-template-js + - include: literal-string-template-json + - include: literal-string-template-sql + - include: literal-string-template-raw + - include: immediately-pop + + literal-string-template-css: + - match: (?i:((/\*)\s*css\s*(\*/))|(css))\s*(({{tagged_template_quote_begin}}){{trailing_wspace}}?) + captures: + 1: comment.block.js + 2: punctuation.definition.comment.begin.js + 3: punctuation.definition.comment.end.js + 4: variable.function.tagged-template.js + 5: meta.string.template.js string.quoted.other.js + 6: punctuation.definition.string.begin.js + embed: scope:source.css.js-template + embed_scope: meta.string.template.js source.css.embedded.js + escape: '{{leading_wspace}}?({{tagged_template_quote_escape}})' + escape_captures: + 0: meta.string.template.js string.quoted.other.js + 1: punctuation.definition.string.end.js + pop: 1 + + literal-string-template-html: + - match: (?i:((/\*)\s*html\s*(\*/))|(html))\s*(({{tagged_template_quote_begin}}){{trailing_wspace}}?) + captures: + 1: comment.block.js + 2: punctuation.definition.comment.begin.js + 3: punctuation.definition.comment.end.js + 4: variable.function.tagged-template.js + 5: meta.string.template.js string.quoted.other.js + 6: punctuation.definition.string.begin.js + embed: scope:text.html.js-template + embed_scope: meta.string.template.js text.html.embedded.js + escape: '{{leading_wspace}}?({{tagged_template_quote_escape}})' + escape_captures: + 0: meta.string.template.js string.quoted.other.js + 1: punctuation.definition.string.end.js + pop: 1 + + literal-string-template-js: + - match: (?i:((/\*)\s*js\s*(\*/))|(js))\s*(({{tagged_template_quote_begin}}){{trailing_wspace}}?) + captures: + 1: comment.block.js + 2: punctuation.definition.comment.begin.js + 3: punctuation.definition.comment.end.js + 4: variable.function.tagged-template.js + 5: meta.string.template.js string.quoted.other.js + 6: punctuation.definition.string.begin.js + embed: scope:source.js.js-template + embed_scope: meta.string.template.js source.js.embedded.js + escape: '{{leading_wspace}}?({{tagged_template_quote_escape}})' + escape_captures: + 0: meta.string.template.js string.quoted.other.js + 1: punctuation.definition.string.end.js + pop: 1 + + literal-string-template-json: + - match: (?i:((/\*)\s*json\s*(\*/))|(json))\s*(({{tagged_template_quote_begin}}){{trailing_wspace}}?) + captures: + 1: comment.block.js + 2: punctuation.definition.comment.begin.js + 3: punctuation.definition.comment.end.js + 4: variable.function.tagged-template.js + 5: meta.string.template.js string.quoted.other.js + 6: punctuation.definition.string.begin.js + embed: scope:source.json.js-template + embed_scope: meta.string.template.js source.json.embedded.js + escape: '{{leading_wspace}}?({{tagged_template_quote_escape}})' + escape_captures: + 0: meta.string.template.js string.quoted.other.js + 1: punctuation.definition.string.end.js + pop: 1 + + literal-string-template-sql: + - match: (?i:((/\*)\s*sql\s*(\*/))|(sql))\s*(({{tagged_template_quote_begin}}){{trailing_wspace}}?) + captures: + 1: comment.block.js + 2: punctuation.definition.comment.begin.js + 3: punctuation.definition.comment.end.js + 4: variable.function.tagged-template.js + 5: meta.string.template.js string.quoted.other.js + 6: punctuation.definition.string.begin.js + embed: scope:source.sql.js-template + embed_scope: meta.string.template.js source.sql.embedded.js + escape: '{{leading_wspace}}?({{tagged_template_quote_escape}})' + escape_captures: + 0: meta.string.template.js string.quoted.other.js + 1: punctuation.definition.string.end.js + pop: 1 + + literal-string-template-raw: + # Consume block comments as patterns of `block-comments` context don't match if followed by backtick. + - match: /\* + scope: punctuation.definition.comment.begin.js + push: block-comment-body + - match: (?:({{identifier_name}})\s*)?({{tagged_template_quote_begin}}) + captures: + 1: variable.function.tagged-template.js + 2: meta.string.template.js string.quoted.other.js punctuation.definition.string.begin.js + set: literal-string-template-content + + literal-string-template-content: + - meta_include_prototype: false + - meta_content_scope: meta.string.template.js string.quoted.other.js + - match: '{{tagged_template_quote_end}}' + scope: meta.string.template.js string.quoted.other.js punctuation.definition.string.end.js + pop: 1 + - include: string-interpolations + - include: string-content + + string-content: + - match: \\\n + scope: constant.character.escape.newline.js + - match: \\(?:x\h\h|u\h\h\h\h|.) + scope: constant.character.escape.js + + string-interpolations: + - match: \$\{ + scope: punctuation.section.interpolation.begin.js + push: string-interpolation-content + + string-interpolation-content: + - clear_scopes: 1 + - meta_scope: meta.interpolation.js + - meta_content_scope: source.js.embedded + - include: text-interpolation-content + + text-interpolations: + - match: \$\{ + scope: punctuation.section.interpolation.begin.js + push: text-interpolation-content + + text-interpolation-content: + - meta_scope: meta.interpolation.js + - meta_content_scope: source.js.embedded + - match: \} + scope: punctuation.section.interpolation.end.js + pop: 1 + - include: expressions + + regexp-complete: + - match: '/' + scope: punctuation.definition.string.begin.js + set: regexp + + regexp: + - meta_include_prototype: false + - meta_scope: meta.string.js string.regexp.js + - match: "/" + scope: punctuation.definition.string.end.js + set: + - meta_include_prototype: false + - meta_content_scope: meta.string.js string.regexp.js + - match: '[gimyus]' + scope: keyword.other.js + - match: '[A-Za-z0-9]' # Ignore unknown flags for future-compatibility + - include: immediately-pop + - match: '(?=.|\n)' + push: + - meta_include_prototype: false + - match: '(?=/)' + pop: 1 + - include: scope:source.regexp.js + + instantiation: + - match: new{{identifier_break}} + scope: keyword.operator.word.new.js + set: + - instantiation-meta + - instantiation-body + + instantiation-meta: + - meta_include_prototype: false + - meta_scope: meta.instantiation.js + - include: immediately-pop + + instantiation-body: + - match: \. + scope: punctuation.accessor.dot.js + set: instantiation-target + - match: (?=\S) + set: + - instantiation-expect-arguments + - instantiation-expect-class-end + - instantiation-expect-class-name + + instantiation-expect-arguments: + - meta_content_scope: meta.function-call.identifier.js + - include: function-call-arguments + - include: else-pop + + instantiation-expect-class-end: + - include: property-access + - include: else-pop + + instantiation-expect-class-name: + - match: (?={{non_reserved_identifier}}\s*\() + set: instantiation-class-name + - include: expression-begin + + instantiation-class-name: + - include: support + - match: '{{dollar_only_identifier}}' + scope: support.class.dollar.only.js punctuation.dollar.js + pop: 1 + - match: '{{dollar_identifier}}' + scope: support.class.dollar.js + captures: + 1: punctuation.dollar.js + pop: 1 + - match: '{{identifier_name}}' + scope: support.class.js + pop: 1 + - include: else-pop + + instantiation-target: + - match: target{{identifier_break}} + scope: variable.language.target.js + pop: 1 + - include: else-pop + + prefix-operators: + - match: '~' + scope: keyword.operator.bitwise.js + - match: '!(?!=)' + scope: keyword.operator.logical.js + - match: '--' + scope: keyword.operator.arithmetic.js + - match: '\+\+' + scope: keyword.operator.arithmetic.js + - match: \.\.\. + scope: keyword.operator.spread.js + - match: \+|\- + scope: keyword.operator.arithmetic.js + - match: (?:delete|typeof|void){{identifier_break}} + scope: keyword.operator.js + + binary-operators: + - match: instanceof{{identifier_break}} + scope: keyword.operator.js + push: expression-begin + - match: in{{identifier_break}} + scope: keyword.operator.js + push: expression-begin + - match: '=(?![=>])' + scope: keyword.operator.assignment.js + push: expression-begin + - match: |- + (?x) + %= | # assignment right-to-left both + &= | # assignment right-to-left both + \*= | # assignment right-to-left both + \+= | # assignment right-to-left both + -= | # assignment right-to-left both + /= | # assignment right-to-left both + \^= | # assignment right-to-left both + \|= | # assignment right-to-left both + <<= | # assignment right-to-left both + >>= | # assignment right-to-left both + >>>= | # assignment right-to-left both + &&= | + \|\|= | + \?\?= + scope: keyword.operator.assignment.augmented.js + push: expression-begin + - match: '&&|\|\|' + scope: keyword.operator.logical.js + push: expression-begin + - match: \?\? + scope: keyword.operator.null-coalescing.js + push: expression-begin + - match: |- + (?x) + << | # bitwise-shift left-to-right both + >>> | # bitwise-shift left-to-right both + >> | # bitwise-shift left-to-right both + & | # bitwise-and left-to-right both + \^ | # bitwise-xor left-to-right both + \| # bitwise-or left-to-right both + scope: keyword.operator.bitwise.js + push: expression-begin + - match: |- + (?x) + <= | # comparison left-to-right both + >= | # comparison left-to-right both + < | # comparison left-to-right both + > # comparison left-to-right both + scope: keyword.operator.comparison.js + push: expression-begin + - match: |- + (?x) + === | # equality left-to-right both + !== | # equality left-to-right both + == | # equality left-to-right both + != # equality left-to-right both + scope: keyword.operator.comparison.js + push: expression-begin + - match: |- + (?x) + / | # division left-to-right both + % | # modulus left-to-right both + \* | # multiplication left-to-right both + \+ | # addition left-to-right both + - # subtraction left-to-right both + scope: keyword.operator.arithmetic.js + push: expression-begin + - match: ',' + scope: keyword.operator.comma.js # Comma operator, not punctuation. + push: expression-begin + + ternary-operator: + - match: '\?(?=[^.]|\.[0-9])' + scope: keyword.operator.ternary.js + set: + - ternary-operator-expect-colon + - expression-no-comma + + ternary-operator-expect-colon: + - match: ':' + scope: keyword.operator.ternary.js + set: expression-no-comma + - include: else-pop + + postfix-operators: + - match: '--' + scope: keyword.operator.arithmetic.js + - match: '\+\+' + scope: keyword.operator.arithmetic.js + + yield-expression: + - match: yield{{identifier_break}} + scope: keyword.control.flow.yield.js + set: + - match: $ + pop: 1 + - match: \* + scope: storage.modifier.generator.js + set: expression-begin + - match: (?=\S) + set: expression-begin + + await-expression: + - match: await{{identifier_break}} + scope: keyword.control.flow.await.js + + class: + - match: class{{identifier_break}} + scope: keyword.declaration.class.js + set: + - class-meta + - class-body + - class-implements + - class-extends + - class-name + + class-meta: + - meta_include_prototype: false + - meta_scope: meta.class.js + - include: immediately-pop + + class-body: + - match: '\{' + scope: punctuation.section.block.begin.js + set: class-body-contents + + - include: else-pop + + class-body-contents: + - meta_scope: meta.block.js + + - match: '\}' + scope: punctuation.section.block.end.js + pop: 1 + + - match: \; + scope: punctuation.terminator.statement.empty.js + + - include: decorator + + - match: constructor{{identifier_break}} + scope: entity.name.function.constructor.js + push: + - function-meta + - function-declaration-expect-body + - function-declaration-expect-parameters + + - match: (?=static{{identifier_break}}) + branch_point: static-block + branch: + - static-block + - class-element + + - match: (?=\S) + push: class-element + + static-block: + - match: static{{identifier_break}} + scope: storage.modifier.js + set: + - include: block + - match: (?=\S) + fail: static-block + + class-extends: + - match: extends{{identifier_break}} + scope: storage.modifier.extends.js + set: + - inherited-class-expression-end + - inherited-class-expression-begin + - include: else-pop + + class-implements: + - match: implements{{identifier_break}} + scope: invalid.illegal.unexpected-token.js + pop: 1 + - include: else-pop + + inherited-class-name: + - match: '{{non_reserved_identifier}}{{left_expression_end_lookahead}}' + scope: entity.other.inherited-class.js + pop: 1 + + inherited-class-expression-end: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + push: + - include: inherited-class-name + - include: object-property + + - include: left-expression-end + + inherited-class-expression-begin: + - include: inherited-class-name + - include: expression-begin + + class-name: + - match: '{{non_reserved_identifier}}' + scope: entity.name.class.js + pop: 1 + - include: else-pop + + class-element: + - meta_include_prototype: false + - match: (?=\*) + set: method-declaration + - match: '' + pop: 1 + branch_point: class-field + branch: + - class-field + - method-declaration + + class-field: + - meta_include_prototype: false + - match: '' + set: + - expect-semicolon + - initializer + - class-field-check + - field-name + - class-element-modifiers + + class-field-check: + - match: (?=\() + fail: class-field + - include: else-pop + + class-element-modifiers: + - match: (?={{modifier}}) + branch_point: class-element-modifier + branch: + - - match: '{{modifier}}' + scope: storage.modifier.js + set: + - match: (?={{class_element_name}}|\*) + pop: 1 + - match: (?=\S) + fail: class-element-modifier + + - immediately-pop-2 + - include: else-pop + + special-name: + - match: true{{identifier_break}} + scope: constant.language.boolean.true.js + pop: 1 + - match: false{{identifier_break}} + scope: constant.language.boolean.false.js + pop: 1 + - match: null{{identifier_break}} + scope: constant.language.null.js + pop: 1 + - match: super{{identifier_break}} + scope: variable.language.super.js + pop: 1 + - match: this{{identifier_break}} + scope: variable.language.this.js + pop: 1 + + function-name-meta: + - meta_include_prototype: false + - meta_scope: entity.name.function.js + - include: immediately-pop + + regular-function: + - match: (?={{func_lookahead}}) + set: function-declaration + + function-declaration: + - meta_include_prototype: false + - match: '' + set: + - function-meta + - function-declaration-expect-body + - function-declaration-expect-parameters + - function-declaration-expect-name + - function-declaration-expect-generator-star + - function-declaration-expect-function-keyword + - function-declaration-expect-async + + function-declaration-expect-body: + - include: function-block + - include: else-pop + + function-meta: + - meta_include_prototype: false + - meta_scope: meta.function.js + - include: immediately-pop + + function-declaration-expect-parameters: + - include: function-declaration-parameters + - include: else-pop + + function-declaration-expect-name: + - match: '{{non_reserved_identifier}}' + scope: entity.name.function.js + pop: 1 + - include: else-pop + + function-declaration-expect-generator-star: + - match: \* + scope: storage.modifier.generator.js + pop: 1 + - include: else-pop + + function-declaration-expect-function-keyword: + - match: function{{identifier_break}} + scope: keyword.declaration.function.js + pop: 1 + - include: else-pop + + function-declaration-expect-async: + - match: 'async{{identifier_break}}' + scope: keyword.declaration.async.js + pop: 1 + - include: else-pop + + arrow-function-declaration: + - meta_include_prototype: false + - match: '' + set: + - function-meta + - arrow-function-expect-body + - arrow-function-expect-arrow + - arrow-function-expect-parameters + + arrow-function-expect-body: + - include: function-block + - match: (?=\S) + set: + - block-meta + - expression-no-comma + + arrow-function-expect-arrow: + - match: '=>' + scope: keyword.declaration.function.arrow.js + pop: 1 + - include: else-pop + + arrow-function-expect-parameters: + - match: (?={{identifier_start}}) + set: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.js + - match: '{{identifier_name}}' + scope: variable.parameter.function.js + pop: 1 + - include: function-declaration-parameters + - include: else-pop + + function-block: + - match: '\{' + scope: punctuation.section.block.begin.js + set: + - meta_scope: meta.block.js + - match: '\}' + scope: punctuation.section.block.end.js + pop: 1 + - include: statements + + function-declaration-parameters: + - match: \( + scope: punctuation.section.group.begin.js + set: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.js + - match: \) + scope: punctuation.section.group.end.js + pop: 1 + - include: function-parameter-binding-list + + label: + - match: '({{identifier_name}})\s*(:)' + captures: + 1: entity.name.label.js + 2: punctuation.separator.js + + object-literal: + - match: '\{' + scope: punctuation.section.mapping.begin.js + set: object-literal-contents + + object-literal-contents: + - meta_scope: meta.mapping.js + + - match: '\}' + scope: punctuation.section.mapping.end.js + pop: 1 + + - match: \.\.\. + scope: keyword.operator.spread.js + push: expression-no-comma + + - match: >- + (?x)(?= + {{property_name}}\s*:\s* + {{either_func_lookahead}} + ) + push: + - object-literal-meta-key + - method-name + + - match: (?=\*) + push: method-declaration + + - match: (?={{property_name}}) + push: object-literal-element + + - include: comma-separator + + - match: ':' + scope: punctuation.separator.key-value.js + push: expression-no-comma + + # If there's any garbage, parse it as an expression + # so that close braces won't break things. + - match: (?=\S) + push: expression-no-comma + + object-literal-element: + - match: '{{identifier_name}}(?=\s*(?:[},]|$|//|/\*))' + scope: variable.other.readwrite.js + pop: 1 + - match: (?=\S) + pop: 1 + branch_point: object-literal-property + branch: + - object-literal-property + - method-declaration + + object-literal-property: + - match: '' + set: + - object-literal-property-check + - object-literal-meta-key + - object-property-name + + object-property-name: + - include: computed-property-name + - include: literal-string + - include: literal-number + + - match: (?:get|set|async){{identifier_break}} + pop: 2 + set: + - match: (?=\*|{{class_element_name}}) + fail: object-literal-property + - include: else-pop + + - match: '{{identifier_name}}' + pop: 1 + + - include: else-pop + + object-literal-property-check: + - match: (?=\() + fail: object-literal-property + - include: else-pop + + computed-property-name: + - match: \[ + scope: punctuation.section.brackets.begin.js + set: + - meta_scope: meta.brackets.js + - match: \] + scope: punctuation.section.brackets.end.js + pop: 1 + - match: (?=\S) + push: expression + + object-literal-meta-key: + - meta_include_prototype: false + - meta_scope: meta.mapping.key.js + - include: else-pop + + method-name: + - match: '{{dollar_identifier}}' + scope: meta.mapping.key.dollar.js entity.name.function.js + captures: + 1: punctuation.dollar.js + pop: 1 + - match: '{{identifier_name}}' + scope: entity.name.function.js + pop: 1 + - match: '(#){{identifier_name}}' + scope: entity.name.function.js + captures: + 1: punctuation.definition.js + pop: 1 + - match: "'" + scope: punctuation.definition.string.begin.js + set: + - meta_include_prototype: false + - meta_scope: meta.string.js string.quoted.single.js + - meta_content_scope: entity.name.function.js + - match: \' + scope: punctuation.definition.string.end.js + pop: 1 + - match: \n + scope: invalid.illegal.newline.js + pop: 1 + - include: string-content + - match: '"' + scope: punctuation.definition.string.begin.js + set: + - meta_include_prototype: false + - meta_scope: meta.string.js string.quoted.double.js + - meta_content_scope: entity.name.function.js + - match: \" + scope: punctuation.definition.string.end.js + pop: 1 + - match: \n + scope: invalid.illegal.newline.js + pop: 1 + - include: string-content + + - include: computed-property-name + + - include: else-pop + + field-name: + - match: |- + (?x)(?= + \#? {{identifier_name}} + {{nothing}} = + {{nothing}} {{either_func_lookahead}} + ) + set: + - function-name-meta + - literal-variable-base + + - match: (?:get|set|async){{identifier_break}} + scope: variable.other.readwrite.js + set: + - match: (?=\*|{{class_element_name}}) + fail: class-field + - include: else-pop + - include: literal-variable-base + + - match: "'" + scope: punctuation.definition.string.begin.js + set: + - meta_include_prototype: false + - meta_scope: meta.string.js string.quoted.single.js + - meta_content_scope: variable.other.readwrite.js + - match: \' + scope: punctuation.definition.string.end.js + pop: 1 + - match: \n + scope: invalid.illegal.newline.js + pop: 1 + - include: string-content + - match: '"' + scope: punctuation.definition.string.begin.js + set: + - meta_include_prototype: false + - meta_scope: meta.string.js string.quoted.double.js + - meta_content_scope: variable.other.readwrite.js + - match: \" + scope: punctuation.definition.string.end.js + pop: 1 + - match: \n + scope: invalid.illegal.newline.js + pop: 1 + - include: string-content + + - include: computed-property-name + + - include: else-pop + + method-declaration: + - meta_include_prototype: false + - match: '' + set: + - function-meta + - function-declaration-expect-body + - function-declaration-expect-parameters + - method-name + - method-declaration-expect-asterisk + - method-declaration-prefix + - class-element-modifiers + + method-declaration-expect-asterisk: + - match: \* + scope: keyword.generator.asterisk.js + - include: else-pop + + method-declaration-prefix: + - match: (?=(?:get|set|async){{identifier_break}}) + pop: 1 + branch_point: method-declaration-prefix + branch: + - - match: (?:get|set){{identifier_break}} + scope: storage.type.accessor.js + set: method-declaration-prefix-check + - match: (?:async){{identifier_break}} + scope: keyword.declaration.async.js + set: method-declaration-prefix-check + - immediately-pop + - include: else-pop + + method-declaration-prefix-check: + - match: (?=\*|{{class_element_name}}) + pop: 1 + - match: (?=\S) + fail: method-declaration-prefix + + parenthesized-expression: + - match: \( + scope: punctuation.section.group.begin.js + set: parenthesized-expression-body + + parenthesized-expression-body: + - meta_scope: meta.group.js + - match: \) + scope: punctuation.section.group.end.js + pop: 1 + - include: expressions + + function-call-arguments: + - meta_content_scope: meta.function-call.js + - match: '\?\.' + scope: punctuation.accessor.js + - match: \( + scope: punctuation.section.group.begin.js + set: + - meta_scope: meta.function-call.arguments.js meta.group.js + - match: \) + scope: punctuation.section.group.end.js + pop: 1 + - include: expression-list + + array-literal: + - match: '\[' + scope: punctuation.section.sequence.begin.js + set: + - meta_scope: meta.sequence.js + - match: '\]' + scope: punctuation.section.sequence.end.js + pop: 1 + - include: expression-list + + property-access: + - match: (\?\.)?(\[) + captures: + 1: punctuation.accessor.js + 2: punctuation.section.brackets.begin.js + push: + - meta_scope: meta.brackets.js + - match: '\]' + scope: punctuation.section.brackets.end.js + pop: 1 + - match: (?=\S) + push: expression + + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + push: object-property + + literal-number: + # floats + - match: |- + (?x: + # 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1 | 1e1, 1e-1 + {{dec_integer}} (?: (\.) {{dec_digit}}* (?:{{dec_exponent}})? | {{dec_exponent}} ) + # .1, .1e1, .1e-1 + | (\.) {{dec_digit}}+ (?:{{dec_exponent}})? + ){{identifier_break}} + scope: meta.number.float.decimal.js constant.numeric.value.js + captures: + 1: punctuation.separator.decimal.js + 2: punctuation.separator.decimal.js + pop: 1 + + # integers + - match: (0)({{dec_digit}}+){{identifier_break}} + scope: meta.number.integer.octal.js + captures: + 1: constant.numeric.base.js invalid.deprecated.numeric.octal.js + 2: constant.numeric.value.js invalid.deprecated.numeric.octal.js + pop: 1 + + - match: (0[Xx])({{hex_digit}}*)(n)?{{identifier_break}} + scope: meta.number.integer.hexadecimal.js + captures: + 1: constant.numeric.base.js + 2: constant.numeric.value.js + 3: constant.numeric.suffix.js + pop: 1 + + - match: (0[Oo])({{oct_digit}}*)(n)?{{identifier_break}} + scope: meta.number.integer.octal.js + captures: + 1: constant.numeric.base.js + 2: constant.numeric.value.js + 3: constant.numeric.suffix.js + pop: 1 + + - match: (0[Bb])({{bin_digit}}*)(n)?{{identifier_break}} + scope: meta.number.integer.binary.js + captures: + 1: constant.numeric.base.js + 2: constant.numeric.value.js + 3: constant.numeric.suffix.js + pop: 1 + + - match: ({{dec_integer}})(n|(?!\.)){{identifier_break}} + scope: meta.number.integer.decimal.js + captures: + 1: constant.numeric.value.js + 2: constant.numeric.suffix.js + pop: 1 + + # illegal numbers + - match: 0[Xx]{{identifier_part}}+ + scope: invalid.illegal.numeric.hexadecimal.js + pop: 1 + + - match: 0[Bb]{{identifier_part}}+ + scope: invalid.illegal.numeric.binary.js + pop: 1 + + - match: 0{{identifier_part}}+ + scope: invalid.illegal.numeric.octal.js + pop: 1 + + - match: '[1-9]{{identifier_part}}+(?:\.{{identifier_part}}*)?' + scope: invalid.illegal.numeric.decimal.js + pop: 1 + + literal-variable: + - include: special-identifier + - include: support + + - match: '(?={{identifier_name}}{{function_assignment_lookahead}})' + set: + - function-name-meta + - literal-variable-base + + - include: literal-string-template + + - match: '{{constant_identifier}}(?=\s*(?:{{dot_accessor}}|\[))' + scope: support.class.js + pop: 1 + + # If we don't capture the trailing space here, + # it'll get eaten by the arrow function detection. + - match: '({{dollar_only_identifier}}){{nothing}}{{function_call_after_lookahead}}' + scope: meta.function-call.js + captures: + 1: variable.function.js variable.other.dollar.only.js punctuation.dollar.js + pop: 1 + - match: '({{identifier_name}}){{nothing}}{{function_call_after_lookahead}}' + scope: meta.function-call.js + captures: + 1: variable.function.js + pop: 1 + + - include: literal-variable-base + + literal-variable-base: + - match: '{{dollar_only_identifier}}' + scope: variable.other.dollar.only.js punctuation.dollar.js + pop: 1 + - match: '{{dollar_identifier}}' + scope: variable.other.dollar.js + captures: + 1: punctuation.dollar.js + pop: 1 + - match: '{{constant_identifier}}' + scope: variable.other.constant.js + pop: 1 + - match: '{{identifier_name}}' + scope: variable.other.readwrite.js + pop: 1 + - include: literal-private-variable + + literal-private-variable: + - match: (#)({{identifier_name}}) + captures: + 1: punctuation.definition.variable.js + 2: variable.other.readwrite.js + pop: 1 + + special-identifier: + # These are ordinary identifiers, not reserved words + - match: arguments{{identifier_break}} + scope: variable.language.arguments.js + pop: 1 + - match: globalThis{{identifier_break}} + scope: variable.language.global.js + pop: 1 + - match: undefined{{identifier_break}} + scope: constant.language.undefined.js + pop: 1 + - match: NaN{{identifier_break}} + scope: constant.language.nan.js + pop: 1 + - match: Infinity{{identifier_break}} + scope: constant.language.infinity.js + pop: 1 + + support: + - include: support-variable-ecma + - include: support-variable-console + - include: support-variable-dom + - include: support-variable-node + + support-variable-ecma: + - match: Array{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-array + - include: object-property + - include: else-pop + - include: else-pop + + - match: ArrayBuffer{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-arraybuffer + - include: object-property + - include: else-pop + - include: else-pop + + - match: Atomics{{identifier_break}} + scope: support.constant.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-atomics + - include: object-property + - include: else-pop + - include: else-pop + + - match: BigInt{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-bigint + - include: object-property + - include: else-pop + - include: else-pop + + - match: Date{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-date + - include: object-property + - include: else-pop + - include: else-pop + + - match: JSON{{identifier_break}} + scope: support.constant.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-json + - include: object-property + - include: else-pop + - include: else-pop + + - match: Math{{identifier_break}} + scope: support.constant.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-math + - include: object-property + - include: else-pop + - include: else-pop + + - match: Number{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-number + - include: object-property + - include: else-pop + - include: else-pop + + - match: Object{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-object + - include: object-property + - include: else-pop + - include: else-pop + + - match: Promise{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-promise + - include: object-property + - include: else-pop + - include: else-pop + + - match: Proxy{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-proxy + - include: object-property + - include: else-pop + - include: else-pop + + - match: Reflect{{identifier_break}} + scope: support.constant.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-reflect + - include: object-property + - include: else-pop + - include: else-pop + + - match: String{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-string + - include: object-property + - include: else-pop + - include: else-pop + + - match: Symbol{{identifier_break}} + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-symbol + - include: object-property + - include: else-pop + - include: else-pop + + - match: |- + (?x: + (?: + BigInt64| + BigUint64| + Float(?:32|64)| + Int(?:8|16|32)| + Uint(?:8|16|32|32Clamped) + ) + Array{{identifier_break}} + ) + scope: support.class.builtin.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-ecma-typedarray + - include: object-property + - include: else-pop + - include: else-pop + + # Classes with no constructor properties + - match: (?:Boolean|DataView|Function|Map|RegExp|Set|WeakMap|WeakSet){{identifier_break}} + scope: support.class.builtin.js + pop: 1 + - match: (?:Eval|Range|Reference|Syntax|Type|URI)?Error{{identifier_break}} + scope: support.class.builtin.js + pop: 1 + + - match: (?:eval|isFinite|isNaN|parseFloat|parseInt|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent){{identifier_break}} + scope: meta.function-call.js support.function.js + pop: 1 + + support-property-ecma-array: + - match: (?:from|isArray|of){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-arraybuffer: + - match: isView{{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-atomics: + - match: (?:and|add|compareExchange|exchange|isLockFree|load|or|store|sub|wait|wake|xor){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-bigint: + - match: (?:asUintN|asIntN){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-date: + - match: (?:now|parse|UTC){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-json: + - match: (?:parse|stringify){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-math: + - match: (?:E|LN10|LN2|LOG10E|LOG2E|PI|SQRT1_2|SQRT2){{identifier_break}} + scope: support.constant.builtin.js + pop: 1 + - match: (?:abs|acos|acosh|asin|asin|atan|atanh|atan2|cbrt|ceil|clz32|cos|cosh|exp|expm1|floor|fround|hypot|imul|log|log1p|log10|log2|max|min|pow|random|round|sign|sin|sinh|sqrt|tan|tanh|trunc){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-number: + - match: (?:EPSILON|MAX_SAFE_INTEGER|MAX_VALUE|MIN_SAFE_INTEGER|MIN_VALUE|NEGATIVE_INFINITY|POSITIVE_INFINITY){{identifier_break}} + scope: support.constant.builtin.js + pop: 1 + - match: (?:isFinite|isInteger|isNaN|isSafeInteger|NaN|parseFloat|parseInt){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-object: + - match: (?:assign|create|defineProperties|defineProperty|entries|freeze|fromEntries|getOwnPropertyDescriptors?|getOwnPropertyNames|getOwnPropertySymbols|getPrototypeOf|is|isExtensible|isFrozen|isSealed|keys|preventExtensions|seal|setPrototypeOf|values){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-promise: + - match: (?:all|race|reject|resolve|allSettled|any){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-proxy: + - match: revocable{{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-reflect: + - match: (?:apply|construct|defineProperty|deleteProperty|get|getOwnPropertyDescriptor|getPrototypeOf|has|isExtensible|ownKeys|preventExtensions|set|setPrototypeOf){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-string: + - match: (?:fromCharCode|fromCodePoint|raw){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-symbol: + - match: (?:asyncDispose|asyncIterator|dispose|hasInstance|isConcatSpreadable|iterator|match|replace|search|species|split|toPrimitive|toStringTag|unscopeables){{identifier_break}} + scope: support.constant.builtin.js + pop: 1 + - match: (?:for|keyFor){{identifier_break}} + scope: meta.function-call.js support.function.builtin.js + pop: 1 + + support-property-ecma-typedarray: + - match: (?:BYTES_PER_ELEMENT){{identifier_break}} + scope: support.constant.builtin.js + pop: 1 + + support-variable-console: + # https://console.spec.whatwg.org/ + - match: console{{identifier_break}} + scope: support.type.object.console.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: builtin-console-properties + - include: else-pop + + support-variable-dom: + - match: XMLHttpRequest{{identifier_break}} + scope: support.class.dom.js + pop: 1 + - match: (?:document|window|navigator){{identifier_break}} + scope: support.type.object.dom.js + pop: 1 + - match: (?:clearTimeout|clearInterval|setTimeout|setInterval){{identifier_break}} + scope: meta.function-call.js support.function.dom.js + pop: 1 + + support-variable-node: + - match: global{{identifier_break}} + scope: support.type.object.node.js + pop: 1 + + - match: Buffer{{identifier_break}} + scope: support.class.node.js + pop: 1 + + - match: process{{identifier_break}} + scope: support.constant.node.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-node-process + - include: object-property + - include: else-pop + - include: else-pop + + # Module-level variables + - match: (?:__dirname|__filename|exports){{identifier_break}} + scope: support.constant.node.js + pop: 1 + - match: module{{identifier_break}} + scope: support.constant.node.js + set: + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - include: support-property-node-module + - include: object-property + - include: else-pop + - include: else-pop + - match: require{{identifier_break}} + scope: meta.function-call.js support.function.node.js + pop: 1 + + support-property-node-process: + - match: (?:arch|argv|argv0|channel|config|connected|debugPort|env|execArgv|execPath|exitCode|mainModule|noDeprecation|pid|platform|ppid|release|stderr|stdin|stdout|throwDeprecation|title|traceDeprecation|version|versions){{identifier_break}} + scope: support.constant.node.js + pop: 1 + - match: (?:abort|chdir|cpuUsage|cwd|disconnect|dlopen|emitWarning|exit|getegid|geteuid|getgit|getgroups|getuid|hasUncaughtExceptionCaptureCallback|hrtime|initGroups|kill|memoryUsage|nextTick|send|setegid|seteuid|setgid|setgroups|setuid|hasUncaughtExceptionCaptureCallback|umask|uptime){{identifier_break}} + scope: meta.function-call.js support.function.node.js + pop: 1 + + support-property-node-module: + - match: (?:children|exports|filename|id|loaded|parent|paths){{identifier_break}} + scope: support.constant.node.js + pop: 1 + - match: require{{identifier_break}} + scope: meta.function-call.js support.function.node.js + pop: 1 + + builtin-console-properties: + - match: (?:warn|info|log|error|time|timeEnd|assert|count|dir|group|groupCollapsed|groupEnd|profile|profileEnd|table|trace|timeStamp){{identifier_break}} + scope: meta.function-call.js support.function.console.js + pop: 1 + - include: object-property + + object-property: + - include: support-property + + - match: (?=\#?{{identifier_name}}{{function_assignment_lookahead}}) + set: + - function-name-meta + - object-property-base + + - match: '(?=#?{{identifier_name}}{{function_call_after_lookahead}})' + set: call-method-name + + - include: literal-string-template + + - include: object-property-base + - include: else-pop + + call-method-name: + - include: support-property + - match: '(#)?{{identifier_name}}' + scope: meta.function-call.js variable.function.js + captures: + 1: punctuation.definition.js + pop: 1 + - include: else-pop + + object-property-base: + - match: '{{dollar_only_identifier}}' + scope: meta.property.object.dollar.only.js punctuation.dollar.js + pop: 1 + - match: '{{dollar_identifier}}' + scope: meta.property.object.dollar.js + captures: + 1: punctuation.dollar.js + pop: 1 + - match: '{{identifier_name}}' + scope: meta.property.object.js + pop: 1 + - match: '{{identifier_part}}+{{identifier_break}}' + scope: invalid.illegal.illegal-identifier.js + pop: 1 + - match: (#)({{identifier_name}}) + captures: + 1: punctuation.definition.variable.js + 2: meta.property.object.js + pop: 1 + + support-property: + - include: support-property-ecma + + support-property-ecma: + - match: constructor{{identifier_break}} + scope: variable.language.constructor.js + pop: 1 + - match: prototype{{identifier_break}} + scope: support.constant.prototype.js + pop: 1 + + - match: (?:hasOwnProperty|isPrototypeOf|propertyIsEnumerable|toLocaleString|toString|valueOf){{identifier_break}} + scope: meta.function-call.js support.function.js + pop: 1 + + # Annex B + - match: __proto__{{identifier_break}} + scope: invalid.deprecated.js variable.language.prototype.js + pop: 1 + - match: (?:__defineGetter__|__defineSetter__|__lookupGetter__){{identifier_break}} + scope: invalid.deprecated.js meta.function-call.js support.function.js + pop: 1 + + import-meta-expression: + - match: import{{identifier_break}} + scope: keyword.control.import.js + set: import-expression-end + + import-expression-end: + - match: (?=\() + set: function-call-arguments + - match: '{{dot_accessor}}' + scope: punctuation.accessor.js + set: + - match: meta{{identifier_break}} + scope: variable.language.import.js + pop: 1 + - include: object-property + - include: else-pop
diff --git /dev/null b/syntax/LICENSE @@ -0,0 +1,8 @@ +If not otherwise specified (see below), files in this repository fall under the following license: + + Permission to copy, use, modify, sell and distribute this + software is granted. This software is provided "as is" without + express or implied warranty, and with no claim as to its + suitability for any purpose. + +An exception is made for files in readable text which contain their own license information, or files where an accompanying file exists (in the same directory) with a β-licenseβ suffix added to the base-name name of the original file, and an extension of txt, html, or similar. For example βtidyβ is accompanied by βtidy-license.txtβ.
diff --git /dev/null b/syntax/LaTeX/LaTeX.sublime-syntax @@ -0,0 +1,1375 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/syntax.html +name: LaTeX +scope: text.tex +version: 2 + +file_extensions: + - tex + +contexts: + + prototype: + - include: comments + + main: + - include: expressions + - include: includes + - include: preamble + - include: sections + - include: pkg-array + - include: pkg-beamer-envs + - include: pkg-minted-envs + + expressions: + # NOTE: within braces, it is possible that only part of some nested + # structure is present. Don't include any context's here that break if + # they are only partially matched. + - include: block-math + - include: inline-math + - include: braces + - include: macro-variables + - include: math-builtins + - include: controls + - include: boxes + - include: macros + - include: registers + - include: character-codes + - include: tex-constants + - include: general-constants + - include: general-commands + - include: structure + - include: pkg-minted-cmds + +###[ COMMENTS ]################################################################ + + comments: + - match: \% + scope: punctuation.definition.comment.tex + push: comment-body + - include: merge-conflict-markers + + comment-body: + - meta_scope: comment.line.percentage.tex + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ BLOCKS ]################################################################## + + braces: + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: brace-group-body + + brace-group-begin: + - meta_include_prototype: false + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + pop: 1 + + brace-group-body: + - meta_scope: meta.group.brace.tex + - include: brace-group-end + - include: expressions + + brace-group-end: + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: 1 + +###[ BOXES ]################################################################### + + boxes: + - match: ((\\)[hv]box)\s*(\{) + captures: + 1: support.function.box.tex + 2: punctuation.definition.backslash.tex + 3: punctuation.definition.group.brace.begin.tex + push: box-body + + box-body: + - meta_scope: meta.function.box.tex + - include: brace-group-body + +###[ CHARACTER CODES ]######################################################### + + character-codes: + - match: (\\)(?:cat|math|uc|lc|del|sf)code{{endcs}} + scope: keyword.control.character-code.tex + captures: + 1: punctuation.definition.backslash.tex + push: + - character-code-value + - tex-assignment + - character-code-number + + character-code-number: + - include: tex-simple-integer + - include: else-pop + - include: paragraph-pop + + character-code-value: + - meta_scope: meta.function.character-code.tex + - include: tex-simple-integer + - include: else-pop + - include: paragraph-pop + +###[ CONTROLS ]################################################################ + + controls: + - match: (\\)ifcase{{endcs}} + scope: keyword.control.conditional.switch.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)or{{endcs}} + scope: keyword.control.conditional.case.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)loop{{endcs}} + scope: keyword.control.loop.do-while.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)repeat{{endcs}} + scope: keyword.control.loop.end.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)expandafter{{endcs}} + scope: keyword.control.flow.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)if(?:cat|dim|eof|false|hbox|hmode|inner|mmode|num|odd|true|undefined|vbox|vmode|void|x)?{{endcs}} + scope: keyword.control.conditional.if.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)else{{endcs}} + scope: keyword.control.conditional.else.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)fi{{endcs}} + scope: keyword.control.conditional.end.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)input{{endcs}} + scope: meta.function.input.tex keyword.control.input.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)relax{{endcs}} + scope: keyword.control.flow.relax.tex + captures: + 1: punctuation.definition.backslash.tex + +###[ COMMANDS ]################################################################ + + general-commands: + - match: (\\){{macroname}} + scope: support.function.internal.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{letter}}+ + scope: support.function.general.tex + captures: + 1: punctuation.definition.backslash.tex + +###[ CONSTANTS ]############################################################### + + general-constants: + - match: \\\\ + scope: constant.character.newline.tex + - match: '&' + scope: constant.character.ampersand.tex + - match: '~' + scope: constant.character.space.tex + - include: escaped-character + + escaped-character: + - match: (\\)(?!{{macroname}}){{nonletter}} + scope: constant.character.escape.tex + captures: + 1: punctuation.definition.backslash.tex + + tex-constants: + - match: (\\){{constants}}{{endcs}} + scope: support.function.tex + captures: + 1: punctuation.definition.backslash.tex + push: + - tex-dimension-value + - tex-assignment + - match: (\\){{macroconst}}{{endcs}} + scope: support.function.tex + captures: + 1: punctuation.definition.backslash.tex + +###[ REGISTERS ]############################################################### + + registers: + - match: (\\)new{{registers}}{{endcs}} + scope: keyword.declaration.register.tex + captures: + 1: punctuation.definition.backslash.tex + push: register-allocation-identifier + - match: (\\){{registers}}{{endcs}} + scope: storage.type.register.tex + captures: + 1: punctuation.definition.backslash.tex + push: + - tex-dimension-value + - tex-assignment + - register-definition-identifier + + register-allocation-identifier: + - meta_scope: meta.register.tex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: register-allocation-wrapped-identifier + - match: (\\){{cmdname}} + scope: entity.name.constant.tex + captures: + 1: punctuation.definition.backslash.tex + pop: 1 + - include: else-pop + + register-allocation-wrapped-identifier: + - meta_scope: meta.group.brace.tex + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: 2 + - match: (\\){{cmdname}} + scope: entity.name.constant.tex + captures: + 1: punctuation.definition.backslash.tex + + register-definition-identifier: + - meta_scope: meta.register.tex + - match: (\\){{cmdname}} + scope: support.function.general.tex + captures: + 1: punctuation.definition.backslash.tex + pop: 1 + - include: tex-simple-integer + - include: else-pop + +###[ NUMBERS ]################################################################# + + # These match integers/floats that are written in a simple form, i.e. not extending + # across lines + # we are also not handling the case where there are multiple signs + + tex-simple-integer: + - match: ([+-]?)\s*\d+ + scope: meta.number.integer.decimal.tex constant.numeric.value.tex + captures: + 1: keyword.operator.arithmetic.tex + pop: 1 + - match: ([+-]?)\s*"{{uchexdigit}}+ + scope: meta.number.integer.hexadecimal.tex constant.numeric.value.tex + captures: + 1: keyword.operator.arithmetic.tex + pop: 1 + - match: ([+-]?)\s*'[0-7]+ + scope: meta.number.integer.octal.tex constant.numeric.value.tex + captures: + 1: keyword.operator.arithmetic.tex + pop: 1 + - match: ([+-]?)\s*(`)(\\)?({{charbycode}}|.) + scope: meta.number.integer.tex constant.numeric.value.tex + captures: + 1: keyword.operator.arithmetic.tex + 2: keyword.operator.tex + 3: punctuation.definition.backslash.tex + 4: constant.character.tex + pop: 1 + +###[ DIMENSIONS ]############################################################## + + tex-assignment: + - match: = + scope: keyword.operator.assignment.tex + pop: 1 + - include: else-pop + - include: paragraph-pop + + tex-dimension-value: + - match: (-?)(?:\d+(\.)\d*|(\.)\d+) + scope: constant.numeric.value.tex + captures: + 1: keyword.operator.arithmetic.tex + 2: punctuation.separator.decimal.tex + 3: punctuation.separator.decimal.tex + set: + - tex-dimension-glue + - tex-dimension-decimal-float + - match: (-?)\d+ + scope: constant.numeric.value.tex + captures: + 1: keyword.operator.arithmetic.tex + set: + - tex-dimension-glue + - tex-dimension-decimal-integer + - match: (`)(\\)?({{charbycode}}|.) + captures: + 1: keyword.operator.tex + 2: punctuation.definition.backslash.tex + 3: constant.character.tex + set: + - tex-dimension-glue + - tex-dimension-decimal-integer + - include: else-pop + - include: paragraph-pop + + tex-dimension-glue: + - match: (?:plus|minus){{endcs}} + scope: keyword.operator.arithmetic.tex + set: tex-dimension-value + - include: else-pop + - include: paragraph-pop + + tex-dimension-decimal-float: + - meta_scope: meta.number.float.decimal.tex + - include: tex-dimension-suffix + + tex-dimension-decimal-integer: + - meta_scope: meta.number.integer.decimal.tex + - include: tex-dimension-suffix + + tex-dimension-suffix: + - match: '{{dimunits}}' + scope: constant.numeric.suffix.tex + pop: 1 + - include: else-pop + - include: paragraph-pop + +###[ MACROS ]################################################################## + + macros: + - match: (\\)[gex]?def{{endcs}} + scope: meta.function.tex keyword.declaration.function.tex + captures: + 1: punctuation.definition.backslash.tex + push: macro-identifier + - match: (\\)(?:outer|long|global){{endcs}} + scope: storage.modifier.definition.tex + captures: + 1: punctuation.definition.backslash.tex + + macro-identifier: + - meta_content_scope: meta.function.tex + - match: (\\){{macroname}} + scope: meta.function.identifier.tex entity.name.function.internal.tex + captures: + 1: punctuation.definition.backslash.tex + set: macro-parameter-list + - match: (\\){{cmdname}} + scope: meta.function.identifier.tex entity.name.function.tex + captures: + 1: punctuation.definition.backslash.tex + set: macro-parameter-list + - match: (?=[#\[\{]) + set: macro-parameter-list + - include: else-pop + + macro-parameter-list: + - meta_content_scope: meta.function.parameters.tex + - include: macro-replacement + - include: macro-parameter-content + - include: stray-brace-pop + - include: stray-bracket-pop + + macro-parameter-content: + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: macro-parameter-brace-body + - match: \[ + scope: punctuation.definition.group.bracket.begin.tex + push: macro-parameter-bracket-body + - include: macro-parameters + - include: general-constants + + macro-parameter-brace-body: + - meta_scope: meta.group.brace.tex + - include: brace-group-end + - include: macro-parameter-content + - include: stray-bracket-pop + + macro-parameter-bracket-body: + - meta_scope: meta.group.bracket.tex + - match: \] + scope: punctuation.definition.group.bracket.end.tex + pop: 1 + - include: macro-parameter-content + - include: stray-brace-pop + + macro-replacement: + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + set: macro-replacement-body + + macro-replacement-body: + - meta_scope: meta.function.body.tex meta.group.brace.tex + - include: brace-group-body + + macro-parameters: + # parameter declarations in macro signatures + - match: (\#+)[0-9] + scope: variable.parameter.tex + captures: + 1: punctuation.definition.variable.tex + + macro-variables: + # parameter references in macro code + - match: (\#+)[0-9] + scope: variable.other.readwrite.tex + captures: + 1: punctuation.definition.variable.tex + +###[ MATH ]#################################################################### + + block-math: + - match: \$\$ + scope: string.other.math.tex punctuation.definition.string.begin.tex + push: block-math-dollar-body + + block-math-dollar-body: + - meta_scope: meta.environment.math.block.dollar.tex + - meta_content_scope: markup.math.block + - include: block-math-dollar-end + - include: math-content + + block-math-dollar-end: + - match: \$\$ + scope: string.other.math.tex punctuation.definition.string.end.tex + pop: 1 + + inline-math: + - match: \$ + scope: string.other.math.tex punctuation.definition.string.begin.tex + push: inline-math-dollar-body + + inline-math-dollar-body: + - meta_scope: meta.environment.math.inline.dollar.tex + - meta_content_scope: markup.math.inline + - include: inline-math-dollar-end + - include: math-content + + inline-math-dollar-end: + - match: \$ + scope: string.other.math.tex punctuation.definition.string.end.tex + pop: 1 + + math-content: + - include: math-builtins + - include: math-brackets + - include: math-braces + - include: math-commands + - include: math-operators + - include: math-variables + - include: math-numbers + - include: macro-variables + - include: boxes + - include: general-constants + - include: stray-brace-pop + + math-builtins: + - match: (\\){{greeks}}{{endcs}} + scope: keyword.other.math.greek.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{mathfun}}{{endcs}} + scope: keyword.other.math.function.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{relations}}{{endcs}} + scope: keyword.other.math.relation.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{largeops}}{{endcs}} + scope: keyword.other.math.large-operator.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{binops}}{{endcs}} + scope: keyword.other.math.binary-operator.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{symbols}}{{endcs}} + scope: keyword.other.math.symbol.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{accents}}{{endcs}} + scope: keyword.other.math.accent.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{arrows}}{{endcs}} + scope: keyword.other.math.arrow.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\){{delimiters}}{{endcs}} + scope: keyword.other.math.delimiter.tex + captures: + 1: punctuation.definition.backslash.tex + + math-commands: + - match: (\\){{letter}}+ + scope: support.function.math.tex + captures: + 1: punctuation.definition.backslash.tex + + math-operators: + # note: in math notation, = usually denotes that two terms are equal, instead + # of an assignment. + - match: '[<>]=?|=' + scope: keyword.operator.comparison.tex + - match: '[-+*/!]' + scope: keyword.operator.arithmetic.tex + - match: _ + scope: punctuation.separator.subscript.tex + - match: \^ + scope: punctuation.separator.superscript.tex + + math-braces: + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: math-brace-body + + math-brace-body: + - meta_scope: meta.group.brace.tex + - include: brace-group-end + - include: math-content + + math-brackets: + - match: \( + scope: punctuation.section.parens.begin.tex + - match: \) + scope: punctuation.section.parens.end.tex + - match: \[ + scope: punctuation.section.brackets.begin.tex + - match: \] + scope: punctuation.section.brackets.end.tex + - match: (\\){ + scope: punctuation.section.braces.begin.tex constant.character.escape.tex + captures: + 1: punctuation.definition.backslash.tex + - match: (\\)} + scope: punctuation.section.braces.end.tex constant.character.escape.tex + captures: + 1: punctuation.definition.backslash.tex + + math-numbers: + - match: \d*(\.)\d+ + scope: meta.number.float.decimal.tex constant.numeric.value.tex + captures: + 1: punctuation.separator.decimal.tex + - match: \d+ + scope: meta.number.integer.decimal.tex constant.numeric.value.tex + + math-variables: + - match: '[A-Za-z]+' + scope: variable.other.math.tex + +###[ PROTOTYPES ]############################################################## + + # matches any nospace and pops the context + else-pop: + - match: (?=\S) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + # pops out of the current context if there is a new paragraph + paragraph-pop: + - match: ^(?=\s*$) + pop: 1 + + stray-brace-pop: + - match: (?=}) + pop: 1 + + stray-bracket-pop: + - match: (?=]) + pop: 1 + +###[ PREAMBLE COMMANDS ]####################################################### + + preamble: + - match: (\\)documentclass{{endcs}} + scope: keyword.control.preamble.latex + captures: + 1: punctuation.definition.backslash.latex + push: document-class-args + - match: (\\)usepackage{{endcs}} + scope: keyword.control.import.latex + captures: + 1: punctuation.definition.backslash.latex + push: usepackage-args + + document-class-args: + - meta_include_prototype: false + - meta_scope: meta.preamble.documentclass.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: document-class-args-body + - include: optional-arguments + + document-class-args-body: + - meta_scope: meta.group.braces.tex + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: 2 + - match: ',' + scope: punctuation.separator.sequence.latex + - match: '[0-9A-Za-z-]+' + scope: support.class.latex + - include: macro-variables + + usepackage-args: + - meta_include_prototype: false + - meta_scope: meta.preamble.usepackage.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: usepackage-args-body + - include: optional-arguments + + usepackage-args-body: + - meta_scope: meta.group.braces.tex + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: 2 + - match: ',' + scope: punctuation.separator.sequence.latex + - match: '[0-9A-Za-z-]+' + scope: support.class.latex + - include: macro-variables + +###[ SECTION COMMANDS ]######################################################## + + sections: + - match: |- + (?x) + (\\) + (?: + (?:sub){0,2}section + | (?:sub)?paragraph + | chapter | part | addpart + | addchap | addsec | minisec + ) + (?: \* | {{endcs}} ) + scope: support.function.section.latex + captures: + 1: punctuation.definition.backslash.latex + push: section-args + + section-args: + - meta_include_prototype: false + - meta_scope: meta.section.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: section-name-body + - include: optional-arguments # optional Title + + section-name-body: + - meta_scope: meta.group.brace.tex + - meta_content_scope: entity.name.section.latex + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: 2 + - include: expressions + + structure: + - match: (\\)(?:frontmatter|mainmatter|backmatter|appendix|printindex){{endcs}} + scope: keyword.control.latex + captures: + 1: punctuation.definition.backslash.latex + push: structure-args + + structure-args: + - meta_scope: meta.function.structure.latex + - include: optional-arguments + +###[ INCLUDE COMMANDS ]######################################################## + + includes: + - match: (\\)includegraphics{{endcs}} + scope: support.function.includegraphics.latex + captures: + 1: punctuation.definition.backslash.latex + push: includegraphics-args + - match: (\\)include(?:only)?{{endcs}} + scope: support.function.include.latex + captures: + 1: punctuation.definition.backslash.latex + push: include-args + + includegraphics-args: + - meta_include_prototype: false + - meta_scope: meta.function.includegraphics.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: includegraphics-args-body + - include: optional-arguments + + includegraphics-args-body: + - meta_scope: meta.group.braces.tex + - meta_content_scope: markup.underline.link.latex + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: 2 + - match: ',' + scope: punctuation.separator.sequence.latex + push: + - clear_scopes: 1 + - meta_include_prototype: false + - include: immediately-pop + - include: macro-variables + + include-args: + - meta_include_prototype: false + - meta_scope: meta.function.include.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: include-args-body + - include: optional-arguments + + include-args-body: + - meta_scope: meta.group.braces.tex + - meta_content_scope: markup.underline.link.latex + - match: \} + scope: punctuation.definition.group.brace.end.tex + pop: 2 + - match: ',' + scope: punctuation.separator.sequence.latex + push: + - clear_scopes: 1 + - meta_include_prototype: false + - include: immediately-pop + - include: macro-variables + +###[ PACKAGE: ARRAY ]########################################################## + + pkg-array: + - match: ((\\)newcolumntype)\s*((\{)\s*((\\){{letter}}+|{{letter}})\s*(\})) + scope: meta.function.newcolumntype.latex + captures: + 1: keyword.declaration.newcolumntype.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: entity.name.newcolumntype.latex + 6: punctuation.definition.backslash.latex + 7: punctuation.definition.group.brace.end.tex + push: newcolumntype-args + - match: ((\\)begin)\s*((\{)\s*(tabular)\s*(\})) + scope: meta.function.begin.latex + captures: + 1: support.function.begin.latex keyword.control.flow.begin.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: variable.parameter.function.latex + 6: punctuation.definition.group.brace.end.tex + push: + - tabular-env-body + - tabular-env-args + + newcolumntype-args: + - meta_include_prototype: false + - meta_content_scope: meta.function.newcolumntype.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + set: newcolumntype-body + - include: optional-arguments + + newcolumntype-body: + - meta_scope: meta.function.newcolumntype.latex meta.group.brace.tex + - include: brace-group-end + - include: array-preamble + - include: macro-variables + + tabular-env-args: + - meta_include_prototype: false + - meta_content_scope: meta.function.begin.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + set: tabular-column-spec-body + - match: (\[)\s*([bct])\s*(\]) + scope: meta.group.brackets.latex + captures: + 1: punctuation.definition.group.bracket.begin.latex + 2: constant.other.column-type.latex + 3: punctuation.definition.group.bracket.end.latex + - include: optional-arguments + + tabular-column-spec-body: + - meta_scope: meta.function.begin.latex meta.column-spec.latex meta.group.brace.tex + - include: brace-group-end + - include: array-preamble + - include: macro-variables + + tabular-env-body: + - meta_scope: meta.environment.tabular.latex + - match: ((\\)end)\s*((\{)\s*(tabular)\s*(\})) + scope: meta.funciton.end.latex + captures: + 1: support.function.end.latex keyword.control.flow.end.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: variable.parameter.function.latex + 6: punctuation.definition.group.brace.end.tex + pop: 1 + - include: main + + array-preamble: + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + push: array-preamble-group-body + - match: \| + scope: keyword.operator.inter-column-line.latex + - match: '[crl]' + scope: keyword.other.column-type.latex + - match: ([bmp])\s*(\{) + captures: + 1: support.function.parbox-column.latex + 2: meta.group.brace.tex punctuation.definition.group.brace.begin.tex + push: array-preamble-parbox-body + - match: (>)\s*(\{) + captures: + 1: support.function.insert-before-column.latex + 2: meta.group.brace.tex punctuation.definition.group.brace.begin.tex + push: array-preamble-column-body + - match: (<)\s*(\{) + captures: + 1: support.function.insert-after-column.latex + 2: meta.group.brace.tex punctuation.definition.group.brace.begin.tex + push: array-preamble-column-body + - match: (@)\s*(\{) + captures: + 1: support.function.inter-column-nospace.latex + 2: meta.group.brace.tex punctuation.definition.group.brace.begin.tex + push: array-preamble-column-body + - match: (!)\s*(\{) + captures: + 1: support.function.inter-column.latex + 2: meta.group.brace.tex punctuation.definition.group.brace.begin.tex + push: array-preamble-column-body + - match: (\*)\s*(\{) + captures: + 1: support.function.insert-repeated.latex + 2: meta.group.brace.tex punctuation.definition.group.brace.begin.tex + push: array-preamble-insert-count-body + + array-preamble-column-body: + - meta_scope: meta.function.column-decl.latex + - meta_content_scope: meta.group.brace.tex + - match: \} + scope: meta.group.brace.tex punctuation.definition.group.brace.end.tex + pop: 1 + - include: expressions + + array-preamble-parbox-body: + - meta_scope: meta.function.parbox-column.latex + - meta_content_scope: meta.group.brace.tex + - match: \} + scope: meta.group.brace.tex punctuation.definition.group.brace.end.tex + pop: 1 + - include: expressions + + array-preamble-insert-count-body: + - meta_scope: meta.function.insert-repeated.count.latex + - meta_content_scope: meta.group.brace.tex + - match: \} + scope: meta.group.brace.tex punctuation.definition.group.brace.end.tex + set: array-preamble-insert-content + - match: \d+ + scope: meta.number.integer.decimal.latex constant.numeric.value.latex + - include: expressions + + array-preamble-insert-content: + - meta_include_prototype: false + - meta_content_scope: meta.function.insert-repeated.latex + - match: \{ + scope: punctuation.definition.group.brace.begin.tex + set: array-preamble-insert-content-body + - include: else-pop + + array-preamble-insert-content-body: + - meta_scope: meta.function.insert-repeated.content.latex meta.group.brace.tex + - include: brace-group-end + - include: array-preamble + - include: macro-variables + + array-preamble-group-body: + - meta_scope: meta.group.brace.tex + - include: array-preamble + - include: brace-group-body + +###[ PACKAGE: BEAMER ]######################################################### + + pkg-beamer-envs: + - match: ((\\)begin)\s*((\{)\s*(frame)\s*(\})) + scope: meta.function.begin.latex + captures: + 1: support.function.begin.latex keyword.control.flow.begin.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: variable.parameter.function.latex + 6: punctuation.definition.group.brace.end.tex + push: beamer-env-body + + beamer-env-body: + - meta_scope: meta.environment.frame.latex + - match: ((\\)end)\s*((\{)\s*(frame)\s*(\})) + scope: meta.function.end.latex + captures: + 1: support.function.end.latex keyword.control.flow.end.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: variable.parameter.function.latex + 6: punctuation.definition.group.brace.end.tex + pop: 1 + - match: ((\\)frametitle)\s*((\{)(.*)(\})) + scope: meta.function.frametitle.latex + captures: + 1: support.function.frametitle.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: entity.name.section.frame.latex + 6: punctuation.definition.group.brace.end.tex + - include: main + +###[ PACKAGE: MINTED ]######################################################### + + pkg-minted-envs: + - match: ((\\)begin)\s*((\{)\s*(minted)\s*(\})) + scope: meta.function.begin.latex + captures: + 1: support.function.begin.latex keyword.control.flow.begin.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: variable.parameter.function.latex + 6: punctuation.definition.group.brace.end.tex + embed: pkg-minted-env-body + escape: (?:^\s*)?((\\)end)\s*((\{)\s*(minted)\s*(\}))(\s*\n)? + escape_captures: + 0: meta.environment.verbatim.minted.latex meta.function.end.latex + 1: support.function.end.latex keyword.control.flow.end.latex + 2: punctuation.definition.backslash.latex + 3: meta.group.brace.tex + 4: punctuation.definition.group.brace.begin.tex + 5: variable.parameter.function.latex + 6: punctuation.definition.group.brace.end.tex + 7: meta.fold.end.latex + + pkg-minted-env-body: + - meta_include_prototype: false + - meta_scope: meta.environment.verbatim.minted.latex + - include: general-optional-arguments + - match: ((\{)\s*(bash|sh(?:ell)?)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.shell.bash + embed_scope: markup.raw.verb.latex source.shell.bash.embedded.latex + escape: (?!) + - match: ((\{)\s*(c)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.c + embed_scope: markup.raw.verb.latex source.c.embedded.latex + escape: (?!) + - match: ((\{)\s*(cpp|c\+\+)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.c++ + embed_scope: markup.raw.verb.latex source.c++.embedded.latex + escape: (?!) + - match: ((\{)\s*(css)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.css + embed_scope: markup.raw.verb.latex source.css.embedded.latex + escape: (?!) + - match: ((\{)\s*(diff)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.diff + embed_scope: markup.raw.verb.latex source.diff.embedded.latex + escape: (?!) + - match: ((\{)\s*(go|golang)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.go + embed_scope: markup.raw.verb.latex source.go.embedded.latex + escape: (?!) + - match: ((\{)\s*(haskell|hs)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.haskell + embed_scope: markup.raw.verb.latex source.haskell.embedded.latex + escape: (?!) + - match: ((\{)\s*(html)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:text.html.basic + embed_scope: markup.raw.verb.latex text.html.embedded.latex + escape: (?!) + - match: ((\{)\s*(java)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.java + embed_scope: markup.raw.verb.latex source.java.embedded.latex + escape: (?!) + - match: ((\{)\s*(javascript|js)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.js + embed_scope: markup.raw.verb.latex source.js.embedded.latex + escape: (?!) + - match: ((\{)\s*(json)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.json + embed_scope: markup.raw.verb.latex source.json.embedded.latex + escape: (?!) + - match: ((\{)\s*(tex|latex)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:text.tex.latex + embed_scope: markup.raw.verb.latex text.tex.latex.embedded.latex + escape: (?!) + - match: ((\{)\s*(lisp)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.lisp + embed_scope: markup.raw.verb.latex source.lisp.embedded.latex + escape: (?!) + - match: ((\{)\s*(lua)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.lua + embed_scope: markup.raw.verb.latex source.lua.embedded.latex + escape: (?!) + - match: ((\{)\s*(obj(?:ective-)?c)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.objc + embed_scope: markup.raw.verb.latex source.objc.embedded.latex + escape: (?!) + - match: ((\{)\s*(obj(?:ective-)?c\+\+)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.objc++ + embed_scope: markup.raw.verb.latex source.objc++.embedded.latex + escape: (?!) + - match: ((\{)\s*(perl)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.perl + embed_scope: markup.raw.verb.latex source.perl.embedded.latex + escape: (?!) + - match: ((\{)\s*(php)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.php + embed_scope: markup.raw.verb.latex source.php.embedded.latex + escape: (?!) + - match: ((\{)\s*(python|py)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.python + embed_scope: markup.raw.verb.latex source.python.embedded.latex + escape: (?!) + - match: ((\{)\s*(r)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.r + embed_scope: markup.raw.verb.latex source.r.embedded.latex + escape: (?!) + - match: ((\{)\s*(ruby)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.ruby + embed_scope: markup.raw.verb.latex source.ruby.embedded.latex + escape: (?!) + - match: ((\{)\s*(sql|ddl|dml)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.sql + embed_scope: markup.raw.verb.latex source.sql.embedded.latex + escape: (?!) + - match: ((\{)\s*(xml)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:text.xml + embed_scope: markup.raw.verb.latex text.xml.embedded.latex + escape: (?!) + - match: ((\{)\s*(ya?ml)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.yaml + embed_scope: markup.raw.verb.latex source.yaml.embedded + escape: (?!) + - match: ((\{)\s*(zsh)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + embed: scope:source.shell.zsh + embed_scope: markup.raw.verb.latex source.shell.zsh.embedded.latex + escape: (?!) + - match: ((\{)\s*([^}]+)\s*(\}))(\s*\n)? + captures: + 1: meta.group.brace.tex + 2: punctuation.definition.group.brace.begin.tex + 3: constant.other.language-name.latex + 4: punctuation.definition.group.brace.end.tex + 5: meta.fold.begin.latex + push: pkg-minted-env-raw-body + - match: (?=\S) + push: pkg-minted-env-raw-body + + pkg-minted-env-raw-body: + - meta_include_prototype: false + - meta_content_scope: markup.raw.verb.latex + +############################################################################### + +variables: + + greeks: |- + (?x: alpha | beta | gamma | delta | epsilon | varepsilon | zeta | eta | theta + | vartheta | iota | kappa | lambda | mu | nu | xi | o | pi | varpi | rho + | varrho | sigma | varsigma | tau | upsilon | phi | varphi | chi | psi + | omega | Gamma | Delta | Theta | Lambda | Xi | Pi | Sigma | Upsilon | Phi + | Psi | Omega ) + mathfun: |- + (?x: arccos | cos | csc | exp | ker | limsup | min | sinh + | arcsin | cosh | deg | gcd | lg | ln | Pr | sup + | arctan | cot | det | hom | lim | log | sec | tan + | arg | coth | dim | inf | liminf | max | sin | tan | pmod | bmod) + relations: |- + (?x: leq | lq | geq | ge | equiv | prec | succ | sim + | preceq | succeq | simeq | ll | gg | subset | supset | approx + | subseteq | supseteq | cong | sqsubseteq | sqsupseteq | bowtie + | in | notin | ne | ni | owns | vdash | dashv | models | smile | mid + | doteq | frown | parallel | perp | propto) + largeops: |- + (?x: sum | prod | coprod | int | oint | bigcap | bigcup | bigsqcup + | bigvee | bigwedge | bigodot | bigotimes | bigoplus | biguplus) + binops: |- + (?x: pm | mp | setminus | cdot | times | ast | star | diamond | circ | bullet + | div | cap | cup | uplus | sqcap | sqcup | triangleleft | triangleright + | wr | bigcirc | bigtriangleup | bigtriangledown | vee | lor + | wedge | land | oplus | ominus | otimes | oslash | odot | dagger + | ddagger | amalg) + accents: |- + (?x: hat | widehat | check | tilde | widetilde | acute | grave | dot + | ddot | breve | bar | vec) + symbols: |- + (?x: aleph | hbar | imath | jmath | ell | wp | Re | Im | partial | infty + | prime | emptyset | nabla | surd | top | bot | \| | angle | triangle + | backslash | forall | exists | neg | lnot | flat | natural | sharp + | clubsuit | diamondsuit | heartsuit | spadesuit) + arrows: |- + (?x: leftarrow | gets | longleftarrow | Leftarrow | Longleftarrow + | rightarrow | to | longrightarrow | Rightarrow | Longrightarrow + | leftrightarrow | longleftrightarrow | Leftrightarrow + | Longleftrightarrow | mapsto | longmapsto | hookleftarrow + | hookrightarrow | uparrow | Uparrow | downarrow | Downarrow + | updownarrow | Updownarrow | nearrow | searrow | nwarrow | swarrow) + delimiters: |- + (?x: lbrack | lbrace | langle | rbrack | rbrace | rangle + | vert | lfloor | lceil | Vert | rfloor | rceil) + + registers: |- + (?x: box | count | dimen | muskip | skip | toks) + + # here, we define variables for the names of the constants and parameters + # of the TeX algorithm. Some of these are defined in terms of pre-reserved + # registers instead of built-ins, but in terms of syntax highlighting this + # should not make a difference + penalties: |- + (?x: line | hyphen | exhyphen | binop | rel | club | widow + | displaywidow | broken | predisplay | postdisplay | interline + | floating | output | inter(?:display|footnote)line) + + tracings: |- + (?x: online | macros | stats | paragraphs | pages | output | lostchars + | commands | restores) + + skips: |- + (?x: baseline | line | par | (?:above|below)display(?:short)? + | left | right | top | splittop | tab | space | xspace | parfill + | (?:thin|med|thick)mu | normalbaseline | normalline | hide) + + constants: |- + (?x: (?:pre)?tolerance | [hv]badness + | (?:doublehyphen|finalhyphen|adj)demerits + | looseness | pausing | holdinginserts | language | uchyph | lefthyphenmin + | righthyphenmin | globaldefs | maxdeadcycles | hangafter | fam | mag + | (?:escape|defaulthyphen|defaultskew|endline|newline)char + | delimiterfactor | time | day | month | year + | showboxbreadth | showboxdepth | errorcontextlines + | [hv]fuzz | overfullrule | [hv]size | maxdepth | splitmaxdepth + | boxmaxdepth | lineskiplimit | delimitershortfall | nulldelimiterspace + | scriptspace | mathsurround | predisplaysize | displaywidth | displayindent + | parindent | hangindent | [hv]offset | (?:small|med|big)skipamount + | normallineskiplimit | jot | {{skips}}skip | tracing{{tracings}} + | {{penalties}}penalty | maxdimen | centering | p@ | z@ | z@skip | voidb@x + | magstephalf | magstep\d | @ne | tw@ | thr@@ | sixt@@n | @cclv | @cclvi + | @m | @M | @MM | m@ne | count@ | dimen@ | dimen@i | dimen@ii | skip@ + | toks@ | insc@unt | allocationnumber) + + # These constants are implemented as macros, and thus cannot be = assigned + macroconst: |- + (?x: (?:thin|negthin|en)space | enskip | q?quad | (?:small|med|big)skip + | [lr]q | [lr]brack | space | empty | null ) + + dimunits: |- + (?x: pt | pc | bp | in | cm | mm | dd | cc | sp | ex | em + | fil | fill | filll | mu) + + # letters in the sense of macro names. Whether @ is a letter or not can vary + # from a syntax-highlighting perspective, however, we are much safer to + # assume it is a letter. Situations where we have `\macro` followed immediately + # by `@text` that is to be typeset should be very rare, and if it happens, the + # user can still put an explicit space (ignored by TeX) to ensure correct + # highlighting. On the other hand, within packages we get lots of \module@macro + # type names, and if they were highlighted wrongly the user could not fix this. + letter: '[A-Za-z@]' + nonletter: '[^A-Za-z@]' + # look-ahead for end of command sequence + endcs: '(?!{{macrosep}}?{{letter}})' + # a command name: either a sequence of letters, or a single non-letter + cmdname: '(?x: {{letter}}+ | {{nonletter}})' + # internal macro name: a sequence of letters containing `_` and `:` for structure + macroname: '_*{{letter}}+(?:{{macrosep}}+{{letter}}+)+' + macrosep: '[_:]' + # hexadecimal digits in different casing + lchexdigit: '[0-9a-f]' + uchexdigit: '[0-9A-F]' + anyhexdigit: '[0-9a-fA-F]' + # special notation to refer to (non-printable) characters in TeX + charbycode: (?:\^\^(?:{{lchexdigit}}{{lchexdigit}}|.))
diff --git /dev/null b/syntax/Lisp/Lisp.sublime-syntax @@ -0,0 +1,2308 @@ +%YAML 1.2 +--- +# https://www.sublimetext.com/docs/syntax.html +# +# `Common Lisp` Language Reference: +# https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/index.html +# https://www.lispworks.com/documentation/lw70/CLHS/Front/Contents.htm +name: Lisp +scope: source.lisp +version: 2 + +file_extensions: + - lisp + - cl + - clisp + - l + - el + - scm + - ss + - lsp + +first_line_match: |- + (?xi: + ^ \s* ; .*? -\*- .*? \blisp\b .*? -\*- # editorconfig + ) + +############################################################################### + +contexts: + main: + - include: statements + + statements: + - include: parens + - include: expressions + - match: \) + scope: invalid.illegal.stray-bracket-end.lisp + + expressions: + - include: comments + - include: numbers + - include: strings + - include: annotations + - include: keywords + - include: quotes + - include: macros + - include: modifiers + - include: identifiers + +###[ COMMENTS ]################################################################ + + comments: + - include: line-comments + - include: block-comments + - include: merge-conflict-markers + - match: \|# + scope: invalid.illegal.stray-comment-end.lisp + + block-comments: + - match: '#\|' + scope: punctuation.definition.comment.begin.lisp + push: block-comment-body + + block-comment-body: + - meta_scope: comment.block.lisp + - match: '\|#' + scope: punctuation.definition.comment.end.lisp + pop: 1 + - include: block-comments + + line-comments: + - match: ;+ + scope: punctuation.definition.comment.lisp + push: line-comment-body + + line-comment-body: + - meta_scope: comment.line.semicolon.lisp + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ PARENTHESES ]############################################################# + + parens: + - match: \( + scope: punctuation.section.parens.begin.lisp + push: + - paren-body + - paren-begin + + paren-begin: + - include: class-declaration + - include: function-declaration + - include: macro-declaration + - include: struct-declaration + - include: type-declaration + - include: variable-declaration + - include: other-declaration + - include: declare + - include: control + - include: loop + - include: operator + - include: quote + - include: namespaces + - include: builtin-function + - include: other-function + - include: comments + - include: else-pop + + paren-body: + - meta_scope: meta.parens.lisp + - include: paren-end + - include: parens + - include: expressions + + paren-end: + - meta_include_prototype: false + - meta_scope: meta.parens.lisp + - match: \) + scope: punctuation.section.parens.end.lisp + pop: 1 + +###[ LISTS ]################################################################### + + expect-list: + # a list expression + # skips function-like parentheses on next level + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: paren-body + - include: comments + - include: else-pop + + expect-lists-list: + # a list of list expressions + # skips function-like parentheses on next 2 levels + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: lists-list-body + - include: comments + - include: else-pop + + lists-list-body: + - meta_scope: meta.parens.lisp + - include: paren-end + - include: lists + - include: expressions + + lists: + - match: \( + scope: punctuation.section.parens.begin.lisp + push: paren-body + +###[ QUOTED EXPRESSIONS ]###################################################### + + quotes: + # abbreviation of (quote ...) function + - match: \' + scope: punctuation.definition.quoted.lisp + push: quoted-content + + quoted-content: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: quoted-paren-body + # A quoted symbol evaluates to the symbol. + - match: '{{identifier}}' + scope: constant.other.symbol.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: immediately-pop + + quoted-parens: + - match: \( + scope: punctuation.section.parens.begin.lisp + push: quoted-paren-body + + quoted-paren-body: + - meta_scope: meta.parens.lisp + - include: paren-end + - include: quoted-parens + - include: expressions + +###[ CLASS DECLARATIONS ]###################################################### + + class-declaration: + # https://www.lispworks.com/documentation/lw70/CLHS/Body/m_defcla.htm + - match: (?i:defclass|define-class){{break}} + scope: meta.class.lisp keyword.declaration.class.lisp + set: + - class-declaration-slots + - class-declaration-parent-list + - class-declaration-name + + class-declaration-name: + - match: '{{identifier}}' + scope: entity.name.class.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + + class-declaration-parent-list: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: class-declaration-parent-list-body + - include: comments + - include: else-pop + + class-declaration-parent-list-body: + - meta_scope: meta.parens.lisp + - include: namespaces + - match: '{{identifier}}' + scope: entity.other.inherited-class.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + - include: comments + - include: paren-end + + class-declaration-slots: + - meta_content_scope: meta.class.lisp + - include: paren-pop + - include: lists + - include: expressions + +###[ FUNCTION DECLARATIONS ]################################################### + + function-declaration: + # https://www.lispworks.com/documentation/HyperSpec/Body/s_lambda.htm + - match: (?i:lambda){{break}} + scope: meta.function.lisp keyword.declaration.function.inline.lisp + set: + - function-body + - function-parameter-list + # https://www.lispworks.com/documentation/HyperSpec/Body/m_defun.htm + - match: (?i:def(?:[a-z]+f)?un|defgeneric|define-(?:command(?:-global)?|parenscript)){{break}} + scope: meta.function.lisp keyword.declaration.function.lisp + set: + - function-body + - function-parameter-list + - function-declaration-name + # https://www.lispworks.com/documentation/HyperSpec/Body/m_defmet.htm + - match: (?i:defmethod){{break}} + scope: meta.function.lisp keyword.declaration.function.lisp + set: + - function-body + - function-parameter-list + - method-qualifier + - function-declaration-name + # https://www.lispworks.com/documentation/HyperSpec/Body/s_flet_.htm + - match: (?i:flet|labels){{break}} + scope: keyword.declaration.function.lisp + set: function-declaration-list + + function-declaration-list: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: function-declaration-list-body + - include: comments + - include: else-pop + + function-declaration-list-body: + - meta_scope: meta.parens.lisp + - match: \( + scope: punctuation.section.parens.begin.lisp + push: + - paren-end + - function-body + - function-parameter-list + - function-declaration-name + - include: comments + - include: paren-end + + function-declaration-name: + - include: namespaces + - match: '{{identifier}}' + scope: entity.name.function.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + + method-qualifier: + # qualifiers may be anything but lists + - include: expressions + - include: else-pop + + function-parameter-list: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parameters.begin.lisp + set: function-parameter-list-body + - include: comments + - include: else-pop + + function-parameter-list-body: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.lisp + - match: \) + scope: punctuation.section.parameters.end.lisp + pop: 1 + - include: comments + - include: annotations + - include: keywords + - include: modifiers + - include: parameters + + function-body: + - meta_content_scope: meta.function.lisp + - include: paren-pop + - include: parens + - include: expressions + +###[ MACRO DECLARATIONS ]###################################################### + + macro-declaration: + # https://www.lispworks.com/documentation/HyperSpec/Body/m_defmac.htm + - match: (?i:defmacro){{break}} + scope: meta.macro.lisp keyword.declaration.macro.lisp + set: + - macro-body + - macro-parameter-list + - macro-declaration-name + # https://www.lispworks.com/documentation/HyperSpec/Body/s_flet_.htm + - match: (?i:macrolet){{break}} + scope: keyword.declaration.macro.lisp + set: macro-declaration-list + + macro-declaration-list: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: macro-declaration-list-body + - include: comments + - include: else-pop + + macro-declaration-list-body: + - meta_scope: meta.parens.lisp + - match: \( + scope: punctuation.section.parens.begin.lisp + push: + - paren-end + - macro-body + - macro-parameter-list + - macro-declaration-name + - include: comments + - include: paren-end + + macro-declaration-name: + - include: namespaces + - match: '{{identifier}}' + scope: entity.name.macro.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + + macro-parameter-list: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parameters.begin.lisp + set: macro-parameter-list-body + - include: comments + - include: else-pop + + macro-parameter-list-body: + - clear_scopes: 1 + - meta_scope: meta.macro.parameters.lisp + - match: \) + scope: punctuation.section.parameters.end.lisp + pop: 1 + - include: comments + - include: annotations + - include: keywords + - include: modifiers + - include: parameters + + macro-body: + - meta_content_scope: meta.macro.lisp + - include: paren-pop + - include: parens + - include: expressions + +###[ STRUCT DECLARATIONS ]##################################################### + + struct-declaration: + # https://www.lispworks.com/documentation/lw70/CLHS/Body/m_defstr.htm + - match: (?i:defstruct|define-struct){{break}} + scope: meta.struct.lisp keyword.declaration.struct.lisp + set: + - struct-declaration-body + - struct-declaration-name + + struct-declaration-name: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: + - paren-body + - struct-declaration-qualified-name + - include: struct-declaration-qualified-name + + struct-declaration-qualified-name: + - include: namespaces + - match: '{{identifier}}' + scope: entity.name.struct.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + + struct-declaration-body: + - meta_content_scope: meta.struct.lisp + - include: paren-pop + - include: lists + - include: expressions + +###[ TYPE DECLARATIONS ]####################################################### + + type-declaration: + # https://www.lispworks.com/documentation/lw70/CLHS/Body/m_deftp.htm + - match: (?i:deftype|define-type){{break}} + scope: meta.type.lisp keyword.declaration.type.lisp + set: + - type-body + - type-parameter-list + - type-declaration-name + + type-declaration-name: + - include: namespaces + - match: '{{identifier}}' + scope: entity.name.type.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + + type-parameter-list: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parameters.begin.lisp + set: type-parameter-list-body + - include: comments + - include: else-pop + + type-parameter-list-body: + - clear_scopes: 1 + - meta_scope: meta.type.parameters.lisp + - match: \) + scope: punctuation.section.parameters.end.lisp + pop: 1 + - include: comments + - include: annotations + - include: keywords + - include: modifiers + - include: parameters + + type-body: + - meta_content_scope: meta.type.lisp + - include: paren-pop + - include: parens + - include: expressions + +###[ VARIABLE DECLARATIONS ]################################################### + + variable-declaration: + # https://www.lispworks.com/documentation/HyperSpec/Body/s_let_l.htm + - match: (?i:let\*?){{break}} + scope: keyword.declaration.variable.lisp + set: variable-declaration-list + # https://www.lispworks.com/documentation/lw445/CLHS/Body/m_defcon.htm + - match: (?i:defconstant){{break}} + scope: meta.declaration.lisp keyword.declaration.constant.lisp + set: constant-declaration-name + # https://www.lispworks.com/documentation/HyperSpec/Body/m_defpar.htm + - match: (?i:defparameter|defvar){{break}} + scope: meta.declaration.lisp keyword.declaration.variable.lisp + set: variable-declaration-name + + variable-declaration-list: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.parens.begin.lisp + set: variable-declaration-list-body + - include: comments + - include: else-pop + + variable-declaration-list-body: + - meta_scope: meta.parens.lisp + - match: \( + scope: punctuation.section.parens.begin.lisp + push: + - paren-body + - variable-declaration-name + - match: '{{identifier}}' + scope: meta.declaration.lisp variable.other.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + - include: comments + - include: paren-end + + constant-declaration-name: + - meta_content_scope: meta.declaration.lisp + - match: '{{identifier}}' + scope: meta.declaration.lisp constant.other.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + + variable-declaration-name: + - meta_content_scope: meta.declaration.lisp + - match: '{{identifier}}' + scope: meta.declaration.lisp variable.other.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + +###[ OTHER DECLARATIONS ]###################################################### + + other-declaration: + - match: '{{declaration_keywords}}' + scope: keyword.declaration.lisp + pop: 1 + +###[ DECLARE STATEMENTS ]###################################################### + + declare: + # https://www.lispworks.com/documentation/HyperSpec/Body/s_declar.htm + - match: (?i:declare){{break}} + scope: keyword.declaration.declare.lisp + set: declare-specifier-list + + declare-specifier-list: + - match: \( + scope: punctuation.section.parens.begin.lisp + push: + - paren-body + - declare-identifier + - include: comments + - include: else-pop + + declare-identifier: + - match: '{{declaration_identifiers}}' + scope: storage.modifier.lisp + pop: 1 + - include: comments + - include: else-pop + +###[ CONTROL FLOW STATEMENTS ]################################################# + + control: + # Conditional + - match: (?i:if|case|cond|otherwise|unless|when|[ce]?typecase){{break}} + scope: keyword.control.conditional.lisp + pop: 1 + # Flow + - match: (?i:return(?:-from)?){{break}} + scope: keyword.control.flow.return.lisp + pop: 1 + # Loop + # https://www.lispworks.com/documentation/lw70/CLHS/Body/m_dolist.htm + # https://www.lispworks.com/documentation/lw70/CLHS/Body/m_dotime.htm + - match: (?i:dolist|dotimes){{break}} + scope: keyword.control.loop.lisp + set: expect-list + # https://www.lispworks.com/documentation/lw70/CLHS/Body/m_do_do.htm + - match: (?i:do\*?|do-(?:all-|external-)?symbols|iterate){{break}} + scope: keyword.control.loop.lisp + set: expect-lists-list + # Other + - match: (?xi:block|map(?:can|car|con|c|list|l)){{break}} + scope: keyword.control.lisp + pop: 1 + +###[ LOOP STATEMENTS ]######################################################### + + loop: + # https://www.lispworks.com/documentation/lw70/CLHS/Body/06_a.htm + # https://www.lispworks.com/documentation/lw70/CLHS/Body/m_loop.htm + - match: (?i:loop){{break}} + scope: keyword.control.loop.lisp + set: loop-body + + loop-body: + - meta_scope: meta.loop.lisp + - include: paren-pop + + # declaration keywords + - match: (?i:named){{break}} + scope: keyword.declaration.name.lisp + push: loop-name + - match: (?i:with){{break}} + scope: keyword.declaration.variable.lisp + + # loop termination test keywords + - match: (?i:always|as|do|doing|for|never|repeat|thereis|until|while){{break}} + scope: keyword.control.loop.lisp + # conditional keywords + - match: (?i:end|else|if|then|unless|when){{break}} + scope: keyword.control.conditional.lisp + # control flow keywords + - match: (?i:finally|initially){{break}} + scope: keyword.control.flow.lisp + - match: (?i:return(?:-from)?){{break}} + scope: keyword.control.flow.return.lisp + + # operator keywords + - match: ={{break}} # can be both, assignment and comparison + scope: keyword.operator.lisp + - match: (?i:into){{break}} + scope: keyword.operator.assignment.lisp + - match: (?i:and){{break}} + scope: keyword.operator.logical.lisp + - match: |- + (?xi: across | above | being | below | by | each | in | of | on | the + | (?:down|up)?to | (?:up)?from | using ){{break}} + scope: keyword.other.loop.lisp + + # expressions + - include: comments + - include: parens + - include: numbers + - include: strings + - include: annotations + - include: keywords + - include: quotes + - include: macros + - include: modifiers + - match: (?={{identifier}}) + push: loop-identifier + + loop-identifier: + - include: builtin-function + - include: identifier + + loop-name: + - match: '{{identifier}}' + scope: entity.name.loop.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + +###[ QUOTE STATEMENTS ]######################################################## + + quote: + - match: (?i:quote){{break}} + scope: meta.function-call.lisp support.function.lisp + set: quote-args + + quote-args: + - include: paren-pop + - include: quoted-parens + - include: expressions + +###[ FUNCTIONS ]############################################################### + + builtin-function: + - match: '{{builtin_functions}}' + scope: meta.function-call.lisp support.function.lisp + pop: 1 + + other-function: + # functions starting with `make-` are most likely used as constructors + - match: make-{{identifier}} + scope: meta.function-call.lisp variable.function.constructor.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + # mutating functions changing data in-place end with ! + - match: (?![+*#`'&]\S){{identifier}}\!{{break}} + scope: meta.function-call.lisp variable.function.mutating.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + # predicate functions returning boolean values end with ? or -p + - match: (?![+*#`'&]\S){{identifier}}(?:\?|-p){{break}} + scope: meta.function-call.lisp variable.function.predicate.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + # anything not looking like global variable, constant or macro + - match: (?![+*#`'&]\S|{{builtin_constants}}|{{builtin_types}}){{identifier}} + scope: meta.function-call.lisp variable.function.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + +###[ MACROS ]################################################################## + + macros: + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node191.html + - include: macro-arrays + - include: macro-characters + - include: macro-conditionals + - include: macro-functions + - include: macro-numbers + - include: macro-pathnames + - include: macro-structures + - include: macro-throw-exceptions + - include: macro-variables + - include: macro-vectors + + macro-conditionals: + # Feature-flags + - match: (#[-+])({{identifier}})? + captures: + 1: keyword.control.conditional.lisp + 2: constant.other.feature.lisp + 3: punctuation.definition.symbol.begin.lisp + 4: punctuation.definition.symbol.end.lisp + + macro-arrays: + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node29.html + - match: (#\d*[aA])(\() + captures: + 1: punctuation.definition.array.lisp + 2: meta.parens.lisp punctuation.section.parens.begin.lisp + push: macro-array-body + - match: (#\d*[aA])({{identifier}}) + captures: + 1: punctuation.definition.array.lisp + 2: variable.other.lisp + 3: punctuation.definition.symbol.begin.lisp + 4: punctuation.definition.symbol.end.lisp + + macro-array-body: + - meta_scope: meta.array.lisp + - meta_content_scope: meta.parens.lisp + - match: \) + scope: meta.parens.lisp punctuation.section.parens.end.lisp + pop: 1 + - include: parens + - include: expressions + + macro-characters: + # Standard Characters + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node22.html + # Non-Standard Characters + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node24.html + # Character Attributes + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node25.html + - match: (#(\d*)\\){{char_attributes}}?(?i:Space|NewLine){{break}} + scope: constant.character.standard.lisp + captures: + 1: punctuation.definition.constant.lisp + 2: storage.modifier.attributes.lisp + - match: (#(\d*)\\){{char_attributes}}?(?i:Backspace|Tab|Linefeed|Page|Return|RubOut){{break}} + scope: constant.character.semi-standard.lisp + captures: + 1: punctuation.definition.constant.lisp + 2: storage.modifier.attributes.lisp + - match: (#(\d*)\\){{char_attributes}}?{{standard_char}}{{break}} + scope: constant.character.standard.lisp + captures: + 1: punctuation.definition.constant.lisp + 2: storage.modifier.attributes.lisp + - match: (#(\d*)\\){{char_attributes}}?{{identifier_char}}+{{break}} + scope: constant.character.non-standard.lisp + captures: + 1: punctuation.definition.constant.lisp + 2: storage.modifier.attributes.lisp + + macro-functions: + # Function reference + - match: \#[Mm'] + scope: punctuation.definition.function.lisp + push: macro-function-name + + macro-function-name: + - include: namespaces + - include: operator + - include: builtin-function + - include: other-function + - include: immediately-pop + + macro-numbers: + # binary rational numbers + - match: |- + (?xi) + ( \#(?: b | 2r ) ) + ( [-+]? ) + ( [01]+ (/) [01]+ ) + {{break}} + scope: meta.number.rational.binary.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: keyword.operator.arithmetic.lisp + # binary integer numbers + - match: |- + (?xi) + ( \#(?: b | 2r ) ) + ( [-+]? ) + ( [01]+ (?: (\.)(?![01]) | {{break}} ) ) + scope: meta.number.integer.binary.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: punctuation.separator.decimal.lisp + # octal rational numbers + - match: |- + (?xi) + ( \#(?: o | 8r ) ) + ( [-+]? ) + ( [0-7]+ (/) [0-7]+ ) + {{break}} + scope: meta.number.rational.octal.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: keyword.operator.arithmetic.lisp + # octal integer numbers + - match: |- + (?xi) + ( \#(?: o | 8r ) ) + ( [-+]? ) + ( [0-7]+ (?: (\.)(?![0-7]) | {{break}} ) ) + scope: meta.number.integer.octal.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: punctuation.separator.decimal.lisp + # hexadecimal rational numbers + - match: |- + (?xi) + ( \#(?: x | 16r ) ) + ( [-+]? ) + ( \h+ (/) \h+ ) + {{break}} + scope: meta.number.rational.hexadecimal.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: keyword.operator.arithmetic.lisp + # hexadecimal integer numbers + - match: |- + (?xi) + ( \#(?: x | 16r ) ) + ( [-+]? ) + ( \h+ (?: (\.)(?!\h) | {{break}} ) ) + scope: meta.number.integer.hexadecimal.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: punctuation.separator.decimal.lisp + # radix rational numbers + - match: |- + (?xi) + ( \#\d+r ) + ( [-+]? ) + ( [[:alnum:]]+ (/) [[:alnum:]]+ ) + {{break}} + scope: meta.number.rational.other.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: keyword.operator.arithmetic.lisp + # radix integer numbers + - match: |- + (?xi) + ( \#\d+r ) + ( [-+]? ) + ( [[:alnum:]]+ (?: (\.)(?![[:alnum:]]) | {{break}} ) ) + scope: meta.number.integer.other.lisp + captures: + 1: constant.numeric.base.lisp + 2: keyword.operator.arithmetic.lisp + 3: constant.numeric.value.lisp + 4: punctuation.separator.decimal.lisp + # complex numbers + - match: (#[cC])(\() + captures: + 1: punctuation.definition.complex.lisp + 2: meta.parens.lisp punctuation.section.parens.begin.lisp + push: macro-numbers-complex-body + + macro-numbers-complex-body: + - meta_scope: meta.number.complex.lisp + - meta_content_scope: meta.parens.lisp + - match: \) + scope: meta.parens.lisp punctuation.section.parens.end.lisp + pop: 1 + - include: parens + - include: expressions + + macro-pathnames: + - match: (#\d*[pP])(\") + captures: + 1: punctuation.definition.pathname.lisp + 2: string.quoted.double.lisp punctuation.definition.string.begin.lisp + push: macro-pathname-body + + macro-pathname-body: + - meta_scope: meta.path.lisp + - meta_content_scope: string.quoted.double.lisp + - match: \" + scope: string.quoted.double.lisp punctuation.definition.string.end.lisp + pop: 1 + - match: \\. + scope: constant.character.escape.lisp + + macro-structures: + # Structures + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node39.html + - match: (#\d*[sS])(\() + captures: + 1: punctuation.definition.struct.lisp + 2: meta.parens.lisp punctuation.section.parens.begin.lisp + push: + - macro-struct-body + - macro-struct-name + + macro-struct-name: + - match: '{{identifier}}' + scope: entity.name.struct.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: else-pop + + macro-struct-body: + - meta_scope: meta.struct.lisp + - meta_content_scope: meta.parens.lisp + - match: \) + scope: meta.parens.lisp punctuation.section.parens.end.lisp + pop: 1 + - include: lists + - include: expressions + + macro-vectors: + # Vector + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node30.html + - match: (#\d*)(\() + captures: + 1: punctuation.definition.vector.lisp + 2: meta.parens.lisp punctuation.section.parens.begin.lisp + push: macro-vector-body + # Bit vector + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node32.html + - match: (#\d*\*)([01]*){{break}} + scope: meta.vector.lisp + captures: + 1: punctuation.definition.vector.lisp + 2: meta.number.integer.binary constant.numeric.value.lisp + + macro-vector-body: + - meta_scope: meta.vector.lisp + - meta_content_scope: meta.parens.lisp + - match: \) + scope: meta.parens.lisp punctuation.section.parens.end.lisp + pop: 1 + - include: parens + - include: expressions + + macro-throw-exceptions: + - match: '#[ \t\n\r)<]' + scope: keyword.control.exception.throw.lisp + + macro-variables: + # Inline runtime/loadtime eval + - match: \#[.,:] + scope: punctuation.definition.variable.lisp + # Local assignment + - match: ((#)\d+)\s*(=) + captures: + 1: variable.other.local.lisp + 2: punctuation.definition.variable.lisp + 3: keyword.operator.assignment.lisp + - match: (#)(\d+)(#) + scope: variable.other.lisp + captures: + 1: punctuation.definition.variable.begin.lisp + 2: variable.other.local.lisp + 3: punctuation.definition.variable.end.lisp + +###[ OPERATORS ]############################################################### + + modifiers: + # https://www.lispworks.com/documentation/lw70/CLHS/Body/02_df.htm + - match: '[`'']' + scope: punctuation.definition.quoted.lisp + - match: ',@?' + scope: punctuation.definition.variable.lisp + + operator: + # Contains 'Standardized Compound Type Specifier Names' + # https://www.lispworks.com/documentation/lw70/CLHS/Body/04_bc.htm + - match: (?:(?:/=|>=|<=|=|>|<)|(?i:max|min|eq|neq|eql|equalp|equal)){{break}} + scope: keyword.operator.comparison.lisp + pop: 1 + - match: ={{break}} + scope: keyword.operator.assignment.lisp + pop: 1 + - match: (?:[-+*/]|(?i:mod|rem|incf|decf)){{break}} + scope: keyword.operator.arithmetic.lisp + pop: 1 + - match: (?i:and|or|not|satisfies){{break}} + scope: keyword.operator.logical.lisp + pop: 1 + - match: (?i:logand|logior|logxor|lognor|logeqv){{break}} + scope: keyword.operator.bitwise.lisp + pop: 1 + +###[ LITERALS ]################################################################ + + numbers: + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node16.html + # https://www.lispworks.com/documentation/lw70/CLHS/Body/02_ca.htm + # decimal floating point + - match: |- + (?x) + ( [-+]? ) + ( \d* (?: (\.) \d+ ) {{exponent}}? + | \d+ (?: (\.) \d* )? {{exponent}}) + {{break}} + scope: meta.number.float.decimal.lisp + captures: + 1: keyword.operator.arithmetic.lisp + 2: constant.numeric.value.lisp + 3: punctuation.separator.decimal.lisp + 4: punctuation.separator.decimal.lisp + # decimal rational numbers + - match: |- + (?x) + ( [-+]? ) + ( \d+ (/) \d+ ) + {{break}} + scope: meta.number.rational.decimal.lisp + captures: + 1: keyword.operator.arithmetic.lisp + 2: constant.numeric.value.lisp + 3: keyword.operator.arithmetic.lisp + # decimal integer numbers + - match: |- + (?x) + ( [-+]? ) + ( \d+ (?: (\.)(?!\d) | {{break}} ) ) + scope: meta.number.integer.decimal.lisp + captures: + 1: keyword.operator.arithmetic.lisp + 2: constant.numeric.value.lisp + 3: punctuation.separator.decimal.lisp + + strings: + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node31.html + - match: \" + scope: punctuation.definition.string.begin.lisp + push: string-body + + string-body: + - meta_include_prototype: false + - meta_scope: meta.string.lisp string.quoted.double.lisp + - match: \" + scope: punctuation.definition.string.end.lisp + pop: 1 + - match: \\. + scope: constant.character.escape.lisp + - include: string-format-mini-language + + string-format-mini-language: + # https://www.hexstreamsoft.com/articles/common-lisp-format-reference/clhs-summary/#subsections-summary-table + - match: (~)(\d*)[%&|~] + scope: constant.character.escape.lisp + captures: + 1: punctuation.definition.placeholder.lisp + # 2: constant.numeric.integer.decimal.lisp + - match: (~):?@?[CR] + scope: constant.other.placeholder.lisp + captures: + 1: punctuation.definition.placeholder.lisp + # ~R + - match: |- + (?x: + (~) + (?:(\d*) # Radix + (?:(,)\d* # mincol + (?:(,)(?:'.)? # padchar + (?:(,)(?:'.)? # comma-char + (?:(,)\d*)? # comma-interval + )?)?)?) + ):?@?[rR] + scope: constant.other.placeholder.lisp + captures: + 1: punctuation.definition.placeholder.lisp + 2: punctuation.definition.numeric.base.lisp + 3: punctuation.separator.sequence.lisp + 4: punctuation.separator.sequence.lisp + 5: punctuation.separator.sequence.lisp + 6: punctuation.separator.sequence.lisp + # ~b, ~o, ~d, ~x + - match: |- + (?x: + (~) + (?:\d* # mincol + (?:(,)(?:'.)? # padchar + (?:(,)(?:'.)? # comma-char + (?:(,)\d*)? # comma-interval + )?)?)? + ):?@?[bBoOdDxX] + scope: constant.other.placeholder.lisp + captures: + 1: punctuation.definition.placeholder.lisp + 2: punctuation.separator.sequence.lisp + 3: punctuation.separator.sequence.lisp + 4: punctuation.separator.sequence.lisp + # ~f + - match: |- + (?x: + (~) + (?:\d* # width + (?:(,)\d* # decimals + (?:(,)\d* # scale + (?:(,)(?:'.)? # overflowchar + (?:(,)(?:'.)? # padchar + )?)?)?)?)? + )@?[fF] + scope: constant.other.placeholder.lisp + captures: + 1: punctuation.definition.placeholder.lisp + 2: punctuation.separator.sequence.lisp + 3: punctuation.separator.sequence.lisp + 4: punctuation.separator.sequence.lisp + 5: punctuation.separator.sequence.lisp + # ~e, ~g + - match: |- + (?x: + (~) + (?:\d* # width + (?:(,)\d* # decimals + (?:(,)\d* # exponent-width + (?:(,)\d* # scale + (?:(,)(?:'.)? # overflowchar + (?:(,)(?:'.)? # padchar + (?:(,)(?:'.)? # exponentchar + )?)?)?)?)?)?)? + )@?[eEgG] + scope: constant.other.placeholder.lisp + captures: + 1: punctuation.definition.placeholder.lisp + 2: punctuation.separator.sequence.lisp + 3: punctuation.separator.sequence.lisp + 4: punctuation.separator.sequence.lisp + 5: punctuation.separator.sequence.lisp + 6: punctuation.separator.sequence.lisp + 7: punctuation.separator.sequence.lisp + # ~$ + - match: |- + (?x: + (~) + (?:\d* # decimals + (?:(,)\d* # min-units + (?:(,)\d* # min-width + (?:(,)(?:'.)? # padchar + )?)?)?)? + ):?@?\$ + scope: constant.other.placeholder.lisp + captures: + 1: punctuation.definition.placeholder.lisp + 2: punctuation.separator.sequence.lisp + 3: punctuation.separator.sequence.lisp + 4: punctuation.separator.sequence.lisp + # ~a, ~s + - match: |- + (?x: + (~) + (?:\d* # min-col + (?:(,)\d* # col-inc + (?:(,)\d* # min-pad + (?:(,)(?:'.)? # padchar + )?)?)?)? + ):?@?[aAsS] + scope: constant.other.placeholder.lisp + captures: + 1: punctuation.definition.placeholder.lisp + 2: punctuation.separator.sequence.lisp + 3: punctuation.separator.sequence.lisp + 4: punctuation.separator.sequence.lisp + +###[ SYMBOLS ]################################################################# + + annotations: + - match: (&){{identifier}} + scope: variable.annotation.lisp + captures: + 1: punctuation.definition.annotation.lisp + 2: punctuation.definition.symbol.begin.lisp + 3: punctuation.definition.symbol.end.lisp + + keywords: + # The colon : is a package marker. + # If the package name is missing, the symbol is in the KEYWORD package. + - match: (::?)({{identifier}}) + captures: + 1: punctuation.accessor.lisp + 2: keyword.other.symbol.lisp + 3: punctuation.definition.symbol.begin.lisp + 4: punctuation.definition.symbol.end.lisp + - match: \.{{break}} + scope: keyword.control.lisp + + identifiers: + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node27.html + # Pushing a dedicated context reduces syntax cache size + # and increases parsing performance, significantly. + - match: (?={{identifier}}) + push: identifier + + identifier: + - include: namespaces + # types + - match: '{{builtin_types}}' + scope: storage.type.lisp + pop: 1 + # constants + - match: (?i:false){{break}} + scope: constant.language.boolean.false.lisp + pop: 1 + - match: (?i:true){{break}} + scope: constant.language.boolean.true.lisp + pop: 1 + - match: (?i:nil|null){{break}} + scope: constant.language.null.lisp + pop: 1 + - match: '{{builtin_constants}}' + scope: constant.language.lisp + pop: 1 + - match: \+\S+\+{{break}} + scope: constant.other.lisp + pop: 1 + # variables + - match: '{{builtin_variables}}' + scope: variable.language.lisp + pop: 1 + - match: '{{identifier}}' + scope: variable.other.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: immediately-pop + + parameters: + # parameter with initial value + - match: \( + scope: punctuation.section.parens.begin.lisp + push: + - paren-body + - parameter-name + # parameter without initial value + - match: '{{identifier}}' + scope: variable.parameter.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + + parameter-name: + - include: annotations + - include: keywords + - include: modifiers + - match: '{{identifier}}' + scope: variable.parameter.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + pop: 1 + - include: comments + - include: else-pop + + namespaces: + # built-in namespace indicating keyword symbols + # note: accessor is consumed by `keywords` context + - match: (\|?)keyword(\|?)(?=:) + scope: variable.namespace.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + # normal namespaces but not an escaped char #\: + - match: ((?!#\\?){{identifier}})(::?) + captures: + 1: variable.namespace.lisp + 2: punctuation.definition.symbol.begin.lisp + 3: punctuation.definition.symbol.end.lisp + 4: punctuation.accessor.lisp + + variables: + # Symbols evaluate to their values + # https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node27.html + - match: '{{identifier}}' + scope: variable.other.lisp + captures: + 1: punctuation.definition.symbol.begin.lisp + 2: punctuation.definition.symbol.end.lisp + +###[ PROTOTYPES ]############################################################## + + else-pop: + - match: (?=\S) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + paren-pop: + - match: (?=\)) + pop: 1 + +############################################################################### + +variables: + + # variables / keyword-symbols + identifier: (?:{{identifier_char}}*{{identifier_must_have}}{{identifier_char}}*|{{quoted_identifier}}) + identifier_char: (?:\\.|[^{{break_char}}]) + identifier_must_have: (?:\\.|[^\d.{{break_char}}]) # May not be only digits or periods + quoted_identifier: (\|)(?:\\.|[^|])*(\|) + + break: (?={{break_char}}|$) + break_char: '[\s()"'',:;|]' + + # characters + standard_char: '[0-9A-Za-z!"#$%&''()*+,\-./:;<=>?@\\\[\]^_`{|}~]' + char_attributes: (?:(?:[[:alnum:]_]+-)+\\?) + + # numbers + exponent: (?:[esfdlESFDL][-+]?\d+) + + declaration_keywords: |- + (?xi: + declaim + | define-(?: compiler-macro | condition | declaration | method-combination | modify-macro | setf-method ) + | def(?: class | constant | generic | macro | method | package | parameter | setf | struct | type | un | var ) + | generic-(?: flet | function | labels ) + | flet + | labels + | let\*? + | locally + | macrolet + | multiple-value-bind + | proclaim + | prog\*? + | with-(?: accessors | added-methods | condition-restarts | input-from-string | open-file | open-stream | output-to-string | standard-io-syntax ) + ){{break}} + + declaration_identifiers: |- + (?xi: + dynamic-extent + | ftype + | ignorable + | ignore + | inline + | notinline + | optimize + | special + | type + ){{break}} + + builtin_constants: |- + (?xi: + t | true | false | null | nil | pi + | array-(?: rank | dimension | total-size )-limit + | call-arguments-limit + | char-(?: (?: super | hyper | meta | control )-bit | (?: font | code | bits )-limit ) + | internal-time-units-per-second + | lambda-(?: parameters-limit | list-keywords ) + | least-(?: positive | negative )-normalized-(?: single | short | long | double )-float + | most-(?: positive | negative )-fixnum + | (?: most | least )-(?: positive | negative )-(?: single | short | long | double )-float + | multiple-values-limit + | (?: single | short | long | double )-float-(?: negative- )?epsilon + ){{break}} + + builtin_functions: |- + (?xi: + abort + | abs + | acons + | acos + | acosh + | add-method + | adjoin + | adjust-array + | adjustable-array-p + | alpha-char-p + | alphanumericp + | alter + | append + | appending + | apply + | applyhook + | apropos + | apropos-list + | aref + | arithmetic-error-operands + | arithmetic-error-operation + | array-dimension + | array-dimensions + | array-element-type + | array-has-fill-pointer-p + | array-in-bounds-p + | array-rank + | array-row-major-index + | array-total-size + | arrayp + | ash + | asin + | asinh + | assert + | assoc + | assoc-if + | assoc-if-not + | atan + | atanh + | atom + | augment-environment + | bit + | bit-and + | bit-andc1 + | bit-andc2 + | bit-eqv + | bit-ior + | bit-nand + | bit-nor + | bit-not + | bit-orc1 + | bit-orc2 + | bit-vector-p + | bit-xor + | boole + | both-case-p + | boundp + | break + | broadcast-stream-streams + | butlast + | byte + | byte-position + | byte-size + | caaaar + | caaadr + | caaar + | caadar + | caaddr + | caadr + | caar + | cadaar + | cadadr + | cadar + | caddar + | cadddr + | caddr + | cadr + | call-method + | call-next-method + | car + | catenate + | ccase + | cdaaar + | cdaadr + | cdaar + | cdadar + | cdaddr + | cdadr + | cdar + | cddaar + | cddadr + | cddar + | cdddar + | cddddr + | cdddr + | cddr + | cdr + | ceiling + | cell-error-name + | cerror + | change-class + | char + | char-bit + | char-bits + | char-code + | char-downcase + | char-equal + | char-font + | char-greaterp + | char-int + | char-lessp + | char-name + | char-not-equal + | char-not-greaterp + | char-not-lessp + | char-upcase + | char/= + | char< + | char<= + | char= + | char> + | char>= + | character + | characterp + | check-type + | choose + | choose-if + | chunk + | cis + | class-name + | class-of + | clear-input + | close + | clrhash + | code-char + | coerce + | collect + | collect-alist + | collect-and + | collect-append + | collect-file + | collect-first + | collect-fn + | collect-hash + | collect-last + | collect-length + | collect-max + | collect-min + | collect-nconc + | collect-nth + | collect-or + | collect-plist + | collect-sum + | collecting + | collecting-fn + | commonp + | compile + | compile-file + | compile-file-pathname + | compiled-function-p + | compiler-let + | compiler-macro-function + | compiler-macroexpand + | compiler-macroexpand-1 + | complement + | complex + | complexp + | compute-applicable-methods + | compute-restarts + | concatenate + | concatenated-stream-streams + | conjugate + | cons + | consp + | constantp + | continue + | copy-alist + | copy-list + | copy-pprint-dispatch + | copy-readtable + | copy-seq + | copy-symbol + | copy-tree + | cos + | cosh + | cotruncate + | count + | count-if + | count-if-not + | counting + | declaim + | declaration-information + | decode-float + | decode-universal-time + | delete + | delete-duplicates + | delete-file + | delete-if + | delete-if-not + | delete-package + | denominator + | deposit-field + | describe + | describe-object + | destructuring-bind + | digit-char + | digit-char-p + | directory + | directory-namestring + | disassemble + | do-all-keyword-symbols + | do-external-keyword-symbols + | do-keyword-symbols + | documentation + | dolist + | dpb + | dribble + | ecase + | echo-stream-input-stream + | echo-stream-output-stream + | ed + | eighth + | elt + | encapsulated + | enclose + | encode-universal-time + | endp + | enough-namestring + | ensure-generic-function + | error + | eval + | evalhook + | evenp + | every + | exp + | expand + | export + | expt + | f + | fboundp + | fdefinition + | ffloor + | fifth + | file-author + | file-error-pathname + | file-length + | file-namestring + | file-position + | file-string-length + | file-write-date + | fill + | fill-pointer + | find + | find-all-keyword-symbols + | find-class + | find-if + | find-if-not + | find-method + | find-package + | find-restart + | find-symbol + | finish-output + | first + | float + | float-digits + | float-precision + | float-radix + | float-sign + | floatp + | floor + | format + | formatter + | fourth + | funcall + | function-information + | function-keywords + | function-lambda-expression + | functionp + | gatherer + | gathering + | gcd + | generator + | generic-function + | gensym + | gentemp + | get + | get-decoded-time + | get-internal-real-time + | get-internal-run-time + | get-output-stream-string + | get-properties + | get-setf-method + | get-setf-method-multiple-value + | get-universal-time + | getf + | gethash + | graphic-char-p + | handler-bind + | handler-case + | hash-table-count + | hash-table-p + | hash-table-rehash-size + | hash-table-rehash-threshold + | hash-table-size + | hash-table-test + | host-namestring + | identity + | ignore-errors + | imagpart + | import + | in-package + | initialize-instance + | input-stream-p + | inspect + | int-char + | integer-decode-float + | integer-length + | integerp + | interactive-stream-p + | intern + | intersection + | invalid-method-error + | invoke-debugger + | invoke-restart + | isqrt + | iterate + | keywordp + | last + | latch + | lcm + | ldb + | ldb-test + | ldiff + | length + | lisp-implementation-type + | lisp-implementation-version + | list + | list-all-packages + | list-length + | list\* + | listen + | listp + | load + | load-logical-pathname-translations + | locally + | log + | logandc1 + | logandc2 + | logbitp + | logcount + | logical-pathname + | logical-pathname-translations + | lognand + | lognot + | logorc1 + | logorc2 + | logtest + | long-site-name + | loop-finish + | lower-case-p + | machine-instance + | machine-type + | machine-version + | macro-function + | macroexpand + | macroexpand-1 + | make-array + | make-broadcast-stream + | make-char + | make-concatenated-stream + | make-condition + | make-dispatch-macro-character + | make-echo-stream + | make-hash-table + | make-instance + | make-instances-obsolete + | make-list + | make-load-form + | make-load-form-saving-slots + | make-package + | make-pathname + | make-random-state + | make-sequence + | make-string + | make-string-input-stream + | make-string-output-stream + | make-symbol + | make-synonym-stream + | make-two-way-stream + | makunbound + | map + | map-fn + | map-into + | maphash + | mapping + | mask + | mask-field + | maximize + | maximizing + | member + | member-if + | member-if-not + | memberp + | merge + | merge-pathnames + | method-combination-error + | method-qualifiers + | mingle + | minimize + | minimizing + | minusp + | mismatch + | muffle-warning + | multiple-value-bind + | multiple-value-list + | multiple-value-setq + | name-char + | namestring + | nbutlast + | nconc + | nconcing + | next-in + | next-method-p + | next-out + | nintersection + | ninth + | no-applicable-method + | no-next-method + | notany + | notevery + | nreconc + | nreverse + | nset-difference + | nset-exclusive-or + | nstring-capitalize + | nstring-downcase + | nstring-upcase + | nsublis + | nsubst + | nsubst-if + | nsubst-if-not + | nsubstitute + | nsubstitute-if + | nsubstitute-if-not + | nth + | nth-value + | nthcdr + | numberp + | numerator + | nunion + | oddp + | open + | open-stream-p + | output-stream-p + | package-error-package + | package-name + | package-nicknames + | package-shadowing-keyword-symbols + | package-use-list + | package-used-by-list + | packagep + | pairlis + | parse-integer + | parse-macro + | parse-namestring + | pathname + | pathname-device + | pathname-directory + | pathname-host + | pathname-match-p + | pathname-name + | pathname-type + | pathname-version + | pathnamep + | peek-char + | phase + | plusp + | pop + | position + | position-if + | position-if-not + | positions + | pprint-dispatch + | pprint-exit-if-list-exhausted + | pprint-fill + | pprint-indent + | pprint-linear + | pprint-logical-block + | pprint-newline + | pprint-pop + | pprint-tab + | pprint-tabular + | previous + | prin1 + | print + | print-object + | print-unreadable-object + | probe-file + | producing + | prog1 + | prog2 + | progn + | provide + | psetf + | psetq + | push + | pushnew + | quote + | random + | random-state-p + | rassoc + | rassoc-if + | rassoc-if-not + | rational + | rationalize + | rationalp + | read + | read-byte + | read-char + | read-char-no-hang + | read-delimited-list + | read-from-string + | read-line + | read-preserving-whitespace + | readtable-case + | readtablep + | realp + | realpart + | reduce + | reinitialize-instance + | remf + | remhash + | remove + | remove-duplicates + | remove-method + | remprop + | rename-file + | rename-package + | replace + | require + | rest + | restart-bind + | restart-case + | restart-name + | result-of + | revappend + | reverse + | room + | rotatef + | round + | row-major-aref + | rplaca + | rplacd + | sbit + | scale-float + | scan + | scan-alist + | scan-file + | scan-fn + | scan-fn-inclusive + | scan-hash + | scan-lists-of-lists + | scan-lists-of-lists-fringe + | scan-multiple + | scan-plist + | scan-range + | scan-sublists + | scan-symbols + | schar + | search + | second + | series + | set + | set-char-bit + | set-difference + | set-dispatch-macro-character + | set-exclusive-or + | set-macro-character + | set-pprint-dispatch + | set-syntax-from-char + | setf + | setq + | seventh + | shadow + | shadowing-import + | shared-initialize + | shiftf + | short-site-name + | signal + | signum + | simple-bit-vector-p + | simple-condition-format-arguments + | simple-condition-format-string + | simple-string-p + | simple-vector-p + | sin + | sinh + | sixth + | sleep + | slot-boundp + | slot-exists-p + | slot-makunbound + | slot-missing + | slot-unbound + | slot-value + | software-type + | software-version + | some + | sort + | special-form-p + | split + | split-if + | sqrt + | stable-sort + | standard-char-p + | step + | store-value + | stream-element-type + | stream-error-stream + | stream-external-format + | streamp + | string + | string-capitalize + | string-downcase + | string-equal + | string-greaterp + | string-left-trim + | string-lessp + | string-not-equal + | string-not-greaterp + | string-not-lessp + | string-right-trim + | string-trim + | string-upcase + | string/= + | string< + | string<= + | string= + | string> + | string>= + | stringp + | sublis + | subseq + | subseries + | subsetp + | subst + | subst-if + | subst-if-not + | substitute + | substitute-if + | substitute-if-not + | subtypep + | sum + | summing + | svref + | sxhash + | symbol-function + | symbol-name + | symbol-package + | symbol-plist + | symbol-value + | symbolp + | synonym-stream-symbol + | tailp + | tan + | tanh + | tenth + | terminate-producing + | terpri + | third + | time + | to-alter + | trace + | translate-logical-pathname + | translate-pathname + | tree-equal + | truename + | truncate + | two-way-stream-input-stream + | two-way-stream-output-stream + | type-error-datum + | type-error-expected-type + | type-of + | typep + | unexport + | unintern + | union + | unread-char + | untrace + | unuse-package + | update-instance-for-different-class + | update-instance-for-redefined-class + | upgraded-array-element-type + | upgraded-complex-part-type + | upper-case-p + | use-package + | use-value + | user-homedir-pathname + | values + | values-list + | variable-information + | vector + | vector-pop + | vector-push + | vector-push-extend + | vectorp + | warn + | wild-pathname-p + | with-compilation-unit + | with-hash-table-iterator + | with-package-iterator + | with-simple-restart + | with-standard-io-syntax + | write + | write-byte + | write-char + | write-string + | write-to-string + | y-or-n-p + | yes-or-no-p + | zerop + ){{break}} + + # Built-in atomic type specifiers + # https://www.lispworks.com/documentation/lw70/CLHS/Body/04_bc.htm + # Note: Some of them are scoped function when appearing as first list item. + builtin_types: |- + (?xi: + arithmetic-error + | array + | atom + | base-char + | base-string + | bignum + | bit + | bit-vector + | broadcast-stream + | built-in-class + | cell-error + | character + | class + | compiled-function + | complex + | concatenated-stream + | condition + | cons + | control-error + | division-by-zero + | double-float + | echo-stream + | end-of-file + | error + | extended-char + | file-error + | file-stream + | fixnum + | float + | floating-point-inexact + | floating-point-invalid-operation + | floating-point-overflow + | floating-point-underflow + | function + | generic-function + | hash-table + | integer + | keyword + | list + | logical-pathname + | long-float + | method + | method-combination + | number + | package + | package-error + | parse-error + | pathname + | print-not-readable + | program-error + | random-state + | ratio + | rational + | reader-error + | readtable + | real + | restart + | sequence + | serious-condition + | short-float + | signed-byte + | simple-array + | simple-base-string + | simple-bit-vector + | simple-condition + | simple-error + | simple-string + | simple-type-error + | simple-vector + | simple-warning + | single-float + | standard-char + | standard-class + | standard-generic-function + | standard-method + | standard-object + | storage-condition + | stream + | stream-error + | string + | string-stream + | structure-class + | structure-object + | style-warning + | symbol + | synonym-stream + | two-way-stream + | type-error + | unbound-slot + | unbound-variable + | undefined-function + | unsigned-byte + | vector + | warning + ){{break}} + + builtin_variables: |- + \*(?xi: + applyhook + | break-on-signals + | break-on-warnings + | compile-file-pathname + | compile-file-truename + | compile-print + | compile-verbose + | debug-io + | debugger-hook + | default-pathname-defaults + | error-output + | evalhook + | features + | gensym-counter + | load-pathname + | load-print + | load-truename + | load-verbose + | macroexpand-hook + | modules + | package + | print-array + | print-base + | print-case + | print-circle + | print-escape + | print-gensym + | print-length + | print-level + | print-lines + | print-miser-width + | print-pprint-dispatch + | print-pretty + | print-radix + | print-readably + | print-right-margin + | query-io + | random-state + | read-base + | read-default-float-format + | read-eval + | read-suppress + | readtable + | standard-input + | standard-output + | suppress-series-warnings + | terminal-io + | trace-output + )\*{{break}}
diff --git /dev/null b/syntax/OCaml/OCaml.sublime-syntax @@ -0,0 +1,775 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: OCaml +scope: source.ocaml + +file_extensions: + - ml + - mli + +first_line_match: |- + (?xi: + ^ \s* \(\* .*? -\*- .*? \bocaml\b .*? -\*- # editorconfig + ) + +variables: + sign: (?:-|\b) + suffix: (?:[lLn]|(?!\.))\b + bin_digit: '[01_]' + oct_digit: '[0-7_]' + dec_digit: '[0-9_]' + hex_digit: '[\h_]' + bin_integer: (?:[01]{{bin_digit}}*) + oct_integer: (?:[0-7]{{oct_digit}}*) + dec_integer: (?:[0-9]{{dec_digit}}*) + hex_integer: (?:\h{{hex_digit}}*) + exponent: '[-+]??(_?){{dec_integer}}' + dec_exponent: (?:[Ee]{{exponent}}) + hex_exponent: (?:[Pp]{{exponent}}) + + identifier: '[a-z][a-zA-Z0-9''_]*' + capIdentifier: '[A-Z][a-zA-Z0-9''_]*' + +contexts: + main: + - match: '\b(let)\s+(module)\s+({{capIdentifier}})\s*(=)' + scope: meta.module.binding + captures: + 1: keyword.other.module-binding.ocaml + 2: keyword.other.module-definition.ocaml + 3: support.other.module.ocaml + 4: punctuation.separator.module-binding.ocaml + - match: \b(let|and)\s+(open)\s+{{capIdentifier}}(\.{{capIdentifier}})*\b + captures: + 1: keyword.other.ocaml + 2: keyword.control.import.ocaml + - match: '\b(let|and)\s+(?!\(\*)((rec\s+)([a-z_][a-zA-Z0-9_'']*)\b|([a-z_][a-zA-Z0-9_'']*|\([^)]+\))(?=\s)((?=\s*=\s*(?=fun(?:ction)\b))|(?!\s*=)))' + captures: + 1: keyword.other.function-definition.ocaml + 3: keyword.other.function-definition.ocaml + 4: entity.name.function.ocaml + 5: entity.name.function.ocaml + push: + - meta_scope: meta.function.ocaml + - match: '(?:(:)\s*([^=]+))?(?:(=)|(=)\s*(?=fun(?:ction)\b))' + captures: + 1: punctuation.separator.function.type-constraint.ocaml + 2: storage.type.ocaml + 3: keyword.operator.ocaml + 4: keyword.operator.ocaml + pop: true + - include: variables + - match: \b(let|and)\s+({{identifier}})\s*(=)\s* + captures: + 1: keyword.other.ocaml + 2: variable.other.constant.ocaml + 3: keyword.operator.assignment.ocaml + - match: (\(|\s)(?=fun\s) + captures: + 1: punctuation.definition.function.anonymous.ocaml + push: + - meta_scope: meta.function.anonymous.ocaml + - match: (\)) + captures: + 1: punctuation.definition.function.anonymous.ocaml + pop: true + - match: (?<=(\(|\s))(fun)\s + captures: + 2: keyword.other.function-definition.ocaml + push: + - meta_scope: meta.function.anonymous.definition.ocaml + - match: (->) + captures: + 1: punctuation.separator.function-definition.ocaml + pop: true + - include: variables + - include: main + - match: ^\s*(?=type\s) + push: + - meta_scope: meta.type-definition-group.ocaml + - match: \b(?=let|end|val)|^\s*$ + pop: true + - match: '\b(type|and)\s+([^=]*)(=)?' + captures: + 1: keyword.other.type-definition.ocaml + 2: storage.type.ocaml + 3: punctuation.separator.type-definition.ocaml + push: + - meta_scope: meta.type-definition.ocaml + - match: (?=\b(type|and|let|end|val)\b)|(?=^\s*$) + pop: true + - include: typedefs + - match: \b(with|function)(?=(\s*$|.*->))\b|((?<!\S)(\|)(?=(\w|\s).*->)) + captures: + 1: keyword.control.match-definition.ocaml + 2: keyword.other.function-definition.ocaml + 3: keyword.control.match-definition.ocaml + push: + - meta_scope: meta.pattern-match.ocaml + - match: (?:(->)|\b(when)\b|\s(?=\|)) + captures: + 1: punctuation.separator.match-definition.ocaml + 2: keyword.control.match-condition.ocaml + pop: true + - include: matchpatterns + - match: '^[ \t]*(class\s+type\s+)((\[\s*(''[A-Za-z][a-zA-Z0-9_'']*(?:\s*,\s*''[A-Za-z][a-zA-Z0-9_'']*)*)\s*\]\s+)?[a-z_][a-zA-Z0-9''_]*)' + scope: meta.class.type-definition.ocaml + captures: + 1: keyword.other.class-type-definition.ocaml + 2: entity.name.type.class-type.ocaml + 4: storage.type.ocaml + - match: '^[ \t]*(class)(?:\s+(?!(?:virtual)\s+))((\[\s*(''[A-Za-z][a-zA-Z0-9_'']*(?:\s*,\s*''[A-Za-z][a-zA-Z0-9_'']*)*)\s*\]\s+)?[a-z_][a-zA-Z0-9''_]*)' + captures: + 1: keyword.other.class-definition.ocaml + 2: entity.name.type.class.ocaml + 4: storage.type.ocaml + push: + - meta_scope: meta.class.ocaml + - match: (=) + captures: + 1: keyword.operator.ocaml + pop: true + - include: variables + - match: '^[ \t]*(class\s+virtual\s+)((\[\s*(''[A-Za-z][a-zA-Z0-9_'']*(?:\s*,\s*''[A-Za-z][a-zA-Z0-9_'']*)*)\s*\]\s+)?[a-z_][a-zA-Z0-9''_]*)' + captures: + 1: keyword.other.class-definition.ocaml + 2: entity.name.type.class.ocaml + 4: storage.type.ocaml + push: + - meta_scope: meta.class.virtual.ocaml + - match: (=) + captures: + 1: keyword.operator.ocaml + pop: true + - include: variables + - match: '^[ \t]*(class\s+type\s+virtual)((\[\s*(''[A-Za-z][a-zA-Z0-9_'']*(?:\s*,\s*''[A-Za-z][a-zA-Z0-9_'']*)*)\s*\]\s+)?[a-z_][a-zA-Z0-9''_]*)' + scope: meta.class.virtual.type-definition.ocaml + captures: + 1: keyword.other.class-type-definition.ocaml + 2: entity.name.type.class-type.ocaml + 4: storage.type.ocaml + - match: '\b(object)\s*(?:(\()(_?[a-z]+)(\)))?\s*$' + captures: + 1: keyword.other.object-definition.ocaml + 2: punctuation.definition.self-binding.ocaml + 3: entity.name.type.self-binding.ocaml + 4: punctuation.definition.self-binding.ocaml + push: + - meta_scope: meta.object.ocaml + - match: \b(end)\b + captures: + 1: keyword.control.object.ocaml + 2: punctuation.terminator.expression.ocaml + pop: true + - match: '\b(method)\s+(virtual\s+)?(private\s+)?([a-z_][a-zA-Z0-9''_]*)' + captures: + 1: keyword.other.method-definition.ocaml + 2: keyword.other.method-definition.ocaml + 3: keyword.other.method-restriction.ocaml + 4: entity.name.function.method.ocaml + push: + - meta_scope: meta.method.ocaml + - match: (=|:) + captures: + 1: keyword.operator.ocaml + pop: true + - include: variables + - match: '(constraint)\s+([a-z_''][a-zA-Z0-9''_]*)\s+(=)' + captures: + 1: keyword.other.language.ocaml + 2: storage.type.ocaml + 3: keyword.operator.ocaml + push: + - meta_scope: meta.object.type-constraint.ocaml + - match: '(#[a-z_][a-zA-Z0-9''_]*)|(int|char|float|string|list|array|bool|unit|exn|option|int32|int64|nativeint|format4|lazy_t)|([a-z_][a-zA-Z0-9''_]*)\s*$' + captures: + 1: storage.type.polymorphic-variant.ocaml + 2: storage.type.ocaml + 3: storage.type.ocaml + pop: true + - include: main + - match: '(?<=\w|\)|'')(#)[a-z_][a-zA-Z0-9''_]*' + scope: meta.method-call.ocaml + captures: + 1: punctuation.separator.method-call.ocaml + - match: '^[ \t]*(module)\s+([A-Z_][a-zA-Z0-9''_]*)(?:\s*(:)\s*([A-Z][a-zA-Z0-9''_]*)?)?' + scope: meta.module.ocaml + captures: + 1: keyword.other.module-definition.ocaml + 2: entity.name.type.module.ocaml + 3: punctuation.separator.module-definition.ocaml + 4: entity.name.type.module-type.ocaml + - match: '^[ \t]*(module\s+type\s+)([A-Z][a-zA-Z0-9''_]*)' + scope: meta.module.type.ocaml + captures: + 1: keyword.other.module-type-definition.ocaml + 2: entity.name.type.module-type.ocaml + - match: \b(sig)\b + captures: + 1: keyword.other.module.signature.ocaml + push: + - meta_scope: meta.module.signature.ocaml + - match: \b(end)\b + captures: + 1: keyword.other.module.signature.ocaml + 2: punctuation.terminator.expression.ocaml + 3: keyword.operator.ocaml + pop: true + - include: module-signature + - include: main + - match: \b(struct)\b + captures: + 1: keyword.other.module.structure.ocaml + push: + - meta_scope: meta.module.structure.ocaml + - match: \b(end)\b + captures: + 1: keyword.other.module.structure.ocaml + pop: true + - include: main + - include: moduleref + - match: '\b(open)\s+([A-Z][a-zA-Z0-9''_]*)(?=(\.[A-Z][a-zA-Z0-9_]*)*)' + captures: + 1: keyword.other.ocaml + 2: support.other.module.ocaml + push: + - meta_scope: meta.module.open.ocaml + - match: (\s|$) + pop: true + - match: '(\.)([A-Z][a-zA-Z0-9''_]*)' + scope: support.other.module.ocaml + captures: + 1: punctuation.separator.module-reference.ocaml + - match: '\b(exception)\s+([A-Z][a-zA-Z0-9''_]*)\b' + scope: meta.exception.ocaml + captures: + 1: keyword.other.ocaml + 2: entity.name.type.exception.ocaml + - match: '(?=(\[<)(?![^\[]+?[^>]]))' + push: + - meta_scope: source.camlp4.embedded.ocaml + - match: "(>])" + captures: + 1: punctuation.definition.camlp4-stream.ocaml + pop: true + - include: scope:source.camlp4.ocaml + - include: strings + - include: constants + - include: comments + - include: arrays + - include: lists + - include: records + - match: '(\()(?=(~[a-z][a-zA-Z0-9_]*:|("(\\"|[^"])*")|[^\(\)~"])+(?<!:)(:>|:(?![:=])))' + captures: + 1: punctuation.section.type-constraint.ocaml + push: + - meta_scope: meta.type-constraint.ocaml + - match: '(?<!:)(:>|:(?![:=]))(.*?)(\))' + captures: + 1: punctuation.separator.type-constraint.ocaml + 2: storage.type.ocaml + 3: punctuation.section.type-constraint.ocaml + pop: true + - include: main + - match: '^[ \t]*#[a-zA-Z]+' + scope: keyword.control.directive.ocaml + - match: '^[ \t]*#[0-9]*' + scope: keyword.control.directive.line-number.ocaml + - include: storagetypes + - match: \b(mutable|ref)\b + scope: storage.modifier.ocaml + - match: '`[A-Za-z][a-zA-Z0-9''_]*\b' + scope: entity.name.type.variant.polymorphic.ocaml + - match: '\b[A-Z][a-zA-Z0-9''_]*\b' + scope: entity.name.type.variant.ocaml + - match: "!=|:=|>|<" + scope: keyword.operator.symbol.ocaml + - match: '[*+/-]\.' + scope: keyword.operator.infix.floating-point.ocaml + - match: ~-\. + scope: keyword.operator.prefix.floating-point.ocaml + - match: "::" + scope: punctuation.definition.list.constructor.ocaml + - match: ;; + scope: punctuation.terminator.expression.ocaml + - match: ; + scope: punctuation.separator.ocaml + - match: "->" + scope: punctuation.separator.function-return.ocaml + - match: '[=<>@^&+\-*/$%|][|!$%&*+./:<=>?@^~-]*' + scope: keyword.operator.infix.ocaml + - match: '\bnot\b|!|[!\?~][!$%&*+./:<=>?@^~-]+' + scope: keyword.operator.prefix.ocaml + - match: "~[a-z][a-z0-9'_]*(:)?" + scope: entity.name.tag.label.ocaml + captures: + 1: punctuation.separator.argument-label.ocaml + - match: \b(begin)\b + captures: + 1: keyword.control.begin-end.ocaml + push: + - meta_scope: meta.begin-end-group.ocaml + - match: \b(end)\b + captures: + 1: keyword.control.begin-end.ocaml + pop: true + - include: main + - match: \b(for)\b + captures: + 1: keyword.control.for-loop.ocaml + push: + - meta_scope: meta.for-loop.ocaml + - match: \b(done)\b + captures: + 1: keyword.control.for-loop.ocaml + pop: true + - match: \bdo\b + scope: keyword.control.loop.ocaml + - include: main + - match: \b(while)\b + captures: + 1: keyword.control.while-loop.ocaml + push: + - meta_scope: meta.while-loop.ocaml + - match: \b(done)\b + captures: + 1: keyword.control.while-loop.ocaml + pop: true + - match: \bdo\b + scope: keyword.control.loop.ocaml + - include: main + - match: \( + push: + - meta_scope: meta.paren-group.ocaml + - match: \) + pop: true + - include: main + - match: \b(and|land|lor|lsl|lsr|lxor|mod|or)\b + scope: keyword.operator.ocaml + - match: \b(downto|if|else|match|then|to|when|with|try)\b + scope: keyword.control.ocaml + - match: \b(as|assert|class|constraint|exception|functor|in|include|inherit|initializer|lazy|let|mod|module|mutable|new|object|open|private|rec|sig|struct|type|virtual)\b + scope: keyword.other.ocaml + - include: module-signature + - match: (β|β|β|β) + scope: invalid.illegal.unrecognized-character.ocaml + arrays: + - match: '(\[\|)' + captures: + 1: punctuation.definition.array.begin.ocaml + push: + - meta_scope: meta.array.ocaml + - match: '(\|])' + captures: + 1: punctuation.definition.array.end.ocaml + pop: true + - include: arrays + - include: main + comments: + - match: \(\*+(\*)\) + scope: comment.block.ocaml + captures: + 1: comment.block.empty.ocaml + - match: \(\* + push: + - meta_scope: comment.block.ocaml + - match: \*\) + pop: true + - include: comments + - match: '(?=[^\\])(")' + push: + - meta_scope: comment.block.string.quoted.double.ocaml + - match: '"' + pop: true + - match: '\\(x[a-fA-F0-9][a-fA-F0-9]|[0-2]\d\d|[bnrt''"\\])' + scope: comment.block.string.constant.character.escape.ocaml + - include: merge-conflict-markers + - include: merge-conflict-markers + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + constants: + - match: '(?:\[\s*(\])|\((\))|\(\s*(\)))' + scope: constant.language.pseudo-variable.ocaml + captures: + 1: meta.empty-typing-pair.ocaml + 2: meta.empty-typing-pair.parens.ocaml + 3: meta.empty-typing-pair.ocaml + - match: \bfalse\b + scope: constant.language.boolean.false.ocaml + - match: \btrue\b + scope: constant.language.boolean.true.ocaml + - match: '''(.|\\(x[a-fA-F0-9][a-fA-F0-9]|[0-2]\d\d|[bnrt''"\\]))''' + scope: constant.character.ocaml + + # http://caml.inria.fr/pub/docs/manual-ocaml/lex.html + # hexadecimal floats + - match: ({{sign}})(0[xX])((_*){{hex_integer}}(?:(\.){{hex_digit}}*{{hex_exponent}}?|{{hex_exponent}})) + scope: meta.number.float.hexadecimal.ocaml + captures: + 1: keyword.operator.arithmetic.ocaml + 2: constant.numeric.base.ocaml + 3: constant.numeric.value.ocaml + 4: invalid.illegal.numeric.ocaml + 5: punctuation.separator.decimal.ocaml + 6: invalid.illegal.numeric.ocaml + 7: invalid.illegal.numeric.ocaml + # decimal floats + - match: ({{sign}})({{dec_integer}}(?:(\.){{dec_digit}}*{{dec_exponent}}?|{{dec_exponent}})) + scope: meta.number.float.decimal.ocaml + captures: + 1: keyword.operator.arithmetic.ocaml + 2: constant.numeric.value.ocaml + 3: punctuation.separator.decimal.ocaml + 4: invalid.illegal.numeric.ocaml + 5: invalid.illegal.numeric.ocaml + # hexadecimal integers + - match: ({{sign}})(0[xX])(_*)({{hex_integer}}*)({{suffix}}) + scope: meta.number.integer.hexadecimal.ocaml + captures: + 1: keyword.operator.arithmetic.ocaml + 2: constant.numeric.base.ocaml + 3: invalid.illegal.numeric.ocaml + 4: constant.numeric.value.ocaml + 5: constant.numeric.suffix.ocaml + # octal integers + - match: ({{sign}})(0[oO])(_*)({{oct_integer}}*)({{suffix}}) + scope: meta.number.integer.octal.ocaml + captures: + 1: keyword.operator.arithmetic.ocaml + 2: constant.numeric.base.ocaml + 3: invalid.illegal.numeric.ocaml + 4: constant.numeric.value.ocaml + 5: constant.numeric.suffix.ocaml + # binary integers + - match: ({{sign}})(0[bB])(_*)({{bin_integer}}*)({{suffix}}) + scope: meta.number.integer.binary.ocaml + captures: + 1: keyword.operator.arithmetic.ocaml + 2: constant.numeric.base.ocaml + 3: invalid.illegal.numeric.ocaml + 4: constant.numeric.value.ocaml + 5: constant.numeric.suffix.ocaml + # decimal integers + - match: ({{sign}})({{dec_integer}})({{suffix}}) + scope: meta.number.integer.decimal.ocaml + captures: + 1: keyword.operator.arithmetic.ocaml + 2: constant.numeric.value.ocaml + 3: constant.numeric.suffix.ocaml + # invalid numbers + - match: '{{sign}}\d+.*\b' + scope: invalid.illegal.numeric.ocaml + + definite_storagetypes: + - include: storagetypes + - match: '\b[a-zA-Z0-9''_]+\b' + scope: storage.type.ocaml + lists: + - match: '(\[)(?!\||<|>)' + captures: + 1: punctuation.definition.list.begin.ocaml + push: + - meta_scope: meta.list.ocaml + - match: '(?<!\||>)(])' + captures: + 1: punctuation.definition.list.end.ocaml + pop: true + - include: lists + - include: main + matchpatterns: + - match: \b_\b + scope: constant.language.universal-match.ocaml + - match: \|(?=\s*\S) + scope: punctuation.separator.match-pattern.ocaml + - match: (\()(?=(?!=.*?->).*?\|) + captures: + 1: punctuation.definition.match-option.ocaml + push: + - meta_scope: meta.match-option.ocaml + - match: (\)) + captures: + 1: punctuation.definition.match-option.ocaml + pop: true + - match: \| + scope: punctuation.separator.match-option.ocaml + - include: matchpatterns + - include: moduleref + - include: constants + - include: variables + - include: main + module-signature: + - match: '(val)\s+(?:([a-z_][a-zA-Z0-9_'']*)|(\()([^\s)]+)(\)))\s*(:)' + captures: + 1: keyword.other.ocaml + 2: entity.name.type.value-signature.ocaml + 3: punctuation.section.parens.begin.ocaml + 4: entity.name.type.value-signature.ocaml + 5: punctuation.section.parens.end.ocaml + 6: punctuation.separator.type-constraint.ocaml + push: + - meta_scope: meta.module.signature.val.ocaml + - match: (?=\b(type|val|external|class|module|end)\b)|^\s*$ + pop: true + - match: '(\?)([a-z][a-zA-Z0-9_]*)\s*(:)' + scope: variable.parameter.optional.ocaml + captures: + 1: punctuation.definition.optional-parameter.ocaml + 2: entity.name.tag.label.optional.ocaml + 3: punctuation.separator.optional-parameter.ocaml + - match: '([a-z][a-zA-Z0-9''_]*)\s*(:)\s*' + captures: + 1: entity.name.tag.label.ocaml + 2: punctuation.separator.label.ocaml + 3: storage.type.ocaml + push: + - meta_scope: variable.parameter.labeled.ocaml + - match: \s + pop: true + - include: definite_storagetypes + - include: typedefs + - match: '(external)\s+([a-z_][a-zA-Z0-9_'']*)\s*(:)' + captures: + 1: keyword.other.ocaml + 2: entity.name.type.external-signature.ocaml + 3: punctuation.separator.type-constraint.ocaml + push: + - meta_scope: meta.module.signature.external.ocaml + - match: (?=\b(type|val|external|class|module|let|end)\b)|^\s*$ + pop: true + - match: '(\?)([a-z][a-zA-Z0-9_]*)\s*(:)' + scope: variable.parameter.optional.ocaml + captures: + 1: punctuation.definition.optional-parameter.ocaml + 2: entity.name.tag.label.optional.ocaml + 3: punctuation.separator.optional-parameter.ocaml + - match: '(~)([a-z][a-zA-Z0-9''_]*)\s*(:)\s*' + captures: + 1: punctuation.definition.labeled-parameter.ocaml + 2: entity.name.tag.label.ocaml + 3: punctuation.separator.label.ocaml + push: + - meta_scope: variable.parameter.labeled.ocaml + - match: \s + pop: true + - include: variables + - include: strings + - include: typedefs + moduleref: + - match: '\b([A-Z][a-zA-Z0-9''_]*)(\.)' + scope: meta.module-reference.ocaml + storagetypes: + - match: \b(int|char|float|string|list|array|bool|unit|exn|option|int32|int64|nativeint|format4|lazy_t)\b + scope: storage.type.ocaml + - match: '#[a-z_][a-zA-Z0-9_]*' + scope: storage.type.variant.polymorphic.ocaml + + records: + - match: \{ + scope: punctuation.definition.record.begin.ocaml + push: record-body + + record-body: + - meta_scope: meta.record.ocaml + - match: \} + scope: punctuation.definition.record.end.ocaml + pop: true + - match: \bwith\b + scope: keyword.other.language.ocaml + - match: \b(?:(mutable)\s+)?([a-z_][a-zA-Z0-9_'']*)\s*(:) + captures: + 1: storage.modifier.ocaml + 2: variable.other.member.ocaml + 3: punctuation.definition.record.ocaml + push: record-member-type + - include: main + + record-member-type: + - meta_scope: meta.record.definition.ocaml + - match: ; + scope: keyword.operator.ocaml + pop: true + - match: (?=}) + pop: true + - include: typedefs + + strings: + - match: \" + scope: punctuation.definition.string.begin.ocaml + push: string-double-quoted-body + - match: \{([^\s|}]*)\| + scope: punctuation.definition.string.begin.ocaml + push: string-other-quoted-body + + string-double-quoted-body: + - meta_scope: meta.string.ocaml string.quoted.double.ocaml + - match: \" + scope: punctuation.definition.string.end.ocaml + pop: true + - match: (\\)\s*$ + captures: + 1: punctuation.separator.continuation.line.ocaml + - match: \\[bnrt''"\\] + scope: constant.character.escape.ocaml + - match: \\x\h{2} + scope: constant.character.escape.hexadecimal.ocaml + - match: \\[0-2]\d{2} + scope: constant.character.escape.decimal.ocaml + - match: \\[1-9|$^.*+?()\[\]] + scope: constant.character.escape.regexp.ocaml + - match: \\. + scope: invalid.illegal.character.escape.ocaml + + string-other-quoted-body: + - meta_scope: meta.string.ocaml string.quoted.other.ocaml + - match: \|\1\} + scope: punctuation.definition.string.end.ocaml + pop: true + + typedefs: + - match: \| + scope: punctuation.separator.variant-definition.ocaml + - include: comments + - match: \( + push: + - meta_scope: meta.paren-group.ocaml + - match: \) + pop: true + - include: typedefs + - match: \bof\b + scope: keyword.other.ocaml + - include: storagetypes + - match: '(?<=\s|\()[''a-z_][a-zA-Z0-9_]*\b' + scope: storage.type.ocaml + - match: '\b((?:[A-Z][a-zA-Z0-9''_]*)(?:\.[A-Z][a-zA-Z0-9''_]+)*)(\.[a-zA-Z0-9''_]+)' + scope: meta.module.type.ocaml + captures: + 1: support.other.module.ocaml + 2: storage.type.module.ocaml + - match: '(\[(>|<)?)' + captures: + 1: punctuation.definition.polymorphic-variant.ocaml + push: + - meta_scope: meta.polymorphic-variant.definition.ocaml + - match: '(\])' + captures: + 1: punctuation.definition.polymorphic-variant.ocaml + pop: true + - include: typedefs + - include: main + - match: \| + scope: punctuation.separator.algebraic-type.ocaml + variables: + - match: \(\) + scope: variable.parameter.unit.ocaml + - include: constants + - include: moduleref + - match: '(~)([a-z][a-zA-Z0-9''_]*)(\s*:\s*)?' + captures: + 1: punctuation.definition.labeled-parameter.ocaml + 2: entity.name.tag.label.ocaml + 3: punctuation.separator.label.ocaml + push: + - meta_scope: variable.parameter.labeled.ocaml + - match: (?=(->|\s)) + pop: true + - include: variables + - match: '(\?)([a-z][a-zA-Z0-9_]*)' + scope: variable.parameter.optional.ocaml + captures: + 1: punctuation.definition.optional-parameter.ocaml + 2: entity.name.tag.label.optional.ocaml + - match: '(\?)(\()([a-z_][a-zA-Z0-9''_]*)\s*(=)' + captures: + 1: punctuation.definition.optional-parameter.ocaml + 2: punctuation.definition.optional-parameter.ocaml + 3: entity.name.tag.label.optional.ocaml + 4: punctuation.separator.optional-parameter-assignment.ocaml + push: + - meta_scope: variable.parameter.optional.ocaml + - match: (\)) + captures: + 1: punctuation.definition.optional-parameter.ocaml + pop: true + - include: main + - match: '(\()(?=(~[a-z][a-zA-Z0-9_]*:|("(\\"|[^"])*")|[^\(\)~"])+(?<!:)(:>|:(?![:=])))' + captures: + 1: punctuation.section.type-constraint.ocaml + push: + - meta_scope: meta.parameter.type-constrained.ocaml + - match: (\)) + captures: + 1: punctuation.section.type-constraint.ocaml + pop: true + - match: "(?<!:)(:>|:(?![:=]))" + captures: + 1: punctuation.separator.type-constraint.ocaml + push: + - meta_scope: storage.type.ocaml + - match: (?=\)) + pop: true + - match: \( + push: + - meta_scope: meta.paren.group + - match: \) + pop: true + - include: variables + - include: comments + - match: \( + push: + - meta_scope: meta.paren-group.ocaml + - match: \) + pop: true + - include: variables + - match: (\() + captures: + 1: punctuation.definition.tuple.ocaml + push: + - meta_scope: variable.parameter.tuple.ocaml + - match: (\)) + captures: + 1: punctuation.definition.tuple.ocaml + pop: true + - include: matchpatterns + - include: variables + - match: "," + scope: punctuation.separator.tuple.ocaml + - match: '(\{)' + captures: + 1: punctuation.definition.record.ocaml + push: + - meta_scope: variable.parameter.record.ocaml + - match: '(\})' + captures: + 1: punctuation.definition.record.ocaml + pop: true + - include: moduleref + - match: '\b([a-z][a-zA-Z0-9''_]*)\s*(=)' + captures: + 1: entity.name.tag.record.ocaml + 2: punctuation.separator.record.field-assignment.ocaml + push: + - meta_scope: meta.recordfield.match.ocaml + - match: '(;)|(?=\})' + captures: + 1: punctuation.separator.record.ocaml + pop: true + - include: matchpatterns + - include: storagetypes + - match: '\b[a-z_][a-zA-Z0-9''_]*' + scope: variable.parameter.ocaml
diff --git /dev/null b/syntax/Python/Python.sublime-syntax @@ -0,0 +1,4352 @@ +%YAML 1.2 +--- +name: Python +scope: source.python +version: 2 + +file_extensions: + - py + +hidden_file_extensions: + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* \# .*? -\*- .*? \bpython(?:\d(?:\.\d+)?)?\b .*? -\*- # editorconfig + ) + +contexts: + main: + - meta_include_prototype: false + - match: '' + push: [statements, shebang] + + statements: + - include: docstrings + - include: decorators + # definitions + - include: class-definitions + - include: function-definitions + - include: type-definitions + # block statements + - include: case-statements + - include: conditional-statements + - include: exception-statements + - include: for-statements + - include: match-statements + - include: while-statements + - include: with-statements + # line statements + - include: assignment-statements + - include: import-statements + - include: modifier-statements + - include: flow-statements + - include: other-statements + # expressions + - include: statement-terminators + - include: expression-as-a-statement + + # Always include these last and only one at a time! + expression-as-a-statement: + - include: comments + - include: line-continuations + - include: illegal-assignment-expressions + - include: lambdas + - include: expressions-common + - include: qualified-names + + expression-in-a-statement: + # Differs from expression-as-a-statement in that: + # - invalid-name matches will pop the current context + # - assignment expressions + - include: assignment-expressions + - include: lambdas + - include: expressions-common + - include: illegal-name + - include: qualified-names + + expression-in-a-group: # Always include this last! + # Differs from expression-in-a-statement in that: + # - no assignment expressions allowed + # - accessor and lambda matching continues into the next line + - include: comments + - include: line-continuations + - include: illegal-assignment-expressions + - include: lambda-in-groups + - include: expressions-common + - include: illegal-name + - include: qualified-names + + expression-in-a-sequence: # Always include this last! + # Differs from expression-in-a-statement in that: + # - accessor and lambda matching continues into the next line + - include: for-expressions + - include: comments + - include: line-continuations + - include: assignment-expressions + - include: lambda-in-groups + - include: expressions-common + - include: illegal-name + - include: qualified-names + + expressions-common: + - include: dictionaries-and-sets + - include: generators-groups-and-tuples + - include: lists + - include: constants + - include: numbers + - include: strings + - include: keywords + - include: operators + - include: illegal-stray-brackets + - include: illegal-stray-braces + - include: illegal-stray-parens + +###[ COMMENTS ]############################################################### + + comments: + # PEP 723 Inline script metadata + - match: ^\s*(#)\s+(///)\s+(script)\b + scope: comment.line.number-sign.python + captures: + 1: punctuation.definition.comment.python + 2: punctuation.section.raw.begin.python + 3: constant.other.lanugage-name.python + embed: scope:source.toml.embedded.python#toml + embed_scope: comment.line.number-sign.python source.toml.embedded.python + escape: ^(?:\s*(#)\s+(///)$\n?|(?!\s*#)) + escape_captures: + 0: comment.line.number-sign.python + 1: punctuation.definition.comment.python + 2: punctuation.section.raw.end.python + # Special Sphinx comment syntax to denote documentation + # https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute + - match: '#:' + scope: punctuation.definition.comment.python + push: comment-sphinxdoc-body + - match: '#+' + scope: punctuation.definition.comment.python + push: + - comment-body + - type-hint + - include: merge-conflict-markers + + comment-body: + - meta_scope: comment.line.number-sign.python + - match: $\n? + pop: 1 + - match: '#+$' + scope: punctuation.definition.comment.python + + comment-sphinxdoc-body: + - meta_scope: comment.line.documentation.python + - match: $\n? + pop: 1 + - match: '#+$' + scope: punctuation.definition.comment.python + + shebang: + - meta_include_prototype: false + - match: ^\s*(#!) + captures: + 1: punctuation.definition.comment.python + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if Python is embedded. + pop: 1 + + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.python + - match: '{{shebang_language}}' + scope: constant.language.shebang.python + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ TYPE HINTS ]############################################################# + + type-hint: + # 1st type hint may be of any type + - match: (type)(:) + captures: + 1: keyword.other.type.python + 2: punctuation.separator.type.python + set: type-hint-any + - include: else-pop + - include: eol-pop + + type-hint-any: + - meta_scope: meta.type.python + - include: type-hint-end + - match: ignore\b + scope: keyword.other.ignore.python + set: + - type-hint-type + - type-hint-error-list + - match: (?=\S) + set: + - type-hint-ignore + - type-hint-begin + + type-hint-ignore: + # 2nd type hint may only be a `type: ignore` + # As it isn't a real start of a comment `#` is not scoped punctuation. + - match: \s*\#\s*((type)(:)\s*(ignore\b)) + captures: + 1: meta.type.python + 2: keyword.other.type.python + 3: punctuation.separator.type.python + 4: keyword.other.ignore.python + set: type-hint-error-list + - include: immediately-pop + + type-hint-type: + # 2nd type hint must not be a `type: ignore` + # As it isn't a real start of a comment `#` is not scoped punctuation. + - match: \s*\#\s*((type)(:)(?!\s*ignore\b)) + captures: + 1: meta.type.python + 2: keyword.other.type.python + 3: punctuation.separator.type.python + set: type-hint-begin + - include: immediately-pop + + type-hint-error-list: + - meta_content_scope: meta.type.python + - match: \[ + scope: punctuation.section.sequence.begin.python + set: type-hint-error-list-body + - include: type-hint-end + + type-hint-error-list-body: + - meta_scope: meta.type.python meta.sequence.list.errors.python + - match: \] + scope: punctuation.section.sequence.end.python + pop: 1 + - include: type-hint-end + - include: sequence-separators + - match: \b[[:alpha:]_-][[:alnum:]_-]+\b + scope: constant.other.error-code.python + + type-hint-begin: + - meta_content_scope: meta.type.python + - match: \( + scope: punctuation.section.parameters.begin.python + set: type-hint-function-parameter-list-body + - match: (?=\S) + set: type-hint-body + + type-hint-function-parameter-list-body: + - meta_scope: meta.type.function.parameters.python + - match: \) + scope: punctuation.section.parameters.end.python + set: type-hint-function-return-type + - include: type-hint-body + + type-hint-function-return-type: + - meta_content_scope: meta.type.function.python + - match: -> + scope: punctuation.separator.return-type.python + set: type-hint-function-return-type-body + - include: type-hint-end + + type-hint-function-return-type-body: + - meta_scope: meta.type.function.return-type.python + - include: type-hint-body + + type-hint-body: + - meta_scope: meta.type.python + - include: type-hint-end + - include: type-hint-expressions + + type-hint-end: + - match: (?=\s*[\n#]) + pop: 1 + + type-hint-expressions: + - include: type-hint-lists + - include: type-separators + - include: type-constants + - include: constants + - include: double-quoted-strings + - include: single-quoted-strings + - include: type-hint-names + + type-hint-lists: + - match: \[ + scope: punctuation.section.brackets.begin.python + push: type-hint-list-body + + type-hint-list-body: + # As annotations contain normal expressions use a generic `meta.brackets` + # for sake of consistent scoping/highlighting. + - meta_scope: meta.brackets.python + - match: \] + scope: punctuation.section.brackets.end.python + pop: 1 + - include: type-hint-body + + type-hint-names: + - match: (?=(?:{{identifier}}\s*)?\.) + push: + - type-hint-qualified-name-content + - unqualified-name-content + - match: (?={{identifier_start}}) + push: unqualified-name-content + + type-hint-qualified-name-content: + - meta_include_prototype: false + - meta_scope: meta.path.python + - match: \s*(\.)\s* + captures: + 1: punctuation.accessor.dot.python + push: qualified-name-content + - include: immediately-pop + + type-constants: + # Note: Enables `None = None` in type hints. + - match: None\b + scope: constant.language.null.python + + type-separators: + # Note: Scoped as normal arithmetic operator for consistency reasons with + # type-hints in annotations, which share syntax with normal expressions + - match: \| + scope: keyword.operator.arithmetic.python + - match: ',' + scope: punctuation.separator.sequence.python + +###[ DECORATORS ]############################################################# + + decorators: + - match: ^\s*(@) + captures: + 1: meta.annotation.python punctuation.definition.annotation.python + push: decorator-body + + decorator-body: + - meta_content_scope: meta.annotation.python + - include: line-continuation-or-pop + - include: assignment-expressions + - include: lambdas + - include: dictionaries-and-sets + - include: generators-groups-and-tuples + - include: lists + - include: constants + - include: numbers + - include: strings + - include: keywords + - include: operators + - include: decorator-variables + - include: illegal-stray-brackets + - include: illegal-stray-braces + - include: illegal-stray-parens + + decorator-variables: + # qualified variables + - match: \. + scope: punctuation.accessor.dot.python + push: decorator-qualified-name-element + # note: assume qualified identifier if followed by line continuation + - match: ({{identifier}})\s*(?={{item_access}}*(?:\.|\\$)) + scope: meta.path.python + captures: + 1: variable.annotation.namespace.python + push: + - decorator-qualified-name-accessor + - after-expression + # unqualified variables + - match: '{{identifier}}' + scope: meta.function-call.identifier.python variable.annotation.python + push: after-expression + + decorator-qualified-name-accessor: + - meta_include_prototype: false + - meta_content_scope: meta.path.python + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.python + set: decorator-qualified-name-element + - include: line-continuation-immediately-pop + + decorator-qualified-name-element: + - meta_include_prototype: false + - meta_scope: meta.path.python + - match: \s*({{identifier}})\s*(?={{item_access}}*(?:\.|\\$)) + captures: + 1: variable.annotation.namespace.python + set: + - decorator-qualified-name-accessor + - after-expression + - match: \s*({{identifier}}) + captures: + 1: meta.function-call.identifier.python variable.annotation.python + set: after-expression + - include: line-continuation-immediately-pop + +###[ IMPORT STATEMENTS ]###################################################### + + import-statements: + - match: (?:(lazy)\s+)?(import\b) + captures: + 1: keyword.control.import.lazy.python + 2: keyword.control.import.python + push: + - imports-import-body + - expect-absolute-import + - match: (?:(lazy)\s+)?(from\b) + captures: + 1: keyword.control.import.lazy.python + 2: keyword.control.import.from.python + push: + - imports-from-body + - maybe-relative-import + + imports-import-body: + - meta_scope: meta.statement.import.python + - include: line-continuation-or-pop + - match: ',' + scope: punctuation.separator.import-list.python + push: expect-absolute-import + - include: imports-as + - include: qualified-names + - include: import-illegal-names + + imports-from-body: + - meta_scope: meta.statement.import.python + - meta_content_scope: meta.import-source.python + - match: import\b + scope: keyword.control.import.python + set: imports-from-import-body + - match: as\b + scope: keyword.control.import.as.python + set: imports-from-import-names + - match: '{{illegal_names}}' + scope: meta.import-path.python invalid.illegal.name.python + - match: '{{identifier}}' + scope: meta.import-path.python meta.import-name.python + - match: \s*(\.)\s*(?={{identifier}}|$) + scope: meta.import-path.python + captures: + 1: punctuation.accessor.dot.python + - match: \s*(\.\s*\S+) # matches and consumes the remainder of "abc.123" or "abc.+" + scope: meta.import-path.python + captures: + 1: invalid.illegal.name.python + - include: line-continuation-or-pop + - include: else-pop + + imports-from-import-body: + - meta_content_scope: meta.statement.import.python + - include: line-continuation-or-pop + - match: \* + scope: meta.statement.import.python constant.other.wildcard.asterisk.python + set: expect-import-end + - match: \( + scope: punctuation.section.import-list.begin.python + set: imports-from-import-list-body + - match: (?=\S) + set: imports-from-import-names + + imports-from-import-list-body: + - meta_scope: meta.statement.import.python meta.import-list.python + - match: \) + scope: punctuation.section.import-list.end.python + pop: 1 + - include: comments + - include: imports-as-inlist + - include: import-names + - include: import-illegal-names-inlist + + imports-as-inlist: + - match: as\b + scope: keyword.control.import.as.python + push: imports-as-inlist-body + + imports-as-inlist-body: + - include: unqualified-name + - include: import-illegal-names-inlist + - include: else-pop + + import-illegal-names-inlist: + - match: '[^\s,)]+' + scope: invalid.illegal.name.import.python + + imports-from-import-names: + - meta_content_scope: meta.statement.import.python + - include: line-continuation-or-pop + - include: imports-as + - include: import-names + - include: import-illegal-names + + imports-as: + - match: as\b + scope: keyword.control.import.as.python + push: imports-as-body + + imports-as-body: + - include: unqualified-name + - include: import-illegal-names + - include: line-continuation-or-pop + - include: else-pop + + import-illegal-names: + - match: '[^\s,]+' + scope: invalid.illegal.name.import.python + + import-names: + - match: ',' + scope: punctuation.separator.import-list.python + - include: unqualified-names + + expect-import-end: + - match: $ + pop: 1 + - match: (?=#) + pop: 1 + - match: '[^\s#]+' + scope: invalid.illegal.unexpected-import.python + + expect-absolute-import: + - include: line-continuation-or-pop + - match: \.+ + scope: invalid.illegal.unexpected-relative-import.python + - include: else-pop + + maybe-relative-import: + - include: line-continuation-or-pop + - match: \.+ + scope: meta.import-path.python keyword.control.import.relative.python + - include: else-pop + +###[ CLASS DEFINITIONS ]###################################################### + + class-definitions: + - match: class\b + scope: meta.class.python keyword.declaration.class.python + push: + - class-definition-base-list + - type-parameter-list + - class-definition-name + + class-definition-name: + - include: illegal-name + - match: '{{identifier}}' + scope: entity.name.class.python + pop: 1 + - include: class-definition-end + + class-definition-base-list: + - meta_include_prototype: false + - meta_content_scope: meta.class.python + - match: \( + scope: punctuation.section.inheritance.begin.python + set: + - class-definition-base-list-body + - maybe-unpack-operator-in-brackets + - include: class-definition-end + + class-definition-base-list-body: + - meta_scope: meta.class.inheritance.python + - match: \) + scope: punctuation.section.inheritance.end.python + set: class-definition-end + - match: '{{colon}}' + scope: invalid.illegal.no-closing-parens.python + pop: 1 + - match: ',' + scope: punctuation.separator.inheritance.python + push: maybe-unpack-operator-in-brackets + # expression-in-a-group (without qualified-names) + - include: comments + - include: line-continuations + - include: illegal-assignment-expressions + - include: lambda-in-groups + - include: expressions-common + - include: illegal-name + # specific "qualified-names" patterns + - match: ({{identifier}})\s*({{assignment_operator}}) + captures: + 1: variable.parameter.class-inheritance.python + 2: keyword.operator.assignment.python + - match: (?={{identifier}}\s*{{item_access}}*(?:\.|\\$)) + push: + - qualified-base-class-separator + - after-expression + - unqualified-name-content + - match: (?={{identifier}}\s*\() + push: + - function-call-argument-list + - unqualified-function-call-name + - match: (?={{identifier_start}}) + push: unqualified-base-class-name-content + + unqualified-base-class-name-content: + - include: builtin-exception + - include: builtin-type + - include: class-variable + - include: magic-function + - include: magic-variable + - include: wildcard-variable + - include: constant-name + - match: '{{identifier_class}}' + scope: entity.other.inherited-class.python + pop: 1 + - include: generic-name + - include: immediately-pop + + qualified-base-class-separator: + - meta_include_prototype: false + - meta_content_scope: meta.path.python + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.python + set: qualified-base-class-element + - include: line-continuation-immediately-pop + + qualified-base-class-element: + - meta_include_prototype: false + - meta_scope: meta.path.python + - match: (?=\s*{{illegal_names}}) + pop: 1 + - match: \s*(?={{identifier}}\s*{{item_access}}*(?:\.|\\$)) + set: + - qualified-base-class-separator + - after-expression + - qualified-name-content + - match: \s*(?={{identifier}}\s*\() + set: + - function-call-argument-list + - qualified-function-call-name + - match: \s*({{identifier_class}}) + captures: + 1: entity.other.inherited-class.python + pop: 1 + - match: \s*({{identifier}}) + captures: + 1: variable.other.python + pop: 1 + - include: line-continuation-immediately-pop + + class-definition-end: + - meta_content_scope: meta.class.python + - match: '{{colon}}' + scope: meta.class.python punctuation.section.block.begin.python + pop: 1 + - include: line-continuation-or-pop + +###[ FUNCTION DEFINITIONS ]################################################### + + function-definitions: + - match: (?:(async)\s+)?(def)\b + scope: meta.function.python + captures: + 1: keyword.declaration.function.async.python + 2: keyword.declaration.function.python + push: + - function-parameter-list + - type-parameter-list + - function-definition-name + + function-definition-name: + - include: illegal-name + - match: '{{magic_functions}}' + scope: entity.name.function.python support.function.magic.python + pop: 1 + - match: '{{identifier}}' + scope: entity.name.function.python + pop: 1 + - include: function-definition-end + + function-parameter-list: + - meta_include_prototype: false + - meta_content_scope: meta.function.python + - match: \( + scope: meta.function.parameters.python punctuation.section.parameters.begin.python + set: + - function-parameter-list-body + - function-parameter-maybe-unpack-operator + - include: function-definition-end + + function-parameter-list-body: + - meta_content_scope: meta.function.parameters.python + - match: \) + scope: meta.function.parameters.python punctuation.section.parameters.end.python + set: function-after-parameters + - match: ',' + scope: punctuation.separator.parameters.python + push: function-parameter-maybe-unpack-operator + - match: / + scope: storage.modifier.positional-args-only.python + push: function-parameter-expect-comma + - match: '{{assignment_operator}}' + scope: keyword.operator.assignment.python + set: function-parameter-default-value + - match: '{{colon}}' + scope: punctuation.separator.annotation.python + set: function-parameter-annotation + - include: comments + - include: function-parameter-tuples + - include: parameter-names + - include: line-continuations + - include: illegal-assignment-expressions + + function-parameter-maybe-unpack-operator: + - meta_include_prototype: false + - match: (?=\*(?!\*)) + branch_point: unpack-or-separator + branch: + - function-parameter-unpack-operator + - function-parameter-named-only-operator + - include: maybe-unpack-operator-in-brackets + + function-parameter-named-only-operator: + - meta_include_prototype: false + - match: \* + scope: storage.modifier.named-args-only.python + pop: 2 + + function-parameter-unpack-operator: + - meta_include_prototype: false + - match: \* + scope: keyword.operator.unpacking.sequence.python + set: function-parameter-unpack-operator-check + + function-parameter-unpack-operator-check: + - meta_include_prototype: false + - include: comments + - match: (?=,) + fail: unpack-or-separator + - match: (?=\S) + pop: 2 + + function-parameter-expect-comma: + - meta_include_prototype: false + - include: comments + - match: (?=[,)]) + pop: 1 + - match: '[^\s,)]+' + scope: invalid.illegal.expected-comma.python + + function-parameter-annotation: + - meta_include_prototype: false + - meta_scope: meta.function.parameters.annotation.python + - include: line-continuations + - match: (?=\S) + set: function-parameter-annotation-body + + function-parameter-annotation-body: + - meta_scope: meta.function.parameters.annotation.python + - meta_content_scope: meta.type.python + - match: \s*(?=[,)=]) + set: function-parameter-list-body + # Scope newline `meta.type` only, if type continues on next line. + # Note: This is required to workaround ST's line blindness. + - match: (?=\s*\n) + branch_point: function-parameter-annotation-end + branch: + - function-parameter-annotation-continue + - function-parameter-annotation-end + - include: function-parameter-annotation-content + + function-parameter-annotation-content: + # Note: maybe type-hint expressions + - include: type-constants + - include: expression-in-a-group + + function-parameter-annotation-continue: + - meta_include_prototype: false + - match: \s*(?=[,)=]) + fail: function-parameter-annotation-end + - include: comments + - include: else-pop + + function-parameter-annotation-end: + - meta_include_prototype: false + - match: '' + pop: 2 + push: function-parameter-list-body + + function-parameter-default-value: + - meta_scope: meta.function.parameters.default-value.python + - match: (?=[,)=]) + set: function-parameter-list-body + - include: expression-in-a-group + + function-parameter-tuples: + # python 2 style tuple arguments + # removed from python 3 since PEP-3113 + - match: \( + scope: punctuation.section.group.begin.python + push: + - function-parameter-tuple-body + - maybe-unpack-operator-in-brackets + + function-parameter-tuple-body: + - meta_scope: meta.group.python + - match: \) + scope: punctuation.section.group.end.python + set: after-expression + - match: ',' + scope: punctuation.separator.parameters.python + push: maybe-unpack-operator-in-brackets + # default values should follow the argument + - match: '{{assignment_operator}}' + push: function-parameter-illegal-default-value + # python 2 does not support type annotations + - match: '{{colon}}' + push: function-parameter-illegal-annotation + - include: comments + - include: parameter-names + - include: line-continuations + - include: illegal-assignment-expressions + + function-parameter-illegal-annotation: + - meta_include_prototype: false + - meta_scope: invalid.illegal.annotation.python + - match: (?=[,)=]) + pop: 1 + + function-parameter-illegal-default-value: + - meta_include_prototype: false + - meta_scope: invalid.illegal.default-value.python + - match: (?=[,)=]) + pop: 1 + + function-after-parameters: + - meta_content_scope: meta.function.python + - match: -> + scope: punctuation.separator.return-type.python + set: function-return-type + - include: function-definition-end + + function-return-type: + - meta_include_prototype: false + - meta_scope: meta.function.return-type.python + - include: line-continuation-or-pop + - match: (?=\S) + set: function-return-type-body + + function-return-type-body: + - meta_content_scope: meta.function.return-type.python meta.type.python + - match: (\s*)({{colon}}) + captures: + 1: meta.function.return-type.python + 2: meta.function.python punctuation.section.block.begin.python + pop: 1 + - include: line-continuation-or-pop + - include: function-return-type-content + + function-return-type-content: + # Note: maybe type-hint expressions + - include: illegal-assignment-expressions + - include: type-constants + - include: expression-in-a-statement + + function-definition-end: + - match: '{{colon}}' + scope: meta.function.python punctuation.section.block.begin.python + pop: 1 + - include: line-continuation-or-pop + - include: illegal-assignment-expressions + +###[ TYPE DEFINITIONS ]####################################################### + + type-definitions: + - match: (?=type\b) + branch_point: type-definitions + branch: + - type-definition + - soft-keyword-fallback + + type-definition: + - meta_include_prototype: false + - match: type\b + scope: keyword.declaration.class.python + set: + - type-definition-meta + - type-definition-value-assignment + - type-parameter-list + - type-definition-name + + type-definition-meta: + - meta_include_prototype: false + - meta_scope: meta.type-alias.python + - include: immediately-pop + + type-definition-name: + - match: (?={{illegal_names}}) + fail: type-definitions + - match: '{{identifier}}' + scope: entity.name.type.alias.python + pop: 1 + - include: line-continuations + - match: $|(?=\S) + fail: type-definitions + + type-definition-value-assignment: + - match: = + scope: keyword.operator.assignment.python + set: variable-annotation + - include: line-continuation-or-pop + +###[ TYPE PARAMETERS ]######################################################## + + type-parameter-list: + - match: \[ + scope: meta.generic.python punctuation.definition.generic.begin.python + set: + - type-parameter-list-body + - maybe-unpack-operator-in-brackets + - include: line-continuation-or-pop + - include: else-pop + + type-parameter-list-body: + - meta_content_scope: meta.generic.python + - match: \] + scope: meta.generic.python punctuation.definition.generic.end.python + pop: 1 + - match: ',' + scope: punctuation.separator.parameters.python + push: maybe-unpack-operator-in-brackets + - match: '{{colon}}' + scope: meta.generic.python punctuation.separator.bound.python + set: type-parameter-bound + - include: comments + - include: type-parameter-names + - include: line-continuations + + type-parameter-bound: + - meta_include_prototype: false + - meta_content_scope: meta.generic.bound.python + - include: line-continuations + - match: (?=\S) + set: type-parameter-bound-body + + type-parameter-bound-body: + - meta_scope: meta.generic.bound.python + - meta_content_scope: meta.type.python + - match: \s*(?=[],=]) + set: type-parameter-list-body + # Scope newline `meta.type` only, if type continues on next line. + # Note: This is required to workaround ST's line blindness. + - match: (?=\s*\n) + branch_point: type-parameter-bound-end + branch: + - type-parameter-bound-continue + - type-parameter-bound-end + - include: type-parameter-bound-content + + type-parameter-bound-content: + # Note: maybe type-hint expressions + - include: type-constants + - include: expression-in-a-group + + type-parameter-bound-continue: + - meta_include_prototype: false + - match: \s*(?=[],=]) + fail: type-parameter-bound-end + - include: comments + - include: else-pop + + type-parameter-bound-end: + - meta_include_prototype: false + - match: '' + pop: 2 + push: type-parameter-list-body + +###[ ASSIGNMENT STATEMENTS ]################################################## + + assignment-statements: + - match: '{{colon}}' + scope: punctuation.separator.annotation.python + push: variable-annotation + - match: '{{augmented_assignment_operators}}' + scope: keyword.operator.assignment.augmented.python + push: assignment-statement-value + - match: '{{assignment_operator}}' + scope: keyword.operator.assignment.python + + assignment-statement-value: + - include: line-continuation-or-pop + - include: illegal-assignment-expressions + - include: expression-in-a-statement + + variable-annotation: + - meta_include_prototype: false + - include: line-continuation-or-pop + - match: (?=\S) + set: variable-annotation-body + + variable-annotation-body: + - meta_content_scope: meta.type.python + - match: (?=\s*[\n#):;=\]}]) + pop: 1 + - include: line-continuations + - include: variable-annotation-content + + variable-annotation-content: + # Note: maybe type-hint expressions + - include: type-constants + - include: expression-in-a-statement + +###[ CASE STATEMENTS ]######################################################## + + case-statements: + # https://www.python.org/dev/peps/pep-0634 + - match: (?=case\b) + branch_point: case-statements + branch: + - case-statement + - soft-keyword-fallback + + case-statement: + - meta_include_prototype: false + - match: case + scope: + meta.statement.conditional.case.python + keyword.control.conditional.case.python + set: + - case-statement-pattern + - case-statement-begin + + case-statement-begin: + - meta_include_prototype: false + # fail if match is directly followed by `:` or end of statement + - match: (?=$|#|;|:) + fail: case-statements + - include: maybe-unpack-operator + + case-statement-end: + # Note: Consume any whitespace up to eol, including newline, to apply + # `meta.disable-dedentation` to full line, which is requied to actually + # disable default dedentation rules. + - match: ({{colon}})(?:\s*\n)? + captures: + 1: meta.statement.conditional.case.python + punctuation.section.block.begin.python + pop: 1 + + case-statement-fail: + - match: (?=$|#|;) + fail: case-statements + + case-statement-guard: + - meta_content_scope: meta.statement.conditional.case.guard.python + - include: case-statement-end + - include: case-statement-fail + - include: line-continuations + - include: expression-in-a-statement + + case-statement-pattern: + - meta_content_scope: meta.statement.conditional.case.patterns.python + - match: (?=if\b) + set: case-statement-guard + - include: case-statement-end + - include: case-statement-fail + - include: case-pattern-expressions + + case-pattern-expressions: + - include: case-pattern-capture-targets + - include: case-pattern-classes + - include: case-pattern-dictionaries + - include: case-pattern-groups-or-tuples + - include: case-pattern-lists + - include: case-pattern-operators + - include: illegal-assignment-expressions + - include: sequence-separators + - include: comments + - include: booleans + - include: nones + - include: numbers + - include: strings + - include: case-pattern-names + - include: illegal-stray-brackets + - include: illegal-stray-braces + - include: illegal-stray-parens + - include: line-continuations + + case-pattern-capture-targets: + - match: as\b + scope: keyword.control.conditional.case.as.python + push: case-pattern-capture-target + + case-pattern-capture-target: + - include: unqualified-name + - include: line-continuation-or-pop + - include: else-pop + + case-pattern-classes: + - match: (?={{identifier}}\s*\() + push: + - case-pattern-class-arguments-begin + - case-pattern-class-name + + case-pattern-names: + - match: (?={{identifier}}\s*{{item_access}}*(?:\.|\\$)) + push: + - case-pattern-name-accessor + - maybe-item-access + - unqualified-name-content + - include: unqualified-names + + case-pattern-name-accessor: + - meta_include_prototype: false + - meta_content_scope: meta.path.python + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.python + set: case-pattern-name-element + - include: line-continuation-immediately-pop + + case-pattern-name-element: + - meta_include_prototype: false + - meta_scope: meta.path.python + - match: (?=\s*{{illegal_names}}) + pop: 1 + - match: \s*(?={{identifier}}\s*{{item_access}}*(?:\.|\\$)) + set: + - case-pattern-name-accessor + - maybe-item-access + - qualified-name-content + - match: \s*(?={{identifier}}\s*\() + set: + - case-pattern-class-arguments-begin + - qualified-name-meta + - case-pattern-class-name + - match: \s*(?={{identifier_start}}) + set: + - qualified-name-meta + - maybe-item-access + - qualified-name-content + - include: line-continuation-immediately-pop + + case-pattern-class-name: + - include: builtin-type + - include: illegal-name + - match: '{{identifier}}' + scope: support.class.python + pop: 1 + - include: immediately-pop + + case-pattern-class-arguments-begin: + - meta_include_prototype: false + - meta_content_scope: meta.function-call.identifier.python + - match: \( + scope: punctuation.section.arguments.begin.python + set: + - case-pattern-class-arguments-body + - maybe-unpack-operator-in-brackets + + case-pattern-class-arguments-body: + - meta_scope: meta.function-call.arguments.python + - match: \) + scope: punctuation.section.arguments.end.python + pop: 1 + - include: argument-separators + - include: case-pattern-keyword-arguments + - include: case-pattern-expressions + + case-pattern-keyword-arguments: + - match: (?={{identifier}}\s*{{assignment_operator}}) + push: case-pattern-keyword-argument-name + + case-pattern-keyword-argument-name: + - match: '{{assignment_operator}}' + scope: keyword.operator.assignment.python + set: maybe-unpack-operator-in-brackets + - include: parameter-names + + case-pattern-operators: + - match: '[-+]' + scope: keyword.operator.arithmetic.python + - match: \| + scope: keyword.operator.logical.python + + case-pattern-dictionaries: + - include: empty-dictionaries + - match: \{ + scope: punctuation.section.mapping.begin.python + push: case-pattern-dictionary-body + + case-pattern-dictionary-end: + - match: \} + scope: punctuation.section.mapping.end.python + pop: 1 + + case-pattern-dictionary-body: + - meta_scope: meta.mapping.python + - include: case-pattern-dictionary-end + - include: comments + - include: illegal-assignment-expressions + - match: ',' + scope: punctuation.separator.sequence.python + - match: \*\* + scope: keyword.operator.unpacking.mapping.python + set: case-pattern-dictionary-unpacking + - match: '{{colon}}' + scope: punctuation.separator.key-value.python + set: case-pattern-dictionary-value + - match: (?=\S) + set: case-pattern-dictionary-key + + case-pattern-dictionary-unpacking: + - meta_content_scope: meta.mapping.python + - match: (?=\s*[,:}]) + set: case-pattern-dictionary-body + - include: case-pattern-expressions + + case-pattern-dictionary-key: + - meta_content_scope: meta.mapping.key.python + - match: (?=\s*[,:}]) + set: case-pattern-dictionary-body + - include: case-pattern-expressions + + case-pattern-dictionary-value: + - meta_include_prototype: false + - meta_content_scope: meta.mapping.python + - include: comments + - match: (?=\S) + set: + - case-pattern-dictionary-value-body + - maybe-unpack-operator-in-brackets + + case-pattern-dictionary-value-body: + - meta_content_scope: meta.mapping.value.python + - match: (?=\s*[,}]) + set: case-pattern-dictionary-body + - include: case-pattern-expressions + + case-pattern-groups-or-tuples: + - include: empty-tuples + - match: (?=\() + branch_point: case-pattern-groups-or-tuples + branch: + - case-pattern-group + - case-pattern-tuple + + case-pattern-group: + - match: \( + scope: punctuation.section.group.begin.python + set: case-pattern-group-body + + case-pattern-group-body: + - meta_scope: meta.group.python + - match: \) + scope: punctuation.section.group.end.python + pop: 1 + - match: (?=,) + fail: case-pattern-groups-or-tuples + - include: case-pattern-expressions + + case-pattern-lists: + - include: empty-lists + - match: \[ + scope: punctuation.section.sequence.begin.python + push: + - case-pattern-list-body + - maybe-unpack-operator-in-brackets + + case-pattern-list-body: + - meta_scope: meta.sequence.list.python + - match: \] + scope: punctuation.section.sequence.end.python + pop: 1 + - include: case-pattern-expressions + + case-pattern-tuple: + - match: \( + scope: punctuation.section.sequence.begin.python + set: + - case-pattern-tuple-body + - maybe-unpack-operator-in-brackets + + case-pattern-tuple-body: + - meta_scope: meta.sequence.tuple.python + - match: \) + scope: punctuation.section.sequence.end.python + pop: 1 + - include: case-pattern-expressions + +###[ CONDITIONAL STATEMENTS ]################################################# + + conditional-statements: + - match: if\b + scope: keyword.control.conditional.if.python + push: if-statement-condition + - match: elif\b + scope: keyword.control.conditional.elseif.python + push: elif-statement-condition + - match: (else)(?:\s*(:)|\b) + scope: meta.statement.conditional.else.python + captures: + 1: keyword.control.conditional.else.python + 2: punctuation.section.block.begin.python + + if-statement-condition: + - meta_scope: meta.statement.conditional.if.python + - match: '{{colon}}' + scope: punctuation.section.block.begin.python + pop: 1 + - include: line-continuation-or-pop + - include: expression-in-a-statement + + elif-statement-condition: + - meta_scope: meta.statement.conditional.elseif.python + - match: '{{colon}}' + scope: punctuation.section.block.begin.python + pop: 1 + - include: line-continuation-or-pop + - include: expression-in-a-statement + +###[ EXCEPTION STATEMENTS ]################################################### + + exception-statements: + - match: (try)(?:\s*(:)|\b) + scope: meta.statement.exception.try.python + captures: + 1: keyword.control.exception.try.python + 2: punctuation.section.block.exception.try.python + - match: (finally)(?:\s*(:)|\b) + scope: meta.statement.exception.finally.python + captures: + 1: keyword.control.exception.finally.python + 2: punctuation.section.block.exception.finally.python + - match: except\b + scope: keyword.control.exception.catch.python + push: except-statement-exception-list + + except-statement-exception-list: + - meta_scope: meta.statement.exception.catch.python + - match: '{{colon}}' + scope: punctuation.section.block.begin.python + pop: 1 + - match: as\b + scope: keyword.control.exception.catch.as.python + push: except-statement-as + - include: illegal-assignment-expressions + - include: line-continuation-or-pop + - include: expression-in-a-statement + + except-statement-as: + - include: unqualified-name + - include: line-continuation-or-pop + - include: else-pop + +###[ FOR STATEMENTS ]######################################################### + + for-statements: + - match: (?:(async)\s+)?(for)\b + captures: + 1: keyword.control.loop.for.async.python + 2: keyword.control.loop.for.python + push: for-statement-target-list + + for-statement-target-list: + - meta_scope: meta.statement.loop.for.python + - match: '{{colon}}' + scope: invalid.illegal.missing-in.python + pop: 1 + - match: in\b + scope: keyword.control.loop.in.python + set: for-statement-in + - include: line-continuation-or-pop + - include: expression-in-a-statement + + for-statement-in: + - meta_content_scope: meta.statement.loop.for.python + - match: '{{colon}}' + scope: meta.statement.loop.for.python punctuation.section.block.begin.python + pop: 1 + - include: line-continuation-or-pop + - include: expression-in-a-statement + +###[ MATCH STATEMENTS ]####################################################### + + match-statements: + - match: (?=match\b) + branch_point: match-statements + branch: + - match-statement + - soft-keyword-fallback + + match-statement: + - match: match + scope: keyword.control.conditional.match.python + set: + - match-statement-body + - match-statement-begin + + match-statement-begin: + # fail if match is directly followed by `:` or end of statement + - match: (?=$|#|;|:) + fail: match-statements + - include: line-continuations + - include: maybe-unpack-operator + + match-statement-body: + - meta_scope: meta.statement.conditional.match.python + - match: (?=$|#|;) + fail: match-statements + - include: match-statement-end + - include: line-continuations + - include: expression-in-a-statement + + match-statement-end: + - match: '{{colon}}' + scope: punctuation.section.block.begin.python + set: maybe-first-case-statement + + maybe-first-case-statement: + # Disable dedentation of first case statement by special indentation rule. + # see: https://github.com/sublimehq/Packages/issues/3456 + - match: (?=case\b) + set: first-case-statement + - include: line-continuations + - include: comments + - include: else-pop + + first-case-statement: + - meta_include_prototype: false + - meta_scope: meta.disable-dedentation.python + - include: case-statements + - include: immediately-pop + + soft-keyword-fallback: + - meta_include_prototype: false + # qualified function call or identifier + - match: (?={{identifier}}\s*{{item_access}}*(?:\.|\\$)) + set: + - qualified-name-accessor + - after-expression + - generic-name + # unqualified function call + - match: (?={{identifier}}\s*\() + set: + - function-call-argument-list + - unqualified-function-call-name + # unqualified identifier + - include: generic-name + +###[ MODIFIER STATEMENTS ]#################################################### + + modifier-statements: + - match: global\b + scope: storage.modifier.global.python + push: modifier-statement-body + - match: nonlocal\b + scope: storage.modifier.nonlocal.python + push: modifier-statement-body + + modifier-statement-body: + - meta_scope: meta.statement.modifier.python + - include: line-continuation-or-pop + - include: unqualified-names + - match: ',' + scope: punctuation.separator.storage-list.python + - match: \S+ + scope: invalid.illegal.name.storage.python + +###[ WHILE STATEMENTS ]####################################################### + + while-statements: + - match: while\b + scope: keyword.control.loop.while.python + push: while-statement-condition + + while-statement-condition: + - meta_scope: meta.statement.loop.while.python + - match: '{{colon}}' + scope: punctuation.section.block.begin.python + pop: 1 + - include: line-continuation-or-pop + - include: expression-in-a-statement + +###[ WITH STATEMENTS ]######################################################## + + with-statements: + - match: (?:(async)\s+)?(with)\b + captures: + 1: keyword.control.context.with.async.python + 2: keyword.control.context.with.python + branch_point: with-statement-tuple + branch: + - with-statement-tuple + - with-statement-plain + + with-statement-plain: + - meta_scope: meta.statement.with.python + - match: '{{colon}}' + scope: punctuation.section.block.begin.python + pop: 1 + - match: as\b + scope: keyword.control.context.with.as.python + push: with-statement-plain-as + - include: line-continuation-or-pop + - include: expression-in-a-statement + + with-statement-plain-as: + - include: unqualified-name + - include: line-continuation-or-pop + - include: else-pop + + with-statement-tuple: + - meta_scope: meta.statement.with.python + - match: \( + scope: punctuation.section.sequence.begin.python + set: + - with-statement-tuple-end + - with-statement-tuple-body + - include: with-statement-tuple-else-fail + + with-statement-tuple-body: + - meta_scope: meta.sequence.tuple.python + - match: \) + scope: punctuation.section.sequence.end.python + pop: 1 + - match: (?={{colon}}) + pop: 1 + - match: as\b + scope: keyword.control.context.with.as.python + push: with-statement-tuple-as + - include: expression-in-a-sequence + + with-statement-tuple-as: + - include: comments + - include: unqualified-name + - include: line-continuations + - include: else-pop + + with-statement-tuple-end: + - meta_content_scope: meta.statement.with.python + - match: '{{colon}}' + scope: meta.statement.with.python punctuation.section.block.begin.python + pop: 1 + - include: with-statement-tuple-else-fail + + with-statement-tuple-else-fail: + - include: line-continuations + - match: (?=\S|$) + fail: with-statement-tuple + +###[ FLOW STATEMENTS ]######################################################## + + flow-statements: + - match: assert\b + scope: keyword.control.flow.assert.python + - match: return\b + scope: keyword.control.flow.return.python + - match: break\b + scope: keyword.control.flow.break.python + - match: continue\b + scope: keyword.control.flow.continue.python + - match: pass\b + scope: keyword.control.flow.pass.python + - match: raise\b + scope: keyword.control.flow.raise.python + push: raise-statement-body + + raise-statement-body: + - meta_scope: meta.statement.raise.python + - match: from\b + scope: keyword.control.flow.raise.from.python + set: raise-statement-from + - include: line-continuation-or-pop + - include: expression-in-a-statement + + raise-statement-from: + - meta_content_scope: meta.statement.raise.python + - include: line-continuation-or-pop + - include: expression-in-a-statement + +###[ OTHER STATEMENTS ]####################################################### + + other-statements: + - match: del\b + scope: keyword.other.del.python + - match: exec\b(?!\s*($|[,.()\]}])) + scope: keyword.other.exec.python + - match: print\b(?!\s*([,.()\]}])) + scope: keyword.other.print.python + +###[ FOR EXPRESSIONS ]######################################################## + + for-expressions: + - match: (?:(async)\s+)?(for)\b + captures: + 1: keyword.control.loop.for.generator.async.python + 2: keyword.control.loop.for.generator.python + push: for-expression-target-list + + for-expression-target-list: + - meta_scope: meta.expression.generator.python + - match: in\b + scope: keyword.control.loop.in.python + pop: 1 + - match: (?=[)\]}]) + pop: 1 + - include: expression-in-a-group + +###[ FLOW EXPRESSIONS ]####################################################### + + keywords: + - match: if\b + scope: keyword.control.conditional.if.python + - match: else\b + scope: keyword.control.conditional.else.python + - match: await\b + scope: keyword.control.flow.await.python + - match: (yield)(?:\s+(from))?\b + captures: + 1: keyword.control.flow.yield.python + 2: keyword.control.flow.yield-from.python + +###[ FUNCTION CALLS ]######################################################### + + qualified-function-call-name: + - meta_scope: meta.path.python + - include: magic-function + - include: magic-variable + - include: wildcard-variable + - include: illegal-name + - include: class-name + - include: function-name + - include: immediately-pop + + unqualified-function-call-name: + - include: builtin-exception + - include: builtin-function + - include: builtin-type + - include: class-variable + - include: magic-function + - include: magic-variable + - include: wildcard-variable + - include: illegal-name + - include: class-name + - include: function-name + - include: immediately-pop + + function-call-argument-list: + - meta_include_prototype: false + - meta_content_scope: meta.function-call.identifier.python + - match: \( + scope: punctuation.section.arguments.begin.python + set: + - function-call-argument-list-body + - maybe-unpack-operator-in-brackets + + function-call-argument-list-body: + - meta_scope: meta.function-call.arguments.python + - match: \) + scope: punctuation.section.arguments.end.python + set: after-expression + - include: arguments + + arguments: + - include: argument-separators + - include: keyword-arguments + - include: expression-in-a-sequence + + argument-separators: + - match: ',' + scope: punctuation.separator.arguments.python + push: maybe-unpack-operator-in-brackets + + keyword-arguments: + - match: (?={{identifier}}\s*{{assignment_operator}}) + push: keyword-argument-name + + keyword-argument-name: + - match: '{{assignment_operator}}' + scope: keyword.operator.assignment.python + set: + - keyword-argument-value + - maybe-unpack-operator-in-brackets + - include: parameter-names + + keyword-argument-value: + - match: (?=[,)]|:(?!=)) + pop: 1 + - include: expression-in-a-group + +###[ LAMBDAS ]################################################################ + + lambda-in-groups: + # A lambda keyword within a group may be part of a generator expression + # Hence pop contexts off stack if `for` keyword is matched in order to + # not scope it invalid. + - match: lambda\b + scope: + meta.function.inline.python + storage.type.function.inline.python + keyword.declaration.function.inline.python + push: + - lambda-in-group-parameters + - maybe-unpack-operator-in-brackets + + lambda-in-group-parameters: + - meta_content_scope: meta.function.inline.parameters.python + - match: '{{colon}}' + scope: meta.function.inline.python punctuation.section.block.begin.python + set: + - meta_include_prototype: false + - match: '' + set: lambda-in-group-body + - match: (?=[)\]}]|for\b) + pop: 1 + - include: line-continuations + - include: comments + - match: ',' + scope: punctuation.separator.parameters.python + push: maybe-unpack-operator-in-brackets + - match: '{{assignment_operator}}' + scope: keyword.operator.assignment.python + push: + - keyword-argument-value + - maybe-unpack-operator-in-brackets + - include: function-parameter-tuples + - include: parameter-names + - match: \S + scope: invalid.illegal.expected-parameter.python + + lambda-in-group-body: + - meta_scope: meta.function.inline.body.python + - match: (?=[,)\]}]|for\b) + pop: 1 + - include: expression-in-a-group + + lambdas: + - match: lambda\b + scope: + meta.function.inline.python + storage.type.function.inline.python + keyword.declaration.function.inline.python + push: + - lambda-parameters + - maybe-unpack-operator + + lambda-parameters: + - meta_content_scope: meta.function.inline.parameters.python + - match: '{{colon}}' + scope: meta.function.inline.python punctuation.section.block.begin.python + set: + - meta_include_prototype: false + - match: '' + set: lambda-body + - include: line-continuation-or-pop + - match: ',' + scope: punctuation.separator.parameters.python + push: maybe-unpack-operator + - match: '{{assignment_operator}}' + scope: keyword.operator.assignment.python + push: + - keyword-argument-value + - maybe-unpack-operator + - include: function-parameter-tuples + - include: parameter-names + - match: \S + scope: invalid.illegal.expected-parameter.python + + lambda-body: + - meta_scope: meta.function.inline.body.python + - include: line-continuation-or-pop + - include: illegal-assignment-expressions + - include: expression-in-a-statement + +###[ GENERATORS GROUPS TUPLES ]############################################### + + generators-groups-and-tuples: + - include: empty-tuples + - match: (?=\() + branch_point: generators-groups-and-tuples + branch: + - maybe-group + - maybe-tuple + - maybe-generator + + maybe-group: + - match: \( + scope: punctuation.section.group.begin.python + set: + - group-body + - maybe-group-begin + + maybe-group-begin: + - match: (?=\*) + fail: generators-groups-and-tuples + - include: else-pop + + group-body: + - meta_scope: meta.group.python + - match: \) + scope: punctuation.section.group.end.python + set: after-expression + - match: (?=,|\bfor\b) + fail: generators-groups-and-tuples + - include: expression-in-a-sequence + + maybe-generator: + - match: \( + scope: punctuation.section.sequence.begin.python + set: + - generator-body + - maybe-unpack-operator-in-brackets + + generator-body: + - meta_scope: meta.sequence.generator.python + - match: \) + scope: punctuation.section.sequence.end.python + set: after-expression + - include: expression-in-a-sequence + + maybe-tuple: + - match: \( + scope: punctuation.section.sequence.begin.python + set: + - tuple-body + - maybe-unpack-operator-in-brackets + + tuple-body: + - meta_scope: meta.sequence.tuple.python + - match: \) + scope: punctuation.section.sequence.end.python + set: after-expression + - match: (?=for\b) + fail: generators-groups-and-tuples + - include: expression-in-a-sequence + + empty-tuples: + - match: (\()\s*(\)) + scope: meta.sequence.tuple.empty.python + captures: + 1: punctuation.section.sequence.begin.python + 2: punctuation.section.sequence.end.python + push: after-expression + + illegal-stray-parens: + - match: \) + scope: invalid.illegal.stray.python + +###[ LISTS ]################################################################## + + lists: + - include: empty-lists + - match: \[ + scope: punctuation.section.sequence.begin.python + push: + - list-body + - maybe-unpack-operator-in-brackets + + list-body: + - meta_scope: meta.sequence.list.python + - match: \] + scope: punctuation.section.sequence.end.python + set: after-expression + - include: expression-in-a-sequence + + empty-lists: + - match: (\[)\s*(\]) + scope: meta.sequence.list.empty.python + captures: + 1: punctuation.section.sequence.begin.python + 2: punctuation.section.sequence.end.python + push: after-expression + + illegal-stray-brackets: + - match: \] + scope: invalid.illegal.stray.python + +###[ DICTIONARIES AND SETS ]################################################## + + dictionaries-and-sets: + - include: empty-dictionaries + - match: (?=\{) + branch_point: dictionaries-and-sets + branch: + - maybe-set + - maybe-dictionary + + maybe-dictionary: + - match: \{ + scope: punctuation.section.mapping.begin.python + set: maybe-dictionary-unpack-operator + + dictionary-end: + - match: \} + scope: meta.mapping.python punctuation.section.mapping.end.python + set: after-expression + + dictionary-separator: + - match: ',' + scope: punctuation.separator.sequence.python + set: maybe-dictionary-unpack-operator + + maybe-dictionary-unpack-operator: + - meta_include_prototype: false + - meta_scope: meta.mapping.python + - match: \*{3,} + scope: invalid.illegal.syntax.python + set: dictionary-unpacking-body + - match: \*\* + scope: keyword.operator.unpacking.mapping.python + set: dictionary-unpacking-body + - match: \* + scope: invalid.illegal.unexpected-operator.python + set: dictionary-unpacking-body + - include: line-continuations + - include: comments + - match: (?=\S) + set: dictionary-body + + dictionary-unpacking-body: + - meta_content_scope: meta.mapping.python + - include: dictionary-end + - include: dictionary-separator + - include: expression-in-a-sequence + + dictionary-body: + - meta_content_scope: meta.mapping.python + - include: dictionary-end + - include: comments + - include: illegal-assignment-expressions + - include: illegal-commas + - match: '{{colon}}' + scope: meta.mapping.python punctuation.separator.key-value.python + set: dictionary-value + - match: (?=\S) + set: directory-key-body + + directory-key-body: + - meta_scope: meta.mapping.key.python + - match: (?=\s*[,:}]) + set: dictionary-body + - include: expression-in-a-group + + dictionary-value: + - meta_include_prototype: false + - meta_content_scope: meta.mapping.python + - include: dictionary-end + - include: dictionary-separator + - match: (?=\S) + set: directory-value-body + + directory-value-body: + - meta_content_scope: meta.mapping.value.python + - match: (?=\s*[,}]) + set: after-dictionary-value + - match: (?=\s*(?:async|for)\b) + set: dictionary-generator-body + - include: expression-in-a-group + + after-dictionary-value: + - meta_include_prototype: false + - meta_content_scope: meta.mapping.python + - include: dictionary-end + - include: dictionary-separator + + dictionary-generator-body: + - meta_content_scope: meta.mapping.python + - include: dictionary-end + - include: illegal-commas + - include: expression-in-a-sequence + + maybe-set: + - match: \{ + scope: punctuation.section.set.begin.python + set: + - maybe-set-body + - maybe-set-begin + + maybe-set-begin: + - match: (?=\*\*) # looks like a dictionary + fail: dictionaries-and-sets + - include: maybe-sequence-unpack-operator + + maybe-set-body: + - meta_scope: meta.set.python + - match: (?=,|:=) + set: set-body + - match: (?=:) + fail: dictionaries-and-sets + - include: set-body + + set-body: + - meta_scope: meta.set.python + - match: \} + scope: punctuation.section.set.end.python + set: after-expression + - match: ',' + scope: punctuation.separator.set.python + push: maybe-sequence-unpack-operator + - include: expression-in-a-sequence + - include: illegal-colons + + maybe-sequence-unpack-operator: + - meta_include_prototype: false + - match: \*{3,} + scope: invalid.illegal.syntax.python + pop: 1 + - match: \*\* + scope: invalid.illegal.unexpected-operator.python + pop: 1 + - match: \* + scope: keyword.operator.unpacking.sequence.python + pop: 1 + - include: line-continuations + - include: comments + - include: else-pop + + empty-dictionaries: + - match: (\{)\s*(\}) + scope: meta.mapping.empty.python + captures: + 1: punctuation.section.mapping.begin.python + 2: punctuation.section.mapping.end.python + push: after-expression + + illegal-colons: + - match: '{{colon}}' + scope: invalid.illegal.unexpected-colon.python + + illegal-commas: + - match: ',' + scope: invalid.illegal.unexpected-comma.python + + illegal-stray-braces: + - match: \} + scope: invalid.illegal.stray.python + +###[ ITEM ACCESS ]############################################################ + + maybe-item-access: + - include: item-access + - include: line-continuation-immediately-pop + + item-access: + - match: \s*(\[) + captures: + 1: meta.brackets.python punctuation.section.brackets.begin.python + push: item-access-body + + item-access-body: + - meta_content_scope: meta.brackets.python + - match: \] + scope: meta.brackets.python punctuation.section.brackets.end.python + pop: 1 + - match: '{{colon}}' + scope: punctuation.separator.slice.python + - include: expression-in-a-group + +###[ OPERATORS ]############################################################## + + assignment-expressions: + - match: := + scope: keyword.operator.assignment.inline.python + + illegal-assignment-expressions: + - match: := + scope: invalid.illegal.assignment.python + + illegal-assignment: + - match: \:?= + scope: invalid.illegal.assignment.python + pop: 1 + - include: line-continuation-or-pop + - include: else-pop + + operators: + - match: '{{augmented_assignment_operators}}' + scope: invalid.illegal.assignment.python + - match: <> + scope: invalid.deprecated.operator.python + - match: <<|>>|\*\*|//|[-%&*+/@^|~] + scope: keyword.operator.arithmetic.python + - match: <=|>=|==|\!=|<|> + scope: keyword.operator.comparison.python + - match: = + scope: invalid.illegal.assignment.python + - match: (?:and|in|is|not|or)\b + scope: keyword.operator.logical.python + - include: sequence-separators + + maybe-unpack-operator-in-brackets: + - meta_include_prototype: false + - match: \*{3,} + scope: invalid.illegal.syntax.python + pop: 1 + - match: \*\* + scope: keyword.operator.unpacking.mapping.python + pop: 1 + - match: \* + scope: keyword.operator.unpacking.sequence.python + pop: 1 + - include: line-continuations + - include: comments + - include: else-pop + + maybe-unpack-operator: + - meta_include_prototype: false + - match: \*{3,} + scope: invalid.illegal.syntax.python + pop: 1 + - match: \*\* + scope: keyword.operator.unpacking.mapping.python + pop: 1 + - match: \* + scope: keyword.operator.unpacking.sequence.python + pop: 1 + - include: line-continuation-or-pop + - include: else-pop + + sequence-separators: + - match: ',' + scope: punctuation.separator.sequence.python + push: maybe-unpack-operator-in-brackets + + statement-terminators: + - match: ; + scope: punctuation.terminator.statement.python + +###[ IDENTIFIERS ]############################################################ + + parameter-names: + - match: (?={{identifier_start}}) + push: parameter-name-content + + parameter-name-content: + - meta_scope: variable.parameter.python + - include: illegal-name + - include: class-variable + - match: '{{identifier}}' + pop: 1 + - include: immediately-pop + + type-parameter-names: + - match: (?={{identifier_start}}) + push: type-parameter-name-content + + type-parameter-name-content: + - meta_scope: variable.parameter.type.python + - include: illegal-name + - include: class-variable + - match: '{{identifier}}' + pop: 1 + - include: immediately-pop + + qualified-names: + - match: \. + scope: punctuation.accessor.dot.python + push: qualified-name-element + - match: (?={{identifier_start}}) + push: qualified-name + + qualified-name: + - meta_include_prototype: false + # qualified function call or identifier + # note: assume qualified identifier if followed by line continuation + - match: (?={{identifier}}\s*{{item_access}}*(?:\.|\\$)) + set: + - qualified-name-accessor + - after-expression + - unqualified-name-content + # unqualified function call + - match: (?={{identifier}}\s*\() + set: + - function-call-argument-list + - unqualified-function-call-name + # unqualified identifier + - include: unqualified-name + + qualified-name-accessor: + - meta_include_prototype: false + - meta_content_scope: meta.path.python + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.python + set: qualified-name-element + - include: line-continuation-immediately-pop + + qualified-name-element: + - meta_include_prototype: false + - meta_scope: meta.path.python + - match: (?=\s*{{illegal_names}}) + pop: 1 + - match: \s*(?={{identifier}}\s*{{item_access}}*(?:\.|\\$)) + set: + - qualified-name-accessor + - after-expression + - qualified-name-content + - match: \s*(?={{identifier}}\s*\() + set: + - function-call-argument-list + - qualified-function-call-name + - match: \s*(?={{identifier_start}}) + set: + - after-expression + - qualified-name-meta + - maybe-item-access + - qualified-name-content + - include: line-continuation-immediately-pop + + qualified-name-content: + - include: magic-function + - include: magic-variable + - include: wildcard-variable + - include: illegal-name + - include: constant-name + - include: class-name + - include: generic-name + - include: immediately-pop + + qualified-name-meta: + - meta_include_prototype: false + - meta_content_scope: meta.path.python + - include: immediately-pop + + unqualified-names: + - match: (?={{identifier_start}}) + push: + - after-expression + - unqualified-name-content + + unqualified-name: + - match: (?={{identifier_start}}) + set: + - after-expression + - unqualified-name-content + + unqualified-name-content: + - include: builtin-exception + - include: builtin-type + - include: class-variable + - include: magic-function + - include: magic-variable + - include: wildcard-variable + - include: illegal-name + - include: constant-name + - include: class-name + - include: generic-name + - include: immediately-pop + + builtin-exception: + - match: '{{builtin_exceptions}}' + scope: support.class.exception.python + pop: 1 + + builtin-function: + - match: '{{builtin_functions}}' + scope: support.function.builtin.python + pop: 1 + - match: '{{typing_functions}}' + scope: support.function.typing.python + pop: 1 + + builtin-type: + - match: '{{builtin_types}}' + scope: support.type.python + pop: 1 + + magic-function: + # these methods have magic interpretation by python and are generally called indirectly through syntactic constructs + # https://docs.python.org/2/reference/datamodel.html + # https://docs.python.org/3/reference/datamodel.html + - match: '{{magic_functions}}' + scope: support.function.magic.python + pop: 1 + + magic-variable: + # magic variables which a class/module/object may have. + # https://docs.python.org/3/library/inspect.html#types-and-members + # https://docs.python.org/3/reference/datamodel.html#object.__slots__ + # https://docs.python.org/3/reference/datamodel.html#preparing-the-class-namespace + - match: '{{magic_variables}}' + scope: support.variable.magic.python + pop: 1 + + class-name: + - match: '{{identifier_class}}' + scope: support.class.python + pop: 1 + + class-variable: + - match: (?:self|cls)\b + scope: variable.language.this.python + pop: 1 + + constant-name: + - match: '{{identifier_constant}}' + scope: variable.other.constant.python + pop: 1 + + function-name: + - match: '{{identifier}}' + scope: variable.function.python + pop: 1 + + generic-name: + - match: '{{identifier}}' + scope: variable.other.python + pop: 1 + + illegal-name: + - match: '{{illegal_names}}' + scope: invalid.illegal.name.python + pop: 1 + + wildcard-variable: + - match: _(?!{{identifier_char}}) + scope: variable.language.anonymous.python + pop: 1 + +###[ LITERALS ]############################################################### + + constants: + - include: booleans + - include: nones + - match: (?:Ellipsis|NotImplemented|__debug__)\b + scope: constant.language.python + push: illegal-assignment + - match: \.{3}(?!\w) + scope: constant.language.python + + booleans: + - match: False\b + scope: constant.language.boolean.false.python + push: illegal-assignment + - match: True\b + scope: constant.language.boolean.true.python + push: illegal-assignment + + nones: + - match: None\b + scope: constant.language.null.python + push: illegal-assignment + + numbers: + # https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals + # hexadecimal + - match: (0[xX])(\h*)([lL]) # py2 + scope: meta.number.integer.hexadecimal.python + captures: + 1: constant.numeric.base.python + 2: constant.numeric.value.python + 3: constant.numeric.suffix.python + - match: (0[xX])((?:_?\h)+) + scope: meta.number.integer.hexadecimal.python + captures: + 1: constant.numeric.base.python + 2: constant.numeric.value.python + # octal + - match: (0[oO]?)((?=[oO]|[0-7])[0-7]*)([lL]) # py2 + scope: meta.number.integer.octal.python + captures: + 1: constant.numeric.base.python + 2: constant.numeric.value.python + 3: constant.numeric.suffix.python + - match: (0)([0-7]+)(\d*) # py2 + scope: meta.number.integer.octal.python + captures: + 1: constant.numeric.base.python + 2: constant.numeric.value.python + 3: invalid.illegal.digit.python + - match: (0[oO])((?:_?[0-7])+)(\d*) + scope: meta.number.integer.octal.python + captures: + 1: constant.numeric.base.python + 2: constant.numeric.value.python + 3: invalid.illegal.digit.python + # binary + - match: (0[bB])([01]*)([lL]) # py2 + scope: meta.number.integer.binary.python + captures: + 1: constant.numeric.base.python + 2: constant.numeric.value.python + 3: constant.numeric.suffix.python + - match: (0[bB])((?:_?[01])*)(\d*) + scope: meta.number.integer.binary.python + captures: + 1: constant.numeric.base.python + 2: constant.numeric.value.python + 3: invalid.illegal.digit.python + # complex + - match: |- + (?x) + ( + # 1.j, 1.1j, 1.1e1j, 1.1e-1j, 1.e1j, 1.e-1 | 1e1j, 1e-1j + {{digits}} (\.)? {{digits}}? {{exponent}}? + # .1j, .1e1j, .1e-1j + | (\.) {{digits}} {{exponent}}? + ) + ([jJ]) + scope: meta.number.imaginary.decimal.python + captures: + 1: constant.numeric.value.python + 2: punctuation.separator.decimal.python + 3: punctuation.separator.decimal.python + 4: constant.numeric.suffix.python + # floating point + - match: |- + (?x: + # 1., 1.1, 1.1e1, 1.1e-1, 1.e1, 1.e-1 | 1e1, 1e-1 + {{digits}} (?: (\.) {{digits}}? {{exponent}}? | {{exponent}} ) + # .1, .1e1, .1e-1 + | (\.) {{digits}} {{exponent}}? + ) + scope: meta.number.float.decimal.python constant.numeric.value.python + captures: + 1: punctuation.separator.decimal.python + 2: punctuation.separator.decimal.python + # integer + - match: ([1-9]\d*|0)([lL])\b # py2 + scope: meta.number.integer.decimal.python + captures: + 1: constant.numeric.value.python + 2: constant.numeric.suffix.python + - match: (?:(0?)[1-9][\d_]*|0) + scope: meta.number.integer.decimal.python constant.numeric.value.python + captures: + 1: invalid.illegal.digits.python + +###[ DOCSTRINGS ]############################################################# + + docstrings: + - include: double-quoted-docstrings + - include: single-quoted-docstrings + + double-quoted-docstrings: + - match: ^\s*(?i)(u)?(""") + captures: + 1: storage.type.string.python + 2: comment.block.documentation.python punctuation.definition.comment.begin.python + push: maybe-double-quoted-docstring-summery + - match: ^\s*(?i)(ur|ru?)(""") + captures: + 1: storage.type.string.python + 2: comment.block.documentation.python punctuation.definition.comment.begin.python + push: maybe-double-quoted-raw-docstring-summery + + maybe-double-quoted-docstring-summery: + - meta_content_scope: comment.block.documentation.python + - include: double-quoted-docstring-end + - match: (?=\S) + set: double-quoted-docstring-summery + + double-quoted-docstring-summery: + - meta_content_scope: comment.block.documentation.summary.python + - match: $ + set: double-quoted-docstring-body + - include: double-quoted-docstring-body + + double-quoted-docstring-end: + - match: '"""' + scope: comment.block.documentation.python punctuation.definition.comment.end.python + pop: 1 + - include: merge-conflict-markers + + double-quoted-docstring-body: + - meta_content_scope: comment.block.documentation.python + - include: double-quoted-docstring-end + - include: escaped-unicode-chars + - include: escaped-chars + + maybe-double-quoted-raw-docstring-summery: + - meta_content_scope: comment.block.documentation.python + - include: double-quoted-docstring-end + - match: (?=\S) + set: double-quoted-raw-docstring-summery + + double-quoted-raw-docstring-summery: + - meta_content_scope: comment.block.documentation.summary.python + - match: $ + set: double-quoted-raw-docstring-body + - include: double-quoted-raw-docstring-body + + double-quoted-raw-docstring-body: + - meta_content_scope: comment.block.documentation.python + - include: double-quoted-docstring-end + - include: escaped-raw-quotes + + single-quoted-docstrings: + - match: ^\s*(?i)(u)?(''') + captures: + 1: storage.type.string.python + 2: comment.block.documentation.python punctuation.definition.comment.begin.python + push: maybe-single-quoted-docstring-summery + - match: ^\s*(?i)(ur|ru?)(''') + captures: + 1: storage.type.string.python + 2: comment.block.documentation.python punctuation.definition.comment.begin.python + push: maybe-single-quoted-raw-docstring-summery + + single-quoted-docstring-end: + - match: "'''" + scope: comment.block.documentation.python punctuation.definition.comment.end.python + pop: 1 + - include: merge-conflict-markers + + maybe-single-quoted-docstring-summery: + - meta_content_scope: comment.block.documentation.python + - include: single-quoted-docstring-end + - match: (?=\S) + set: single-quoted-docstring-summery + + single-quoted-docstring-summery: + - meta_content_scope: comment.block.documentation.summary.python + - match: $ + set: single-quoted-docstring-body + - include: single-quoted-docstring-body + + single-quoted-docstring-body: + - meta_content_scope: comment.block.documentation.python + - include: single-quoted-docstring-end + - include: escaped-unicode-chars + - include: escaped-chars + + maybe-single-quoted-raw-docstring-summery: + - meta_content_scope: comment.block.documentation.python + - include: single-quoted-docstring-end + - match: (?=\S) + set: single-quoted-raw-docstring-summery + + single-quoted-raw-docstring-summery: + - meta_content_scope: comment.block.documentation.summary.python + - match: $ + set: single-quoted-raw-docstring-body + - include: single-quoted-raw-docstring-body + + single-quoted-raw-docstring-body: + - meta_content_scope: comment.block.documentation.python + - include: single-quoted-docstring-end + - include: escaped-raw-quotes + +###[ STRINGS ]################################################################ + + strings: + - match: (?={{string_prefix}}['"]) + push: string + + string: + - meta_include_prototype: false + # triple-quoted versions must be matched first + - include: triple-double-quoted-string + - include: double-quoted-string + - include: triple-single-quoted-string + - include: single-quoted-string + +###[ TRIPLE DOUBLE QUOTED STRINGS ]########################################### + + triple-double-quoted-string: + - include: triple-double-quoted-plain-raw-b-string + - include: triple-double-quoted-raw-b-string + - include: triple-double-quoted-plain-raw-f-string + - include: triple-double-quoted-raw-f-string + - include: triple-double-quoted-plain-raw-u-string + - include: triple-double-quoted-raw-u-string + - include: triple-double-quoted-b-string + - include: triple-double-quoted-f-string + - include: triple-double-quoted-u-string + + triple-double-quoted-string-end: + - match: '"""' + scope: meta.string.python string.quoted.double.block.python punctuation.definition.string.end.python + set: after-expression + - include: merge-conflict-markers + + triple-double-quoted-string-pop: + - match: (?=""") + pop: 1 + + triple-double-quoted-plain-raw-b-string: + # Triple-quoted capital R raw string, bytes, no syntax embedding + - match: ([bB]R|R[bB])(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-plain-raw-b-string-body + + triple-double-quoted-plain-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-plain-raw-b-string-content + + triple-double-quoted-plain-raw-b-string-content: + - include: string-prototype + - include: escaped-raw-quotes + + triple-double-quoted-raw-b-string: + # Triple-quoted raw string, bytes, will use regex + - match: ([bB]r|r[bB])(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-raw-b-string-body + + triple-double-quoted-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python source.regexp.python + - include: triple-double-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal-extended + with_prototype: + - include: triple-double-quoted-string-pop + - include: triple-double-quoted-raw-b-string-content + + triple-double-quoted-raw-b-string-content: + - include: string-prototype + + triple-double-quoted-plain-raw-f-string: + # Triple-quoted raw f-string or t-string + - match: ([fFtT]R|R[fFtT])(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-plain-raw-f-string-body + + triple-double-quoted-plain-raw-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-plain-raw-f-string-content + + triple-double-quoted-plain-raw-f-string-content: + - include: string-prototype + - include: escaped-raw-quotes + - include: triple-double-quoted-f-string-replacements + + triple-double-quoted-raw-f-string: + # Triple-quoted raw f-string or t-string, treated as regex + - match: ([fFtT]r|r[fFtT])(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-raw-f-string-body + + triple-double-quoted-raw-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python source.regexp.python + - include: triple-double-quoted-string-end + - match: '' + push: scope:source.regexp.python.embedded.raw-f-string#base-literal-extended + with_prototype: + - include: triple-double-quoted-string-pop + - include: triple-double-quoted-raw-f-string-content + + triple-double-quoted-raw-f-string-content: + - include: string-prototype + - include: triple-double-quoted-f-string-replacements-regexp + + triple-double-quoted-plain-raw-u-string: + # Triple-quoted capital R raw string, unicode or not, no syntax embedding + - match: ([uU]?R)(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-plain-raw-u-string-body + + triple-double-quoted-plain-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-plain-raw-u-string-content + + triple-double-quoted-plain-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: triple-double-quoted-string-replacements + - include: escaped-raw-quotes + + triple-double-quoted-raw-u-string: + # Triple-quoted raw string, unicode or not, will detect SQL, otherwise regex + - match: ([uU]?r)(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-raw-u-string-body + + triple-double-quoted-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-raw-u-string-syntax + + triple-double-quoted-raw-u-string-syntax: + - match: (?={{sql_indicator}}) + set: triple-double-quoted-sql-raw-u-string-body + - match: (?=\S) + set: triple-double-quoted-regexp-raw-u-string-body + + triple-double-quoted-regexp-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python source.regexp.python + - include: triple-double-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal-extended + with_prototype: + - include: triple-double-quoted-string-pop + - include: triple-double-quoted-regexp-raw-u-string-content + + triple-double-quoted-regexp-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + + triple-double-quoted-sql-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: triple-double-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: triple-double-quoted-string-pop + - include: triple-double-quoted-sql-raw-u-string-content + + triple-double-quoted-sql-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: triple-double-quoted-string-replacements + - include: escaped-raw-quotes + + triple-double-quoted-b-string: + # Triple-quoted string, bytes, no syntax embedding + - match: ([bB])(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-b-string-body + + triple-double-quoted-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-b-string-content + + triple-double-quoted-b-string-content: + - include: string-prototype + - include: string-continuations + - include: string-placeholders + - include: escaped-chars + + triple-double-quoted-f-string: + # Triple-quoted f-string or t-string + - match: ([fFtT])(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-f-string-body + + triple-double-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-f-string-content + + triple-double-quoted-f-string-content: + - include: string-prototype + - include: string-continuations + - include: triple-double-quoted-f-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + triple-double-quoted-u-string: + # Triple-quoted string, unicode or not, will detect SQL + - match: ([uU]?)(""") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.block.python punctuation.definition.string.begin.python + set: triple-double-quoted-u-string-body + + triple-double-quoted-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: string-continuations + - include: triple-double-quoted-u-string-syntax + + triple-double-quoted-u-string-syntax: + - match: (?={{sql_indicator}}) + set: triple-double-quoted-sql-u-strings-body + - match: (?=\S) + set: double-quoted-plain-u-block-string-body + + double-quoted-plain-u-block-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: triple-double-quoted-string-end + - include: triple-double-quoted-u-string-content + + triple-double-quoted-sql-u-strings-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: triple-double-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: triple-double-quoted-string-pop + - include: triple-double-quoted-u-string-content + + triple-double-quoted-u-string-content: + - include: string-prototype + - include: string-continuations + - include: string-placeholders + - include: triple-double-quoted-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + triple-double-quoted-string-replacements: + - include: escaped-string-braces + - match: (?=\{) + branch_point: triple-double-quoted-string-replacement + branch: + - triple-double-quoted-string-replacement + - string-replacement-fallback + + triple-double-quoted-string-replacement: + - match: \{ + scope: punctuation.definition.placeholder.begin.python + set: triple-double-quoted-string-replacement-body + + triple-double-quoted-string-replacement-body: + - meta_scope: constant.other.placeholder.python + - include: string-replacement-body + - match: \[ + scope: punctuation.section.brackets.begin.python + push: triple-double-string-replacement-brackets-body + - match: ':' + scope: punctuation.separator.format-spec.python + push: triple-double-quoted-string-replacement-formatspec-body + - match: (?!\w) # restrict field names to reduce risk of false positives + fail: triple-double-quoted-string-replacement + + triple-double-string-replacement-brackets-body: + - include: string-replacement-brackets-body + - include: triple-double-quoted-string-replacement-fail + + triple-double-quoted-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: string-replacement-formatspec-body + - match: \{ + scope: punctuation.definition.placeholder.begin.python + push: triple-double-quoted-string-replacement-body + - include: triple-double-quoted-string-replacement-fail + + triple-double-quoted-string-replacement-fail: + - match: (?="""|$) + fail: triple-double-quoted-string-replacement + + triple-double-quoted-f-string-replacements: + - include: escaped-string-braces + - include: invalid-f-string-replacements + - match: \{ + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-meta + - triple-double-quoted-f-string-replacement-formatspec + - triple-double-quoted-f-string-replacement-expression + + triple-double-quoted-f-string-replacements-regexp: + # Same as f-string-replacements, but will reset the entire scope stack. + # Escaped f-string characters are handled by regexp syntax. + - include: invalid-f-string-replacements + - match: \{(?!{) + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-regexp-meta + - triple-double-quoted-f-string-replacement-formatspec + - triple-double-quoted-f-string-replacement-expression + + triple-double-quoted-f-string-replacement-expression: + - include: f-string-replacement-expression + + triple-double-quoted-f-string-replacement-formatspec: + - meta_include_prototype: false + - match: ':' + scope: punctuation.separator.format-spec.python + set: triple-double-quoted-f-string-replacement-formatspec-body + - include: triple-double-quoted-f-string-replacement-end + + triple-double-quoted-f-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: triple-double-quoted-f-string-replacement-end + - include: triple-double-quoted-f-string-replacements + + triple-double-quoted-f-string-replacement-end: + - include: f-string-replacement-end + - match: (?=""") + pop: 2 + +###[ DOUBLE QUOTED STRINGS ]################################################## + + double-quoted-strings: + - match: (?={{string_prefix}}"(?!")) + push: double-quoted-string + + double-quoted-string: + - meta_include_prototype: false + - include: double-quoted-plain-raw-b-string + - include: double-quoted-raw-b-string + - include: double-quoted-plain-raw-f-string + - include: double-quoted-raw-f-string + - include: double-quoted-plain-raw-u-string + - include: double-quoted-raw-u-string + - include: double-quoted-b-string + - include: double-quoted-f-string + - include: double-quoted-u-string + + double-quoted-string-end: + - match: '"' + scope: meta.string.python string.quoted.double.python punctuation.definition.string.end.python + set: after-expression + - match: \n + scope: meta.string.python string.quoted.double.python invalid.illegal.unclosed-string.python + set: after-expression + - include: string-continuations + - include: merge-conflict-markers + + double-quoted-string-pop: + - match: (?="|\n) + pop: 1 + - include: string-continuations + + double-quoted-plain-raw-b-string: + # Single-line capital R raw string, bytes, no syntax embedding + - match: ([bB]R|R[bB])(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-plain-raw-b-string-body + + double-quoted-plain-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python + - include: double-quoted-string-end + - include: double-quoted-plain-raw-b-string-content + + double-quoted-plain-raw-b-string-content: + - include: string-prototype + - include: escaped-raw-quotes + + double-quoted-raw-b-string: + # Single-line raw string, bytes, treated as regex + - match: ([bB]r|r[bB])(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-raw-b-string-body + + double-quoted-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python source.regexp.python + - include: double-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal + with_prototype: + - include: double-quoted-string-pop + - include: double-quoted-raw-b-string-content + + double-quoted-raw-b-string-content: + - include: string-prototype + + double-quoted-plain-raw-f-string: + # Single-line raw f-string or t-string + - match: ([fFtT]R|R[fFtT])(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-plain-raw-f-string-body + + double-quoted-plain-raw-f-string-body: + - meta_content_scope: meta.string.python string.quoted.double.python + - meta_include_prototype: false + - include: double-quoted-string-end + - include: double-quoted-plain-raw-f-string-content + + double-quoted-plain-raw-f-string-content: + - include: string-prototype + - include: escaped-raw-quotes + - include: double-quoted-f-string-replacements + + double-quoted-raw-f-string: + # Single-line raw f-string or t-string, treated as regex + - match: ([fFtT]r|r[fFtT])(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-raw-f-string-body + + double-quoted-raw-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python source.regexp.python + - include: double-quoted-string-end + - match: '' + push: scope:source.regexp.python.embedded.raw-f-string#base-literal + with_prototype: + - include: double-quoted-string-pop + - include: double-quoted-raw-f-string-content + + double-quoted-raw-f-string-content: + - include: string-prototype + - include: double-quoted-f-string-replacements-regexp + + double-quoted-plain-raw-u-string: + # Single-line capital R raw string, unicode or not, no syntax embedding + - match: ([uU]?R)(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-plain-raw-u-string-body + + double-quoted-plain-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python + - include: double-quoted-string-end + - include: double-quoted-plain-raw-u-string-content + + double-quoted-plain-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: double-quoted-string-replacements + - include: escaped-raw-quotes + + double-quoted-raw-u-string: + - match: ([uU]?r)(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-raw-u-string-body + + double-quoted-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.block.python + - include: double-quoted-string-end + - include: double-quoted-raw-u-string-syntax + + double-quoted-raw-u-string-syntax: + # Single-line raw string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: double-quoted-sql-raw-u-string-body + # Single-line raw string, unicode or not, treated as regex + - match: (?=\S) + set: double-quoted-regexp-raw-u-string-body + + double-quoted-regexp-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python source.regexp.python + - include: double-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal + with_prototype: + - include: double-quoted-string-pop + - include: double-quoted-regexp-raw-u-string-content + + double-quoted-regexp-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + + double-quoted-sql-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: double-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: double-quoted-string-pop + - include: double-quoted-sql-raw-u-string-content + + double-quoted-sql-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: double-quoted-string-replacements + - include: escaped-raw-quotes + + double-quoted-b-string: + # Single-line string, bytes + - match: ([bB])(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-b-string-body + + double-quoted-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python + - include: double-quoted-string-end + - include: double-quoted-b-string-content + + double-quoted-b-string-content: + - include: string-prototype + - include: string-placeholders + - include: escaped-chars + + double-quoted-f-string: + # Single-line f-string or t-string + - match: ([fFtT])(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-f-string-body + + double-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python + - include: double-quoted-string-end + - include: double-quoted-f-string-content + + double-quoted-f-string-content: + - include: string-prototype + - include: double-quoted-f-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + double-quoted-u-string: + - match: ([uU]?)(") + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.double.python punctuation.definition.string.begin.python + set: double-quoted-u-string-body + + double-quoted-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python + - include: double-quoted-string-end + - include: double-quoted-u-string-syntax + + double-quoted-u-string-syntax: + # Single-line string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: double-quoted-sql-u-string-body + # Single-line string, unicode or not + - match: (?=\S) + set: double-quoted-plain-u-string-body + + double-quoted-plain-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.double.python + - include: double-quoted-string-end + - include: double-quoted-u-string-content + + double-quoted-sql-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: double-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: double-quoted-string-pop + - include: double-quoted-u-string-content + + double-quoted-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: double-quoted-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + double-quoted-string-replacements: + - include: escaped-string-braces + - match: (?=\{) + branch_point: double-quoted-string-replacement + branch: + - double-quoted-string-replacement + - string-replacement-fallback + + double-quoted-string-replacement: + - match: \{ + scope: punctuation.definition.placeholder.begin.python + set: double-quoted-string-replacement-body + + double-quoted-string-replacement-body: + - meta_scope: constant.other.placeholder.python + - include: string-replacement-body + - match: \[ + scope: punctuation.section.brackets.begin.python + push: double-quoted-string-replacement-brackets-body + - match: ':' + scope: punctuation.separator.format-spec.python + push: double-quoted-string-replacement-formatspec-body + - match: (?!\w) # restrict field names to reduce risk of false positives + fail: double-quoted-string-replacement + + double-quoted-string-replacement-brackets-body: + - include: string-replacement-brackets-body + - include: double-quoted-string-replacement-fail + + double-quoted-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: string-replacement-formatspec-body + - match: \{ + scope: punctuation.definition.placeholder.begin.python + push: double-quoted-string-replacement-body + - include: double-quoted-string-replacement-fail + + double-quoted-string-replacement-fail: + - match: (?="|$) + fail: double-quoted-string-replacement + + double-quoted-f-string-replacements: + - include: escaped-string-braces + - include: invalid-f-string-replacements + - match: \{ + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-meta + - double-quoted-f-string-replacement-formatspec + - double-quoted-f-string-replacement-expression + + double-quoted-f-string-replacements-regexp: + # Same as f-string-replacements, but will reset the entire scope stack. + # Escaped f-string characters are handled by regexp syntax. + - include: invalid-f-string-replacements + - match: \{(?!{) + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-regexp-meta + - double-quoted-f-string-replacement-formatspec + - double-quoted-f-string-replacement-expression + + double-quoted-f-string-replacement-expression: + - include: f-string-replacement-expression + - include: eol-pop + + double-quoted-f-string-replacement-formatspec: + - meta_include_prototype: false + - match: ':' + scope: punctuation.separator.format-spec.python + set: double-quoted-f-string-replacement-formatspec-body + - include: double-quoted-f-string-replacement-end + + double-quoted-f-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: double-quoted-f-string-replacement-end + - include: double-quoted-f-string-replacements + + double-quoted-f-string-replacement-end: + - include: f-string-replacement-end + - match: (?="|$) + pop: 2 + +###[ TRIPLE SINGLE QUOTED STRINGS ]########################################### + + triple-single-quoted-string: + - include: triple-single-quoted-plain-raw-b-string + - include: triple-single-quoted-raw-b-string + - include: triple-single-quoted-plain-raw-f-string + - include: triple-single-quoted-raw-f-string + - include: triple-single-quoted-plain-raw-u-string + - include: triple-single-quoted-raw-u-string + - include: triple-single-quoted-b-string + - include: triple-single-quoted-f-string + - include: triple-single-quoted-u-string + + triple-single-quoted-string-end: + - match: "'''" + scope: meta.string.python string.quoted.single.block.python punctuation.definition.string.end.python + set: after-expression + - include: merge-conflict-markers + + triple-single-quoted-string-pop: + - match: (?=''') + pop: 1 + + triple-single-quoted-plain-raw-b-string: + # Triple-quoted capital R raw string, bytes, no syntax embedding + - match: ([bB]R|R[bB])(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-plain-raw-b-string-body + + triple-single-quoted-plain-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-plain-raw-b-string-content + + triple-single-quoted-plain-raw-b-string-content: + - include: string-prototype + - include: escaped-raw-quotes + + triple-single-quoted-raw-b-string: + # Triple-quoted raw string, bytes, will use regex + - match: ([bB]r|r[bB])(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-raw-b-string-body + + triple-single-quoted-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python source.regexp.python + - include: triple-single-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal-extended + with_prototype: + - include: triple-single-quoted-string-pop + - include: triple-single-quoted-raw-b-string-content + + triple-single-quoted-raw-b-string-content: + - include: string-prototype + + triple-single-quoted-plain-raw-f-string: + # Triple-quoted raw f-string or t-string + - match: ([fFtT]R|R[fFtT])(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-plain-raw-f-string-body + + triple-single-quoted-plain-raw-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-plain-raw-f-string-content + + triple-single-quoted-plain-raw-f-string-content: + - include: string-prototype + - include: escaped-raw-quotes + - include: triple-single-quoted-f-string-replacements + + triple-single-quoted-raw-f-string: + # Triple-quoted raw f-string or t-string, treated as regex + - match: ([fFtT]r|r[fFtT])(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-raw-f-string-body + + triple-single-quoted-raw-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python source.regexp.python + - include: triple-single-quoted-string-end + - match: '' + push: scope:source.regexp.python.embedded.raw-f-string#base-literal-extended + with_prototype: + - include: triple-single-quoted-string-pop + - include: triple-single-quoted-raw-f-string-content + + triple-single-quoted-raw-f-string-content: + - include: string-prototype + - include: triple-single-quoted-f-string-replacements-regexp + + triple-single-quoted-plain-raw-u-string: + # Triple-quoted capital R raw string, unicode or not, no syntax embedding + - match: ([uU]?R)(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-plain-raw-u-string-body + + triple-single-quoted-plain-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-plain-raw-u-string-content + + triple-single-quoted-plain-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: triple-single-quoted-string-replacements + - include: escaped-raw-quotes + + triple-single-quoted-raw-u-string: + # Triple-quoted raw string, unicode or not, will detect SQL, otherwise regex + - match: ([uU]?r)(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-raw-u-string-body + + triple-single-quoted-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-raw-u-string-syntax + + triple-single-quoted-raw-u-string-syntax: + - match: (?={{sql_indicator}}) + set: triple-single-quoted-sql-raw-u-string-body + - match: (?=\S) + set: triple-single-quoted-regexp-raw-u-string-body + + triple-single-quoted-regexp-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python source.regexp.python + - include: triple-single-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal-extended + with_prototype: + - include: triple-single-quoted-string-pop + - include: triple-single-quoted-regexp-raw-u-string-content + + triple-single-quoted-regexp-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + + triple-single-quoted-sql-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: triple-single-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: triple-single-quoted-string-pop + - include: triple-single-quoted-sql-raw-u-string-content + + triple-single-quoted-sql-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: triple-single-quoted-string-replacements + - include: escaped-raw-quotes + + triple-single-quoted-b-string: + # Triple-quoted string, bytes, no syntax embedding + - match: ([bB])(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-b-string-body + + triple-single-quoted-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-b-string-content + + triple-single-quoted-b-string-content: + - include: string-prototype + - include: string-continuations + - include: string-placeholders + - include: escaped-chars + + triple-single-quoted-f-string: + # Triple-quoted f-string or t-string + - match: ([fFtT])(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-f-string-body + + triple-single-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-f-string-content + + triple-single-quoted-f-string-content: + - include: string-prototype + - include: string-continuations + - include: triple-single-quoted-f-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + triple-single-quoted-u-string: + # Triple-quoted string, unicode or not, will detect SQL + - match: ([uU]?)(''') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.block.python punctuation.definition.string.begin.python + set: triple-single-quoted-u-string-body + + triple-single-quoted-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: string-continuations + - include: triple-single-quoted-u-string-syntax + + triple-single-quoted-u-string-syntax: + - match: (?={{sql_indicator}}) + set: triple-single-quoted-sql-u-string-body + - match: (?=\S) + set: single-quoted-plain-u-block-string-body + + single-quoted-plain-u-block-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.block.python + - include: triple-single-quoted-string-end + - include: triple-single-quoted-u-string-content + + triple-single-quoted-sql-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: triple-single-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: triple-single-quoted-string-pop + - include: triple-single-quoted-u-string-content + + triple-single-quoted-u-string-content: + - include: string-prototype + - include: string-continuations + - include: string-placeholders + - include: triple-single-quoted-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + triple-single-quoted-string-replacements: + - include: escaped-string-braces + - match: (?=\{) + branch_point: triple-single-quoted-string-replacement + branch: + - triple-single-quoted-string-replacement + - string-replacement-fallback + + triple-single-quoted-string-replacement: + - match: \{ + scope: punctuation.definition.placeholder.begin.python + set: triple-single-quoted-string-replacement-body + + triple-single-quoted-string-replacement-body: + - meta_scope: constant.other.placeholder.python + - include: string-replacement-body + - match: \[ + scope: punctuation.section.brackets.begin.python + push: triple-single-string-replacement-brackets-body + - match: ':' + scope: punctuation.separator.format-spec.python + push: triple-single-quoted-string-replacement-formatspec-body + - match: (?!\w) # restrict field names to reduce risk of false positives + fail: triple-single-quoted-string-replacement + + triple-single-string-replacement-brackets-body: + - include: string-replacement-brackets-body + - include: triple-single-quoted-string-replacement-fail + + triple-single-quoted-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: string-replacement-formatspec-body + - match: \{ + scope: punctuation.definition.placeholder.begin.python + push: triple-single-quoted-string-replacement-body + - include: triple-single-quoted-string-replacement-fail + + triple-single-quoted-string-replacement-fail: + - match: (?='''|$) + fail: triple-single-quoted-string-replacement + + triple-single-quoted-f-string-replacements: + - include: escaped-string-braces + - include: invalid-f-string-replacements + - match: \{ + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-meta + - triple-single-quoted-f-string-replacement-formatspec + - triple-single-quoted-f-string-replacement-expression + + triple-single-quoted-f-string-replacements-regexp: + # Same as f-string-replacements, but will reset the entire scope stack. + # Escaped f-string characters are handled by regexp syntax. + - include: invalid-f-string-replacements + - match: \{(?!{) + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-regexp-meta + - triple-single-quoted-f-string-replacement-formatspec + - triple-single-quoted-f-string-replacement-expression + + triple-single-quoted-f-string-replacement-expression: + - include: f-string-replacement-expression + + triple-single-quoted-f-string-replacement-formatspec: + - meta_include_prototype: false + - match: ':' + scope: punctuation.separator.format-spec.python + set: triple-single-quoted-f-string-replacement-formatspec-body + - include: triple-single-quoted-f-string-replacement-end + + triple-single-quoted-f-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: triple-single-quoted-f-string-replacement-end + - include: triple-single-quoted-f-string-replacements + + triple-single-quoted-f-string-replacement-end: + - include: f-string-replacement-end + - match: (?=''') + pop: 2 + +###[ SINGLE QUOTED STRINGS ]################################################## + + single-quoted-strings: + - match: (?={{string_prefix}}'(?!')) + push: single-quoted-string + + single-quoted-string: + - meta_include_prototype: false + - include: single-quoted-plain-raw-b-string + - include: single-quoted-raw-b-string + - include: single-quoted-plain-raw-f-string + - include: single-quoted-raw-f-string + - include: single-quoted-plain-raw-u-string + - include: single-quoted-raw-u-string + - include: single-quoted-b-string + - include: single-quoted-f-string + - include: single-quoted-u-string + + single-quoted-string-end: + - match: "'" + scope: meta.string.python string.quoted.single.python punctuation.definition.string.end.python + set: after-expression + - match: \n + scope: meta.string.python string.quoted.single.python invalid.illegal.unclosed-string.python + set: after-expression + - include: string-continuations + - include: merge-conflict-markers + + single-quoted-string-pop: + - match: (?='|\n) + pop: 1 + - include: string-continuations + + single-quoted-plain-raw-b-string: + # Single-line capital R raw string, bytes, no syntax embedding + - match: ([bB]R|R[bB])(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-plain-raw-b-string-body + + single-quoted-plain-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-plain-raw-b-string-content + + single-quoted-plain-raw-b-string-content: + - include: string-prototype + - include: escaped-raw-quotes + + single-quoted-raw-b-string: + # Single-line raw string, bytes, treated as regex + - match: ([bB]r|r[bB])(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-raw-b-string-body + + single-quoted-raw-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python source.regexp.python + - include: single-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal + with_prototype: + - include: single-quoted-string-pop + - include: single-quoted-raw-b-string-content + + single-quoted-raw-b-string-content: + - include: string-prototype + + single-quoted-plain-raw-u-string: + # Single-line capital R raw string, unicode or not, no syntax embedding + - match: ([uU]?R)(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-plain-raw-u-string-body + + single-quoted-plain-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-plain-raw-u-string-content + + single-quoted-plain-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: single-quoted-string-replacements + - include: escaped-raw-quotes + + single-quoted-raw-u-string: + - match: ([uU]?r)(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-raw-u-string-body + + single-quoted-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-raw-u-string-syntax + + single-quoted-raw-u-string-syntax: + # Single-line raw string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: single-quoted-sql-raw-u-string-body + # Single-line raw string, unicode or not, treated as regex + - match: (?=\S) + set: single-quoted-regexp-raw-u-string-body + + single-quoted-regexp-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python source.regexp.python + - include: single-quoted-string-end + - match: '' + push: scope:source.regexp.python#base-literal + with_prototype: + - include: single-quoted-string-pop + - include: single-quoted-regexp-raw-u-string-content + + single-quoted-regexp-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + + single-quoted-sql-raw-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: single-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: single-quoted-string-pop + - include: single-quoted-sql-raw-u-string-content + + single-quoted-sql-raw-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: single-quoted-string-replacements + - include: escaped-raw-quotes + + single-quoted-plain-raw-f-string: + # Single-line raw f-string + - match: ([fFtT]R|R[fFtT])(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-plain-raw-f-string-body + + single-quoted-plain-raw-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-plain-raw-f-string-content + + single-quoted-plain-raw-f-string-content: + - include: string-prototype + - include: escaped-raw-quotes + - include: single-quoted-f-string-replacements + + single-quoted-raw-f-string: + # Single-line raw f-string, treated as regex + - match: ([fFtT]r|r[fFtT])(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-raw-f-string-body + + single-quoted-raw-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python source.regexp.python + - include: single-quoted-string-end + - match: '' + push: scope:source.regexp.python.embedded.raw-f-string#base-literal + with_prototype: + - include: single-quoted-string-pop + - include: single-quoted-raw-f-string-content + + single-quoted-raw-f-string-content: + - include: string-prototype + - include: single-quoted-f-string-replacements-regexp + + single-quoted-b-string: + # Single-line string, bytes + - match: ([bB])(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-b-string-body + + single-quoted-b-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-b-string-content + + single-quoted-b-string-content: + - include: string-prototype + - include: string-placeholders + - include: escaped-chars + + single-quoted-f-string: + # Single-line f-string or t-string + - match: ([fFtT])(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-f-string-body + + single-quoted-f-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-f-string-content + + single-quoted-f-string-content: + - include: string-prototype + - include: single-quoted-f-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + single-quoted-u-string: + - match: ([uU]?)(') + captures: + 1: storage.type.string.python + 2: meta.string.python string.quoted.single.python punctuation.definition.string.begin.python + set: single-quoted-u-string-body + + single-quoted-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-u-string-syntax + + single-quoted-u-string-syntax: + # Single-line string, unicode or not, starting with a SQL keyword + - match: (?={{sql_indicator}}) + set: single-quoted-sql-u-string-body + # Single-line string, unicode or not + - match: (?=\S) + set: single-quoted-plain-u-string-body + + single-quoted-plain-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python string.quoted.single.python + - include: single-quoted-string-end + - include: single-quoted-u-string-content + + single-quoted-sql-u-string-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.python + - include: single-quoted-string-end + - match: '' + push: scope:source.sql + with_prototype: + - include: single-quoted-string-pop + - include: single-quoted-u-string-content + + single-quoted-u-string-content: + - include: string-prototype + - include: string-placeholders + - include: single-quoted-string-replacements + - include: escaped-unicode-chars + - include: escaped-chars + + single-quoted-string-replacements: + - include: escaped-string-braces + - match: (?=\{) + branch_point: single-quoted-string-replacement + branch: + - single-quoted-string-replacement + - string-replacement-fallback + + single-quoted-string-replacement: + - match: \{ + scope: punctuation.definition.placeholder.begin.python + set: single-quoted-string-replacement-body + + single-quoted-string-replacement-body: + - meta_scope: constant.other.placeholder.python + - include: string-replacement-body + - match: \[ + scope: punctuation.section.brackets.begin.python + push: single-string-replacement-brackets-body + - match: ':' + scope: punctuation.separator.format-spec.python + push: single-quoted-string-replacement-formatspec-body + - match: (?!\w) # restrict field names to reduce risk of false positives + fail: single-quoted-string-replacement + + single-string-replacement-brackets-body: + - include: string-replacement-brackets-body + - include: single-quoted-string-replacement-fail + + single-quoted-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: string-replacement-formatspec-body + - match: \{ + scope: punctuation.definition.placeholder.begin.python + push: single-quoted-string-replacement-body + - include: single-quoted-string-replacement-fail + + single-quoted-string-replacement-fail: + - match: (?='|$) + fail: single-quoted-string-replacement + + single-quoted-f-string-replacements: + - include: escaped-string-braces + - include: invalid-f-string-replacements + - match: \{ + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-meta + - single-quoted-f-string-replacement-formatspec + - single-quoted-f-string-replacement-expression + + single-quoted-f-string-replacements-regexp: + # Same as f-string-replacements, but will reset the entire scope stack. + # Escaped f-string characters are handled by regexp syntax. + - include: invalid-f-string-replacements + - match: \{(?!{) + scope: punctuation.section.interpolation.begin.python + push: + - f-string-replacement-regexp-meta + - single-quoted-f-string-replacement-formatspec + - single-quoted-f-string-replacement-expression + + single-quoted-f-string-replacement-expression: + - include: f-string-replacement-expression + - include: eol-pop + + single-quoted-f-string-replacement-formatspec: + - meta_include_prototype: false + - match: ':' + scope: punctuation.separator.format-spec.python + set: single-quoted-f-string-replacement-formatspec-body + - include: single-quoted-f-string-replacement-end + + single-quoted-f-string-replacement-formatspec-body: + - meta_content_scope: meta.format-spec.python constant.other.format-spec.python + - include: single-quoted-f-string-replacement-end + - include: single-quoted-f-string-replacements + + single-quoted-f-string-replacement-end: + - include: f-string-replacement-end + - match: (?='|$) + pop: 2 + +###[ STRING CONTENTS ]######################################################## + + string-continuations: + - match: \\$ + scope: punctuation.separator.continuation.line.python + push: + - meta_include_prototype: false + - match: ^ + pop: 1 + + escaped-chars: + - match: \\x\h{2} + scope: constant.character.escape.hex.python + - match: \\[0-7]{1,3} + scope: constant.character.escape.octal.python + - match: \\[\\"'abfnrtv] + scope: constant.character.escape.python + - match: \\. # deprecated in 3.6 and will eventually be a syntax error + scope: invalid.deprecated.character.escape.python + + escaped-unicode-chars: + - match: \\u\h{4} + scope: constant.character.escape.unicode.16bit.python + - match: \\U\h{8} + scope: constant.character.escape.unicode.32bit.python + - match: \\N\{[-a-zA-Z ]+\} + scope: constant.character.escape.unicode.name.python + + escaped-raw-quotes: + # consume escaped quotes in raw-strings to prevent them terminating strings + # but don't scope them as escapes as they are treated literal + - match: \\[\\'"] + + escaped-string-braces: + # https://peps.python.org/pep-0498 + # https://peps.python.org/pep-0701 + # https://docs.python.org/3.6/reference/lexical_analysis.html#f-strings + - match: (\\)?(?:\{\{|\}\}) + scope: constant.character.escape.python + captures: + 1: invalid.deprecated.character.escape.python + + string-placeholders: + - match: |- # printf style + (?x) + % + ( \( ({{identifier}}) \) )? # mapping key + \#? # alternate form + 0? # pad with zeros + \-? # left-adjust + \ ? # implicit sign + [+-]? # sign + (\d*|\*) # width + (\. (\d*|\*))? # precision + [hlL]? # length modifier (but ignored) + [acdeEfFgGiorsuxX%] + scope: constant.other.placeholder.python + captures: + 2: variable.other.placeholder.python + - match: '{{strftime_spec}}' + scope: constant.other.placeholder.python + + string-replacement-body: + - match: \} + scope: punctuation.definition.placeholder.end.python + pop: 1 + - match: \. + scope: punctuation.accessor.dot.python + - match: '![ars]\b' + scope: storage.modifier.conversion.python + - include: escaped-chars + + string-replacement-brackets-body: + - meta_scope: meta.brackets.python + - match: \] + scope: punctuation.section.brackets.end.python + pop: 1 + - include: eol-pop + - include: escaped-chars + + string-replacement-formatspec-body: + - match: \} + scope: punctuation.definition.placeholder.end.python + pop: 2 + - include: escaped-chars + + string-replacement-fallback: + - match: \{ + pop: 1 + + f-string-replacement-meta: + - clear_scopes: 1 + - meta_include_prototype: false + - meta_scope: meta.interpolation.python + - include: immediately-pop + + f-string-replacement-regexp-meta: + # Same as f-string-replacement, but with clear_scopes: true + - clear_scopes: true + - meta_include_prototype: false + - meta_scope: source.python meta.string.python meta.interpolation.python + - include: immediately-pop + + f-string-replacement-expression: + - match: (?:\s*(=)\s*)?(![ars])?(?=[:}]) + captures: + 1: storage.modifier.debug.python + 2: storage.modifier.conversion.python + pop: 1 + - match: \\ + scope: invalid.illegal.backslash-in-fstring.python + - include: expression-in-a-sequence + + f-string-replacement-end: + - match: \} + scope: punctuation.section.interpolation.end.python + pop: 2 + + invalid-f-string-replacements: + - match: \{\s*\} + scope: invalid.illegal.empty-expression.python + - match: \}(?!}) + scope: invalid.illegal.stray.python + + # for use by inheriting syntaxes to easily inject string interpolation + # in any kind of quoted or unquoted string + string-prototype: [] + +###[ PROTOTYPES ]############################################################# + + after-expression: + - match: \s*(?=\() + scope: meta.function-call.python + set: function-call-argument-list + - include: item-access + - include: line-continuation-immediately-pop + + else-pop: + - match: (?=\S) + pop: 1 + + eol-pop: + - match: $ + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + line-continuation-immediately-pop: + - match: \s*(\\)\s*$ + captures: + 1: punctuation.separator.continuation.line.python + push: line-continuation-body + - include: immediately-pop + + line-continuation-or-pop: + - include: line-continuations + - match: (?=\s*[\n;#]) + pop: 1 + + line-continuations: + - match: (\\)\s*$ + captures: + 1: punctuation.separator.continuation.line.python + push: line-continuation-body + + line-continuation-body: + - meta_include_prototype: false + # This prevents strings after a continuation from being a docstring + - include: triple-double-quoted-string + - include: triple-single-quoted-string + - match: ^(?!\s*{{string_prefix}}['"]{3}) + pop: 1 + +############################################################################## + +variables: + shebang_language: \b(?:python(?:\d(?:\.\d+)?)?|uv)\b + + identifier: '{{identifier_start}}{{identifier_char}}*' + identifier_start: '[[:alpha:]_]' + identifier_char: '[[:alnum:]_]' + identifier_class: '_?[[:upper:]](?:[[:upper:][:digit:]]*[[:lower:]]+[[:alnum:]]*)\b' + identifier_constant: '(?:[_[:upper:]][_[:upper:][:digit:]]*)?[[:upper:]]{2,}[_[:upper:][:digit:]]*\b' # require 2 consecutive upper-case letters + + illegal_names: (?:and|as|assert|break|class|continue|def|del|elif|else|except|finally|for|from|global|if|import|in|is|lambda|not|or|pass|raise|return|try|while|with|yield)\b + + digits: (?:\d+(?:_\d+)*) + exponent: (?:[eE][-+]?{{digits}}) + + strftime_spec: (?:%(?:[aAwdbBGmyYHIpMSfzZjuUVWcxX%]|-[dmHIMSj])) + + augmented_assignment_operators: |- + (?x: >>= | <<= | \*\*= | //= | \+= | -= | \*= | /= | %= | @= | &= | \|= | \^= ) + + assignment_operator: '=(?!=)' + + colon: ':(?!=)' + + # up to 4 nested item_access brackets + item_access: |- + (?x: + \[ + (?: + \[ + (?: + \[ + (?: + \[ + [^\]]* + \] + | "(?:\\.|[^"])*" + | '(?:\\.|[^'])*' + | [^\[\]] + )* + \] + | "(?:\\.|[^"])*" + | '(?:\\.|[^'])*' + | [^\[\]] + )* + \] + | "(?:\\.|[^"])*" + | '(?:\\.|[^'])*' + | [^\[\]] + )* + \] \s* + ) + + string_prefix: '[bBfFrRtTuU]{,2}' + + sql_indicator: |- + (?x: \s* (?: + # dml statements + SELECT | INSERT | REPLACE | DELETE | TRUNCATE | UPDATE | MERGE\s+INTO + # ddl statements + | ADD | ALTER | CREATE | DROP + # conditional + | IF \s+ (?: NOT \s+ )? EXISTS + # declaration + | DECLARE | WITH | BEGIN + ) \s ) + + builtin_exceptions: |- + (?x: + ArithmeticError + | AssertionError + | AttributeError + | BaseException + | BlockingIOError + | BrokenPipeError + | BufferError + | BytesWarning + | ChildProcessError + | ConnectionAbortedError + | ConnectionRefusedError + | ConnectionResetError + | DeprecationWarning + | EnvironmentError + | EOFError + | Exception + | FileExistsError + | FileNotFoundError + | FloatingPointError + | FutureWarning + | GeneratorExit + | ImportError + | ImportWarning + | IndentationError + | IndexError + | InterruptedError + | IOError + | IsADirectoryError + | KeyboardInterrupt + | KeyError + | LookupError + | MemoryError + | ModuleNotFoundError + | NameError + | NotADirectoryError + | NotImplemented + | NotImplementedError + | OSError + | OverflowError + | PendingDeprecationWarning + | PermissionError + | ProcessLookupError + | RecursionError + | ReferenceError + | ResourceWarning + | RuntimeError + | RuntimeWarning + | StandardError + | StopAsyncIteration + | StopIteration + | SyntaxError + | SyntaxWarning + | SystemError + | SystemExit + | TabError + | TimeoutError + | TypeError + | UnboundLocalError + | UnicodeDecodeError + | UnicodeEncodeError + | UnicodeTranslateError + | UnicodeWarning + | UserWarning + | ValueError + | VMSError + | Warning + | WindowsError + | ZeroDivisionError + )\b + + builtin_functions: |- + (?x: + __import__ | all | abs | any | ascii | bin | callable | chr | classmethod + | compile | delattr | dir | divmod | enumerate | eval | filter | format + | getattr | globals | hasattr | hash | help | hex | id | input | isinstance + | issubclass | iter | len | locals | map | max | min | next | oct | open + | ord | pow | property | range | repr | reversed | round | setattr | sorted + | staticmethod | sum | super | type(?=\s*\() | vars | zip + # Python 2 functions + | apply | cmp | coerce | execfile | intern | raw_input | reduce | reload + | unichr | xrange + # Python 3 functions + | aiter| anext| breakpoint | exec | print + )\b + + builtin_types: |- + (?x: + bool | bytearray | bytes | complex | dict | float | frozendict | frozenset + | int | list | memoryview | object | sentinel | set | slice | str | tuple + # Python 2 types + | basestring | long | unicode + # Python 2 types prone to conflicts + # | buffer | file + )\b + + typing_functions: |- + (?x: + assert_type | assert_never | clear_overloads | dataclass_transform | final + | get_args | get_origin | get_overloads | get_type_hints | is_typeddict + | no_type_check | no_type_check_decorator | overload | override | reveal_type + | runtime_checkable + )\b + + magic_functions: |- + (?x: __(?: + # unary operators + invert | neg | pos | abs + # binary operators + | add | and | contains | div | divmod | floordiv | lshift | mod | mul | or + | pow | rshift | sub | truediv | xor + # right-hand binary operators + | radd | rand | rdiv | rdivmod | rfloordiv | rlshift | rmod | rmul | ror + | rpow | rrshift | rsub | rtruediv | rxor + # in-place operator assignments + | iadd | iand | idiv | ifloordiv | ilshift | imod | imul | ior | ipow + | irshift | isub | itruediv | ixor + # comparisons + | eq | ge | gt | le | lt | ne + | cmp | rcmp # py2 + # primary coercion + | bool | str + | nonzero | unicode # py2 + # number coercion (converts something to a number) + | bytes | complex | float | index | int | round + | long # py2 + # other "coercion" + | format | len | length_hint | hash | repr | reversed + | coerce | hex | oct # py2 + | fspath + # iterator (and 'await') + | iter | next + | aiter | anext + | await + # attribute and item access + | delattr | delitem | delslice + | getattr | getattribute | getitem | getslice + | setattr | setitem | setslice + | dir | missing + # context manager + | enter | exit + | aenter | aexit + # other class magic + | call | del | init | new | init_subclass + | instancecheck | sizeof | subclasscheck | subclasshook + # pickling + | getnewargs | getnewargs_ex | getstate | setstate | reduce | reduce_ex + # descriptors + | delete | get | set | set_name + # class-specific + | subclasses + # dataclasses (PEP 557) + | post_init + # for typing core support (PEP 560) + | class_getitem | mro_entries + )__\b ) + + magic_variables: |- + (?x: __(?: + # generic object + class | dict | doc | module | name + # module-specific / global + | all | builtins | cached | file | loader | package | path | spec + # functions & methods + | annotations | closure | code | defaults | func | globals | kwdefaults | self | qualname + # classes (attributes) + | bases | prepare | slots | metaclass | mro | weakref + # Python 2 + | members | methods + # Python 3.12 (PEP 698) + | override + )__\b )
diff --git /dev/null b/syntax/README.txt @@ -0,0 +1,4 @@ +Default syntax set + +Syntax defitions taken from +<https://github.com/sublimehq/Packages/tree/1ba99a47ee234311f7e87fc9d6153d2d9e4d4d93>
diff --git /dev/null b/syntax/Ruby/Ruby.sublime-syntax @@ -0,0 +1,2398 @@ +%YAML 1.2 +--- +# TODO: unresolved issues +# +# text: +# "p << end +# print me! +# end" +# symptoms: +# not recognized as a heredoc +# solution: +# there is no way to distinguish perfectly between the << operator and the start +# of a heredoc. Currently, we require assignment to recognize a heredoc. More +# refinement is possible. +# β’ Heredocs with indented terminators (<<-) are always distinguishable, however. +# β’ Nested heredocs are not really supportable at present +# +# text: +# val?(a):p(b) +# val?'a':'b' +# symptoms: +# ':p' is recognized as a symbol.. its 2 things ':' and 'p'. +# :'b' has same problem. +# solution: +# ternary operator rule, precedence stuff, symbol rule. +# but also consider 'a.b?(:c)' ?? +name: Ruby +scope: source.ruby + +file_extensions: + - rb + +hidden_file_extensions: + - Gemfile + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* \# .*? -\*- .*? \bruby\b .*? -\*- # editorconfig + ) + +variables: + shebang_language: \bj?ruby\b + + bin_digits: (?:[01]+(?:_[01]+)*) + dec_digits: (?:\d+(?:_\d+)*) + hex_digits: (?:\h+(?:_\h+)*) + oct_digits: (?:[0-7]+(?:_[0-7]+)*) + dec_exponent: (?:[Ee][-+]?{{dec_digits}}) + heredoc_type_css: (?:[[:upper:]_]_)?CSS\b + heredoc_type_html: (?:[[:upper:]_]_)?HTML\b + heredoc_type_js: (?:[[:upper:]_]_)?(?:JS|JAVASCRIPT)\b + heredoc_type_ruby: (?:[[:upper:]_]_)?RUBY\b + heredoc_type_shell: (?:[[:upper:]_]_)?(?:SH|SHELL)\b + heredoc_type_sql: (?:[[:upper:]_]_)?SQL\b + identifier: '\b[[:alpha:]_][[:alnum:]_]*\b' + method_punctuation: '(?:[?!]|=(?![>=]))?' + method_name: '{{identifier}}{{method_punctuation}}' + path_lookahead: '(::)?({{identifier}}(\.|::))*{{identifier}}' + +contexts: + main: + - meta_include_prototype: false + - match: '' + push: [expressions, shebang] + + shebang: + - meta_include_prototype: false + - match: ^\s*(\#!) + captures: + 1: punctuation.definition.comment.ruby + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if syntax is embedded. + pop: 1 + + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.ruby + - match: '{{shebang_language}}' + scope: constant.language.shebang.ruby + - match: $\n? + pop: 1 + + expressions: + - include: data-section + - include: constants + - include: class + - include: module + - include: invalid + - include: blocks + - include: keywords + - include: well-known-methods + - include: variables + - include: method + - include: strings + - include: comments + - include: heredocs + - include: punctuation + - include: operators + - include: identifiers-accessors + + comments: + # multiline comments + - match: ^=begin + scope: punctuation.definition.comment.begin.ruby + push: + - meta_scope: comment.block.documentation.ruby + - match: ^=end + scope: punctuation.definition.comment.end.ruby + pop: true + - include: merge-conflict-markers + - match: \#+ + scope: punctuation.definition.comment.ruby + push: + - meta_scope: comment.line.number-sign.ruby + - match: \n + pop: true + - include: merge-conflict-markers + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + + class: + # Defining a class method + - match: \b(class)\s*(<<) + captures: + 1: keyword.declaration.class.ruby + 2: keyword.operator.assignment.augmented.ruby + - match: \bclass\b + scope: keyword.declaration.class.ruby + push: class-declaration + + class-declaration: + - meta_scope: meta.class.ruby + - match: '(?={{path_lookahead}})' + set: class-name + # Escape if no valid match + - match: (?=\S) + pop: true + + class-name: + - meta_content_scope: meta.class.ruby entity.name.class.ruby + - include: name-parts + - match: '' + set: class-inheritance + + class-inheritance: + - meta_content_scope: meta.class.ruby + - match: '<' + scope: punctuation.separator.inheritance.ruby + set: + - meta_content_scope: meta.class.ruby + - match: '(?={{path_lookahead}})' + set: + - meta_content_scope: meta.class.ruby entity.other.inherited-class.ruby + - include: name-parts + - match: '' + pop: true + # Escape if no valid match + - match: '(?=\S)' + pop: true + # Escape if no valid match + - match: '(?=\S)' + pop: true + + module: + - match: \bmodule\b + scope: keyword.declaration.namespace.ruby + push: module-declaration + + module-declaration: + - meta_scope: meta.namespace.ruby + - match: '(?=(::)?({{identifier}}::)*{{identifier}})' + set: + - meta_content_scope: meta.namespace.ruby entity.name.namespace.ruby + - include: name-parts + - match: '' + pop: true + # Escape if no valid match + - match: (?=\S) + pop: true + + name-parts: + - match: ({{identifier}})?(?:(::)|(&?\.)) + captures: + 1: support.other.namespace.ruby + 2: punctuation.accessor.double-colon.ruby + 3: punctuation.accessor.dot.ruby + - match: '{{identifier}}' + + invalid: + # else if is a common mistake carried over from other languages. it works if you put in a second end, but itβs never what you want. + - match: \belse\s+if\b + scope: invalid.deprecated.ruby + + constants: + # constant definition, handles multiple definitions on a single line 'APPLE, ORANGE= 1, 2' + - match: '\b([[:upper:]]\w*)(?=(\s*,\s*[[:upper:]]\w*)*\s*(\|\|)?=(?![=\>]))' + scope: meta.constant.ruby entity.name.constant.ruby + push: after-constant + # Ruby 1.9 symbols + - match: '{{identifier}}[?!]?(:)(?!:)' + scope: constant.other.symbol.ruby + captures: + 1: punctuation.definition.constant.ruby + push: try-regex + - match: '\b(nil)\b(?![?!])' + scope: constant.language.null.ruby + push: after-constant + - match: '\bfalse\b(?![?!])' + scope: constant.language.boolean.false.ruby + - match: '\btrue\b(?![?!])' + scope: constant.language.boolean.true.ruby + push: after-constant + - match: '\b(__(FILE|LINE|ENCODING)__)\b(?![?!])' + scope: variable.language.ruby + push: after-constant + - match: '\bself\b(?![?!])' + scope: variable.language.this.ruby + push: after-constant + # hexadecimal imaginary numbers: 0xAi, 0xAri + - match: '\b(0[xX])({{hex_digits}})(r?i(r)?)\b' + scope: meta.number.imaginary.hexadecimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + 4: invalid.illegal.numeric.ruby + push: after-constant + # octal imaginary numbers: 0o1i, 0o1ri, 01i, 01ri + - match: '\b(0[oO]?)({{oct_digits}})(r?i(r)?)\b' + scope: meta.number.imaginary.octal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + 4: invalid.illegal.numeric.ruby + push: after-constant + # binary imaginary numbers: 0b1i, 0b1ri + - match: '\b(0[bB])({{bin_digits}})(r?i(r)?)\b' + scope: meta.number.imaginary.binary.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + 4: invalid.illegal.numeric.ruby + push: after-constant + # decimal imaginary numbers: 0d1i, 0d1ri, 1i, 1ri, 1.1i, 1.1ri, 1e1i, 1.1e1i + - match: |- + \b(?x: + (?: + # 0d1i, 0d1ri, 1i, 1ri | 1.1i, 1.1ri + (?: (0[dD])? ({{dec_digits}}) | ({{dec_digits}} (\.) {{dec_digits}}) ) (r?i) + # 1e1i, 1.1e1i + | ({{dec_digits}} (?: (\.) {{dec_digits}} )? {{dec_exponent}}) (r)?(i) + ) (r)? + )\b + scope: meta.number.imaginary.decimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.value.ruby + 4: punctuation.separator.decimal.ruby + 5: constant.numeric.suffix.ruby + 6: constant.numeric.value.ruby + 7: punctuation.separator.decimal.ruby + 8: constant.numeric.suffix.ruby invalid.illegal.numeric.ruby + 9: constant.numeric.suffix.ruby + 10: constant.numeric.suffix.ruby invalid.illegal.numeric.ruby + push: after-constant + # hexadecimal rational numbers: 0xAr + - match: '\b(0[xX])({{hex_digits}})(r)\b' + scope: meta.number.rational.hexadecimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + push: after-constant + # octal rational numbers: 0o1r, 01r + - match: '\b(0[oO]?)({{oct_digits}})(r)\b' + scope: meta.number.rational.octal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + push: after-constant + # binary rational numbers: 0b1r + - match: '\b(0[bB])({{bin_digits}})(r)\b' + scope: meta.number.rational.binary.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: constant.numeric.suffix.ruby + push: after-constant + # decimal rational numbers: 0d1r, 1r, 1.1r + - match: '\b(0[dD])?({{dec_digits}}|{{dec_digits}}(\.){{dec_digits}})(r)\b' + scope: meta.number.rational.decimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + 3: punctuation.separator.decimal.ruby + 4: constant.numeric.suffix.ruby + push: after-constant + # decimal floating point numbers: 1.1, 1e1, 1.1e1 + - match: '\b({{dec_digits}})(?:((\.){{dec_digits}})|((?:(\.){{dec_digits}})?{{dec_exponent}})(r)?)\b' + scope: meta.number.float.decimal.ruby + captures: + 1: constant.numeric.value.ruby + 2: constant.numeric.value.ruby + 3: punctuation.separator.decimal.ruby + 4: constant.numeric.value.ruby + 5: punctuation.separator.decimal.ruby + 6: constant.numeric.suffix.ruby invalid.illegal.numeric.rational.ruby + push: after-constant + # hexadecimal integer numbers: 0xA + - match: '\b(0[xX])({{hex_digits}})\b' + scope: meta.number.integer.hexadecimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + push: after-constant + # octal integer numbers: 0o1, 01 + - match: '\b(0[oO]?)({{oct_digits}})\b' + scope: meta.number.integer.octal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + push: after-constant + # binary integer numbers: 0b1 + - match: '\b(0[bB])({{bin_digits}})\b' + scope: meta.number.integer.binary.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + push: after-constant + # decimal integer numbers: 0d1, 1 + - match: '\b(0[dD])?({{dec_digits}})\b' + scope: meta.number.integer.decimal.ruby + captures: + 1: constant.numeric.base.ruby + 2: constant.numeric.value.ruby + push: after-constant + # Quoted symbols + - match: ":'" + scope: punctuation.definition.constant.ruby + push: + - meta_scope: meta.constant.ruby constant.other.symbol.single-quoted.ruby + - match: "'" + scope: punctuation.definition.constant.ruby + pop: true + - match: '\\[''\\]' + scope: constant.character.escape.ruby + - match: ':"' + scope: punctuation.definition.constant.ruby + push: + - meta_scope: meta.constant.ruby constant.other.symbol.double-quoted.ruby + - match: '"' + scope: punctuation.definition.constant.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # Unquoted symbols + - match: |- + (?x: + (:) + ( + {{identifier}}{{method_punctuation}}| + ===?| + >[>=]?| + <[<=]?| + <=>| + [%&`/\|]| + \*\*?| + =?~| + [-+]@?| + \[\]=?| + @@?{{identifier}} + ) + ) + scope: constant.other.symbol.ruby + captures: + 1: punctuation.definition.constant.ruby + # questionmark literals + - match: ((\?)\\u)(\{) + captures: + 1: constant.character.ruby + 2: punctuation.definition.constant.ruby + 3: meta.braces.ruby punctuation.section.braces.begin.ruby + push: + - meta_scope: meta.constant.ruby + - meta_content_scope: meta.braces.ruby + - match: \} + scope: meta.braces.ruby punctuation.section.braces.end.ruby + pop: true + - match: \h{0,6} + scope: meta.number.integer.hexadecimal.ruby constant.numeric.value.ruby + - match: \S + scope: invalid.illegal.escape.ruby + - match: |- + (?x: (\?)(?: + # examples (meta control sequences): + # ?\C-a ?\M-a ?\M-\C-a ?\ca ?\M-ca + (?:\\(?:[MC]-|c)){1,2}[[:ascii:]] | + \\(?: + # examples (hex): + # ?\x1 ?\x61 + x\h{1,2}\b | + # examples (octal): + # ?\0 ?\07 ?\017 + 0[0-7]{0,2}\b | + # examples (escaped): + # ?\n ?\b ?\\ + .(?!\w) + ) | + # examples (illegal): + # ?abc ?\xAG ?\\n + # ?_a0 + ([[:alpha:]_\\]\S+)\b(?!\s*:) | + # examples (normal): + # ?a ?A ?0 + # ?* ?" ?( + # ?. ?# ?\ + [[:alnum:]_]\b(?!\s*:) | [^[:alnum:]_\s] + ) ) + scope: constant.character.ruby + captures: + 1: punctuation.definition.constant.ruby + 2: invalid.illegal.character.ruby + + after-constant: + - include: after-identifier + + blocks: + - match: \bdo\b + scope: keyword.control.block.do.ruby + push: maybe-block-parameters + - match: \{ + scope: punctuation.section.scope.ruby + push: maybe-block-parameters + + maybe-block-parameters: + - match: \| + scope: meta.block.parameters.ruby punctuation.definition.parameters.begin.ruby + set: block-parameters + - match: (?=\s*[^\s\|]) + set: try-regex + + block-parameters: + - meta_content_scope: meta.block.parameters.ruby + - match: \| + scope: meta.block.parameters.ruby punctuation.definition.parameters.end.ruby + set: try-regex + - match: '{{identifier}}' + scope: variable.parameter.ruby + - match: ',' + scope: punctuation.separator.ruby + - match: \* + scope: keyword.operator.splat.ruby + - match: '&' + scope: keyword.operator.ruby + - match: '(?==)' + set: + - meta_content_scope: meta.block.parameters.default-value.ruby + - match: '=' + scope: keyword.operator.assignment.ruby + set: + - meta_content_scope: meta.block.parameters.default-value.ruby + - match: '(?=[,\|])' + set: block-parameters + - include: nest-all + - include: expressions + + keywords: + # blocks + - match: \bbegin\b(?![?!]) + scope: keyword.control.block.begin.ruby + push: after-keyword + - match: \bend\b(?![?!]) + scope: keyword.control.block.end.ruby + # conditional + - match: \bcase\b(?![?!]) + scope: keyword.control.conditional.case.ruby + push: after-keyword + - match: \belse\b(?![?!]) + scope: keyword.control.conditional.if.ruby + push: after-keyword + - match: \belsif\b(?![?!]) + scope: keyword.control.conditional.elseif.ruby + push: after-keyword + - match: \bif\b(?![?!]) + scope: keyword.control.conditional.if.ruby + push: after-keyword + - match: \bthen\b(?![?!]) + scope: keyword.control.conditional.then.ruby + - match: \bunless\b(?![?!]) + scope: keyword.control.conditional.unless.ruby + push: after-keyword + - match: \bwhen\b(?![?!]) + scope: keyword.control.conditional.when.ruby + push: after-keyword + # exception + - match: \bensure\b(?![?!]) + scope: keyword.control.exception.ensure.ruby + push: after-keyword + - match: \brescue\b(?![?!]) + scope: keyword.control.exception.rescue.ruby + push: after-keyword + # loop + - match: \bfor\b(?![?!]) + scope: keyword.control.loop.for.ruby + push: for-variable + - match: \buntil\b(?![?!]) + scope: keyword.control.loop.until.ruby + push: after-keyword + - match: \bwhile\b(?![?!]) + scope: keyword.control.loop.while.ruby + push: after-keyword + # flow + - match: \bbreak\b(?![?!]) + scope: keyword.control.flow.break.ruby + - match: \bnext\b(?![?!]) + scope: keyword.control.flow.next.ruby + - match: \bredo\b(?![?!]) + scope: keyword.control.flow.redo.ruby + - match: \bretry\b(?![?!]) + scope: keyword.control.flow.retry.ruby + - match: \breturn\b(?![?!]) + scope: keyword.control.flow.return.ruby + - match: \byield\b(?![?!]) + scope: keyword.control.flow.yield.ruby + # declarations + - match: \b(?:alias|alias_method)\b(?![?!]) + scope: keyword.declaration.alias.ruby + push: after-keyword + - match: \bundef\b(?![?!]) + scope: keyword.declaration.undef.ruby + push: after-keyword + # operators + - match: \b(?:and|not|or)\b + scope: keyword.operator.logical.ruby + push: after-keyword + - match: \bin\b(?![?!]) + scope: keyword.operator.logical.ruby + push: after-keyword + # other functions + - match: \b(?:BEGIN|END)\b(?![?!]) + scope: entity.name.function.preprocessor.ruby + - match: \b(?:defined|block_given)\? + scope: support.function.builtin.ruby + push: after-keyword + - match: \bsuper\b(?![?!]) + scope: support.function.builtin.ruby + push: after-keyword + + for-variable: + # note: variables are not scoped, currently + - match: \bin\b + scope: keyword.control.loop.in.ruby + set: after-keyword + - match: (?=(?:end|do)\b(?![?!]))|$ + pop: true + + operators: + - match: '>>' + scope: keyword.operator.other.ruby + push: after-operator + # note: `/=` is matched in the `regexes` context + - match: <<=|&&=|\|\|=|\*\*=|[-+*&|^]=|<< + scope: keyword.operator.assignment.augmented.ruby + push: after-operator + - match: <=>|===|<=|>=|==|=~|!=|!~|<|> + scope: keyword.operator.comparison.ruby + push: after-operator + - match: \*\*|[-+*/%] + scope: keyword.operator.arithmetic.ruby + push: after-operator + - match: = + scope: keyword.operator.assignment.ruby + push: after-operator + - match: '!+|&&|\|\|' + scope: keyword.operator.logical.ruby + push: after-operator + - match: '(?:[~|^]|&(?!\.))' + scope: keyword.operator.bitwise.ruby + push: after-operator + - match: \? + scope: keyword.operator.ternary.ruby + push: + # Handle hash-key-lookalike of identifier: in ternary + - match: \s*{{identifier}}(:)(?!:) + captures: + 1: keyword.operator.ternary.ruby + set: after-operator + - include: after-operator + - match: :(?!:) + scope: keyword.operator.ternary.ruby + push: after-operator + - match: \.\.\.? + scope: keyword.operator.range.ruby + push: after-operator + + punctuation: + - match: => + scope: punctuation.separator.key-value.ruby + push: after-operator + - match: ',' + scope: punctuation.separator.sequence.ruby + push: after-operator + - match: ; + scope: punctuation.terminator.statement.ruby + push: after-operator + - match: \[ + scope: punctuation.section.array.ruby + push: after-operator + - match: \( + scope: punctuation.definition.group.begin.ruby + push: after-operator + # Opening { is handled by "block" context to try and detect parameters + - match: \} + scope: punctuation.section.scope.ruby + - match: \] + scope: punctuation.section.array.ruby + - match: \) + scope: punctuation.definition.group.end.ruby + + identifiers-accessors: + # This consumes class/module access to prevent issues parsing : as part + # of a ternary operator + - match: ::(?={{identifier}}{{method_punctuation}}) + scope: punctuation.accessor.double-colon.ruby + push: + - include: well-known-methods + - match: '{{identifier}}{{method_punctuation}}' + - match: '' + set: after-identifier + # This consumes attribute access so we don't need a lookbehind for . + - match: '&?\.(?={{identifier}}{{method_punctuation}})' + scope: punctuation.accessor.dot.ruby + push: + - include: well-known-methods + - match: '{{identifier}}{{method_punctuation}}' + - match: '' + set: after-identifier + # This consumes method names ending in punctuation so we don't need a lookbehind for ?, ! or = + - match: '{{identifier}}{{method_punctuation}}' + # This consumes module/class accessor so we don't need a lookbehind for :: + push: after-identifier + - match: '&?\.' + scope: punctuation.accessor.dot.ruby + - match: '::' + scope: punctuation.accessor.double-colon.ruby + + after-identifier: + # Handles a : right after an identifier. In this case it can't be the + # beginning of a symbol, so it must be part of a ternary operator + - match: ':(?!:)' + scope: keyword.operator.ternary.ruby + set: after-operator + - match: \s*(<<)(?![-~]) + captures: + 1: keyword.operator.assignment.augmented.ruby + set: after-operator + - match: '' + pop: true + + variables: + - match: '(@)[a-zA-Z_]\w*' + scope: variable.other.readwrite.instance.ruby + captures: + 1: punctuation.definition.variable.ruby + push: after-variable + - match: '(@@)[a-zA-Z_]\w*' + scope: variable.other.readwrite.class.ruby + captures: + 1: punctuation.definition.variable.ruby + push: after-variable + - match: '(\$)[a-zA-Z_]\w*' + scope: variable.other.readwrite.global.ruby + captures: + 1: punctuation.definition.variable.ruby + push: after-variable + - match: '(\$)(!|@|&|`|''|\+|\d+|~|=|/|\\|,|;|\.|<|>|_|\*|\$|\?|:|"|-[0adFiIlpv])' + scope: variable.other.readwrite.global.pre-defined.ruby + captures: + 1: punctuation.definition.variable.ruby + - match: '\b(ENV)\[' + captures: + 1: variable.other.constant.ruby + push: + - meta_scope: meta.environment-variable.ruby + - match: '\]' + pop: true + - include: expressions + # maybe nested (trailing) constants with uppercase only notation + - match: '(::)?(\b[[:upper:]_][[:upper:][:digit:]_]*\b)' + captures: + 1: punctuation.accessor.double-colon.ruby + 2: variable.other.constant.ruby + push: after-variable + # maybe nested class + - match: '(::)?(\b[[:upper:]]\w*\b)' + captures: + 1: punctuation.accessor.double-colon.ruby + 2: support.class.ruby + push: after-variable + + after-variable: + - include: after-identifier + + well-known-methods: + # exceptions + - match: \bcatch\b(?![?!]) + scope: keyword.control.exception.catch.ruby + # flow + - match: \b(?:fail|raise|throw)\b(?![?!]) + scope: keyword.control.flow.throw.ruby + # loop + - match: \bloop\b(?![?!]) + scope: keyword.control.loop.loop.ruby + # other + - match: \b(initialize|new|include|extend|prepend|attr_reader|attr_writer|attr_accessor|attr|module_function|public|protected|private)\b(?![?!]) + scope: keyword.other.special-method.ruby + - match: \b(require|require_relative|gem)\b + scope: keyword.control.import.ruby + push: + - meta_scope: meta.require.ruby + - match: $|(?=[#}]) + pop: true + - include: expressions + # Conversion methods + - match: |- + (?x: + \b( + to_ary| + to_a| + to_c| + to_enum| + to_f| + to_hash| + to_h| + to_int| + to_io| + to_i| + to_proc| + to_r| + to_str| + to_sym| + to_s + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + # Methods that may be followed by a regex + - match: |- + (?x: + \b( + gsub| + sub + )(!|\b) + | + \b( + eql| + match + )(\?|\b) + | + \b( + assert_match| + assert_no_match| + index| + rindex| + scan + )\b(?![!?=]) + ) + scope: support.function.builtin.ruby + push: try-regex + # Methods from the Object class not handled elsewhere, ending in punctuation + - match: |- + (?x: + \b( + instance_of\?| + instance_variable_defined\?| + is_a\?| + kind_of\?| + nil\?| + respond_to\?| + respond_to_missing\?| + tainted\?| + untrusted\? + ) + ) + scope: support.function.builtin.ruby + # Methods from the Object class not handled elsewhere + - match: |- + (?x: + \b( + class| + clone| + define_singleton_method| + display| + dup| + enum_for| + extend| + freeze| + frozen?| + hash| + inspect| + instance_variable_get| + instance_variable_set| + instance_variables| + itself| + method| + methods| + object_id| + private_methods| + protected_methods| + public_method| + public_methods| + public_send| + remove_instance_variable| + send| + singleton_class| + singleton_method| + singleton_methods| + taint| + tap| + trust| + untaint| + untrust + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + # Methods from the Kernel class not handled elsewhere, ending in punctuation + - match: |- + (?x: + \b( + autoload\?| + iterator\?| + exit! + ) + ) + scope: support.function.builtin.ruby + # Methods from the Kernel class not handled elsewhere + - match: |- + (?x: + \b( + Array| + Complex| + Float| + Hash| + Integer| + Rational| + String| + __callee__| + __dir__| + __method__| + abort| + at_exit| + autoload| + binding| + callcc| + caller| + caller_locations| + chomp| + chop| + eval| + exec| + exit| + fork| + format| + gets| + global_variables| + gsub| + lambda| + load| + local_variables| + open| + p| + print| + printf| + proc| + putc| + puts| + rand| + readline| + readlines| + require| + require_relative| + select| + set_trace_func| + sleep| + spawn| + sprintf| + srand| + sub| + syscall| + system| + test| + trace_var| + trap| + untrace_var| + warn + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + # Methods from the Kernel class not handled elsewhere, ending in punctuation + - match: |- + (?x: + \b( + class_variable_defined\?| + const_defined\?| + include\?| + instance_methods\?| + method_defined\?| + private_method_defined\?| + protected_method_defined\?| + public_method_defined\?| + singleton_class\? + ) + ) + scope: support.function.builtin.ruby + # Lambda operator from the Kernel class not handled elsewhere + - match: '->' + scope: meta.function.ruby keyword.declaration.function.anonymous.ruby + push: try-regex + # Methods from the Module class not handled elsewhere + - match: |- + (?x: + \b( + ancestors| + append_features| + class_eval| + class_exec| + class_variable_get| + class_variable_set| + class_variables| + const_get| + const_missing| + const_set| + constants| + define_method| + extend_object| + extended| + freeze| + included| + included_modules| + inspect| + method_added| + method_removed| + method_undefined| + module_eval| + module_exec| + name| + prepend_features| + prepended| + private_class_method| + private_constant| + private_instance_methods| + protected_instance_methods| + public_class_method| + public_constant| + public_instance_method| + public_instance_methods| + refine| + remove_class_variable| + remove_const| + remove_method| + undef_method| + using + )\b + (?![!?=]) + ) + scope: support.function.builtin.ruby + + method: + - match: \bdef\b + scope: meta.function.ruby keyword.declaration.function.ruby + push: + - meta_content_scope: meta.function.ruby + - match: '(self)(\.)({{identifier}}{{method_punctuation}}|===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?)' + captures: + 1: variable.language.this.ruby + 2: punctuation.accessor.dot.ruby + 3: entity.name.function.ruby + set: method-parameters-start + - match: '===?|>[>=]?|<=>|<[<=]?|[%&`/\|]|\*\*?|=?~|[-+]@?|\[\]=?' + scope: entity.name.function.ruby + set: method-parameters-start + - match: '(?:({{identifier}})(?:(::)|(\.)))?{{identifier}}{{method_punctuation}}' + scope: entity.name.function.ruby + captures: + 1: support.other.namespace.ruby + 2: punctuation.accessor.double-colon.ruby + 3: punctuation.accessor.dot.ruby + set: method-parameters-start + - match: '$' + pop: true + - match: '(?=\S)' + pop: true + + method-parameters-start: + - meta_content_scope: meta.function.ruby + - match: '(?=\()' + set: + - meta_content_scope: meta.function.parameters.ruby + - match: '\(' + scope: punctuation.definition.group.begin.ruby + set: method-parameters + # No parameters + - match: '(?=$|;|#)' + pop: true + # No parentheses around parameters + - match: '(?=[[:alpha:]_*])' + set: method-bare-parameters + + method-parameters: + - meta_content_scope: meta.function.parameters.ruby + - match: '\)' + scope: meta.function.parameters.ruby punctuation.definition.group.end.ruby + pop: true + - match: '{{identifier}}' + scope: variable.parameter.ruby + - include: comments + - match: ',' + scope: punctuation.separator.ruby + - match: '\*' + scope: keyword.operator.splat.ruby + - match: '&' + scope: keyword.operator.ruby + # De-structuring + - match: \( + scope: punctuation.definition.group.begin.ruby + push: + - match: \) + scope: punctuation.definition.group.end.ruby + pop: true + - match: '{{identifier}}' + scope: variable.parameter.ruby + - match: ',' + scope: punctuation.separator.ruby + - match: '\*' + scope: keyword.operator.splat.ruby + # Default values + - match: (?==) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '=' + scope: keyword.operator.assignment.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=[,\)])' + set: method-parameters + - include: nest-all + - include: expressions + # Keyword parameter (with default value support) + - match: (?=:) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: ':' + scope: punctuation.separator.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=[,\)])' + set: method-parameters + - include: nest-all + - include: expressions + + # When no parentheses are placed around the parameters + method-bare-parameters: + - meta_content_scope: meta.function.parameters.ruby + - match: '(?=$|;|#)' + pop: true + - match: '{{identifier}}' + scope: variable.parameter.ruby + - match: ',' + scope: punctuation.separator.ruby + - match: '\*' + scope: keyword.operator.splat.ruby + - match: '&' + scope: keyword.operator.ruby + # Default values + - match: (?==) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '=' + scope: punctuation.operator.assignment.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=$|[,;])' + set: method-bare-parameters + - include: nest-all + - include: expressions + # Keyword parameter (with default value support) + - match: (?=:) + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: ':' + scope: punctuation.separator.ruby + set: + - meta_content_scope: meta.function.parameters.default-value.ruby + - match: '(?=$|[,;])' + set: method-bare-parameters + - include: nest-all + - include: expressions + + strings: + - include: early-strings + - include: regexes + - include: late-strings + + early-strings: + # single quoted string (does not allow interpolation) + - match: "'" + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.single.ruby + - match: "'" + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\'|\\\\ + scope: constant.character.escape.ruby + - include: string-placeholder + # double quoted string (allows for interpolation) + - match: '"' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.double.ruby + - match: '"' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: string-placeholder + # execute string (allows for interpolation) + - match: "`" + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: "`" + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # execute string (allow for interpolation) + - match: '%x\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + # execute string (allow for interpolation) + - match: '%x\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + # execute string (allow for interpolation) + - match: '%x\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + # execute string (allow for interpolation) + - match: '%x\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + # execute string (allow for interpolation) + - match: '%x([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.interpolated.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + + late-strings: + # literal capable of interpolation () + - match: '%[QW]?\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + # "literal capable of interpolation []" + - match: '%[QW]?\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + # literal capable of interpolation <> + - match: '%[QW]?\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + # literal capable of interpolation -- {} + - match: '%[QW]?\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.double.ruby.mod + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + # literal capable of interpolation -- wildcard + - match: '%[QW]([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # literal capable of interpolation -- wildcard + - match: '%([^\w\s=])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.other.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # literal capable of interpolation () + - match: '%I\(' + scope: punctuation.definition.string.begin.ruby + push: + - match: '\w+' + scope: constant.other.symbol.ruby + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + # "literal capable of interpolation []" + - match: '%I\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + # literal capable of interpolation <> + - match: '%I\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + # literal capable of interpolation -- {} + - match: '%I\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.double.ruby.mod + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + # literal capable of interpolation -- wildcard + - match: '%I([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.upper.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + # literal incapable of interpolation -- () + - match: '%[qws]\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\)|\\\\ + scope: constant.character.escape.ruby + - include: nest-parens + # literal incapable of interpolation -- <> + - match: '%[qws]\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\>|\\\\ + scope: constant.character.escape.ruby + - include: nest-ltgt + # literal incapable of interpolation -- [] + - match: '%[qws]\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\]|\\\\' + scope: constant.character.escape.ruby + - include: nest-brackets + # literal incapable of interpolation -- {} + - match: '%[qws]\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\}|\\\\' + scope: constant.character.escape.ruby + - include: nest-curly + # literal incapable of interpolation -- wildcard + - match: '%[qws]([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.quoted.other.literal.lower.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + # Cant be named because its not necessarily an escape + - match: \\. + # symbol literal incapable of interpolation -- () + - match: '%i\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \) + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\)|\\\\ + scope: constant.character.escape.ruby + - include: nest-parens + # symbol literal incapable of interpolation -- <> + - match: '%i\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \> + scope: punctuation.definition.string.end.ruby + pop: true + - match: \\\>|\\\\ + scope: constant.character.escape.ruby + - include: nest-ltgt + # symbol literal incapable of interpolation -- [] + - match: '%i\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\]' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\]|\\\\' + scope: constant.character.escape.ruby + - include: nest-brackets + # symbol literal incapable of interpolation -- {} + - match: '%i\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: '\}' + scope: punctuation.definition.string.end.ruby + pop: true + - match: '\\\}|\\\\' + scope: constant.character.escape.ruby + - include: nest-curly + # symbol literal incapable of interpolation -- wildcard + - match: '%i([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: string.quoted.other.literal.lower.ruby + - match: '\w+' + scope: constant.other.symbol.ruby + - match: \1 + scope: punctuation.definition.string.end.ruby + pop: true + # Cant be named because its not necessarily an escape + - match: \\. + + after-keyword: + - include: try-regex + + after-operator: + # A slash following an operator is most likely the beginning of a regex pattern + # if not an incomplete expression. + - match: \s*(/) + captures: + 1: punctuation.definition.string.begin.ruby + push: regex-body + - match: '' + pop: true + + try-regex: + # Generally for multiline regexes, one of the %r forms below will be used, + # so we bail out if we can't find a second / on the current line + - match: \s*(/)(?=(?!=).*/) + captures: + 1: punctuation.definition.string.begin.ruby + push: regex-body + - match: '' + pop: true + + regex-body: + - meta_scope: meta.string.regexp.ruby string.regexp.classic.ruby + - match: (/)([eimnosux]*) + captures: + 1: punctuation.definition.string.end.ruby + 2: keyword.other.ruby + pop: true + - include: regex-sub + + regexes: + # Needs higher precedence than regular expressions. + - match: /= + scope: keyword.operator.assignment.augmented.ruby + - match: '(?=^\s*/)' + push: try-regex + - match: (?=/\s*[^\w\(\s@"']) + push: try-regex + # regular expressions (literal) + - match: '%r\{' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\}[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-curly-r + # regular expressions (literal) + - match: '%r\[' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\][eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-brackets-r + # regular expressions (literal) + - match: '%r\(' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\)[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-parens-r + # regular expressions (literal) + - match: '%r\<' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\>[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + - include: nest-ltgt-r + # regular expressions (literal) + - match: '%r([^\w])' + scope: punctuation.definition.string.begin.ruby + push: + - meta_scope: meta.string.ruby string.regexp.mod-r.ruby + - match: '\1[eimnosux]*' + scope: punctuation.definition.string.end.ruby + pop: true + - include: regex-sub + + regex-sub: + - include: interpolated-ruby + - include: escaped-char + - match: '(\{)\d+(,\d+)?(\})' + scope: meta.string.ruby string.regexp.arbitrary-repetition.ruby + captures: + 1: punctuation.definition.arbitrary-repetition.ruby + 3: punctuation.definition.arbitrary-repetition.ruby + - match: '\[(?:\^?\])?' + scope: punctuation.definition.character-class.ruby + push: + - meta_scope: meta.string.ruby string.regexp.character-class.ruby + - match: '\]' + scope: punctuation.definition.character-class.ruby + pop: true + - include: escaped-char + - match: \( + scope: punctuation.definition.group.ruby + push: + - meta_scope: meta.string.ruby string.regexp.group.ruby + - match: \) + scope: punctuation.definition.group.ruby + pop: true + - include: regex-sub + # We are restrictive in what we allow to go after the comment character to + # avoid false positives, since the availability of comments depend on regexp + # flags. + - match: '(?:^|\s)(#)\s[[a-zA-Z0-9,. \t?!-][^\x{00}-\x{7F}]]*$' + scope: comment.line.number-sign.ruby + captures: + 1: punctuation.definition.comment.ruby + + nest-brackets-r: + - match: '\[' + scope: punctuation.section.scope.ruby + push: + - match: '\]' + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-brackets-r + nest-curly-r: + - match: '\{' + scope: punctuation.section.scope.ruby + push: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-curly-r + nest-ltgt-r: + - match: \< + scope: punctuation.section.scope.ruby + push: + - match: \> + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-ltgt-r + nest-parens-r: + - match: \( + scope: punctuation.section.scope.ruby + push: + - match: \) + scope: punctuation.section.scope.ruby + pop: true + - include: regex-sub + - include: nest-parens-r + + nest-brackets: + - match: '\[' + scope: punctuation.section.scope.ruby + push: + - match: '\]' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-brackets + nest-curly: + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-curly-inner, maybe-block-parameters] + nest-curly-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-curly + nest-ltgt: + - match: \< + scope: punctuation.section.scope.ruby + push: + - match: \> + scope: punctuation.section.scope.ruby + pop: true + - include: nest-ltgt + nest-parens: + - match: \( + scope: punctuation.section.scope.ruby + push: + - match: \) + scope: punctuation.section.scope.ruby + pop: true + - include: nest-parens + + string-placeholder: + # %[flags][width][.precision]type + # + # A format sequence consists of a percent sign, followed by optional + # flags, width, and precision indicators, then terminated with a field + # type character. + # + # Also this is used for time format in strftime. + - match: |- + (?x)% + ([#0\- +\*]|(\d+\$))* # flags + (-?\d+)? # minimum field width + (\.(\d+)?)? # precision + [diouxXDOUeEfFgGaAcCsSpnvtTbByYhHmMzZ%] # conversion type + scope: constant.other.placeholder.ruby + + escaped-char: + # SEE: https://ruby-doc.org/core-2.6.3/doc/syntax/literals_rdoc.html + # meta control sequence + - match: (?:\\(?:[MC]-|c)){1,2}[[:ascii:]] + scope: constant.character.escape.ruby + # extended unicode character + - match: \\u\{ + push: + - meta_scope: constant.character.escape.ruby + - match: \} + pop: true + - match: \h{0,6} + - match: \S + scope: invalid.illegal.escape.ruby + # octal, hex, unicode, normal escaped character + - match: \\(?:[0-7]{1,3}|x\h{1,2}|u\h{4}|.) + scope: constant.character.escape.ruby + + interpolated-ruby: + - match: '#\{' + scope: punctuation.section.interpolation.begin.ruby + push: + - clear_scopes: 1 # remove `string`/`constant` + - meta_scope: meta.interpolation.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: interpolated-ruby-expressions + - match: '(?=#[@$])' + push: + - clear_scopes: 1 # remove `string`/`constant` + - meta_scope: meta.interpolation.ruby + - include: interpolated-ruby-variables + + embedded-ruby: + - match: '#\{' + scope: punctuation.section.interpolation.begin.ruby + push: + - meta_scope: meta.interpolation.ruby + - meta_content_scope: source.ruby.embedded.ruby + - include: interpolated-ruby-expressions + - match: '(?=#[@$])' + push: + - meta_scope: meta.interpolation.ruby + - include: interpolated-ruby-variables + + interpolated-ruby-expressions: + - match: '\}' + scope: punctuation.section.interpolation.end.ruby + pop: true + - include: nest-curly-expressions + - include: expressions + + interpolated-ruby-variables: + - match: '(#@)[[:alpha:]_]\w*' + scope: variable.other.readwrite.instance.ruby + captures: + 1: punctuation.definition.variable.ruby + pop: true + - match: '(#@@)[[:alpha:]_]\w*' + scope: variable.other.readwrite.class.ruby + captures: + 1: punctuation.definition.variable.ruby + pop: true + - match: '(#\$)[[:alpha:]_]\w*' + scope: variable.other.readwrite.global.ruby + captures: + 1: punctuation.definition.variable.ruby + pop: true + - match: '' + pop: true + + nest-curly-expressions: + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-curly-expressions-inner, maybe-block-parameters] + nest-curly-expressions-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-curly-expressions + - include: expressions + + nest-all: + - match: '\(' + scope: punctuation.definition.group.begin.ruby + push: + - match: '\)' + scope: punctuation.definition.group.end.ruby + pop: true + - include: nest-all + - include: expressions + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-all-inner, maybe-block-parameters] + - match: '\[' + scope: punctuation.section.array.ruby + push: + - match: '\]' + scope: punctuation.section.array.ruby + pop: true + - include: nest-all + - include: expressions + nest-all-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: nest-all + - include: expressions + + nest-brackets-i: + - match: '\[' + scope: punctuation.section.scope.ruby + push: + - match: '\]' + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-brackets-i + nest-curly-i: + - match: '\{' + scope: punctuation.section.scope.ruby + push: [nest-curly-i-inner, maybe-block-parameters] + nest-curly-i-inner: + - match: '\}' + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-curly-i + nest-ltgt-i: + - match: \< + scope: punctuation.section.scope.ruby + push: + - match: \> + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-ltgt-i + nest-parens-i: + - match: \( + scope: punctuation.section.scope.ruby + push: + - match: \) + scope: punctuation.section.scope.ruby + pop: true + - include: interpolated-ruby + - include: escaped-char + - include: nest-parens-i + +###[ HEREDOCS ]################################################################ + + heredocs: + # SEE: https://ruby-doc.org/core-2.5.0/doc/syntax/literals_rdoc.html + - include: heredoc-css + - include: heredoc-js + - include: heredoc-html + - include: heredoc-ruby + - include: heredoc-shell + - include: heredoc-sql + - include: heredoc-plain + + heredoc-css: + - match: (<<[-~])(["`]?)({{heredoc_type_css}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-css-indented-interpolated + - match: (<<[-~])(')({{heredoc_type_css}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-css-indented-literal + - match: (<<)(["`]?)({{heredoc_type_css}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-css-unindented-interpolated + - match: (<<)(')({{heredoc_type_css}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-css-unindented-literal + + heredoc-css-indented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.css.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_css}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-css-indented-literal: + - match: ^ + pop: 1 + embed: scope:source.css + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_css}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-css-unindented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.css.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_css}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-css-unindented-literal: + - match: ^ + pop: 1 + embed: scope:source.css + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_css}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-js: + - match: (<<[-~])(["`]?)({{heredoc_type_js}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-js-indented-interpolated + - match: (<<[-~])(')({{heredoc_type_js}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-js-indented-literal + - match: (<<)(["`]?)({{heredoc_type_js}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-js-unindented-interpolated + - match: (<<)(')({{heredoc_type_js}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-js-unindented-literal + + heredoc-js-indented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.js.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_js}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-js-indented-literal: + - match: ^ + pop: 1 + embed: scope:source.js + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_js}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-js-unindented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.js.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_js}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-js-unindented-literal: + - match: ^ + pop: 1 + embed: scope:source.js + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_js}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-html: + - match: (<<[-~])(["`]?)({{heredoc_type_html}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-html-indented-interpolated + - match: (<<[-~])(')({{heredoc_type_html}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-html-indented-literal + - match: (<<)(["`]?)({{heredoc_type_html}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-html-unindented-interpolated + - match: (<<)(')({{heredoc_type_html}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-html-unindented-literal + + heredoc-html-indented-interpolated: + - match: ^ + pop: 1 + embed: scope:text.html.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_html}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-html-indented-literal: + - match: ^ + pop: 1 + embed: scope:text.html + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_html}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-html-unindented-interpolated: + - match: ^ + pop: 1 + embed: scope:text.html.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_html}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-html-unindented-literal: + - match: ^ + pop: 1 + embed: scope:text.html + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_html}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-ruby: + - match: (<<[-~])(["`]?)({{heredoc_type_ruby}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-ruby-indented-interpolated + - match: (<<[-~])(')({{heredoc_type_ruby}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-ruby-indented-literal + - match: (<<)(["`]?)({{heredoc_type_ruby}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-ruby-unindented-interpolated + - match: (<<)(')({{heredoc_type_ruby}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-ruby-unindented-literal + + heredoc-ruby-indented-interpolated: + - match: ^ + pop: 1 + embed: heredoc-ruby-interpolated + embed_scope: meta.string.heredoc.ruby source.ruby.embedded.ruby + escape: ^\s*({{heredoc_type_ruby}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-ruby-indented-literal: + - match: ^ + pop: 1 + embed: expressions + embed_scope: meta.string.heredoc.ruby source.ruby.embedded.ruby + escape: ^\s*({{heredoc_type_ruby}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-ruby-unindented-interpolated: + - match: ^ + pop: 1 + embed: heredoc-ruby-interpolated + embed_scope: meta.string.heredoc.ruby source.ruby.embedded.ruby + escape: ^{{heredoc_type_ruby}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-ruby-unindented-literal: + - match: ^ + pop: 1 + embed: expressions + embed_scope: meta.string.heredoc.ruby source.ruby.embedded.ruby + escape: ^{{heredoc_type_ruby}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-ruby-interpolated: + - include: escaped-char + - include: embedded-ruby + - include: expressions + + heredoc-plain: + - match: (<<[-~])(["`]?)(\w+)(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-indented-interpolated, trailing-heredoc-start] + - match: (<<[-~])(')(\w+)(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-indented-literal, trailing-heredoc-start] + - match: (<<)(["`]?)(\w+)(["`]?) + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-unindented-interpolated, trailing-heredoc-start] + - match: (<<)(')(\w+)(') + captures: + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: [heredoc-plain-unindented-literal, trailing-heredoc-start] + + heredoc-plain-indented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: indented-heredoc-end + - include: merge-conflict-markers + - include: interpolated-ruby + - include: escaped-char + + heredoc-plain-indented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: indented-heredoc-end + - include: merge-conflict-markers + + heredoc-plain-unindented-interpolated: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: unindented-heredoc-end + - include: merge-conflict-markers + - include: interpolated-ruby + - include: escaped-char + + heredoc-plain-unindented-literal: + - meta_scope: meta.string.heredoc.ruby + - meta_content_scope: string.unquoted.heredoc.ruby + - include: unindented-heredoc-end + - include: merge-conflict-markers + + heredoc-shell: + - match: (<<[-~])(["`]?)({{heredoc_type_shell}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-shell-indented-interpolated + - match: (<<[-~])(')({{heredoc_type_shell}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-shell-indented-literal + - match: (<<)(["`]?)({{heredoc_type_shell}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-shell-unindented-interpolated + - match: (<<)(')({{heredoc_type_shell}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-shell-unindented-literal + + heredoc-shell-indented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.shell.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_shell}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-shell-indented-literal: + - match: ^ + pop: 1 + embed: scope:source.shell + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_shell}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-shell-unindented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.shell.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_shell}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-shell-unindented-literal: + - match: ^ + pop: 1 + embed: scope:source.shell + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_shell}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-sql: + - match: (<<[-~])(["`]?)({{heredoc_type_sql}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-sql-indented-interpolated + - match: (<<[-~])(')({{heredoc_type_sql}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-sql-indented-literal + - match: (<<)(["`]?)({{heredoc_type_sql}})(["`]?) + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-sql-unindented-interpolated + - match: (<<)(')({{heredoc_type_sql}})(') + captures: + 0: meta.string.heredoc.ruby + 1: punctuation.definition.heredoc.ruby + 2: meta.tag.heredoc.ruby punctuation.definition.tag.begin.ruby + 3: meta.tag.heredoc.ruby entity.name.tag.ruby + 4: meta.tag.heredoc.ruby punctuation.definition.tag.end.ruby + push: heredoc-sql-unindented-literal + + heredoc-sql-indented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.sql.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_sql}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-sql-indented-literal: + - match: ^ + pop: 1 + embed: scope:source.sql + embed_scope: meta.string.heredoc.ruby + escape: ^\s*({{heredoc_type_sql}})$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby + 1: entity.name.tag.ruby + - include: expressions + + heredoc-sql-unindented-interpolated: + - match: ^ + pop: 1 + embed: scope:source.sql.embedded.ruby + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_sql}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + heredoc-sql-unindented-literal: + - match: ^ + pop: 1 + embed: scope:source.sql + embed_scope: meta.string.heredoc.ruby + escape: ^{{heredoc_type_sql}}$ + escape_captures: + 0: meta.string.heredoc.ruby meta.tag.heredoc.ruby entity.name.tag.ruby + - include: expressions + + indented-heredoc-end: + - match: ^\s*(\3)$ # HEREDOC delimiter + scope: meta.tag.heredoc.ruby + captures: + 1: entity.name.tag.ruby + pop: true + + unindented-heredoc-end: + - match: ^\3$ # HEREDOC delimiter + scope: meta.tag.heredoc.ruby entity.name.tag.ruby + pop: true + + trailing-heredoc-start: + # This prevents clear_scopes from applying to the push token + - match: '' + set: trailing-heredoc + + trailing-heredoc: + # The rest of the line right after the heredoc tag needs to be handled + # as ordinary ruby source. The embedded syntax starts at the next line. + - clear_scopes: 2 + - match: ^ + pop: true + - include: expressions + +###[ DATA SECTION ]############################################################ + + data-section: + - match: ^__END__$ + scope: keyword.control.flow.end.ruby + set: data-section-body + + data-section-body: + - clear_scopes: true + - meta_include_prototype: false + - meta_content_scope: text.plain + - match: (?=<?xml|<(?i:html\b)|!DOCTYPE (?i:html\b)) + set: data-section-html-body + - include: merge-conflict-markers + + data-section-html-body: + - clear_scopes: true + - meta_include_prototype: false + - meta_scope: text.html.embedded.ruby + - include: scope:text.html.basic + apply_prototype: true
diff --git /dev/null b/syntax/Rust/Rust.sublime-syntax @@ -0,0 +1,1992 @@ +%YAML 1.2 +--- +# http://www.sublimetext.com/docs/3/syntax.html +name: Rust +scope: source.rust + +file_extensions: + - rs + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* // .*? -\*- .*? \brust\b .*? -\*- # editorconfig + ) + +variables: + shebang_language: \b(?:cargo|rust)\b + non_raw_ident: '[[:alpha:]][_[:alnum:]]*|_[_[:alnum:]]+' + # include a word boundary at the end to ensure all possible characters are + # consumed, to prevent catastrophic backtracking + identifier: '(?:(?:r\#)?{{non_raw_ident}}\b)' + camel_ident: '\b_*[A-Z][a-zA-Z0-9_]*[a-z][a-zA-Z0-9_]*\b' + lifetime: '''(?:_|{{identifier}})(?!\'')\b' + escaped_char: '\\([nrt0\"''\\]|x[0-7]\h|u\{(?:\h_*){1,6}\})' + int_suffixes: '[iu](?:8|16|32|64|128|size)' + float_suffixes: 'f(32|64)' + dec_literal: '[0-9](?:[0-9_])*' + float_exponent: '[eE][+-]?[0-9_]*[0-9][0-9_]*' + type_identifier: '\b(?:[[:upper:]]|_*[[:upper:]][[:alnum:]_]*[[:lower:]][[:alnum:]_]*)\b' + # https://doc.rust-lang.org/std/prelude/index.html + prelude_types: |- + (?x: + # std::boxed + |Box + # std::option + |Option|Result + # std::string + |String + # std::vec + |Vec + # Not in prelude + |VecDeque|BTreeMap|BTreeSet|HashMap|HashSet + |Rc|Arc|Mutex + ) + prelude_traits: |- + (?x: + # std::marker + Copy|Send|Sized|Sync|Unpin + # std::ops + |Drop|Fn|FnMut|FnOnce + # std::borrow + |ToOwned + # std::clone + |Clone + # std::cmp + |PartialEq|PartialOrd|Eq|Ord + # std::convert + |Into|From|AsRef|AsMut|TryFrom|TryInto + # std::default + |Default + # std::iter + |Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator|FromIterator + # std::string + |ToString + ) + prelude_enums: |- + (?x: + # std::option + Some|None|Ok|Err + ) + + # Other frequently used types of the std lib. + # https://doc.rust-lang.org/std/index.html#modules + std_types: |- + (?x: + # std::collections + VecDeque|LinkedList|BTreeMap|BTreeSet|HashMap|HashSet|BinaryHeap + # std::rc + |Rc + # std::sync + |Arc|Barrier|Mutex|Once|OnceLock|LazyLock|RwLock + # std::cell + |Cell|OnceCell|LazyCell|Ref|RefCell|UnsafeCell + ) + std_traits: |- + (?x: + # std::ops + |(?:Add|BitAnd|BitOr|BitXor|Div|Mul|Rem|Shl|Shr|Sub)(?:Assign)? + |Deref|DerefMut|Index|IndexMut + |Neg|Not|RangeBounds + |ControlFlow + # already in prelude: Drop|Fn|FnMut|FnOnce + ) +contexts: + main: + - meta_include_prototype: false + - match: '' + push: [statements, frontmatter, shebang] + + prototype: + # Macro metavariables. Ideally we would do this as a with_prototype, + # however then we run into infinite recursion. It needs to be a prototype + # since macro_rules! allows constructing new code, thus the metavariables + # can be inserted in just about any position in the syntax. + - match: '\${{identifier}}' + scope: variable.other.rust + + shebang: + - meta_include_prototype: false + # allow extending syntaxes like Markdown to ignore indentation restrictions + - match: \s*(\#!)(?!\[) + captures: + 1: punctuation.definition.comment.rust + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if Rust is embedded. + pop: 1 + + shebang-body: + - meta_include_prototype: false + - meta_scope: comment.line.shebang.rust + - match: '{{shebang_language}}' + scope: constant.language.shebang.rust + - match: $\n? + pop: 1 + + frontmatter: + - meta_include_prototype: false + - match: \s*(---)\s*$\n? + captures: + 0: meta.frontmatter.rust + 1: punctuation.section.frontmatter.begin.rust + embed: scope:source.toml + embed_scope: meta.frontmatter.rust source.toml.embedded.rust + escape: ^\s*(---)\s*$\n? + escape_captures: + 0: meta.frontmatter.rust + 1: punctuation.section.frontmatter.end.rust + pop: 1 + - match: ^|(?=\S) # Note: Ensure to highlight shebang if Rust is embedded. + pop: 1 + + statements: + # This isn't really just "statements", it also includes all types, + # expressions, items, etc. + + - include: visibility + + - include: terminators + + - match: '(''(?:{{identifier}}))\s*(:)' + captures: + 1: entity.name.label.rust + 2: punctuation.separator.rust + + - include: lifetime + + - include: declarations + - include: comments + - include: attributes + - include: strings + - include: chars + - include: bytes + - include: keywords + - include: numbers + + - include: blocks + + - match: '(?=\()' + push: group + + - match: '\[' + scope: punctuation.section.group.begin.rust + push: + - meta_scope: meta.group.rust + - match: '\]' + scope: punctuation.section.group.end.rust + pop: true + - match: ';' + scope: punctuation.separator.rust + - include: statements + + - match: ',' + scope: punctuation.separator.rust + push: after-operator + + - include: return-type + - include: types-relaxed + - include: identifiers + - include: symbols + + ##[ DECLARATIONS ]########################################################## + + visibility: + - match: '\b(pub)\s*(\()' + captures: + 1: storage.modifier.rust + 2: punctuation.section.group.begin.rust + push: + - include: comments + - match: '\)' + scope: punctuation.section.group.end.rust + pop: true + - match: '(crate|in|self|super)' + scope: keyword.other.rust + - match: '::' + scope: meta.path.rust + - match: '{{identifier}}' + scope: meta.path.rust + - match: '\bpub\b' + scope: storage.modifier.rust + + modules: + - match: '\b(mod)\s+({{identifier}})\b' + captures: + 1: keyword.declaration.module.rust + 2: entity.name.module.rust + push: + - meta_scope: meta.module.rust + - include: terminator + - include: module-block + + module-block: + - match: \{ + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.module.rust meta.block.rust + - include: block-body + + declarations: + - include: modules + + - match: '\b(fn)\s+(?={{identifier}})' + captures: + 1: keyword.declaration.function.rust + push: fn-definition + + - match: '\bstruct\b' + scope: keyword.declaration.struct.rust + push: struct-identifier + + - match: '\bunion\b(?!\s*\()' + scope: keyword.declaration.union.rust + push: union-identifier + + - match: '\btype\b' + scope: keyword.declaration.type.rust + push: type-declaration-identifier + + - match: '\b(trait)\s+({{identifier}})\b' + captures: + 1: keyword.declaration.trait.rust + 2: entity.name.trait.rust + push: + - meta_scope: meta.trait.rust + - match: '(?=:)' + push: impl-where + - match: '(?=\bwhere\b)' + push: impl-where + - match: '(?=<)' + push: generic-angles + - include: trait-block + - include: terminator + - match: '=' + scope: keyword.operator.assignment.rust + push: impl-where + + - match: '\bimpl\b' + scope: keyword.declaration.impl.rust + push: impl-definition + + - match: '\benum\b' + scope: keyword.declaration.enum.rust + push: enum-identifier + + - include: raw-pointer + + # `const` in a function header has a different scope from `const` values. + - match: '\b(const)\s+(?=unsafe|extern|fn)' + captures: + 1: storage.modifier.rust + + - match: '\b(const)\s+({{identifier}})' + captures: + 1: keyword.declaration.variable.constant.rust + 2: entity.name.constant.rust + push: declaration-after-identifier + + - match: '\b(static)\s+(?:(mut)\s+)?({{identifier}})' + captures: + 1: keyword.declaration.variable.static.rust + 2: storage.modifier.rust + 3: entity.name.constant.rust + push: declaration-after-identifier + + - match: \b(let)\s+(?:(mut)\s+)? + captures: + 1: keyword.declaration.variable.rust + 2: storage.modifier.rust + push: declaration-identifier + + - match: '\b(break|continue)\b(?:\s+(''{{identifier}}))?' + captures: + 1: keyword.control.rust + 2: entity.name.label.rust + + - match: '\b(macro_rules!)\s+({{identifier}})\b' + captures: + 1: keyword.declaration.macro.rust + 2: entity.name.macro.rust + push: macro-block + + declaration-identifier: + - match: '\b({{identifier}})\s*(=)\s*(?=\|)' + captures: + 1: entity.name.function.rust + 2: keyword.operator.assignment.rust + set: closure + # highlight (potentially invalid) keywords + - include: keywords + - include: identifiers + - match: (?=:) + set: declaration-after-identifier + - include: else-pop + + declaration-after-identifier: + - match: ':' + scope: punctuation.separator.rust + set: declaration-type + - include: else-pop + + declaration-type: + - match: '=(?!=)' + scope: keyword.operator.assignment.rust + set: after-operator + - include: types + - include: else-pop + + trait-block: + - match: '\{' + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.trait.rust meta.block.rust + - include: block-body + + ##[ ATTRIBUTES ]############################################################ + + attributes: + - match: '(#)\s*(!?)\s*(\[)' + captures: + 1: punctuation.definition.annotation.rust + 2: punctuation.definition.annotation.rust + 3: punctuation.section.group.begin.rust + push: inside-attribute + + inside-attribute: + # https://github.com/sublimehq/Packages/issues/709#issuecomment-266835130 + - meta_scope: meta.annotation.rust + - match: ({{identifier}})\s*(::)\s* + scope: meta.path.rust + captures: + 2: punctuation.accessor.rust + - match: '{{identifier}}' + scope: meta.path.rust variable.annotation.rust + - match: '\(' + scope: punctuation.section.group.begin.rust + push: + - meta_scope: meta.annotation.parameters.rust meta.group.rust + - match: \) + scope: punctuation.section.group.end.rust + pop: true + - include: attribute-call + - match: '=' + scope: keyword.operator.assignment.rust + set: attribute-contents + - match: '\]' + scope: punctuation.section.group.end.rust + pop: true + - include: comments + + attribute-contents: + - meta_content_scope: meta.annotation.rust + - include: strings + - include: chars + - include: bytes + - include: numbers + - include: comments + - include: macro-identifiers + - match: \( + scope: meta.function-call.rust meta.group.rust punctuation.section.group.begin.rust + push: attribute-call + - match: '\]' + scope: meta.annotation.rust punctuation.section.group.end.rust + pop: true + + attribute-call: + - meta_content_scope: meta.function-call.rust meta.group.rust + - match: \) + scope: meta.function-call.rust meta.group.rust punctuation.section.group.end.rust + pop: true + - match: ({{identifier}})\s*(::)\s* + scope: meta.path.rust + captures: + 2: punctuation.accessor.rust + - match: '({{identifier}})\s*(\()' + scope: meta.function-call.rust + captures: + 1: meta.path.rust variable.function.rust + 2: meta.group.rust punctuation.section.group.begin.rust + push: + - meta_content_scope: meta.function-call.rust + - include: attribute-call + - match: ',' + scope: punctuation.separator.rust + - match: '=' + scope: keyword.operator.assignment.rust + - include: attribute-contents + - include: lifetime + - include: keywords + - include: symbols + + ##[ EXPRESSION GROUPS ]##################################################### + + block: + - match: '\{' + scope: punctuation.section.block.begin.rust + set: [block-body, try-closure] + + blocks: + - match: '\{' + scope: punctuation.section.block.begin.rust + push: [block-body, try-closure] + + block-body: + - meta_scope: meta.block.rust + - match: '\}' + scope: punctuation.section.block.end.rust + pop: true + - include: statements + - include: attributes + + group: + - match: '\)' + scope: meta.group.rust punctuation.section.group.end.rust + pop: true + - match: '\(' + scope: punctuation.section.group.begin.rust + push: [group-body, try-closure] + + group-body: + - meta_scope: meta.group.rust + - match: '(?=\))' + pop: true + - include: statements + + group-tail: + - meta_scope: meta.group.rust + - match: '\)' + scope: punctuation.section.group.end.rust + pop: true + - include: statements + + after-operator: + # after-operator tries to handle ambiguous < and | symbols which can be + # either binary operators, or the start of a generic or closure. + - match: '(?=<)' + set: generic-angles + - include: try-closure + + try-closure: + - match: '\s*(?=\|)' + set: closure + # Exit the context if we didn't find a closure + - match: '(?=\S)' + pop: true + + ##[ PATTERNS ]########################################################### + + pattern-param: + # A pattern used in a function or closure parameter. + - include: comments + - match: '&' + scope: keyword.operator.rust + - match: \b(mut|ref)\b + scope: storage.modifier.rust + - match: '@' + scope: keyword.operator.rust + - include: lifetime + - match: '\b{{identifier}}\b(?!\s*(?:::|\{|\[|\())' + scope: variable.parameter.rust + + - match: '\{' + # Struct pattern. + scope: punctuation.section.block.begin.rust + push: + - meta_scope: meta.block.rust + - match: '\}' + scope: punctuation.section.block.end.rust + pop: true + - match: '(\d+)\s*(:)' + # Tuple struct field specifier. + captures: + 1: constant.numeric.integer.decimal.rust + 2: punctuation.separator.rust + - match: '{{identifier}}\s*(:)' + # Struct field specifier. + captures: + 1: punctuation.separator.rust + - match: '\.\.' + scope: keyword.operator.rust + - include: pattern-param + + - match: '\(' + # Tuple or tuple struct pattern. + scope: punctuation.section.group.begin.rust + push: + - meta_scope: meta.group.rust + - match: '\)' + scope: punctuation.section.group.end.rust + pop: true + - match: '\.\.' + scope: keyword.operator.rust + - include: pattern-param + + - match: '\[' + # Slice pattern. + scope: punctuation.section.brackets.begin.rust + push: + - meta_scope: meta.brackets.rust + - match: '\]' + scope: punctuation.section.brackets.end.rust + pop: true + - include: pattern-param + + # Path for struct patterns. + - match: '\bself\b|\bsuper\b' + scope: keyword.other.rust + - match: '\b{{identifier}}\b' + - match: '::' + + - match: ':(?!:)' + # Type + scope: punctuation.separator.rust + push: + - match: '(?=,|\)|\]|\}|\|)' + pop: true + - include: types + + - match: ',' + scope: punctuation.separator.rust + + ##[ CLOSURES ]############################################################## + + closure: + - meta_content_scope: meta.function.closure.rust + - match: '\|' + scope: punctuation.section.parameters.begin.rust + set: [closure-return, closure-parameters] + + closure-parameters: + - meta_scope: meta.function.parameters.rust + - match: '\|' + scope: punctuation.section.parameters.end.rust + pop: true + - include: pattern-param + # If the user has just typed a |, exit the params + # scope as soon as we hit something that it not a + # valid part so the whole rest of the document isn't + # highlighted using the params scope + - match: '(?=[=};)\]])' + pop: true + + closure-return: + - meta_content_scope: meta.function.closure.rust + - include: return-type + - match: (?=\S) + set: closure-body + + closure-body: + - match: '\{' + scope: punctuation.section.block.begin + set: closure-explicit-body + - match: (?=\S) + set: closure-implicit-body + + closure-implicit-body: + - meta_scope: meta.function.closure.rust + - match: '(?=[};)\]\n,])' + pop: true + - include: statements + + closure-explicit-body: + - meta_scope: meta.function.closure.rust meta.block.rust + - include: block-body + + ##[ TYPES ]################################################################# + + types-relaxed: + # only the most obvious type constructs (for fallback matching) + - match: (?=[!?]\s*{{type_identifier}}) + push: type-mark + - include: dyn-types + - match: (?={{type_identifier}}\s*<) + push: + - include: type-names + - match: (?=<) + push: generic-angles + - include: else-pop + + types: + # matches stray identifiers as a types because a type is expected + - include: comments + - include: return-type + - match: '&' + scope: keyword.operator.rust + - include: raw-pointer + - match: \b(mut|ref|const|unsafe)\b + scope: storage.modifier.rust + - match: '\bas\b' + # This is for qualified type paths <Type as TypePath> + scope: keyword.operator.rust + - match: \b(fn)\b\s*(\() + captures: + 1: storage.type.function.rust + 2: meta.group.rust punctuation.section.group.begin.rust + push: + - meta_content_scope: meta.group.rust + - match: \) + scope: meta.group.rust punctuation.section.group.end.rust + set: + - include: return-type + - match: '(?=\S)' + pop: true + - include: types + - include: pattern-param + - include: dyn-types + - include: lifetime + - include: impl-trait + - match: (?={{identifier}}::) + push: type-path + - match: (?=::) + push: type-path-second + - match: (?=<) + push: generic-angles + - match: '\(' + scope: punctuation.section.group.begin.rust + push: + - meta_scope: meta.group.rust + - match: '\)' + scope: punctuation.section.group.end.rust + pop: true + - match: ',' + scope: punctuation.separator.rust + - include: types + - match: '\+' + scope: keyword.operator.arithmetic.union.rust + - match: '\b_\b' + scope: storage.type.inference.rust + - match: '!(?!\w)' + scope: storage.type.never.rust + - include: type-marks + - match: \bextern\b + scope: keyword.other.rust + push: + - include: strings + - include: else-pop + - include: hrtb + - include: type-slice-or-array + - include: type-names + - include: all-generic-type-names + + type-mark: + - include: type-marks + - include: else-pop + + type-marks: + - match: '!' + scope: keyword.operator.negated-type.rust + - match: '\?' + scope: storage.modifier.relaxed-bounds.rust + + type-path: + - meta_scope: meta.path.rust + - include: comments + - match: '::' + scope: punctuation.accessor.rust + set: [type-path-second, path-after-accessor] + - include: type-names + - include: generic-identifier-names + - include: else-pop + + type-path-second: + - meta_scope: meta.path.rust + - match: '::' + scope: punctuation.accessor.rust + push: path-after-accessor + - include: in-path-type-names + - include: immediately-pop + + type-names: + - include: no-path-type-names + - include: in-path-type-names + + type-names-relaxed: + - include: no-path-type-names + - include: support-type-names + - include: generic-type-names + + in-path-type-names: + - include: support-type-names + - include: generic-type-names + + no-path-type-names: + - match: \bSelf\b + scope: storage.type.rust + - include: low-level-type-names + - include: stdsimd-type-names + + support-type-names: + - match: \b{{prelude_types}}\b + scope: support.type.rust + - match: \b{{prelude_traits}}\b + scope: support.type.rust + - match: \b{{prelude_enums}}\b + scope: support.type.rust + - match: \b{{std_types}}\b + scope: support.type.rust + - match: \b{{std_traits}}\b + scope: support.type.rust + + stdsimd-type-names: + - match: |- + (?x) + \b(?: + [ium]8x(?:2|4|8|16|32) | [iu]8x64 | + [ium]16x(?:2|4|8|16) | [iu]16x32 | # f16xN types might come later + [iumf]32x(?:2|4|8) | [iuf]32x16 | + [iumf]64x(?:2|4) | [iuf]64x8 | + m1x(?:64|32|16|8) | # 512-bit masks + __m(?:64|128|256)[di]? # __m512 should come later + )\b + scope: storage.type.rust + + specifier-names: + - match: '\b(c_[[:lower:][:digit:]_]+|[[:lower:]_][[:lower:][:digit:]_]*_t)\b' + scope: storage.type.rust + + low-level-type-names: + - match: \b({{int_suffixes}}|{{float_suffixes}}|bool|char|str)\b + scope: storage.type.rust + + all-generic-type-names: + - match: '{{identifier}}' + scope: storage.type.rust + + generic-type-names: + - match: '\b(?:r#)?_*{{type_identifier}}' + scope: storage.type.rust + + dyn-types: + - match: '\bdyn\b(?=\s*(?:\(|{{lifetime}}|{{identifier}}))' + scope: storage.type.trait.rust + + generic-angles: + - meta_scope: meta.generic.rust + - match: '<' + scope: punctuation.definition.generic.begin.rust + push: generic-angles-body + - include: else-pop + + generic-angles-body: + - include: comments + - include: attributes + - match: '>' + scope: punctuation.definition.generic.end.rust + pop: true + # match a few constants + - include: bool + # bytes must be before types to match the leading `b` + - include: bytes + - include: types + # chars must be after type-any-identifier to deal with conflict with lifetimes + - include: chars + # Handle negative integers (technically unary negative expression with a literal expression) + - match: '-' + scope: keyword.operator.arithmetic.rust + - include: integers + - include: blocks + - match: ':|,' + scope: punctuation.separator.rust + - match: '\+|=' + scope: keyword.operator.rust + - match: '(?=\S)' + pop: true + + hrtb: + - match: \bfor\b + scope: keyword.other.rust + push: + - match: '(?=<)' + push: generic-angles + - include: types + - match: '&' + scope: keyword.operator.rust + - include: lifetime + - match: '(?=\S)' + pop: true + + type-slice-or-array: + - match: '\[' + scope: punctuation.section.group.begin.rust + push: + - meta_scope: meta.group.rust + - match: '\]' + scope: punctuation.section.group.end.rust + pop: true + - match: ';' + scope: punctuation.separator.rust + set: + - meta_scope: meta.group.rust + - match: '\]' + scope: punctuation.section.group.end.rust + pop: true + - include: constant-integer-expression + - include: types + + constant-integer-expression: + - include: integers + - match: \( + scope: punctuation.section.group.begin.rust + push: + - meta_scope: meta.group.rust + - match: \) + scope: punctuation.section.group.end.rust + pop: true + - include: constant-integer-expression + - match: '{{identifier}}' + scope: variable.other.constant.rust + - match: '::' + scope: punctuation.accessor.double-colon.rust + - match: '[-+%/*]' + scope: keyword.operator.arithmetic.rust + + impl-trait: + - match: '\bimpl\b' + scope: storage.type.impl.rust + push: impl-trait-types + + impl-trait-types: + - match: '\buse\b' + scope: keyword.other.rust + push: impl-trait-use + - include: types + - match: '(?=\S)' + pop: true + + impl-trait-use: + - match: '<' + scope: punctuation.definition.generic.begin.rust + set: impl-trait-use-generic-body + - match: '(?=\S)' + pop: true + + impl-trait-use-generic-body: + - meta_scope: meta.generic.rust + - match: '>' + scope: punctuation.definition.generic.end.rust + pop: true + - include: lifetime + - match: ',' + scope: punctuation.separator.rust + - match: '\bSelf\b' + scope: keyword.other.rust + - include: all-generic-type-names + - match: '(?=\S)' + pop: true + + ##[ STRUCTS ]############################################################### + + struct-identifier: + - meta_scope: meta.struct.rust + - include: comments + - match: '{{identifier}}(?=<)' + scope: entity.name.struct.rust + set: + - meta_scope: meta.struct.rust meta.generic.rust + - match: '(?=<)' + push: generic-angles + - match: '' + set: struct-body + - match: '{{identifier}}' + scope: entity.name.struct.rust + set: struct-body + - match: '(?=\S)' + # Abort on invalid character. + pop: true + + struct-body: + - meta_scope: meta.struct.rust + - include: comments + - match: '(?=\bwhere\b)' + push: impl-where + - match: '(?=\()' + push: struct-tuple + - match: '(?=\{)' + set: struct-classic + - match: '(?=\S)' + # Semicolon is valid here, others should just abort. + pop: true + + struct-tuple: + - meta_scope: meta.struct.rust + - match: '\)' + scope: punctuation.section.group.end.rust + pop: true + - match: '\(' + scope: punctuation.section.group.begin.rust + push: inside-struct-tuple + + inside-struct-tuple: + - match: '(?=\))' + pop: true + - meta_scope: meta.group.rust + - include: comments + - include: attributes + - include: visibility + - include: types + - match: ',' + scope: punctuation.separator.rust + + struct-classic: + - meta_scope: meta.struct.rust + - match: '\{' + scope: punctuation.section.block.begin.rust + push: struct-classic-body + - match: '(?=\S)' + # Abort for an invalid match. + pop: true + + struct-classic-body: + - meta_scope: meta.block.rust + - match: '\}' + scope: punctuation.section.block.end.rust + pop: true + - include: comments + - include: attributes + - include: visibility + - match: '{{identifier}}(?=\s*:)' + scope: variable.other.member.rust + push: + - match: ',' + scope: punctuation.separator.rust + pop: true + - match: '(?=\})' + pop: true + - include: comments + - match: ':' + scope: punctuation.separator.rust + - include: types + - match: '(?=\S)' + # Abort for an invalid match. + pop: true + + ##[ UNIONS ]################################################################# + + union-identifier: + - meta_scope: meta.union.rust + - include: comments + - match: '{{identifier}}(?=<)' + scope: entity.name.union.rust + set: + - meta_scope: meta.union.rust meta.generic.rust + - match: '(?=<)' + push: generic-angles + - match: '' + set: union-extra + - match: '{{identifier}}' + scope: entity.name.union.rust + set: union-extra + + union-extra: + - meta_content_scope: meta.union.rust + - include: comments + - match: '(?=\bwhere\b)' + push: impl-where + - match: '\{' + scope: punctuation.section.block.begin.rust + set: union-body + - match: '(?=;)' + pop: true + + union-body: + - meta_scope: meta.union.rust meta.block.rust + - include: struct-classic-body + + ##[ TYPE DECLARATIONS ]##################################################### + + type-declaration-identifier: + - meta_scope: meta.type-declaration.rust + - include: comments + - include: type-declaration-wheres # deprecated + - match: '{{identifier}}' + scope: entity.name.type.rust + - match: '(?=<)' + push: generic-angles + - match: '=(?!=)' + scope: keyword.operator.assignment.rust + set: type-declaration-body + - include: else-pop + + type-declaration-body: + - meta_content_scope: meta.type-declaration.rust + - include: type-declaration-wheres + - include: types + - include: else-pop + + type-declaration-wheres: + - match: '(?=\bwhere\b)' + push: impl-where + + ##[ ENUMS ]################################################################# + + enum-identifier: + - meta_scope: meta.enum.rust + - include: comments + - match: '{{identifier}}(?=<)' + scope: entity.name.enum.rust + set: + - meta_scope: meta.enum.rust meta.generic.rust + - match: '(?=<)' + push: generic-angles + - match: '' + set: enum-maybe-where + - match: '{{identifier}}' + scope: entity.name.enum.rust + set: enum-maybe-where + - match: '(?=\S)' + # Abort on invalid character. + pop: true + + enum-maybe-where: + - meta_scope: meta.enum.rust + - include: comments + - match: '(?=\bwhere\b)' + push: impl-where + - match: '\{' + scope: punctuation.section.block.begin.rust + set: enum-body + - match: '(?=\S)' + # Abort on invalid character. + pop: true + + enum-body: + - meta_scope: meta.block.rust meta.enum.rust + - include: comments + - include: attributes + - match: '\}' + scope: punctuation.section.block.end.rust + pop: true + - match: '\b[[:upper:]_][[:upper:][:digit:]_]*\b' + scope: entity.name.constant.rust + push: enum-variant-type + - match: '{{camel_ident}}' + scope: storage.type.rust + push: enum-variant-type + - match: '{{identifier}}' + push: enum-variant-type + + enum-variant-type: + - include: comments + - match: '(?=\})' + pop: true + - match: ',' + scope: punctuation.separator.rust + pop: true + - match: '=' + set: enum-discriminant + - match: '(?=\()' + push: struct-tuple + - match: '(?=\{)' + push: struct-classic + + enum-discriminant: + - match: ',' + pop: true + - match: '(?=\})' + pop: true + # This is just constant-expression, but we don't have that defined. + - include: statements + + ##[ MACROS DEFINITIONS ]#################################################### + + macro-block: + - meta_scope: meta.macro.rust + - include: comments + - match: '\{' + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.macro.rust + - match: '\}' + scope: punctuation.section.block.end.rust + pop: true + - include: macro-block-contents + + # Note: ) and ] require a trailing semicolon, but this + # does not check for that. + - match: '\(' + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.macro.rust + - match: '\)' + scope: punctuation.section.block.end.rust + pop: true + - include: macro-block-contents + + - match: '\[' + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.macro.rust + - match: '\]' + scope: punctuation.section.block.end.rust + pop: true + - include: macro-block-contents + + macro-block-contents: + # Macro block consists of a series of rules separated by semicolon + # (trailing semicolon is optional). + # + # A rule is: BRACKET matchers BRACKET => BRACKET transcribers BRACKET + # where BRACKET needs to be matched () or [] or {} + - include: comments + - match: '\{' + scope: punctuation.section.block.begin.rust + push: + - meta_include_prototype: false + - meta_scope: meta.macro.matchers.rust + - match: '\}' + scope: punctuation.section.block.end.rust + set: macro-rule-sep + - include: macro-matchers + + - match: '\(' + scope: punctuation.section.block.begin.rust + push: + - meta_include_prototype: false + - meta_scope: meta.macro.matchers.rust + - match: '\)' + scope: punctuation.section.block.end.rust + set: macro-rule-sep + - include: macro-matchers + + - match: '\[' + scope: punctuation.section.block.begin.rust + push: + - meta_include_prototype: false + - meta_scope: meta.macro.matchers.rust + - match: '\]' + scope: punctuation.section.block.end.rust + set: macro-rule-sep + - include: macro-matchers + + macro-matchers: + - include: comments + - match: '\(' + scope: punctuation.section.block.begin.rust + push: + - meta_include_prototype: false + - match: '\)' + scope: punctuation.section.block.end.rust + pop: true + - include: macro-matchers + + - match: '\[' + scope: punctuation.section.block.begin.rust + push: + - meta_include_prototype: false + - match: '\]' + scope: punctuation.section.block.end.rust + pop: true + - include: macro-matchers + + - match: '\{' + scope: punctuation.section.block.begin.rust + push: + - meta_include_prototype: false + - match: '\}' + scope: punctuation.section.block.end.rust + pop: true + - include: macro-matchers + + - match: '(\$\s*{{identifier}})\s*(:)\s*(ident|path|expr|ty|pat_param|pat|stmt|block|item|meta|tt|lifetime|vis|literal)' + captures: + 1: variable.parameter.rust + 2: punctuation.separator.rust + 3: storage.type.rust + + - match: '(\$)\s*(\()' + # Kleene operator. + captures: + 1: keyword.operator.rust + 2: punctuation.section.group.begin.rust + push: + - meta_include_prototype: false + - match: '(\))\s*[^?*+]*\s*([?*+])' + captures: + 1: punctuation.section.group.end.rust + 2: keyword.operator.rust + pop: true + - include: macro-matchers + + # All other tokens except $ and delimiters are allowed here. + - include: numbers + - include: strings + - include: keywords + - include: lifetime + - include: chars + - include: symbols + + macro-rule-sep: + - include: comments + - match: '=>' + scope: keyword.operator.rust + set: macro-transcriber-block + - match: '(?=\S)' + # Abort on unexpected character. + pop: true + + macro-transcriber-block: + - include: comments + + - match: '\{' + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.macro.transcribers.rust + - match: '\}' + scope: punctuation.section.block.end.rust + set: macro-semi-sep + - include: statements + + - match: '\(' + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.macro.transcribers.rust + - match: '\)' + scope: punctuation.section.block.end.rust + set: macro-semi-sep + - include: statements + + - match: '\[' + scope: punctuation.section.block.begin.rust + set: + - meta_scope: meta.macro.transcribers.rust + - match: '\]' + scope: punctuation.section.block.end.rust + set: macro-semi-sep + - include: statements + + - match: '(?=\S)' + # Abort on unexpected character. + pop: true + + macro-semi-sep: + - include: comments + - include: terminator + - match: '(?=[})\]])' + pop: true + - match: '\S' + # This is intended to help make it evident when you forget a semicolon. + scope: invalid.illegal.rust + + ##[ IMPL DEFINITIONS ]###################################################### + + impl-definition: + - meta_scope: meta.impl.rust + - include: comments + - match: '(?=<)' + set: [impl-for, impl-generic] + - match: (?=\S) + set: impl-for + + impl-generic: + - meta_scope: meta.impl.rust + - match: '(?=<)' + push: generic-angles + - match: '' + pop: true + + impl-for: + # `!?` here matches opt-out trait impls + - match: '(?=\s*(?:::|!?{{identifier}}|\$|<)+(<.*?>)?\s+for\s+)' + set: + - meta_scope: meta.impl.rust + - include: comments + - match: '!?(?=\s*{{identifier}})' + scope: keyword.operator.rust meta.impl.opt-out.rust + - match: \bfor\b + scope: keyword.other.rust + set: impl-identifier + - include: types + - match: '' + set: impl-identifier + + impl-identifier: + - meta_content_scope: meta.impl.rust + - include: comments + - include: impl-block + - match: '(?=\bwhere\b)' + push: impl-where + - match: \b(mut|ref)\b + scope: storage.modifier.rust + - match: '{{identifier}}(?=<)' + scope: entity.name.impl.rust + push: generic-angles + - match: '{{identifier}}' + scope: entity.name.impl.rust + - match: '&' + scope: keyword.operator.rust + - include: lifetime + - include: else-pop + + impl-where: + - meta_scope: meta.where.rust + - include: comments + - match: '(?=(\{|;|=))' + pop: true + - match: \bwhere\b + scope: keyword.other.rust + - include: types + - match: ':' + scope: punctuation.separator.rust + + impl-block: + - match: \{ + scope: punctuation.section.block.begin.rust + set: impl-body + + impl-body: + - meta_scope: meta.impl.rust meta.block.rust + - include: block-body + + ##[ FUNCTION DEFINITIONS ]################################################### + + fn-definition: + - meta_scope: meta.function.rust + - include: comments + - match: '{{identifier}}' + scope: entity.name.function.rust + set: fn-generic + + fn-generic: + - include: comments + - match: '(?=<)' + push: generic-angles + - match: '(?=\()' + set: fn-parameters + - match: (?=\bwhere\b) + set: fn-where + - include: else-pop + + fn-parameters: + - meta_scope: meta.function.rust + - match: '\)' + scope: meta.function.parameters.rust punctuation.section.parameters.end.rust + set: fn-after-parameters + - match: '\(' + scope: punctuation.section.parameters.begin.rust + push: + - meta_scope: meta.function.parameters.rust + - include: comments + - match: '(?=\))' + pop: true + - include: pattern-param + + fn-after-parameters: + - meta_scope: meta.function.rust + - include: comments + - match: '\{' + scope: punctuation.section.block.begin.rust + set: fn-body + - include: return-type + - match: (?=\bwhere\b) + push: fn-where + - include: else-pop + + fn-where: + - meta_scope: meta.where.rust + - match: \bwhere\b + scope: keyword.other.rust + - include: comments + - match: '(?=\{)' + pop: true + - include: types + - match: '[:,]' + scope: punctuation.separator.rust + - include: else-pop + + return-type: + - match: '->' + scope: punctuation.separator.rust + push: + - meta_scope: meta.function.return-type.rust + - match: '(?=\s*\{|\bwhere\b)' + pop: true + - match: '(?=<)' + push: generic-angles + - include: types + - match: '{{identifier}}' + # Escape for incomplete expression + - match: '(?=\S)' + pop: true + + fn-body: + - meta_scope: meta.function.rust meta.block.rust + - match: '\}' + scope: punctuation.section.block.end.rust + pop: true + - include: statements + + ##[ COMMENTS ]############################################################## + + comments: + - include: line-comments + - include: block-comments + - include: merge-conflict-markers + + line-comments: + - match: //[!/] + scope: punctuation.definition.comment.rust + push: + - meta_scope: comment.line.documentation.rust + - match: $\n? + pop: true + - match: // + scope: punctuation.definition.comment.rust + push: + - meta_scope: comment.line.double-slash.rust + - match: $\n? + pop: true + + block-comments: + - match: /\*[!\*][^\*/] + scope: punctuation.definition.comment.rust + push: + - meta_scope: comment.block.documentation.rust + - match: \*/ + scope: punctuation.definition.comment.rust + pop: true + # Javadoc style comment with leading * on each line. Helps with word-wrapping. + - match: ^\s*(\*)(?!/) + captures: + 1: punctuation.definition.comment.rust + - include: block-comments + - include: merge-conflict-markers + - match: /\* + scope: punctuation.definition.comment.rust + push: + - meta_scope: comment.block.rust + - match: \*/ + scope: punctuation.definition.comment.rust + pop: true + - include: block-comments + - include: merge-conflict-markers + +##[ MERGE CONFLICT MARKERS ]################################################ + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +##[ STRING LITERALS ]####################################################### + + strings: + - include: byte-string + - include: raw-byte-string + - include: string + - include: raw-string + - include: c-string + - include: raw-c-string + + bytes: + - match: "(b)(')" + captures: + 1: storage.type.string.rust + 2: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.single.rust + # ASCII except ', \, \n, \r or \t + - match: '[\x00-\x08\x0b-\x0c\x0e-\x26\x28-\x5b\x5d-\x7f]' + set: byte-tail + # Don't mark entire file invalid while writing, even though this is + # not valid syntax. + - match: '\n' + pop: true + - include: escaped-byte + set: byte-tail + - match: '' + set: byte-tail + + byte-tail: + - match: "'" + scope: string.quoted.single.rust punctuation.definition.string.end.rust + pop: true + - match: '\n' + pop: true + - match: '.' + scope: invalid.illegal.byte.rust + + byte-string: + - match: '(b)(")' + captures: + 1: storage.type.string.rust + 2: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.rust + - match: '"' + scope: punctuation.definition.string.end.rust + pop: true + - include: escaped-byte + - include: line-continuation + - match: '\\.' + scope: invalid.illegal.character.escape.rust + + raw-byte-string: + - match: (br)(#*)" + captures: + 1: storage.type.string.rust + 2: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.raw.rust + - match: '"\2' + scope: punctuation.definition.string.end.rust + pop: true + + line-continuation: + - match: '\\$' + scope: punctuation.separator.continuation.line.rust + + escaped-byte: + - match: '\\([nrt0\"''\\]|x\h{2})' + scope: constant.character.escape.rust + + escaped-char: + - match: '{{escaped_char}}' + scope: constant.character.escape.rust + - match: '\\u\{[^}]*\}' + scope: invalid.illegal.character.escape.rust + - match: '\\.' + scope: invalid.illegal.character.escape.rust + + chars: + - match: "'" + scope: punctuation.definition.string.begin.rust + push: + - meta_scope: string.quoted.single.rust + - match: "[^'\\\\\n\r\t]" + set: char-tail + # Don't mark entire file invalid while writing, even though this is + # not valid syntax. + - match: '\n' + pop: true + - match: '{{escaped_char}}' + scope: constant.character.escape.rust + set: char-tail + - match: '' + set: char-tail + + char-tail: + - match: "'" + scope: string.quoted.single.rust punctuation.definition.string.end.rust + pop: true + - match: '\n' + pop: true + - match: '.' + scope: invalid.illegal.char.rust + + string: + - match: '"' + scope: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.rust + - match: '"' + scope: punctuation.definition.string.end.rust + pop: true + - include: escaped-char + - include: line-continuation + + raw-string: + - match: (r)((#*)") + captures: + 1: storage.type.string.rust + 2: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.raw.rust + - match: '"\3' + scope: punctuation.definition.string.end.rust + pop: true + + c-string: + - match: '(c)(")' + captures: + 1: storage.type.string.rust + 2: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.rust + - match: '"' + scope: punctuation.definition.string.end.rust + pop: true + - include: escaped-byte + - include: line-continuation + - include: escaped-char + + raw-c-string: + - match: (cr)((#*)") + captures: + 1: storage.type.string.rust + 2: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.raw.rust + - match: '"\3' + scope: punctuation.definition.string.end.rust + pop: true + + format-string: + - match: '"' + scope: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.rust + - match: '"' + scope: punctuation.definition.string.end.rust + pop: true + - include: escaped-char + - include: format-escapes + - include: line-continuation + + format-raw-string: + - match: (r)(#*)" + captures: + 1: storage.type.string.rust + 2: punctuation.definition.string.begin.rust + push: + - meta_include_prototype: false + - meta_scope: string.quoted.double.raw.rust + - match: '"\2' + scope: punctuation.definition.string.end.rust + pop: true + - include: format-escapes + + format-escapes: + - match: '\{\{|\}\}' + scope: constant.character.escape.rust + - match: |- + (?x) # Spec from http://doc.rust-lang.org/std/fmt/ + \{ + (\d+|{{identifier}})? + ( + : # format_spec delimiter + (.?[<>^])? # [[fill]align] + [+-]? # [sign] + \#? # ['#'] + 0? # [0] + ((\d+\$?)|{{identifier}}\$)? # [width] + (\.(\d+\$?|\*|{{identifier}}\$)?)? # ['.' precision] + (([xX]?\?)|{{identifier}})? # [type] + )? + \} + scope: constant.other.placeholder.rust + + ##[ NUMERIC LITERALS ]###################################################### + + numbers: + - include: floats + - include: integers + + floats: + - match: '\b({{dec_literal}}(?:\.{{dec_literal}})?(?:{{float_exponent}})?)({{float_suffixes}})' + captures: + 1: constant.numeric.float.rust + 2: storage.type.numeric.rust + - match: '\b{{dec_literal}}\.{{dec_literal}}(?:{{float_exponent}})?' + scope: constant.numeric.float.rust + - match: '\b{{dec_literal}}{{float_exponent}}' + scope: constant.numeric.float.rust + - match: '\b{{dec_literal}}\.(?![A-Za-z._''])' + scope: constant.numeric.float.rust + + integers: + - match: '\b({{dec_literal}})({{int_suffixes}})?\b' + captures: + 1: constant.numeric.integer.decimal.rust + 2: storage.type.numeric.rust + - match: '\b(0x[\h_]+)({{int_suffixes}})?\b' + captures: + 1: constant.numeric.integer.hexadecimal.rust + 2: storage.type.numeric.rust + - match: '\b(0o[0-7_]+)({{int_suffixes}})?\b' + captures: + 1: constant.numeric.integer.octal.rust + 2: storage.type.numeric.rust + - match: '\b(0b[0-1_]+)({{int_suffixes}})?\b' + captures: + 1: constant.numeric.integer.binary.rust + 2: storage.type.numeric.rust + + lifetime: + - match: '{{lifetime}}' + scope: storage.modifier.lifetime.rust + + ##[ IDENTIFIERS AND FUNCTION CALLS ]######################################## + + identifiers: + - match: (?={{identifier}}\s*\.) + push: identifier-path + - match: (?=\.(?!\.)) + push: identifier-path-second + - match: (?={{identifier}}\s*::) + push: static-identifier-path + - match: (?=::) + push: static-identifier-path-second + - include: identifier-names + + identifier-path: + - meta_scope: meta.path.rust + - include: comments + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.rust + push: [identifier-path-second, path-after-accessor] + - include: identifier-names + - include: immediately-pop + + identifier-path-second: + - meta_scope: meta.path.rust + - include: comments + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.rust + push: path-after-accessor + - include: in-path-identifier-names + - include: immediately-pop + + static-identifier-path: + - meta_scope: meta.path.rust + - include: comments + - match: \s*(::) + captures: + 1: punctuation.accessor.rust + set: [static-identifier-path-second, path-after-accessor] + - include: type-names + - include: identifier-names + - include: immediately-pop + + static-identifier-path-second: + # does not include no-path-identifier-names + - meta_scope: meta.path.rust + - include: comments + - match: '::' + scope: punctuation.accessor.rust + push: path-after-accessor + - include: in-path-type-names + - include: in-path-identifier-names + - match: (?=<) + push: generic-angles + - include: immediately-pop + + path-after-accessor: + - include: comments + - include: else-pop + + identifier-names: + - include: no-path-identifier-names + - include: no-path-type-names + - include: in-path-identifier-names + + in-path-identifier-names: + - include: keywords + - include: macro-identifiers + - include: in-path-type-names + - include: function-identifiers + - include: constant-identifier-names + - include: generic-identifier-names + + no-path-identifier-names: + - match: \b(self)\b + scope: variable.language.rust + - match: \b(super)\b + scope: keyword.other.rust + + constant-identifier-names: + - match: '\b(?:(?:r#)?[[:upper:]_][[:upper:][:digit:]_]+)\b' + scope: constant.other.rust + + macro-identifiers: + # macros which take format specs as the only parameter + - match: '\b((?:format(?:_args)?|e?print(?:ln)?|panic|unreachable|unimplemented)!)\s*(\()' + captures: + 1: support.macro.rust + 2: meta.group.rust punctuation.section.group.begin.rust + push: + - meta_content_scope: meta.group.rust + - include: comments + - include: format-string + - include: format-raw-string + - match: '(?=\S)' + set: group-tail + + # macros which take format specs as the second parameter + - match: '\b((?:write(?:ln)?|(?:debug_)?assert)!)\s*(\()' + captures: + 1: support.macro.rust + 2: meta.group.rust punctuation.section.group.begin.rust + push: + - meta_scope: meta.group.rust + - include: comments + - match: ',' + set: + - meta_content_scope: meta.group.rust + - include: format-string + - include: format-raw-string + - match: '(?=\S)' + set: group-tail + - include: group-tail + + # macros which take format specs as the third parameter + # - match: '\b((?:assert_eq|assert_ne|debug_assert_eq|debug_assert_ne)!)\s*(\()' + # is more performant as the below + # - match: '\b((?:debug_)?assert_(?:eq|ne)!)\s*(\()' + - match: '\b{{identifier}}!(?=\s*(\(|\{|\[))' + scope: support.macro.rust + + function-identifiers: + - match: '{{identifier}}(?=\s*\()' + scope: variable.function.rust + + generic-identifier-names: + - match: '{{identifier}}' + scope: variable.other.rust + + ##[ KEYWORDS AND SYMBOLS ]################################################## + + symbols: + - match: '=>' + # Making this an operator helps visually break up large + # match blocks containing just enums + scope: keyword.operator.rust + + - match: '<-|->' + scope: keyword.operator.rust + + - match: '\.\.\.|\.\.=|\.\.' + scope: keyword.operator.range.rust + + - match: '[!<>=]=' + scope: keyword.operator.comparison.rust + + - match: '(?:[-+%/*^&|]|<<|>>)?=' + scope: keyword.operator.assignment.rust + + - match: '&&|\|\||!' + scope: keyword.operator.logical.rust + + - match: '[&|^]|<<|>>' + scope: keyword.operator.bitwise.rust + + - match: '[<>]' + scope: keyword.operator.comparison.rust + + - match: '[-+%/*]' + scope: keyword.operator.arithmetic.rust + + - match: '[@~?$#'']' + scope: keyword.operator.rust + + - match: '[:;,]' + scope: punctuation.separator.rust + + bool: + - match: \bfalse\b + scope: constant.language.boolean.false.rust + - match: \btrue\b + scope: constant.language.boolean.true.rust + + raw-pointer: + - match: '\*\s*(?:const|mut)\b' + scope: storage.modifier.rust + + keywords: + # All keywords. Note in `statements` most of these are superseded by more + # specific rules. + - include: bool + + - match: \blet\b + scope: keyword.declaration.variable.rust + + - match: \bstatic\b + scope: keyword.declaration.variable.static.rust + + - match: \bconst\b + # The storage keyword seems more likely to not have been matched earlier. + scope: storage.modifier.rust + # scope: keyword.declaration.variable.constant.rust + + - match: \bfn\b + scope: keyword.declaration.function.rust + + - match: \bmod\b + scope: keyword.declaration.module.rust + + - match: \bstruct\b + scope: keyword.declaration.struct.rust + + - match: \bimpl\b + scope: keyword.declaration.impl.rust + + - match: \benum\b + scope: keyword.declaration.enum.rust + + - match: \btype\b + scope: keyword.declaration.type.rust + + - match: \btrait\b + scope: keyword.declaration.trait.rust + + - match: \b(mut|pub|unsafe|move|ref)\b + scope: storage.modifier.rust + + - match: \b(crate|extern|where)\b + scope: keyword.other.rust + + - match: \buse\b + scope: keyword.declaration.import.rust + + - match: \b(async|await|else|for|if|loop|match|try|while|yield)\b + scope: keyword.control.rust + + - match: \b(break|continue)\b + scope: keyword.control.rust + + - match: \breturn\b + scope: keyword.control.rust + + - match: \b(as|in|box)\b + scope: keyword.operator.rust + + - match: \b(virtual|become|priv|typeof|unsized|do|abstract|final|override|macro)\b + scope: invalid.illegal.rust + + - match: \b(super|Self)\b + scope: keyword.other.rust + + - include: reserved-keywords + + reserved-keywords: + - match: \b(virtual|become|priv|typeof|unsized|do|abstract|final|override|macro|for)\b + scope: invalid.illegal.rust + + terminators: + - match: ';' + scope: punctuation.terminator.rust + + terminator: + - match: ';' + scope: punctuation.terminator.rust + pop: true + + else-pop: + - match: (?=\S) + pop: true + + immediately-pop: + - match: '' + pop: true
diff --git /dev/null b/syntax/SQL/SQL.sublime-syntax @@ -0,0 +1,1753 @@ +%YAML 1.2 +--- +name: SQL +scope: source.sql +version: 2 +hidden: true + +file_extensions: + - sql + +variables: + string_escape: (?:\\.) + simple_identifier: (?:\w+) + simple_identifier_break: (?!\w) + + toplevel_reserved: |- + (?xi: alter | create | cross | delete | drop | from | grant | group | inner | insert | join + | left | on | order | outer | revoke | right | select | set | truncate | union + | update | where ) + additional_toplevel_reserved: (?!) + + # TODO: not all are supported by all dialects! + ddl_target: |- + (?xi: {{ddl_target_other}} + | (?: {{ddl_target_function_modifier}} \s+ )? {{ddl_target_function}} + | (?: {{ddl_target_index_modifier}} \s+ )? index + | (?: {{ddl_target_table_modifier}} \s+ )? table ) + ddl_target_function: |- + (?xi: procedure | function ) + ddl_target_other: |- + (?xi: aggregate | column | constraint | conversion | database | domain | group + | language | member | operator\s+class | operator | role | rule | schema | sequence + | tablespace | trigger | type | user | view ) + + ddl_target_inside_alter_table: |- + (?xi: constraint ) + + ddl_target_function_modifier: |- + (?xi: aggregate ) + ddl_target_index_modifier: |- + (?xi: clustered | fulltext | spatial | unique ) + ddl_target_table_modifier: |- + (?xi: temp(?:orary)? ) + + function_parameter_modifier: |- + (?xi: inout | in | out ) + + simple_types: |- + (?xi: boolean | bool | year ) + + types_with_optional_number: |- + (?xi: bit | datetime | int | number | n?(?:var)?char | varbinary ) + + type_modifiers: |- + (?xi: signed | unsigned | zerofill ) + + builtin_scalar_functions: |- + (?xi: current_(?: date | time(?:stamp)? ) ) + + builtin_user_functions: |- + (?xi: (?: current | session | system )_user ) + + like_keyword: |- + (?xi: like ) + +contexts: + prototype: + - include: comments + + main: + - include: sql + + sql: + - include: statements + - include: statement-terminators + - include: expressions-or-column-names + + statements: + - include: create-statements + - include: drop-statements + - include: alter-statements + - include: dml-statements + - include: grant-statements + - include: revoke-statements + - include: other-statements + +###[ COMMENTS ]################################################################ + + comments: + - include: double-dash-comments + - include: block-comments + - include: merge-conflict-markers + + double-dash-comments: + - match: '--' + scope: punctuation.definition.comment.sql + push: inside-double-dash-comment + + block-comments: + - match: /\*(?:\*(?!/))+ + scope: punctuation.definition.comment.begin.sql + push: inside-comment-docblock + - match: /\* + scope: punctuation.definition.comment.begin.sql + push: inside-comment-block + + inside-double-dash-comment: + - meta_scope: comment.line.double-dash.sql + - match: \n + pop: 1 + - include: comment-prototype + + inside-comment-docblock: + - meta_scope: comment.block.documentation.sql + - match: \*+/ + scope: punctuation.definition.comment.end.sql + pop: 1 + - match: ^\s*(\*)(?!\**/) + captures: + 1: punctuation.definition.comment.sql + - include: comment-prototype + - include: merge-conflict-markers + + inside-comment-block: + - meta_scope: comment.block.sql + - match: \*+/ + scope: punctuation.definition.comment.end.sql + pop: 1 + - include: comment-prototype + - include: merge-conflict-markers + + comment-prototype: [] + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ DDL CREATE STATEMENTS ]################################################### + + create-statements: + - match: \b(?i:create)\b + scope: keyword.other.ddl.sql + push: + - create-meta + - create-target + + create-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.create.sql + - include: immediately-pop + + create-target: + - include: create-function + - include: create-index + - include: create-table + - include: create-other + - include: else-pop + + create-function: + - match: \b(?:({{ddl_target_function_modifier}})\s+)?({{ddl_target_function}})\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - expect-function-characteristics + - expect-function-parameters + - expect-function-creation-name + - create-function-condition + + create-function-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-index: + - match: \b(?i:(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - create-index-args + - expect-index-creation-name + - create-index-condition + + create-index-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-index-args: + - meta_scope: meta.index.sql + - include: on-table-names + - include: create-common-args + + create-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - create-table-args + - maybe-column-declaration-list + - expect-table-creation-name + - create-table-condition + + create-table-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-table-args: + - meta_scope: meta.table.sql + - include: create-common-args + + create-other: + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - create-other-args + - expect-other-creation-name + - create-other-condition + + create-other-condition: + - meta_include_prototype: false + - include: maybe-condition + + create-other-args: + - match: \b(?i:(as)\s+(table))\b + captures: + 1: keyword.context.block.sql + 2: support.type.sql + set: maybe-column-declaration-list + - match: \b(?i:as)\b + scope: keyword.context.block.sql + pop: 1 + - include: grant + - include: on-table-names + - include: create-common-args + + create-common-args: + - include: expressions + - include: pop-on-top-level-reserved-word + +###[ DDL DROP STATEMENTS ]##################################################### + + drop-statements: + - match: \b(?i:drop)\b + scope: keyword.other.ddl.sql + push: + - drop-meta + - drop-target + + drop-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.drop.sql + - include: immediately-pop + + drop-target: + - include: drop-function + - include: drop-index + - include: drop-table + - include: drop-other + - include: else-pop + + drop-function: + - match: \b{{ddl_target_function}}\b + scope: keyword.other.ddl.sql + set: + - drop-function-args + - expect-function-name + - drop-function-condition + + drop-function-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-function-args: + - meta_include_prototype: false + - meta_scope: meta.function.sql + - include: immediately-pop + + drop-index: + - match: \b(?i:index)\b + scope: keyword.other.ddl.sql + set: + - drop-index-args + - expect-index-name + - drop-index-condition + + drop-index-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-index-args: + - meta_scope: meta.index.sql + - include: maybe-on-table-name + + drop-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - drop-table-args + - expect-table-name + - drop-table-condition + + drop-table-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-table-args: + - meta_include_prototype: false + - meta_scope: meta.table.sql + - include: immediately-pop + + drop-other: + - match: \b(?i:user)\b + scope: storage.type.sql + set: + - expect-user-name + - maybe-condition + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - drop-other-args + - expect-other-name + - drop-other-condition + + drop-other-condition: + - meta_include_prototype: false + - include: maybe-condition + + drop-other-args: + - include: maybe-on-table-name + +###[ DDL ALTER STATEMENTS ]#################################################### + + alter-statements: + - match: \b(?i:alter)\b + scope: keyword.other.ddl.sql + push: + - alter-meta + - alter-target + + alter-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.alter.sql + - include: immediately-pop + + alter-target: + - include: alter-function + - include: alter-index + - include: alter-table + - include: alter-other + - include: else-pop + +###[ DDL ALTER FUNCTION STATEMENTS ]########################################### + + alter-function: + - match: \b(?:({{ddl_target_function_modifier}})\s+)?({{ddl_target_function}})\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - expect-function-characteristics + - expect-function-parameters + - expect-function-name + - alter-function-condition + + alter-function-condition: + - meta_include_prototype: false + - include: maybe-condition + +###[ DDL ALTER INDEX STATEMENTS ]############################################## + + alter-index: + - match: \b(?i:(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - alter-index-args + - expect-index-name + - alter-index-condition + + alter-index-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-index-args: + - include: alter-common + - include: pop-on-top-level-reserved-word + - include: expressions-or-column-names + +###[ DDL ALTER TABLE STATEMENTS ]############################################## + + alter-table: + - match: \b(?i:(?:({{ddl_target_table_modifier}})\s+)?(table))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + set: + - alter-table-args + - expect-table-name + - alter-table-condition + + alter-table-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-table-args: + - include: alter-columns + - include: alter-common + - include: pop-on-top-level-reserved-word + - include: expressions-or-column-names + + alter-other: + - match: \b{{ddl_target_other}}\b + scope: keyword.other.ddl.sql + set: + - alter-other-args + - expect-other-name + - alter-other-condition + + alter-other-condition: + - meta_include_prototype: false + - include: maybe-condition + + alter-other-args: + - include: alter-common + - include: else-pop + + alter-columns: + - match: \b(?i:(?:(add|alter)\b(?:\s+(column)\b|(?!\s+(?:table|{{ddl_target_inside_alter_table}})\b)))) + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - maybe-type-modifier + - expect-type + - expect-column-name-declaration + - match: \b(?i:(drop)(?:\s+(column)\b|(?!\s+{{ddl_target}}\b))) + scope: keyword.other.ddl.sql + push: expect-column-name + + alter-common: + - match: \b(?i:(add)\s+(constraint))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + push: + - maybe-column-modifier + - expect-constraint-name + - match: \b(?i:(add)\s+(?:({{ddl_target_index_modifier}})\s+)?(index))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql + - match: \b(?i:(add)\s+(primary|foreign)\s+(key))\b + captures: + 1: keyword.other.ddl.sql + 2: keyword.other.ddl.sql + 3: keyword.other.ddl.sql + +###[ DDL STATEMENT PROTOTYPES ]################################################ + + maybe-on-table-name: + - include: on-table-names + - include: else-pop + + on-table-names: + - match: \b(?i:on)\b + scope: keyword.other.sql + push: expect-table-name + +###[ DML STATEMENTS ]########################################################## + + dml-statements: + - match: \b(?i:select)\b + scope: keyword.other.dml.sql + - match: \b(?i:union(?:\s+all)?)\b + scope: keyword.other.dml.sql + - match: \b(?i:(?:delete(?:\s+from)?))\b + scope: keyword.other.dml.sql + push: dml-delete + - match: \b(?i:update)\b + scope: keyword.other.dml.sql + push: dml-update + - match: \b(?i:(?:insert\s+into|truncate))\b + scope: keyword.other.dml.sql + push: expect-table-name + - include: set-statements + # expressions + - match: \b(?i:(?:default\s+)?values)\b + scope: keyword.other.dml.II.sql + - include: distinct + - include: join-expressions + - match: \b(?i:group\s+by|order\s+by|having|where)\b + scope: keyword.other.dml.sql + - match: \b(?i:from)\b + scope: keyword.other.dml.sql + push: table-name-or-subquery + - match: \b(?i:asc|desc)\b + scope: keyword.other.order.sql + + dml-delete: + - include: expect-table-name + + dml-update: + - match: (?={{simple_identifier}}\s*=) + pop: 1 + - include: expect-table-name + + distinct: + - match: \b(?i:distinct)\b + scope: keyword.other.dml.sql + + join-expressions: + - match: \b(?i:(?:(?:cross|inner|(?:full|left|right)(?:\s+outer)?)\s+)?join)\b + scope: keyword.other.dml.sql + push: + - join-condition + - table-name-or-subquery + + join-condition: + - match: \b(?i:on)\b + scope: keyword.control.conditional.sql + set: conditional-expression + - include: else-pop + + conditional-expression: + - match: (?=[,;)}]|\b(?:{{toplevel_reserved}}|{{additional_toplevel_reserved}})\b) + pop: 1 + - include: expressions + - include: expect-column-names + +###[ DML SET STATEMENTS ]###################################################### + + set-statements: + - match: \b(?i:set)\b(?!\s*\() + scope: keyword.other.dml.sql + push: + - set-meta + - set-target + + set-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.set.sql + - include: immediately-pop + + set-target: + - include: else-pop + +###[ GRANT STATEMENTS ]######################################################## + + grant-statements: + - match: \b(?i:grant(?:\s+with\s+grant\s+option)?)\b + scope: keyword.other.authorization.sql + push: + - grant-meta + - grant + + grant-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.grant.sql + - include: immediately-pop + +###[ REVOKE STATEMENTS ]####################################################### + + revoke-statements: + - match: \b(?i:revoke)\b + scope: keyword.other.ddl.sql + push: + - revoke-meta + - grant + + revoke-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.revoke.sql + - include: immediately-pop + +###[ OTHER STATEMENTS ]######################################################## + + other-statements: [] + +###[ EXPRESSIONS ]############################################################# + + expressions-or-column-names: + - include: wildcard-identifiers + - include: expressions + - include: expect-column-names + + expressions: + - include: groups + - include: comma-separators + - include: operators + - include: column-alias-expressions + - include: case-expressions + - include: collate-expressions + - include: constraint-expressions + - include: literals-and-variables + - include: function-calls + - include: illegal-stray-brackets + - include: illegal-stray-parens + - match: (?=;) + pop: 1 + + column-alias-expressions: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + push: expect-column-alias-name + + table-alias-expression: + - match: \b(?i:as)\b + scope: keyword.operator.assignment.alias.sql + set: expect-table-alias-name + + case-expressions: + - match: \b(?i:case)\b + scope: keyword.control.conditional.case.sql + push: inside-case-expression + + inside-case-expression: + - meta_scope: meta.statement.conditional.case.sql + - match: \b(?i:end)\b + scope: keyword.control.conditional.end.sql + pop: 1 + - match: \b(?i:(case)\s+(when))\b + captures: + 1: keyword.control.conditional.case.sql + 2: keyword.control.conditional.when.sql + - match: \b(?i:when)\b + scope: keyword.control.conditional.when.sql + - match: \b(?i:then)\b + scope: keyword.control.conditional.then.sql + - match: \b(?i:else)\b + scope: keyword.control.conditional.else.sql + - include: expressions-or-column-names + + collate-expressions: + - match: \b(?i:collate)\b + scope: keyword.other.sql + push: inside-collate-expression + + inside-collate-expression: + - match: '{{simple_identifier}}' + scope: support.constant.sql + pop: 1 + - include: else-pop + + constraint-expressions: + - match: \b(?i:constraint)\b + scope: storage.modifier.sql + push: expect-constraint-name + + maybe-check: + - match: \b(?i:check)\b + scope: keyword.other.sql + set: maybe-group + - include: else-pop + + maybe-column: + - match: \b(?i:column)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + + maybe-to: + - match: \b(?i:to)\b + scope: keyword.other.ddl.sql + pop: 1 + - include: else-pop + +###[ FUNCTION EXPRESSIONS ]#################################################### + + function-calls: + - include: built-in-aggregate-function-calls + - include: built-in-scalar-function-calls + - include: built-in-user-function-calls + - include: user-defined-function-calls + + built-in-aggregate-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b(?i:AVG|COUNT|MIN|MAX|SUM)(?=\s*\() + scope: support.function.aggregate.sql + push: function-call-arguments + + built-in-scalar-function-calls: + # List of SQL99 built-in functions from http://www.oreilly.com/catalog/sqlnut/chapter/ch04.html + - match: \b{{builtin_scalar_functions}}\b + scope: support.function.scalar.sql + push: function-call-arguments + + built-in-user-function-calls: + - match: \b{{builtin_user_functions}}\b + scope: support.function.user.sql + push: function-call-arguments + + built-in-user-function-call: + - match: \b{{builtin_user_functions}}\b + scope: support.function.user.sql + set: function-call-arguments + + user-defined-function-calls: + - match: \b{{simple_identifier}}(?=\s*\() + scope: support.function.sql + push: function-call-arguments + + function-call-arguments: + - meta_include_prototype: false + - meta_scope: meta.function-call.sql + - match: \( + scope: meta.group.sql punctuation.section.arguments.begin.sql + set: inside-function-call-arguments + - include: else-pop + + inside-function-call-arguments: + - meta_content_scope: meta.function-call.sql meta.group.sql + - match: \) + scope: meta.function-call.sql meta.group.sql punctuation.section.arguments.end.sql + pop: 1 + - match: ',' + scope: punctuation.separator.arguments.sql + - include: distinct + - include: expressions-or-column-names + +###[ GROUPS EXPRESSIONS ]###################################################### + + maybe-group: + - include: group + - include: else-pop + + group: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-group + + groups: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-group + + inside-group: + - meta_scope: meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: sql + +###[ COLUMN EXPRESSIONS ]###################################################### + + expect-column-declaration: + - include: column-declaration-list + - match: (?=\S) + set: + - maybe-column-modifier + - expect-type + - column-name-declaration + - single-identifier + + maybe-column-declaration-list: + - include: column-declaration-list + - include: else-pop + + column-declaration-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-column-declaration-list + + inside-column-declaration-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: column-modifiers + - include: expressions + - include: expect-column-declarations + + expect-column-declarations: + - match: (?=\S) + push: + - maybe-column-modifier + - expect-type + - column-name-declaration + - single-identifier + + maybe-column-modifier: + - include: column-modifiers + - include: maybe-type-modifier + + column-modifiers: + - match: \b(?i:check)\b + scope: keyword.other.sql + push: maybe-group + - match: |- + \b(?xi: + (?: (?: fulltext | primary | unique ) \s+ )? key + | on \s+ (?: delete | update ) (?: \s+ cascade )? + )\b + scope: storage.modifier.sql + - match: \b(?i:default)\b + scope: storage.modifier.sql + push: inside-default-value + - match: |- + \b(?xi: + foreign\s+key + )\b + scope: storage.modifier.sql + push: column-name-list + - match: \b(?i:unique)\b + scope: storage.modifier.sql + push: maybe-column-name-list + - include: logical-operators + - include: constants + - include: column-reference-definitions + + column-reference-definitions: + - match: \b(?i:references)\b + scope: storage.modifier.sql + push: + - maybe-column-name-list + - expect-table-name + + maybe-column-name-list: + - include: column-name-list + - include: else-pop + + column-name-list: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-column-name-list + + column-name-lists: + - match: \( + scope: punctuation.section.group.begin.sql + push: inside-column-name-list + + inside-column-name-list: + - meta_scope: meta.group.table-columns.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: expressions-or-column-names + +###[ FUNCTION EXPRESSIONS ]#################################################### + + expect-function-parameters: + - match: \( + scope: punctuation.section.group.begin.sql + set: inside-function-parameters + - include: else-pop + + inside-function-parameters: + - clear_scopes: 1 + - meta_scope: meta.function.parameters.sql meta.group.sql + - match: \) + scope: punctuation.section.group.end.sql + pop: 1 + - include: comma-separators + - match: (?=\S) + push: + - maybe-default-value + - maybe-type-modifier + - expect-type + - expect-parameter-name + - maybe-parameter-modifier + + expect-parameter-name: + - match: (?=\S) + set: + - variable-parameter + - single-identifier + + maybe-parameter-modifier: + - match: \b{{function_parameter_modifier}}\b + scope: storage.modifier.sql + pop: 1 + - include: else-pop + + expect-function-characteristics: + - meta_scope: meta.function.sql + - match: \b(?i:as|return)\b + scope: keyword.context.block.sql + pop: 1 + - match: \b(?i:language)\b + scope: storage.modifier.sql + push: expect-function-language-name + - match: \b(?i:returns)\b + scope: keyword.other.ddl.sql + push: + - maybe-type-modifier + - expect-type + - include: column-modifiers + - include: create-common-args + + expect-function-language-name: + - match: '{{simple_identifier}}' + scope: constant.other.language.sql + pop: 1 + - include: else-pop + +###[ USER MANAGEMENT EXPRESSIONS ]############################################# + + grant: + - match: \b(?i:to)\b + scope: keyword.context.sql + push: expect-user-name + - include: comma-separators + - include: user-privileges + - include: pop-on-top-level-reserved-word + + user-privileges: + - include: column-name-lists + - match: \b(?i:all(?:\s+privileges)?)\b + scope: constant.language.sql + - match: \b(?i:(?:alter|create|drop|grant|revoke)\s+{{ddl_target}})\b + scope: constant.language.sql + - match: \b(?i:select|insert|update|delete|truncate|execute)\b + scope: constant.language.sql + +###[ TABLE NAMES OR SUBQUERIES ]############################################### + + table-name-or-subquery: + - meta_include_prototype: false + - include: comments + - include: table-subquery + - include: table-name-or-function-call + + table-subquery: + - match: (?=\() + set: + - maybe-table-alias + - group + + table-name-or-function-call: + - match: (?=\S) + pop: 1 # pop `table-name-or-subquery` before evaluating branches + branch_point: table-name-or-function-call + branch: + - table-name-not-function-call + - table-valued-function-call + + table-name-not-function-call: + - meta_include_prototype: false + - match: '' + set: + - maybe-table-alias + - table-name-fail-if-function-call + - table-name + - single-identifier + + table-name-fail-if-function-call: + - meta_include_prototype: false + - match: (?=\() + fail: table-name-or-function-call + - match: (?=\S) + pop: 1 + + table-valued-function-call: + - meta_include_prototype: false + - match: '' + set: + - maybe-table-alias + - function-call-arguments + - table-valued-function-name + - single-identifier + + table-valued-function-name: + - meta_include_prototype: false + - meta_content_scope: meta.table-valued-function-name.sql + - include: immediately-pop + + maybe-table-alias: + - include: pop-on-top-level-reserved-word + - include: table-timespecs + - include: table-alias-expression + - include: expect-table-alias-name + + table-timespecs: + - match: \b(?i:for\s+system_time)\b + scope: keyword.other.dml.sql + push: table-timespec-args + + table-timespec-args: + - match: \b(?i:as\s+of|between|and|from|to)\b + scope: keyword.operator.logical.sql + push: + - table-timespec-expression + - table-timespec-type + - match: \b(?i:all)\b + scope: constant.other.sql + pop: 1 + - include: else-pop + + table-timespec-type: + - match: \b(?i:timestamp|transaction)\b + scope: storage.type.sql + set: else-pop + - include: else-pop + + table-timespec-expression: + - include: expressions + - include: immediately-pop + +###[ TYPES ]################################################################### + + expect-type: + - meta_include_prototype: false + - include: comments + - include: built-in-type + - include: expect-user-type + + built-in-types: + - match: \b(?i:enum)\b + scope: storage.type.sql + push: maybe-group + - match: |- + (?x) + \b(?: {{simple_types}} | {{types_with_optional_number}} ) + (?: ((\()(\d+)(?:\s*(,)\s*(\d+))?(\)) | \b(?!\s*\() ) ) + scope: storage.type.sql + captures: + 1: meta.parens.sql + 2: punctuation.definition.parens.begin.sql + 3: meta.number.integer.decimal.sql constant.numeric.value.sql + 4: punctuation.separator.sequence.sql + 5: meta.number.integer.decimal.sql constant.numeric.value.sql + 6: punctuation.definition.parens.end.sql + - match: \b{{type_modifiers}}\b + scope: storage.modifier.sql + + built-in-type: + - match: \b(?i:enum)\b + scope: storage.type.sql + set: maybe-group + - match: |- + (?x) + \b(?: {{simple_types}} | {{types_with_optional_number}} ) + (?: ((\()(\d+)(?:\s*(,)\s*(\d+))?(\)) | \b(?!\s*\() ) ) + scope: storage.type.sql + captures: + 1: meta.parens.sql + 2: punctuation.definition.parens.begin.sql + 3: meta.number.integer.decimal.sql constant.numeric.value.sql + 4: punctuation.separator.sequence.sql + 5: meta.number.integer.decimal.sql constant.numeric.value.sql + 6: punctuation.definition.parens.end.sql + pop: 1 + + expect-user-type: + - match: (?=\S) + set: [maybe-group, maybe-type-modifier, inside-user-type] + + inside-user-type: + # note: may contain foreign variable interpolation + - meta_include_prototype: false + - meta_scope: support.type.sql + - include: identifier-prototype + - match: '{{simple_identifier_break}}' + pop: 1 + + maybe-type-modifier: + - match: \b{{type_modifiers}}\b + scope: storage.modifier.sql + - include: assignment-operators + - include: else-pop + + maybe-default-value: + - match: \b(?i:default)\b + scope: storage.modifier.sql + set: inside-default-value + - include: else-pop + + inside-default-value: + - include: pop-on-top-level-reserved-word + - include: expressions + - include: else-pop + +###[ IDENTIFIERS ]############################################################# + + expect-table-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [table-alias-name, single-identifier] + + expect-column-alias-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [column-alias-name, single-identifier] + + table-alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.alias.table.sql + - include: immediately-pop + + column-alias-name: + - meta_include_prototype: false + - meta_content_scope: meta.alias.column.sql + - include: immediately-pop + + expect-column-names: + - match: (?=\S) + push: [maybe-operator, column-name, single-identifier] + + expect-column-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [column-name, single-identifier] + + column-name: + - meta_include_prototype: false + - meta_content_scope: meta.column-name.sql + - include: immediately-pop + + expect-column-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [column-name-declaration, single-identifier] + + column-name-declaration: + - meta_include_prototype: false + - meta_content_scope: meta.column-name.sql variable.other.member.declaration.sql + - include: immediately-pop + + expect-constraint-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - match: (?=(?i:check|foreign|primary|unique|index|key|using|with)\b) + pop: 1 + - include: comments + - match: (?=\S) + set: [constraint-name, single-identifier] + + constraint-name: + - meta_include_prototype: false + - meta_content_scope: meta.constraint-name.sql + - include: immediately-pop + + expect-database-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [database-creation-name, single-identifier] + + database-creation-name: + - meta_include_prototype: false + - meta_content_scope: entity.name.struct.database.sql + - include: immediately-pop + + expect-database-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [database-name, single-identifier] + + database-name: + - meta_include_prototype: false + - meta_content_scope: meta.database-name.sql + - include: immediately-pop + + expect-event-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [event-creation-name, single-identifier] + + event-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.event.sql + - include: immediately-pop + + expect-event-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [event-name, single-identifier] + + event-name: + - meta_include_prototype: false + - meta_scope: meta.event-name.sql + - include: immediately-pop + + expect-index-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [index-creation-name, single-identifier] + + index-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.index.sql + - include: immediately-pop + + expect-index-names: + - match: (?=\S) + push: [index-name, single-identifier] + + expect-index-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [index-name, single-identifier] + + index-name: + - meta_include_prototype: false + - meta_scope: meta.index-name.sql + - include: immediately-pop + + expect-function-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [procedure-creation-name, single-identifier] + + expect-partition-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [partition-creation-name, single-identifier] + + partition-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.partition.sql + - include: immediately-pop + + expect-partition-names: + - match: (?=\S) + push: [partition-name, single-identifier] + + expect-partition-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [partition-name, single-identifier] + + partition-name: + - meta_include_prototype: false + - meta_scope: meta.partition-name.sql + - include: immediately-pop + + procedure-creation-name: + - meta_include_prototype: false + - meta_content_scope: entity.name.function.sql + - include: immediately-pop + + expect-function-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [procedure-name, single-identifier] + + procedure-name: + - meta_include_prototype: false + - meta_content_scope: meta.procedure-name.sql + - include: immediately-pop + + expect-table-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [table-creation-name, single-identifier] + + table-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.table.sql + - include: immediately-pop + + expect-table-names: + - match: (?=\S) + push: [table-name, single-identifier] + + expect-table-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [table-name, single-identifier] + + table-name: + - meta_include_prototype: false + - meta_content_scope: meta.table-name.sql + - include: immediately-pop + + expect-type-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [type-creation-name, single-identifier] + + type-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.type.sql + - include: immediately-pop + + expect-other-creation-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [other-creation-name, single-identifier] + + expect-user-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - include: built-in-user-function-call + - match: (?=\S) + set: [user-name, single-identifier] + + user-name: + - meta_include_prototype: false + - meta_content_scope: meta.username.sql + - include: immediately-pop + + expect-user-name-declaration: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [user-name-declaration, single-identifier] + + user-name-declaration: + - meta_include_prototype: false + - meta_content_scope: entity.name.user.sql + - include: immediately-pop + + other-creation-name: + - meta_include_prototype: false + - meta_scope: entity.name.struct.other.sql + - include: immediately-pop + + expect-other-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [other-name, single-identifier] + + other-name: + - meta_include_prototype: false + - meta_scope: meta.other-name.sql + - include: immediately-pop + + expect-variable-name: + # prevent prototypes from inheriting syntaxes + - meta_include_prototype: false + - include: comments + - match: (?=\S) + set: [variable-name, single-identifier] + + variable-name: + - meta_include_prototype: false + - meta_scope: variable.other.sql + - include: immediately-pop + + variable-parameter: + - meta_include_prototype: false + - meta_content_scope: variable.parameter.sql + - include: immediately-pop + + single-identifier: + - meta_include_prototype: false + - include: pop-on-top-level-reserved-word + - match: '' + set: + - maybe-identifier-accessor + - identifier-part + + maybe-identifier-accessor: + - meta_include_prototype: false + - match: \s*(\.)\s*(\*) + captures: + 1: punctuation.accessor.dot.sql + 2: constant.other.wildcard.asterisk.sql + pop: 1 + - match: \s*(\.) + captures: + 1: punctuation.accessor.dot.sql + set: single-identifier + - include: immediately-pop + + identifier-part: + - meta_include_prototype: false + - include: backtick-quoted-identifier-part + - include: double-quoted-identifier-part + - include: single-quoted-identifier-part + - include: simple-identifier-part + + backtick-quoted-identifier-part: + - match: \` + scope: punctuation.definition.identifier.begin.sql + set: inside-backtick-quoted-identifier-part + + inside-backtick-quoted-identifier-part: + # note: may contain foreign variable interpolation + - meta_include_prototype: false + - match: \` + scope: punctuation.definition.identifier.end.sql + pop: 1 + - include: identifier-prototype + + double-quoted-identifier-part: + - match: \" + scope: punctuation.definition.identifier.begin.sql + set: inside-double-quoted-identifier-part + + inside-double-quoted-identifier-part: + # note: may contain foreign variable interpolation + - meta_include_prototype: false + - match: \" + scope: punctuation.definition.identifier.end.sql + pop: 1 + - include: identifier-prototype + + single-quoted-identifier-part: + - match: \' + scope: punctuation.definition.identifier.begin.sql + set: inside-single-quoted-identifier-part + + inside-single-quoted-identifier-part: + # note: may contain foreign variable interpolation + - meta_include_prototype: false + - match: \' + scope: punctuation.definition.identifier.end.sql + pop: 1 + - include: identifier-prototype + + simple-identifier-part: + - match: (?=\S) + set: inside-simple-identifier-part + + inside-simple-identifier-part: + # note: may contain foreign variable interpolation + - meta_include_prototype: false + - include: identifier-prototype + - match: '{{simple_identifier_break}}' + pop: 1 + + identifier-prototype: [] + + wildcard-identifiers: + - match: \* + scope: constant.other.wildcard.asterisk.sql + +###[ LITERALS ]################################################################ + + literals-and-variables: + - include: built-in-types + - include: constants + - include: numbers + - include: strings + + constants: + - match: \b(?i:null)\b + scope: constant.language.null.sql + + booleans: + - match: \b(?i:true)\b + scope: constant.language.boolean.true.sql + - match: \b(?i:false)\b + scope: constant.language.boolean.false.sql + + numbers: + - match: \b\d+(\.)\d+\b + scope: meta.number.float.decimal.sql constant.numeric.value.sql + captures: + 1: punctuation.separator.decimal.sql + - match: \b\d+\b + scope: meta.number.integer.decimal.sql constant.numeric.value.sql + + strings: + - match: \' + scope: punctuation.definition.string.begin.sql + push: inside-single-quoted-string + + inside-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.sql string.quoted.single.sql + - match: \'\' + scope: constant.character.escape.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-prototype + - include: string-escapes + + string-escapes: + - match: '{{string_escape}}' + scope: constant.character.escape.sql + + string-prototype: [] + +###[ LIKE EXPRESSIONS ]######################################################## + + like-expressions: + - match: \b{{like_keyword}}\b + scope: keyword.operator.comparison.sql + branch_point: like-expressions + branch: + - like-string-not-followed-by-escape + - like-string-followed-by-escape-slash + - like-string-followed-by-escape-caret + - like-string-followed-by-escape-hash + - like-string-followed-by-unknown-escape + + like-string-not-followed-by-escape: + - meta_include_prototype: false + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-fail + - inside-like-single-quoted-string + - include: else-pop + + like-string-followed-by-escape-slash: + - meta_include_prototype: false + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-slash + - like-escape + - inside-like-single-quoted-string-slash-escape + - include: else-pop + + like-string-followed-by-escape-caret: + - meta_include_prototype: false + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-caret + - like-escape + - inside-like-single-quoted-string-caret-escape + - include: else-pop + + like-string-followed-by-escape-hash: + - meta_include_prototype: false + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-hash + - like-escape + - inside-like-single-quoted-string-hash-escape + - include: else-pop + + like-string-followed-by-unknown-escape: + - meta_include_prototype: false + - match: \' + scope: punctuation.definition.string.begin.sql + set: + - like-escape-character-any + - like-escape + - inside-like-single-quoted-string + - include: else-pop + + inside-like-single-quoted-string-slash-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \\. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string-caret-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \^. + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string-hash-escape: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: '#.' + scope: constant.character.escape.sql + - include: inside-like-single-quoted-string + + inside-like-single-quoted-string: + - meta_include_prototype: false + - meta_scope: meta.string.like.sql string.quoted.single.sql + - match: \' + scope: punctuation.definition.string.end.sql + pop: 1 + - include: string-prototype + - match: '%' + scope: constant.other.wildcard.percent.sql + - match: '_' + scope: constant.other.wildcard.underscore.sql + + like-else-fail: + - match: (?=\S) + fail: like-expressions + + like-escape-fail: + - match: \b(?i:escape)\b + fail: like-expressions + - include: else-pop + + like-escape: + - match: \b(?i:escape)\b + scope: keyword.operator.word.sql + pop: 1 + - include: else-pop + + like-escape-character-any: + - meta_include_prototype: false + - match: (\')([^'])(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: else-pop + + like-escape-character-caret: + - meta_include_prototype: false + - match: (\')(\^)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + + like-escape-character-slash: + - meta_include_prototype: false + - match: (\')(\\)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + + like-escape-character-hash: + - meta_include_prototype: false + - match: (\')(#)(\') + scope: meta.string.escape.sql string.quoted.single.sql + captures: + 1: punctuation.definition.string.begin.sql + 2: constant.character.escape.sql + 3: punctuation.definition.string.end.sql + pop: 1 + - include: like-else-fail + +###[ OPERATORS ]############################################################### + + maybe-condition: + - meta_include_prototype: false + - include: conditions + - include: else-pop + + conditions: + - match: \b(?i:if)\b + scope: keyword.control.conditional.if.sql + - include: logical-operators + + maybe-operator: + - meta_include_prototype: false + - include: comments + - match: '<=>|[!<>]?=|<>|<|>' + scope: keyword.operator.comparison.sql + pop: 1 + - match: '[-+/*]' + scope: keyword.operator.arithmetic.sql + pop: 1 + - match: \b(?i:and|or|having|exists|between|in|not|is)\b + scope: keyword.operator.logical.sql + pop: 1 + - include: assignment-operators + - include: else-pop + + operators: + - match: '<=>|[!<>]?=|<>|<|>' + scope: keyword.operator.comparison.sql + - match: '[-+/*]' + scope: keyword.operator.arithmetic.sql + - include: logical-operators + + assignment-operators: + - match: '=' + scope: keyword.operator.assignment.sql + + logical-operators: + - match: \b(?i:and|or|having|exists|between|in|not|is)\b + scope: keyword.operator.logical.sql + + comma-separators: + - match: ',' + scope: punctuation.separator.sequence.sql + + statement-terminators: + - match: ';' + scope: punctuation.terminator.statement.sql + +###[ ILLEGALS ]################################################################ + + illegal-stray-brackets: + - match: \] + scope: invalid.illegal.stray.sql + + illegal-stray-parens: + - match: \) + scope: invalid.illegal.stray.sql + +###[ PROTOTYPES ]############################################################## + + else-pop: + - match: (?=\S) + pop: 1 + + immediately-pop: + - match: '' + pop: 1 + + pop-on-top-level-reserved-word: + - match: (?=[;)}]|\b(?:{{toplevel_reserved}}|{{additional_toplevel_reserved}})\b) + pop: 1
diff --git /dev/null b/syntax/Shell/Bash.sublime-syntax @@ -0,0 +1,3684 @@ +%YAML 1.2 +--- +# https://www.sublimetext.com/docs/syntax.html +# https://www.gnu.org/software/bash/manual/bash.html +name: Bash +scope: source.shell.bash +version: 2 + +file_extensions: + - sh + - bash + - bashrc # e.g.: /etc/bash.bashrc + +hidden_file_extensions: + +first_line_match: |- + (?xi: + ^ \#! .* {{shebang_language}} # shebang + | ^ \s* \# .*? -\*- .*? \bshell(-script)?\b .*? -\*- # editorconfig + ) + +############################################################################### + +contexts: + main: + - meta_include_prototype: false + - match: '' + push: [statements, shebang] + + statements: + - include: comments + - include: terminators + - match: (?=\S) + push: statement + + statement: + # reserved words and builtin commands which + # can't be augmented by function definitions + - include: redirections + - include: eoc-pop + - include: operators + - include: cmd-compound-test + - include: cmd-control + - include: cmd-echo + # definitions + - include: def-variable + - include: def-coproc + - include: def-function + # builtin commands + # can be augmented by function definitions + - include: boolean + - include: cmd-alias + - include: cmd-arithmetic + - include: cmd-command + - include: cmd-compound-brace + - include: cmd-compound-paren + - include: cmd-declare + - include: cmd-exec + - include: cmd-export + - include: cmd-historic + - include: cmd-mapfile + - include: cmd-read + - include: cmd-readonly + - include: cmd-sudo + - include: cmd-test + - include: cmd-trap + - include: cmd-unalias + - include: cmd-unset + - include: cmd-builtin + # user defined commands + - include: cmd-basic + - include: illegal-stray + +###[ COMMENTS ]################################################################ + + comments: + - match: \#+ + scope: punctuation.definition.comment.shell + push: comments-body + - include: merge-conflict-markers + + comments-body: + - meta_scope: comment.line.number-sign.shell + # NOTE: The reason for consuming the newline character is as follows. + # When triggering a snippet, its scope is tested to the *right* of the + # cursor. So, if you don't want your snippet to trigger in a comment, + # you have to use something like <scope>source.shell - comment</scope>. + # If the newline character is not scoped as a comment too, then that + # scope will never work, because the scope to the right of the cursor + # will never be a comment scope. That is, unless we consume the newline + # character (or we are editing something in the middle of an existing + # comment). + - match: \n + pop: 1 + + shebang: + # allow extending syntaxes like Markdown to ignore indentation restrictions + - match: '{{no_indent}}(\#!)' + captures: + 1: punctuation.definition.comment.shell + set: shebang-body + - match: ^|(?=\S) # Note: Ensure to highlight shebang if Bash is embedded. + pop: 1 + + shebang-body: + - meta_scope: comment.line.shebang.shell + - match: '{{shebang_language}}' + scope: constant.language.shebang.shell + - match: $\n? + pop: 1 + +###[ MERGE CONFLICT MARKERS ]################################################## + + merge-conflict-markers: + # see also: Diff.sublime-syntax#conflict-markers + - match: ^(<{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.begin.diff + captures: + 1: punctuation.section.block.begin.diff + 2: entity.name.section.diff + - match: ^(>{7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.end.diff + captures: + 1: punctuation.section.block.end.diff + 2: entity.name.section.diff + - match: ^(\|{7}|={7})(?:\s+(\S.*?))?$\n? + scope: meta.block.conflict.separator.diff + captures: + 1: punctuation.section.block.diff + 2: entity.name.section.diff + +###[ COPROC DEFINITIONS ]###################################################### + + def-coproc: + - match: coproc{{cmd_break}} + scope: + meta.coproc.shell + keyword.declaration.coproc.shell + set: def-coproc-identifier + + def-coproc-identifier: + - meta_content_scope: meta.coproc.shell + - include: eoc-pop + # named coproc + - match: ({{cmd_literal}})\s*(?=\(|{\s) + scope: meta.coproc.identifier.shell + captures: + 1: entity.name.function.shell + set: + - def-coproc-command-meta + - statement + # anonymous coproc + - match: (?=\S) + set: + - def-coproc-command-meta + - statement + + def-coproc-command-meta: + - meta_include_prototype: false + - meta_content_scope: meta.coproc.command.shell + - include: immediately-pop + +###[ FUNCTION DEFINITIONS ]#################################################### + + def-function: + # [Bash] 3.3 Shell Functions + - match: function{{cmd_break}} + scope: keyword.declaration.function.shell + branch_point: function + branch: + - def-function-begin + - def-anonymous-begin + pop: 1 + - match: '{{is_bare_function_definition}}' + set: + - def-function-body + - def-function-params + - def-function-name + # anonymous functions are immediately called + # hence scoping as meta.function-call meta.function + - match: (\()\s*(\)) + scope: meta.function-call.shell meta.function.anonymous.parameters.shell + captures: + 1: punctuation.section.parameters.begin.shell + 2: punctuation.section.parameters.end.shell + set: def-anonymous-body + + def-anonymous-begin: + # anonymous functions are immediately called + # hence scoping as meta.function-call meta.function + - meta_include_prototype: false + - meta_scope: meta.function-call.shell meta.function.anonymous.shell + - match: '' + set: def-anonymous-body + + def-anonymous-body: + - meta_include_prototype: false + - meta_content_scope: meta.function-call.shell meta.function.anonymous.shell + - match: \{ # Bash expects `{{cmd_break}}` but we don't care. + scope: punctuation.section.block.begin.shell + set: def-anonymous-block-body + - include: illegal-options + - include: line-continuations + - include: comments + - include: else-pop + + def-anonymous-block-body: + - meta_scope: meta.function-call.shell meta.function.anonymous.body.shell meta.block.shell + - match: \} + scope: punctuation.section.block.end.shell + set: + - cmd-args-meta + - cmd-args + - include: statements + + def-function-begin: + - meta_include_prototype: false + - meta_scope: meta.function.shell + - match: '' + set: + - def-function-body + - def-function-params + - def-function-name + + def-function-name: + - meta_include_prototype: false + - match: '{{cmd_begin}}' + set: def-function-name-chars + - match: (?=\S) + fail: function + + def-function-name-chars: + - meta_scope: entity.name.function.shell + - include: line-continuations + - include: literal-unquoted-content + - match: '{{cmd_break}}' + pop: 1 + + def-function-params: + - clear_scopes: 1 + - meta_include_prototype: false + - meta_content_scope: meta.function.identifier.shell + - match: (\()\s*(\)) + scope: meta.function.parameters.shell + captures: + 1: punctuation.section.parameters.begin.shell + 2: punctuation.section.parameters.end.shell + pop: 1 + - include: line-continuations + - include: comments + - include: else-pop + - include: eol-pop + + def-function-body: + - meta_include_prototype: false + - meta_content_scope: meta.function.shell + - include: def-function-body-braces + - include: def-function-body-parens + - include: line-continuations + - include: comments + - include: else-pop + + def-function-body-braces: + - match: \{ # Bash expects `{{cmd_break}}` but we don't care. + scope: punctuation.section.block.begin.shell + set: def-function-body-braces-body + + def-function-body-braces-body: + - meta_scope: meta.function.body.shell meta.block.shell + - match: \} + scope: punctuation.section.block.end.shell + set: def-function-end + - include: statements + + def-function-body-parens: + - match: \( + scope: punctuation.section.block.begin.shell + set: def-function-body-parens-body + + def-function-body-parens-body: + - meta_scope: meta.function.body.shell meta.block.shell + - match: \) + scope: punctuation.section.block.end.shell + set: def-function-end + - include: statements + + def-function-end: + - meta_content_scope: meta.function.shell + - include: cmd-args-end + - include: illegal-words + +###[ VARIABLE DEFINITIONS ]#################################################### + + def-variable: + - match: (?={{identifier}}(?:\[.*\])*{{varassign}}) + set: + - literal-array-value-assignment + - subscript + - variable-name-begin + + variable-name-begin: + - meta_include_prototype: false + - match: '{{builtin_variables}}' + scope: variable.language.builtin.shell + pop: 1 + - match: '' + set: variable-name-chars + + variable-name-chars: + - meta_scope: variable.other.readwrite.shell + - include: line-continuations + - include: literal-unquoted-content + - match: '{{identifier_break}}' + pop: 1 + + assignment-value-meta: + - meta_include_prototype: false + - meta_content_scope: meta.assignment.r-value.shell + - include: immediately-pop + +###[ ALIAS BUILTINS ]########################################################## + + cmd-alias: + - match: alias{{cmd_break}} + scope: keyword.declaration.alias.shell + set: + - cmd-alias-args-meta + - cmd-alias-args + + cmd-alias-args-meta: + - meta_include_prototype: false + - meta_scope: meta.declaration.alias.shell + - include: immediately-pop + + cmd-alias-args: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-alias-args-definitions + - include: cmd-args-options + - include: cmd-alias-args-definitions + + cmd-alias-args-definitions: + - include: cmd-args-end + - match: '{{word_begin}}' + push: alias-name-chars + + alias-name-chars: + - meta_scope: meta.assignment.l-value.shell meta.command.shell entity.name.function.shell + - include: line-continuations + - include: literal-unquoted-content + - match: '{{opt_break}}' + set: statements-value-assignment + +###[ ARITHMETIC BUILTINS ]##################################################### + + cmd-arithmetic: + - match: (?=\(\() + branch_point: cmd-arithmetic + branch: + - cmd-compound-arithmetic + - cmd-compound-paren + pop: 1 + - match: let{{cmd_break}} + scope: meta.function-call.identifier.shell support.function.shell + set: cmd-arithmetic-args + + cmd-compound-arithmetic: + - meta_include_prototype: false + - match: \(\( + scope: punctuation.section.compound.begin.shell + set: cmd-arithmetic-body + + cmd-arithmetic-body: + - meta_scope: meta.compound.arithmetic.shell + - meta_content_scope: meta.arithmetic.shell + - match: \)\) + scope: punctuation.section.compound.end.shell + pop: 1 + - match: (?=\)) + fail: cmd-arithmetic + - include: expression-content + - include: expression-illegals + + cmd-arithmetic-args: + - meta_content_scope: meta.function-call.arguments.shell meta.arithmetic.shell + - include: cmd-args-end + - include: expression-content + - include: expression-illegals + +###[ COMMAND BUILTINS ]######################################################## + + cmd-command: + - match: command{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: cmd-command-args + + cmd-command-args: + - meta_content_scope: meta.function-call.arguments.shell + - include: cmd-args-end + - include: cmd-args-options + - include: else-pop + +###[ DECLARE BUILTINS ]######################################################## + + cmd-declare: + - match: (declare|local|typeset){{cmd_break}} + scope: keyword.declaration.variable.shell + set: + - cmd-declare-args-meta + - cmd-declare-args + + cmd-declare-args-meta: + - meta_include_prototype: false + - meta_scope: meta.declaration.variable.shell + - include: immediately-pop + + cmd-declare-args: + # option contains -f or -F + - match: ([-+]){{opt_char}}*[Ff]{{opt_char}}* + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-function-declarations + # option contains any mix of iA or Ai + - match: ([-+])(?:{{opt_char}}*i{{opt_char}}*A|{{opt_char}}*A{{opt_char}}*i){{opt_char}}* + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-variables-arithmetic-mappings + # option contains any mix of ia or ai or i + - match: ([-+]){{opt_char}}*i{{opt_char}}* + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-declare-variables-with-arithmetic-values + # option contains A + - match: ([-+]){{opt_char}}*A{{opt_char}}* + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-declare-variables-with-literal-mappings + # anything else is a variable with any value + - include: cmd-args-end-of-options-then-variables-literal-values + + cmd-declare-variables-with-arithmetic-values: + - match: ([-+]){{opt_char}}*A{{opt_char}}* + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-variables-arithmetic-mappings + - include: cmd-args-end-of-options-then-variables-arithmetic-values + + cmd-declare-variables-with-literal-mappings: + - match: ([-+]){{opt_char}}*i{{opt_char}}* + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-variables-arithmetic-mappings + - include: cmd-args-end-of-options-then-variables-literal-mappings + +###[ ECHO BUILTINS ]########################################################### + + cmd-echo: + - match: echo{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: cmd-echo-args + + cmd-echo-args: + - meta_content_scope: meta.function-call.arguments.shell + - include: eoc-pop + - match: ([-+])[neE]+{{opt_break}} + scope: meta.parameter.option.shell variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + - match: (?=\S) + set: cmd-echo-string + + cmd-echo-string: + - meta_content_scope: meta.function-call.arguments.shell + - include: cmd-args-end + - include: string-path-patterns + +###[ EXEC BUILTINS ]########################################################### + + cmd-exec: + - match: exec{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: cmd-exec-args + + cmd-exec-args: + - meta_content_scope: meta.function-call.arguments.shell + - include: cmd-args-end + - match: ([-+])[cl]*[a]{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + push: cmd-args-option-maybe-value + - match: --{{word_break}} + scope: + meta.function-call.arguments.shell + keyword.operator.end-of-options.shell + pop: 1 + - include: cmd-args-options + - include: else-pop + +###[ EXPORT BUILTINS ]######################################################### + + cmd-export: + - match: export{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: + - cmd-args-meta + - cmd-export-args + + cmd-export-args: + - match: ([-+])n?fn?{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-function-declarations + - include: cmd-args-end-of-options-then-variables-literal-values + +###[ MAPFILE BUILTINS ]######################################################## + + cmd-mapfile: + # bash only + - match: (?:mapfile|readarray){{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: + - cmd-args-meta + - cmd-mapfile-args + + cmd-mapfile-args: + - match: ([-+])t*C{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + push: cmd-args-option-maybe-command + - match: ([-+])[t]*[cdnOsu]{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + push: cmd-args-option-maybe-value + - include: cmd-args-end-of-options-then-variables-literal-values + +###[ MAPFILE BUILTINS ]######################################################## + + cmd-read: + - match: read{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: + - cmd-args-meta + - cmd-read-args + + cmd-read-args: + - match: ([-+])[deiNnprstu]*[diNnptu]{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + push: cmd-args-option-maybe-value + - include: cmd-args-end-of-options-then-variables-literal-values + +###[ READONLY BUILTINS ]####################################################### + + cmd-readonly: + - match: readonly{{cmd_break}} + scope: keyword.declaration.variable.shell + set: + - cmd-declare-args-meta + - cmd-readonly-args + + cmd-readonly-args: + # options contain -f => function declarations (wins over -A) + - match: ([-+])[aA]*f[aA]*{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-function-declarations + # options contain -A => associative array (wins over -a) + - match: ([-+])a?Aa?{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-readonly-options-then-mappings + - include: cmd-args-end-of-options-then-variables-literal-values + + cmd-readonly-options-then-mappings: + - match: ([-+])[aA]*f[aA]*{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-function-declarations + - include: cmd-args-end-of-options-then-variables-literal-mappings + +###[ SUDO BUILTINS ]########################################################### + + cmd-sudo: + # https://www.sudo.ws/man/1.8.13/sudo.man.html + - match: sudo{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: cmd-sudo-args + + cmd-sudo-args: + - meta_content_scope: meta.function-call.arguments.shell + - include: cmd-args-end + - match: ([-+])[AbEeHiKklnPSsUuVv]*[aCcghprt]{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + push: cmd-args-option-maybe-value + - match: --{{word_break}} + scope: + meta.function-call.arguments.shell + keyword.operator.end-of-options.shell + pop: 1 + - include: cmd-args-options + - include: else-pop + +###[ COMPOUND TEST BUILTINS ]################################################## + + cmd-compound-test: + - match: \[\[(?=\s) + scope: punctuation.section.compound.begin.shell + set: cmd-compound-test-body + + cmd-compound-test-body: + - meta_include_prototype: false + - meta_scope: meta.compound.conditional.shell + - match: '{{wspace}}(\]\])' + captures: + 1: punctuation.section.compound.end.shell + pop: 1 + - include: illegal-stray + - include: cmd-compound-test-content + + cmd-compound-test-group-body: + - meta_include_prototype: false + - meta_scope: meta.group.shell + - match: \) + scope: punctuation.section.group.end.shell + pop: 1 + - include: cmd-compound-test-end-ahead + - include: cmd-compound-test-content + + cmd-compound-test-end-ahead: + - match: (?={{wspace}}\]\]) + pop: 1 + + cmd-compound-test-content: + - include: comments + # groups + - match: \( + scope: punctuation.section.group.begin.shell + push: cmd-compound-test-group-body + # logical operators + - match: '&&|\|\||!' + scope: keyword.operator.logical.shell + - match: '[&|;]' + scope: invalid.illegal.unexpected-token.shell + # test expressions like `-f file` + - match: '{{test_options}}' + scope: meta.parameter.option.shell variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + push: cmd-compound-test-pattern + # comparison expressions + - match: '{{word_begin}}' + branch_point: cmd-compound-test-comparison + branch: + - cmd-compound-test-string-comparison # note: try string comparison first as it is more likely + - cmd-compound-test-arithmetic-comparison + + cmd-compound-test-arithmetic-comparison: + - meta_include_prototype: false + - match: '' + set: + - cmd-compound-test-arithmetic-word + - cmd-compound-test-arithmetic-operator + - arithmetic-word-body + + cmd-compound-test-arithmetic-operator: + - meta_include_prototype: false + - match: '{{arithmetic_comparison_operators}}' + scope: keyword.operator.comparison.shell + pop: 1 + - include: comments + - include: else-pop + + cmd-compound-test-arithmetic-word: + - meta_include_prototype: false + - include: comments + - include: arithmetic-word + + cmd-compound-test-string-comparison: + # comparison like `string < string` or `string =~ pattern` + - meta_include_prototype: false + - match: '' + set: + - cmd-compound-test-string-operator + - cmd-compound-test-pattern + + cmd-compound-test-string-operator: + - meta_include_prototype: false + - match: '{{file_comparison_operators}}' + scope: keyword.operator.comparison.shell + set: cmd-compound-test-pattern + - match: =~ + scope: keyword.operator.comparison.shell + set: cmd-compound-test-eregexp + - match: '[=!]?=' + scope: keyword.operator.comparison.shell + set: cmd-compound-test-pattern + - match: '[<>]=?' + scope: keyword.operator.comparison.shell + set: cmd-compound-test-pattern + - match: (?={{arithmetic_comparison_operators}}) + fail: cmd-compound-test-comparison + - include: comments + - include: cmd-compound-test-end-ahead + - include: else-pop + + cmd-compound-test-eregexp: + - meta_include_prototype: false + - include: cmd-compound-test-end-ahead + - match: '{{word_begin}}' + set: + - cmd-compound-test-eregexp-body + - eregexp-unexpected-quantifier + - maybe-tilde-interpolation + + cmd-compound-test-eregexp-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.regexp.shell string.unquoted.shell + - include: eregexp-main-content + - include: cmd-compound-test-pattern-end + + cmd-compound-test-pattern: + - meta_include_prototype: false + - include: cmd-compound-test-end-ahead + - include: boolean + - include: devnull + - match: '{{word_begin}}' + set: + - cmd-compound-test-pattern-body + - maybe-tilde-interpolation + + cmd-compound-test-pattern-body: + - meta_include_prototype: false + - meta_content_scope: meta.string.glob.shell string.unquoted.shell + - include: pattern-main-content + - include: cmd-compound-test-pattern-end + + cmd-compound-test-pattern-end: + - match: '[<>]+' # note: would otherwise match as comparison operators + scope: invalid.illegal.unexpected-token.shell + pop: 1 + - include: word-end + +###[ TEST BUILTINS ]########################################################### + + cmd-test: + - match: \[(?=\s) + scope: punctuation.section.compound.begin.shell + set: builtin-test-body + - match: test{{cmd_break}} + scope: meta.function-call.identifier.shell support.function.shell + set: cmd-test-args + + builtin-test-body: + - meta_include_prototype: false + - meta_scope: meta.compound.conditional.shell + - match: \] + scope: punctuation.section.compound.end.shell + pop: 1 + - include: cmd-test-args + + cmd-test-args: + - meta_include_prototype: false + - meta_content_scope: meta.function-call.arguments.shell + - include: eoc-pop + # logical operators + - match: '!' + scope: keyword.operator.logical.shell + - match: -[ao]{{opt_break}} + scope: keyword.operator.logical.shell + # test expressions like `-f file` + - match: '{{test_options}}' + scope: meta.parameter.option.shell variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + push: cmd-test-pattern + # comparison expressions + - match: '{{word_begin}}' + branch_point: cmd-test-comparison + branch: + - cmd-test-string-comparison # note: try string comparison first as it is more likely + - cmd-test-arithmetic-comparison # note: built-in tests only support basic integer expressions + + cmd-test-arithmetic-comparison: + - meta_include_prototype: false + - match: '' + set: + - cmd-test-arithmetic-word + - cmd-test-arithmetic-operator + - arithmetic-word-body + + cmd-test-arithmetic-operator: + - meta_include_prototype: false + - match: '{{arithmetic_comparison_operators}}' + scope: keyword.operator.comparison.shell + pop: 1 + - include: eoc-pop + + cmd-test-arithmetic-word: + - meta_include_prototype: false + - include: eoc-pop + - include: arithmetic-word + + cmd-test-string-comparison: + # comparison like `string < string` or `string =~ pattern` + - meta_include_prototype: false + - match: '' + set: + - cmd-test-string-operator + - cmd-test-pattern + + cmd-test-string-operator: + - meta_include_prototype: false + - match: '{{file_comparison_operators}}' + scope: keyword.operator.comparison.shell + set: cmd-test-pattern + - match: =~ + scope: invalid.illegal.operator.shell + set: cmd-test-pattern + - match: '[=!]?=' + scope: keyword.operator.comparison.shell + set: cmd-test-pattern + - match: '[<>]=' + scope: invalid.illegal.operator.shell + set: cmd-test-pattern + - match: '<(?!<)|>(?!>)' + scope: keyword.operator.comparison.shell + set: cmd-test-pattern + - match: (?={{arithmetic_comparison_operators}}) + fail: cmd-test-comparison + - include: eoc-pop + - include: else-pop + + cmd-test-pattern: + - meta_include_prototype: false + - match: (?=\]) + pop: 1 + - include: eoc-pop + - include: redirection + - include: boolean + - include: string-path-pattern + +###[ TRAP BUILTINS ]########################################################### + + cmd-trap: + - match: trap{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: + - cmd-args-meta + - cmd-trap-sigspec + - cmd-trap-command + + cmd-trap-command: + - include: cmd-args-end + - include: cmd-args-options + - include: statements-word + + cmd-trap-sigspec: + - include: cmd-args-end + - match: '{{signal_names}}' + scope: constant.language.signal.shell + - include: cmd-args-values + +###[ UNALIAS BUILTINS ]######################################################## + + cmd-unalias: + - match: unalias{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: + - cmd-args-meta + - cmd-args-end-of-options-then-function-references + +###[ UNSET BUILTINS ]########################################################## + + cmd-unset: + - match: unset{{cmd_break}} + scope: + meta.function-call.identifier.shell + support.function.shell + set: + - cmd-args-meta + - cmd-unset-args + + cmd-unset-args: + - match: ([-+])[nv]?f[nv]?{{opt_break}} + scope: + meta.parameter.option.shell + variable.parameter.option.shell + captures: + 1: punctuation.definition.parameter.shell + set: cmd-args-end-of-options-then-function-references + - include: cmd-args-end-of-options-then-variables-literal-values + +###[ COMMANDS ]################################################################ + + cmd-compound-brace: + - match: \{{{cmd_break}} + scope: punctuation.section.compound.begin.shell + set: cmd-compound-brace-body + + cmd-compound-brace-body: + - meta_scope: meta.compound.command.shell + - match: \} + scope: punctuation.section.compound.end.shell + pop: 1 + - include: statements + + cmd-compound-paren: + - match: \( + scope: punctuation.section.compound.begin.shell + set: cmd-compound-paren-body + + cmd-compound-paren-body: + - meta_scope: meta.compound.command.shell + - match: \) + scope: punctuation.section.compound.end.shell + pop: 1 + - include: statements + + cmd-historic: + - match: (\!)(-?\d+|!) + scope: variable.language.history.shell + captures: + 1: punctuation.definition.history.shell + - match: \! + scope: punctuation.definition.history.shell + + cmd-builtin: + # cmd modifier commands are directly followed by simple commands + - match: '{{modifier_cmds}}' + scope: meta.function-call.identifier.shell meta.command.shell support.function.shell + # shell built-in commands with arbitrary arguments + - match: '{{builtin_cmds}}' + scope: meta.function-call.identifier.shell meta.command.shell support.function.shell + push: + - cmd-args-meta + - cmd-args + + cmd-basic: + - match: \$?\" + scope: punctuation.definition.quoted.begin.shell + set: + - cmd-name-body + - path-pattern-double-quoted-body + - path-pattern-quoted-begin + - match: \$\' + scope: punctuation.definition.quoted.begin.shell + set: + - cmd-name-body + - path-pattern-ansi-c-body + - path-pattern-quoted-begin + - match: \' + scope: punctuation.definition.quoted.begin.shell + set: + - cmd-name-body + - path-pattern-single-quoted-body + - path-pattern-quoted-begin + - match: '{{cmd_begin}}' + set: + - cmd-name-body + - path-pattern-begin + + cmd-name-body: + - meta_scope: meta.function-call.identifier.shell meta.command.shell variable.function.shell + - include: line-continuations + - include: path-pattern-content + - match: '{{cmd_break}}' + set: + - cmd-args-meta + - cmd-args + + cmd-args-meta: + - meta_include_prototype: false + - meta_content_scope: meta.function-call.arguments.shell + - include: immediately-pop + + cmd-args-end: + - include: redirections + - include: eoc-pop + + cmd-args: + - include: cmd-args-end-of-options-then-ambiguous + + cmd-args-end-of-options-then-ambiguous: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-args-ambiguous + - include: cmd-args-options + - include: cmd-args-ambiguous + + cmd-args-ambiguous: + - include: cmd-args-end + - include: cmd-args-values + + cmd-args-end-of-options-then-function-declarations: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-args-function-declarations + - include: cmd-args-options + - include: cmd-args-function-declarations + + cmd-args-function-declarations: + - include: cmd-args-end + - match: '{{word_begin}}' + push: function-declaration-name-chars + + function-declaration-name-chars: + - meta_scope: meta.command.shell entity.name.function.shell + - include: literal-unquoted-content + - include: word-end + + cmd-args-end-of-options-then-function-references: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-args-function-references + - include: cmd-args-options + - include: cmd-args-function-references + + cmd-args-function-references: + - include: cmd-args-end + - match: '{{word_begin}}' + push: function-reference-name-chars + + function-reference-name-chars: + - meta_scope: meta.command.shell variable.function.shell + - include: literal-unquoted-content + - include: word-end + + cmd-args-end-of-options-then-variables-arithmetic-mappings: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-args-variables-arithmetic-mappings + - include: cmd-args-options + - include: cmd-args-variables-arithmetic-mappings + + cmd-args-variables-arithmetic-mappings: + - include: cmd-args-end + - match: '{{variable_begin}}' + push: + - arithmetic-mapping-value-assignment + - subscript + - variable-name-begin + - include: illegal-words + + cmd-args-end-of-options-then-variables-arithmetic-values: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-args-variables-arithmetic-values + - include: cmd-args-options + - include: cmd-args-variables-arithmetic-values + + cmd-args-variables-arithmetic-values: + - include: cmd-args-end + - match: '{{variable_begin}}' + push: + - arithmetic-array-value-assignment + - subscript + - variable-name-begin + - include: illegal-words + + cmd-args-end-of-options-then-variables-literal-mappings: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-args-variables-literal-mappings + - include: cmd-args-options + - include: cmd-args-variables-literal-mappings + + cmd-args-variables-literal-mappings: + - include: cmd-args-end + - match: '{{variable_begin}}' + push: + - literal-mapping-value-assignment + - subscript + - variable-name-begin + - include: illegal-words + + cmd-args-end-of-options-then-variables-literal-values: + - match: --{{word_break}} + scope: keyword.operator.end-of-options.shell + set: cmd-args-variables-literal-values + - include: cmd-args-options + - include: cmd-args-variables-literal-values + + cmd-args-variables-literal-values: + - include: cmd-args-end + - match: '{{variable_begin}}' + push: + - literal-array-value-assignment + - subscript + - variable-name-begin + - include: illegal-words + + cmd-args-options: + - match: '{{opt_punctuation}}' + scope: punctuation.definition.parameter.shell + push: cmd-args-option-name + + cmd-args-option-name: + - meta_scope: meta.parameter.option.shell variable.parameter.option.shell + - include: line-continuations + - include: literal-unquoted-content + - match: '{{opt_break}}' + set: cmd-args-option-maybe-assignment + + cmd-args-option-maybe-assignment: + - meta_include_prototype: false + - match: = + scope: keyword.operator.assignment.shell + set: cmd-args-option-assignment-value + - include: line-continuations + - include: immediately-pop + + cmd-args-option-assignment-value: + - meta_include_prototype: false + - include: line-continuations + - include: redirection + - include: boolean + - include: number + - include: string-path-pattern + - include: immediately-pop + + cmd-args-option-maybe-command: + - meta_include_prototype: false + - include: eoc-pop + - include: statements-word + + cmd-args-option-maybe-value: + - meta_include_prototype: false + - include: redirection + - include: eoc-pop + - include: boolean + - include: number + - include: string-path-pattern + + cmd-args-values: + - include: booleans + - include: numbers + - include: string-path-patterns + +###[ CONTROL STATEMENTS ]###################################################### + + cmd-control: + # conditional + - match: if{{cmd_break}} + scope: keyword.control.conditional.if.shell + - match: then{{cmd_break}} + scope: keyword.control.conditional.then.shell + - match: elif{{cmd_break}} + scope: keyword.control.conditional.elseif.shell + - match: fi{{cmd_break}} + scope: keyword.control.conditional.endif.shell + - match: else{{cmd_break}} + scope: keyword.control.conditional.else.shell + - match: case{{cmd_break}} + scope: meta.statement.conditional.case.shell keyword.control.conditional.case.shell + set: case-word + - match: esac{{cmd_break}} + scope: keyword.control.conditional.endcase.shell + # loops + - match: do{{cmd_break}} + scope: keyword.control.loop.do.shell + - match: done{{cmd_break}} + scope: keyword.control.loop.end.shell + - match: for{{cmd_break}} + scope: keyword.control.loop.for.shell + set: + - for-meta + - for-args + - match: select{{cmd_break}} + scope: keyword.control.loop.select.shell + set: + - select-meta + - loop-iterator-wordlist + - loop-iterator-var + - match: until{{cmd_break}} + scope: keyword.control.loop.until.shell + - match: while{{cmd_break}} + scope: keyword.control.loop.while.shell + # flow + - match: break{{cmd_break}} + scope: keyword.control.flow.break.shell + set: flow-args + - match: continue{{cmd_break}} + scope: keyword.control.flow.continue.shell + set: flow-args + - match: exit{{cmd_break}} + scope: keyword.control.flow.exit.shell + set: flow-args + - match: return{{cmd_break}} + scope: keyword.control.flow.return.shell + set: flow-args + - match: time{{cmd_break}} + scope: keyword.control.flow.time.shell + set: time-args + + case-word: + - meta_include_prototype: false + - meta_content_scope: meta.statement.conditional.case.word.shell + - match: in{{cmd_break}} + scope: meta.statement.conditional.case.shell keyword.control.conditional.in.shell + set: case-body + - include: case-end + - include: comments + - include: redirections + - include: cmd-args-values + + case-body: + - meta_content_scope: meta.statement.conditional.case.body.shell + - include: case-end + - include: comments + - include: case-clauses + + case-clauses: + - match: \( + scope: punctuation.section.patterns.begin.shell + push: case-clause-paren-pattern-body + - match: (?=\S) + push: case-clause-plain-pattern-body + + case-clause-paren-pattern-body: + # patterns enclosed in parenthesis may continue on next line without \ + - meta_include_prototype: false + - meta_scope: meta.clause.patterns.shell + - include: comments + - include: case-clause-pattern-body + + case-clause-plain-pattern-body: + # patterns not enclosed in parenthesis are terminated at eol + - meta_include_prototype: false + - meta_scope: meta.clause.patterns.shell + - match: $|(?=\s+[#\n]) + set: case-clause-after-pattern + - include: case-clause-pattern-body + + case-clause-pattern-body: + - match: \) + scope: punctuation.section.patterns.end.shell + set: case-clause-after-pattern + - match: \| + scope: keyword.operator.logical.shell + - include: case-end-ahead + - include: line-continuations + - include: group-path-patterns + + case-clause-after-pattern: + # required to handle scope specific indentation rules + - meta_include_prototype: false + - meta_content_scope: meta.clause.shell + - include: comments + - match: ^|(?=\S) + set: case-clause-body + + case-clause-body: + - meta_content_scope: meta.clause.body.shell + - include: case-clause-end + - include: case-end-ahead + - include: statements + + case-clause-end: + - match: '{{case_clause_end}}' + scope: meta.clause.shell punctuation.terminator.clause.shell + pop: 1 + + case-end: + - match: esac{{cmd_break}} + scope: keyword.control.conditional.endcase.shell + set: case-end-meta + + case-end-meta: + # This context is required for case...esac specific + # indentation rules to be correctly applied. + - meta_include_prototype: false + - meta_scope: meta.statement.conditional.case.end.shell + - include: immediately-pop + + case-end-ahead: + - match: (?=esac{{cmd_break}}) + pop: 1 + + flow-args: + - include: redirection + - include: eoc-pop + - include: number + - include: string-path-pattern + + for-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.loop.for.shell + - include: immediately-pop + + for-args: + - meta_include_prototype: false + - include: eoc-pop + - match: \(\( + scope: punctuation.section.compound.begin.shell + set: cmd-arithmetic-body + - match: (?=\S) + set: + - loop-iterator-wordlist + - variable-name-begin + + select-meta: + - meta_include_prototype: false + - meta_scope: meta.statement.loop.select.shell + - include: immediately-pop + + loop-iterator-var: + - include: eoc-pop + - match: (?=\S) + set: variable-name-begin + + loop-iterator-wordlist: + - match: in{{cmd_break}} + scope: keyword.control.loop.in.shell + set: loop-iterator-wordlist-body + - include: cmd-args-end + - include: else-pop + + loop-iterator-wordlist-body: + - meta_include_prototype: false + - meta_content_scope: meta.sequence.list.shell + - match: \( + scope: invalid.illegal.unexpected-token.shell + - include: cmd-args-end + - include: string-path-patterns + + time-args: + - include: cmd-args-end + - include: cmd-args-options + - include: else-pop + +###[ ARITHMETIC VALUE ASSIGNMENTS ]############################################ + + arithmetic-array-value-assignment: + # maybe variable subscripts followed by value assignment + - meta_content_scope: meta.assignment.l-value.shell + - match: '{{varassign}}' + scope: meta.assignment.shell keyword.operator.assignment.shell + set: + - assignment-value-meta + - arithmetic-array-value + - include: line-continuations + - include: immediately-pop + + arithmetic-array-value: + # maybe indexed array of or single arithmetic expression value + - meta_include_prototype: false + - match: \( + scope: punctuation.section.sequence.begin.shell + set: arithmetic-explicit-mapping-body + - include: line-continuations + - include: arithmetic-word + - include: immediately-pop + + arithmetic-mapping-value-assignment: + # maybe variable subscripts followed by value assignment + - meta_content_scope: meta.assignment.l-value.shell + - match: '{{varassign}}' + scope: meta.assignment.shell keyword.operator.assignment.shell + set: + - assignment-value-meta + - arithmetic-mapping-value + - include: line-continuations + - include: immediately-pop + + arithmetic-mapping-value: + # maybe associative of or single arithmetic expression value + - meta_include_prototype: false + - match: \( + scope: punctuation.section.sequence.begin.shell + set: arithmetic-mapping-begin + - include: line-continuations + - include: arithmetic-word + - include: immediately-pop + + arithmetic-mapping-begin: + - meta_scope: meta.sequence.list.shell + - include: list-end + - match: (?=\[) + set: arithmetic-explicit-mapping-body + - match: (?=\S) + set: arithmetic-implicit-mapping-body + + arithmetic-explicit-mapping-body: + - meta_scope: meta.sequence.list.shell + - include: list-end + - include: explicit-mapping-keys + - match: (?=[[:alnum:]_'"]) + push: arithmetic-word + - include: illegal-words + + arithmetic-implicit-mapping-body: + - meta_scope: meta.sequence.list.shell + - include: list-end + - match: '{{word_begin}}' + push: arithmetic-implicit-mapping-key-body + + arithmetic-implicit-mapping-key-body: + - meta_scope: meta.item-access.shell entity.name.key.shell + - include: line-continuations + - include: literal-unquoted-content + - match: '{{word_break}}' + set: arithmetic-implicit-mapping-value + + arithmetic-implicit-mapping-value: + - include: line-continuations + - include: comments + - include: arithmetic-word + +###[ LITERAL VALUE ASSIGNMENTS ]############################################### + + literal-array-value-assignment: + # maybe variable subscripts followed by value assignment + - meta_content_scope: meta.assignment.l-value.shell + - match: '{{varassign}}' + scope: meta.assignment.shell keyword.operator.assignment.shell + set: + - assignment-value-meta + - literal-array-value + - include: line-continuations + - include: immediately-pop + + literal-array-value: + # maybe indexed array of or single literal/string value + - meta_include_prototype: false + - match: \( + scope: punctuation.section.sequence.begin.shell + set: literal-explicit-mapping-body + - include: line-continuations + - include: redirection + - include: boolean + - include: string-path-pattern + - include: immediately-pop + + literal-mapping-value-assignment: + # maybe variable subscripts followed by value assignment + - meta_content_scope: meta.assignment.l-value.shell + - match: '{{varassign}}' + scope: meta.assignment.shell keyword.operator.assignment.shell + set: + - assignment-value-meta + - literal-mapping-value + - include: line-continuations + - include: immediately-pop + + literal-mapping-value: + # maybe associative array of or single literal/string value + - meta_include_prototype: false + - match: \( + scope: punctuation.section.sequence.begin.shell + set: literal-mapping-begin + - include: line-continuations + - include: redirection + - include: boolean + - include: string-path-pattern + - include: immediately-pop + + literal-mapping-begin: + - meta_scope: meta.sequence.list.shell + - include: list-end + - match: (?=\[) + set: literal-explicit-mapping-body + - match: (?=\S) + set: literal-implicit-mapping-body + + literal-explicit-mapping-body: + - meta_scope: meta.sequence.list.shell + - include: list-end + - include: explicit-mapping-keys + - include: booleans + - include: group-path-patterns + + literal-implicit-mapping-body: + - meta_scope: meta.sequence.list.shell + - include: list-end + - match: '{{word_begin}}' + push: literal-implicit-mapping-key-body + + literal-implicit-mapping-key-body: + - meta_scope: meta.item-access.shell entity.name.key.shell + - include: line-continuations + - include: literal-unquoted-content + - match: '{{word_break}}' + set: literal-implicit-mapping-value + + literal-implicit-mapping-value: + - include: line-continuations + - include: comments + - include: boolean + - include: group-path-pattern + +###[ STATEMENT VALUE ASSIGNMENTS ]############################################# + + statements-value-assignment: + - meta_content_scope: meta.assignment.l-value.shell + - match: '{{varassign}}' + scope: meta.assignment.shell keyword.operator.assignment.shell + set: + - assignment-value-meta + - statements-value + - include: line-continuations + - include: immediately-pop + + statements-value: + - meta_include_prototype: false + - include: statements-word + - include: immediately-pop + + statements-word: + - match: \" + scope: meta.quoted.shell punctuation.definition.quoted.begin.shell + embed: statements + embed_scope: meta.quoted.shell + escape: '{{no_escape_behind}}\"' + escape_captures: + 0: meta.quoted.shell punctuation.definition.quoted.end.shell + pop: 1 + - match: \' + scope: meta.quoted.shell punctuation.definition.quoted.begin.shell + embed: statements + embed_scope: meta.quoted.shell + escape: '{{no_escape_behind}}''' + escape_captures: + 0: meta.quoted.shell punctuation.definition.quoted.end.shell + pop: 1 + - match: '{{cmd_begin}}' + set: + - unquoted-statements-word-body + - path-pattern-begin + + unquoted-statements-word-body: + - meta_scope: meta.command.shell variable.function.shell + - include: line-continuations + - include: path-pattern-content + - match: '{{cmd_break}}' + pop: 1 + +###[ ARRAY VALUE PROTOTYPES ]################################################## + + explicit-mapping-keys: + - match: \[ + scope: punctuation.section.item-access.begin.shell + push: explicit-mapping-key-body + + explicit-mapping-key-body: + - meta_scope: meta.item-access.shell + - meta_content_scope: entity.name.key.shell + - match: \] + scope: punctuation.section.item-access.end.shell + set: explicit-mapping-value-assignment + - include: literal-unquoted-content + + explicit-mapping-value-assignment: + - match: '{{varassign}}' + scope: keyword.operator.assignment.shell + pop: 1 + - include: line-continuations + - include: immediately-pop + + list-end: + - match: \) + scope: punctuation.section.sequence.end.shell + pop: 1 + - include: line-continuations + - include: comments + +###[ SUBSCRIPTS ]############################################################## + + subscript: + # 6.7 Arrays + # https://www.gnu.org/software/bash/manual/bash.html#Arrays + - match: (\[)([*@])(\]) + scope: meta.item-access.shell + captures: + 1: punctuation.section.item-access.begin.shell + 2: variable.language.array.shell + 3: punctuation.section.item-access.end.shell + pop: 1 + - match: \[ + scope: punctuation.section.item-access.begin.shell + set: subscript-body + - include: line-continuations + - include: immediately-pop + + subscript-body: + - meta_include_prototype: false + - meta_scope: meta.item-access.shell + - match: \] + scope: punctuation.section.item-access.end.shell + pop: 1 + - include: eoc-pop + - include: comma-separators + - include: subscript-content + + subscript-content: + # attempt to scope subscript content arithmetic expression + # if anything unrecognized was found, fallback to plain string + - match: '' + branch_point: subscript-content + branch: + - subscript-expression-content + - subscript-plain-content + + subscript-else-fail: + - include: line-continuations + - match: (?=\S) + fail: subscript-content + + subscript-expression-content: + - meta_content_scope: meta.arithmetic.shell + - match: (?=[],]) + pop: 1 + # arithmetic expression content without word boundary checks + - match: \" + scope: punctuation.definition.quoted.begin.shell + push: subscript-expression-double-quoted-body + - match: \' + scope: punctuation.definition.quoted.begin.shell + push: subscript-expression-single-quoted-body + - include: subscript-expression-groups + - include: expression-common + - include: subscript-else-fail + + subscript-expression-double-quoted-body: + - match: \" + scope: punctuation.definition.quoted.end.shell + pop: 1 + - include: subscript-expression-double-quoted-groups + - include: expression-common + - include: subscript-else-fail + + subscript-expression-double-quoted-groups: + - match: \( + scope: punctuation.section.group.begin.shell + push: subscript-expression-double-quoted-group-body + + subscript-expression-double-quoted-group-body: + - meta_scope: meta.group.shell + - match: \) + scope: punctuation.section.group.end.shell + pop: 1 + - match: (?=") + pop: 1 + - include: subscript-expression-double-quoted-groups + - include: expression-common + - include: subscript-else-fail + + subscript-expression-single-quoted-body: + - match: \' + scope: punctuation.definition.quoted.end.shell + pop: 1 + - include: subscript-expression-single-quoted-groups + - include: expression-common + - include: subscript-else-fail + + subscript-expression-single-quoted-groups: + - match: \( + scope: punctuation.section.group.begin.shell + push: subscript-expression-single-quoted-group-body + + subscript-expression-single-quoted-group-body: + - meta_scope: meta.group.shell + - match: \) + scope: punctuation.section.group.end.shell + pop: 1 + - match: (?=') + pop: 1 + - include: subscript-expression-single-quoted-groups + - include: expression-common + - include: subscript-else-fail + + subscript-expression-groups: + - match: \( + scope: punctuation.section.group.begin.shell + push: subscript-expression-group-body + + subscript-expression-group-body: + - meta_scope: meta.group.shell + - match: \) + scope: punctuation.section.group.end.shell + pop: 1 + - include: subscript-expression-groups + - include: expression-common + - include: subscript-else-fail + + subscript-plain-content: + - meta_include_prototype: false + - meta_content_scope: meta.string.shell string.unquoted.shell + - match: (?=[],]) + pop: 1 + - include: subscript-plain-common + + subscript-plain-common: + - include: string-quotes + - include: string-prototype + - include: any-escapes + - include: string-interpolations + +###[ ARITHMETIC EXPRESSIONS ]################################################## + + arithmetic-word: + - meta_include_prototype: false + - match: '{{word_begin}}' + set: arithmetic-word-body + + arithmetic-word-body: + - meta_scope: meta.arithmetic.shell + - include: expression-content + - include: word-end + + expression-content: + # arithmetic expression content without word boundary checks + - match: \" + scope: punctuation.definition.quoted.begin.shell + push: + - subscript + - expression-double-quoted-body + - subscript + - match: \' + scope: punctuation.definition.quoted.begin.shell + push: + - subscript + - expression-single-quoted-body + - subscript + - include: expression-groups + - include: expression-common + + expression-double-quoted-body: + - meta_scope: meta.quoted.shell + - match: \" + scope: punctuation.definition.quoted.end.shell + pop: 1 + - include: expression-double-quoted-groups + - include: expression-common + - include: expression-illegals + + expression-double-quoted-groups: + - match: \( + scope: punctuation.section.group.begin.shell + push: expression-double-quoted-group-body + + expression-double-quoted-group-body: + - meta_scope: meta.group.shell + - match: \) + scope: punctuation.section.group.end.shell + pop: 1 + - match: (?=") + pop: 1 + - include: expression-double-quoted-groups + - include: expression-common + - include: expression-illegals + + expression-single-quoted-body: + - meta_scope: meta.quoted.shell + - match: \' + scope: punctuation.definition.quoted.end.shell + pop: 1 + - include: expression-single-quoted-groups + - include: expression-common + - include: expression-illegals + + expression-single-quoted-groups: + - match: \( + scope: punctuation.section.group.begin.shell + push: expression-single-quoted-group-body + + expression-single-quoted-group-body: + - meta_scope: meta.group.shell + - match: \) + scope: punctuation.section.group.end.shell + pop: 1 + - match: (?=') + pop: 1 + - include: expression-single-quoted-groups + - include: expression-common + - include: expression-illegals + + expression-groups: + - match: \( + scope: punctuation.section.group.begin.shell + push: expression-group-body + + expression-group-body: + - meta_scope: meta.group.shell + - match: \) + scope: punctuation.section.group.end.shell + pop: 1 + - include: expression-groups + - include: expression-common + - include: expression-illegals + + expression-common: + # multi char operators + - match: '[-+*/%&|^]=|<<=|>>=' + scope: keyword.operator.assignment.augmented.shell + - match: '<<|>>' + scope: keyword.operator.bitwise.shell + - match: '<=?|>=?|[=!]=' + scope: keyword.operator.comparison.shell + - match: '&&|\|\||!' + scope: keyword.operator.logical.shell + # single char operators + - match: '[-+*/%]' + scope: keyword.operator.arithmetic.shell + - match: '=' + scope: keyword.operator.assignment.shell + - match: '[&|^~]' + scope: keyword.operator.bitwise.shell + - match: \:|\? + scope: keyword.operator.ternary.shell + - include: comma-separators + - include: terminators + # Shell variables are allowed as operands; parameter expansion is performed + # before the expression is evaluated. Within an expression, shell variables + # may also be referenced by name without using the parameter expansion + # syntax. + - include: booleans + - include: expression-numbers + - include: expression-variables + + expression-illegals: + - match: '{{word_char}}' + scope: invalid.illegal.unexpected-token.shell + + expression-numbers: + # lazily consume everything which looks like a number. + # supports interpolation in decimal integers. + - include: base-numbers + - match: (?=\d) + push: dec-number-body + + expression-variables: + # variables within arithmetic expressions must not contain brace expansions + # or quotes, as expressions itself are partitioned by quotation marks + - match: (?=[{{identifier_first_char}}\\`%$]) + push: + - subscript + - expression-variable-chars + + expression-variable-chars: + - meta_scope: variable.other.readwrite.shell + - include: line-continuations + - include: string-interpolations + - include: any-escapes + - match: '{{identifier_break}}' + pop: 1 + +###[ OPERATORS ]############################################################### + + line-continuations: + - match: (\\)\n + captures: + 1: punctuation.separator.continuation.line.shell + push: line-continuation-body + - match: \\(\s+)\n + captures: + 1: invalid.illegal.unexpected-whitespace.shell + + line-continuation-body: + - meta_include_prototype: false + - match: ^ + pop: 1 + + operators: + - match: \|\||\&\&|\!(?!\S) + scope: keyword.operator.logical.shell + - match: \||\& + scope: keyword.operator.assignment.pipe.shell + + comma-separators: + - match: ',' + scope: punctuation.separator.sequence.shell + + terminators: + - match: ; + scope: punctuation.terminator.statement.shell + +###[ REDIRECTIONS AND HEREDOCS ]############################################### + + redirections: + - match: (?=\d*&?[<>]) + push: redirection + + redirection: + - include: redirection-here-string + - include: redirection-here-document + - include: redirection-process + - include: redirection-inout + - include: redirection-input + - include: redirection-output + + redirection-here-document: + - match: (\d*)(<<-)\s*(?=["'\\]?({{heredoc}})) + captures: + 1: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + 2: keyword.operator.assignment.redirection.shell + embed: heredoc-begin + escape: '{{tab_indent}}(\3)$\n?' + escape_captures: + 0: meta.redirection.shell meta.tag.heredoc.end.shell + 1: entity.name.tag.heredoc.shell + pop: 1 + - match: (\d*)(<<)\s*(?=["'\\]?({{heredoc}})) + captures: + 1: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + 2: keyword.operator.assignment.redirection.shell + embed: heredoc-begin + escape: '{{no_indent}}(\3)$\n?' + escape_captures: + 0: meta.redirection.shell meta.tag.heredoc.end.shell + 1: entity.name.tag.heredoc.shell + pop: 1 + + heredoc-begin: + - meta_scope: meta.redirection.shell + # These are the variants that allow tabs before the end token + - match: (')({{heredoc}})(') + scope: meta.tag.heredoc.begin.shell + captures: + 1: punctuation.definition.tag.begin.shell + 2: entity.name.tag.heredoc.shell + 3: punctuation.definition.tag.end.shell + push: + - heredoc-preamble-no-expansion + - cmd-args + - match: (")({{heredoc}})(") + scope: meta.tag.heredoc.begin.shell + captures: + 1: punctuation.definition.tag.begin.shell + 2: entity.name.tag.heredoc.shell + 3: punctuation.definition.tag.end.shell + push: + - heredoc-preamble-no-expansion + - cmd-args + - match: (\\)({{heredoc}}) + scope: meta.tag.heredoc.begin.shell + captures: + 1: punctuation.definition.tag.shell + 2: entity.name.tag.heredoc.shell + push: + - heredoc-preamble-no-expansion + - cmd-args + - match: '{{heredoc}}' + scope: meta.tag.heredoc.begin.shell entity.name.tag.heredoc.shell + push: + - heredoc-preamble + - cmd-args + + heredoc-preamble: + - match: ^ + set: heredoc-body + - include: statements + + heredoc-body: + - meta_include_prototype: false + - meta_scope: meta.string.heredoc.shell string.unquoted.heredoc.shell + # [Bash] 3.6.6: all lines of the here-document are subjected to parameter + # expansion, command substitution, and arithmetic expansion, the character + # sequence \newline is ignored, and β\β must be used to quote the + # characters β\β, β$β, and β`β. + - include: string-prototype + - include: string-escapes + - include: brace-interpolations + - include: string-interpolations + + heredoc-preamble-no-expansion: + - match: ^ + set: heredoc-body-no-expansion + - include: statements + + heredoc-body-no-expansion: + - meta_include_prototype: false + - meta_scope: meta.string.heredoc.shell string.unquoted.heredoc.shell + + redirection-here-string: + - match: (\d*)(<<<)\s*{{word_begin}} + captures: + 1: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + 2: keyword.operator.assignment.herestring.shell + set: here-string-body + + here-string-body: + - meta_include_prototype: false + - meta_scope: meta.redirection.shell + - meta_content_scope: meta.string.herestring.shell string.unquoted.shell + - include: string-unquoted-content + - include: word-end + + redirection-input: + - match: (\d*)(<&?) + captures: + 1: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + 2: keyword.operator.assignment.redirection.shell + set: + - redirection-meta + - redirection-descriptor + + redirection-inout: + - match: (\d*)(<>) + captures: + 1: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + 2: keyword.operator.assignment.redirection.shell + set: + - redirection-meta + - redirection-descriptor + + redirection-output: + - match: (\d*)((?:&>>?|>>?&?)[|!]?) + captures: + 1: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + 2: keyword.operator.assignment.redirection.shell + set: + - redirection-meta + - redirection-descriptor + + redirection-process: + - match: (\d*)([<>])(?=\() + captures: + 1: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + 2: keyword.operator.assignment.redirection.shell + set: + - redirection-meta + - cmd-compound-paren + + redirection-descriptor: + - meta_include_prototype: false + - match: \d+{{word_break}} + scope: meta.file-descriptor.shell meta.number.integer.decimal.shell constant.numeric.value.shell + pop: 1 + - match: '[-p]{{word_break}}' + scope: meta.file-descriptor.shell variable.language.stdio.shell + pop: 1 + - include: eoc-pop + - include: string-path-pattern + + redirection-meta: + - meta_include_prototype: false + - meta_scope: meta.redirection.shell + - include: immediately-pop + +###[ LITERALS ]################################################################ + + booleans: + - match: false\b + scope: constant.language.boolean.false.shell + - match: true\b + scope: constant.language.boolean.true.shell + + boolean: + - match: false\b + scope: constant.language.boolean.false.shell + pop: 1 + - match: true\b + scope: constant.language.boolean.true.shell + pop: 1 + + devnull: + - match: (/)dev(/)null{{word_break}} + scope: meta.string.glob.shell meta.path.shell constant.language.null.shell + captures: + 1: punctuation.separator.path.shell + 2: punctuation.separator.path.shell + pop: 1 + + numbers: + # strictly consume full numbers only, for use in contexts with strings + - include: base-numbers + - match: \d+{{dec_break}} + scope: meta.number.integer.decimal.shell constant.numeric.value.shell + + base-numbers: + # A leading β0xβ, β0Xβ or β16#β denote hexadecimal. + - match: 0[xX]|16# + scope: constant.numeric.base.shell + push: hex-number-body + # Constants with a leading 0 are interpreted as octal numbers. + - match: 0(?=[0-7$])|8# + scope: constant.numeric.base.shell + push: oct-number-body + # Otherwise, numbers take the form [base#]n, where the optional base is a + # decimal number between 2 and 64 representing the arithmetic base, and n is + # a number in that base. When specifying n, the digits greater than 9 are + # represented by the lowercase letters, the uppercase letters, β@β, and β_β, + # in that order. + - match: \d{{dec_digit}}*# + scope: constant.numeric.base.shell + push: other-number-body + + number: + # Note: Leading sign is scoped as operator for consistent highlighting as + # we can't distinguish operators from sign for sure everywhere. + # A leading β0xβ or β0Xβ denotes hexadecimal. + - match: ([-+]?)(0[xX]|16#) + captures: + 1: keyword.operator.arithmetic.shell + 2: constant.numeric.base.shell + set: hex-number-body + # Constants with a leading 0 are interpreted as octal numbers. + - match: ([-+]?)(0(?=[0-7$])|8#) + scope: meta.number.integer.octal.shell + captures: + 1: keyword.operator.arithmetic.shell + 2: constant.numeric.base.shell + set: oct-number-body + # Otherwise, numbers take the form [base#]n, where the optional base is a + # decimal number between 2 and 64 representing the arithmetic base, and n is + # a number in that base. When specifying n, the digits greater than 9 are + # represented by the lowercase letters, the uppercase letters, β@β, and β_β, + # in that order. + - match: ([-+]?)(\d{{dec_digit}}*#) + scope: meta.number.integer.other.she + captures: + 1: keyword.operator.arithmetic.shell + 2: constant.numeric.base.shell + set: other-number-body + # If base# is omitted, then base 10 is used. + # note: consume whole uninterpolated word only to avoid false positives. + - match: ([-+]?)(\d+){{dec_break}} + scope: meta.number.integer.decimal.shell + captures: + 1: keyword.operator.arithmetic.shell + 2: constant.numeric.value.shell + pop: 1 + + dec-number-body: + - meta_include_prototype: false + - meta_scope: meta.number.integer.decimal.shell + - match: '{{dec_digit}}+' + scope: constant.numeric.value.shell + - include: variable-expansions + - include: immediately-pop + + hex-number-body: + - meta_include_prototype: false + - meta_scope: meta.number.integer.hexadecimal.shell + - match: '{{hex_digit}}+' + scope: constant.numeric.value.shell + - include: variable-expansions + - include: immediately-pop + + oct-number-body: + - meta_include_prototype: false + - meta_scope: meta.number.integer.octal.shell + - match: '{{oct_digit}}+' + scope: constant.numeric.value.shell + - include: variable-expansions + - include: immediately-pop + + other-number-body: + - meta_include_prototype: false + - meta_scope: meta.number.integer.other.shell + - match: '[[:alnum:]@_]+' + scope: constant.numeric.value.shell + - include: variable-expansions + - include: immediately-pop + + literal-unquoted-content: + - match: \$?\" + scope: punctuation.definition.quoted.begin.shell + push: literal-double-quoted-body + - match: \$' + scope: punctuation.definition.quoted.begin.shell + push: literal-ansi-c-body + - match: \' + scope: punctuation.definition.quoted.begin.shell + push: literal-single-quoted-body + - include: string-prototype + - include: any-escapes + - include: brace-interpolations + - include: string-interpolations + + literal-ansi-c-body: + - match: \' + scope: punctuation.definition.quoted.end.shell + pop: 1 + - include: line-continuations + - include: string-prototype + - include: string-escapes-ansi-c + + literal-double-quoted-body: + - match: \" + scope: punctuation.definition.quoted.end.shell + pop: 1 + - include: line-continuations + - include: string-prototype + - include: string-escapes + - include: string-interpolations + + literal-single-quoted-body: + - match: \' + scope: punctuation.definition.quoted.end.shell + pop: 1 + - include: string-prototype + +###[ STRINGS ]################################################################# + + string-unquoted-content: + - include: string-quotes + - include: string-prototype + - include: any-escapes + - include: brace-interpolations + - include: string-interpolations + + string-quotes: + # [Bash] 3.1.2.5 + - match: \$?\" + scope: punctuation.definition.string.begin.shell + push: string-double-quoted-body + # [Bash] 3.1.2.4 + - match: \$' + scope: punctuation.definition.string.begin.shell + push: string-ansi-c-body + - match: \' + scope: punctuation.definition.string.begin.shell + push: string-single-quoted-body + + string-ansi-c-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: string.quoted.single.shell + - match: \' + scope: punctuation.definition.string.end.shell + pop: 1 + - include: line-continuations + - include: string-prototype + - include: string-escapes-ansi-c + + string-double-quoted-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: string.quoted.double.shell + - match: \" + scope: punctuation.definition.string.end.shell + pop: 1 + - include: line-continuations + - include: string-prototype + - include: string-escapes + - include: string-interpolations + + string-single-quoted-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: string.quoted.single.shell + - match: \' + scope: punctuation.definition.string.end.shell + pop: 1 + - include: string-prototype + + any-escapes: + - match: \\. + scope: constant.character.escape.shell + + string-escapes: + - match: \\(?:e|033)\[\d{1,3}(?:;\d{1,3}){0,4}m + scope: constant.character.escape.color.shell + - match: \\[$`"\\] + scope: constant.character.escape.shell + + string-escapes-ansi-c: + - match: \\([abfnrtv'"?$`\\]|[0-8]{1,3}|x\h{1,8}|c[a-z]) + scope: constant.character.escape.shell + + string-interpolations: + - match: '{{is_interpolation}}' + push: string-interpolation-body + + string-interpolation-body: + - clear_scopes: 1 + - meta_include_prototype: false + - include: variable-expansions + - include: immediately-pop + + # for use by inheriting syntaxes to easily inject string interpolation + # in any kind of quoted or unquoted string + string-prototype: + - include: merge-conflict-markers + +###[ STRING PATH PATTERN MATCHING ]############################################ + + group-path-patterns: + # This context consumes glob patterns within contexts (groups or lists) + # which do not support redirections or any other kind of pipelines. + # Operators like `&`, `;`, `|`, `<` or `>` are scoped illegal. + - match: (?=\S) + push: group-path-pattern + + group-path-pattern: + - include: devnull + - match: '{{illegal_group_separators}}+' + scope: invalid.illegal.unexpected-token.shell + pop: 1 + - match: '{{word_begin}}' + set: + - group-path-pattern-body + - maybe-tilde-interpolation + + group-path-pattern-body: + - meta_include_prototype: false + - meta_scope: meta.string.glob.shell string.unquoted.shell + - include: string-path-pattern-content + - include: word-end + + string-path-patterns: + # This context consumes glob patterns within contexts + # which support redirections or pipelines. + - match: (?=\S) + push: string-path-pattern + + string-path-pattern: + - include: devnull + - match: '{{word_begin}}' + set: + - string-path-pattern-body + - maybe-tilde-interpolation + + string-path-pattern-body: + - meta_include_prototype: false + - meta_scope: meta.string.glob.shell string.unquoted.shell + - include: string-path-pattern-content + - include: word-end + + string-path-pattern-content: + - match: \$?\" + scope: punctuation.definition.string.begin.shell + push: string-path-pattern-double-quoted-body + - match: \$' + scope: punctuation.definition.string.begin.shell + push: string-path-pattern-ansi-c-body + - match: \' + scope: punctuation.definition.string.begin.shell + push: string-path-pattern-single-quoted-body + - include: string-prototype + - include: any-escapes + - include: brace-interpolations + - include: string-interpolations + - include: job-expansions + - include: pattern-groups + - include: pattern-charsets + - include: pattern-common + - include: string-pathlist-separators + + string-path-pattern-ansi-c-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: string.quoted.single.shell + - include: string-ansi-c-body + - include: string-quoted-pathlist-separators + + string-path-pattern-double-quoted-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: string.quoted.double.shell + - include: string-double-quoted-body + - include: string-quoted-pathlist-separators + + string-path-pattern-single-quoted-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: string.quoted.single.shell + - include: string-single-quoted-body + - include: string-quoted-pathlist-separators + + string-pathlist-separators: + - match: '{{pathlist_separator}}' + scope: punctuation.separator.sequence.shell + push: path-pattern-begin + + string-quoted-pathlist-separators: + - match: '{{pathlist_separator}}' + scope: punctuation.separator.sequence.shell + +###[ PATH PATTERN MATCHING ]################################################### + + path-pattern-begin: + - include: tilde-interpolation + - include: path-pattern-quoted-begin + + path-pattern-quoted-begin: + - meta_include_prototype: false + - match: \.\.(?=/) + scope: constant.other.path.parent.shell + pop: 1 + - match: \.(?=/) + scope: constant.other.path.self.shell + pop: 1 + - include: line-continuations + - include: immediately-pop + + path-pattern-content: + - match: \$?\" + scope: punctuation.definition.quoted.begin.shell + push: path-pattern-double-quoted-body + - match: \$' + scope: punctuation.definition.quoted.begin.shell + push: path-pattern-ansi-c-body + - match: \' + scope: punctuation.definition.quoted.begin.shell + push: path-pattern-single-quoted-body + - include: string-prototype + - include: any-escapes + - include: brace-interpolations + - include: string-interpolations + - include: job-expansions + - include: pattern-groups + - include: pattern-charsets + - include: pattern-common + - include: path-separators + + path-pattern-ansi-c-body: + - meta_include_prototype: false + - include: literal-ansi-c-body + - include: path-separators + + path-pattern-double-quoted-body: + - meta_include_prototype: false + - include: literal-double-quoted-body + - include: path-separators + + path-pattern-single-quoted-body: + - meta_include_prototype: false + - include: literal-single-quoted-body + - include: path-separators + + path-separators: + - match: (/)(?:(?:(\.\.)|(\.))(?=/))? + captures: + 1: punctuation.separator.path.shell + 2: constant.other.path.parent.shell + 3: constant.other.path.self.shell + +###[ SHELL PATTERN MATCHING ]################################################## + + pattern-main-content: + # [3.5.8.1] Pattern Matching in arbitrary expressions + - include: string-unquoted-content + - include: pattern-only-groups # only groups, but no qualifiers (in Zsh) + - include: pattern-charsets + - include: pattern-common + + pattern-charsets: + - match: (?=\[) + branch_point: pattern-charset + branch: + - pattern-charset + - pattern-charset-fallback + + pattern-charset: + - match: (\[)([!^]?) + captures: + 1: punctuation.definition.character-class.begin.glob.shell + 2: keyword.operator.logical.glob.shell + set: + - pattern-charset-body + - pattern-charset-begin + + pattern-charset-body: + - meta_scope: meta.character-class.glob.shell + - match: (?!\S) # also fail at eof + fail: pattern-charset + - include: pattern-charset-end + - include: pattern-charset-content + + pattern-charset-begin: + - meta_include_prototype: false + # a range may start with `]` at the beginning of a set + - match: (?:(\\.)|.)(-)(?:(\\.)|[^\]$]|(?!\])) + scope: constant.other.range.glob.shell + captures: + 1: constant.character.escape.glob.shell + 2: punctuation.separator.sequence.glob.shell + 3: constant.character.escape.glob.shell + pop: 1 + # the following are treated literal at the beginning of a set + - match: '[]-]' + pop: 1 + - include: immediately-pop + + pattern-charset-end: + - match: \] + scope: punctuation.definition.character-class.end.glob.shell + pop: 1 + + pattern-charset-fallback: + - meta_include_prototype: false + - match: \[ + pop: 1 + + pattern-charset-content: + - match: \[\.(?=\S*\.\]) + scope: punctuation.definition.character-class.begin.glob.shell + push: pattern-charset-collate-body + - match: \[=(?=\S*=\]) + scope: punctuation.definition.character-class.begin.glob.shell + push: pattern-charset-equivalence-body + - match: \[:(?=(?:{{posix_classes}}|\$+(?:\{.*?\}|\w+)):\]) + scope: punctuation.definition.character-class.begin.glob.shell + push: pattern-charset-posix-body + - match: (?:(\\.)|[^\\\]])?(-)(?:(\\.)|[^\]$]|(?!\])) + scope: constant.other.range.glob.shell + captures: + 1: constant.character.escape.glob.shell + 2: punctuation.separator.sequence.glob.shell + 3: constant.character.escape.glob.shell + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + pattern-charset-collate-body: + - meta_scope: meta.character-class.glob.shell + - meta_content_scope: constant.other.character-class.collate.glob.shell + - match: \.\] + scope: punctuation.definition.character-class.end.glob.shell + pop: 1 + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + pattern-charset-equivalence-body: + - meta_scope: meta.character-class.glob.shell + - meta_content_scope: constant.other.character-class.equivalence.glob.shell + - match: =\] + scope: punctuation.definition.character-class.end.glob.shell + pop: 1 + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + pattern-charset-posix-body: + - meta_scope: meta.character-class.glob.shell + - meta_content_scope: constant.other.character-class.posix.glob.shell + - match: ({{posix_classes}}?)(:\]) + captures: + 1: constant.other.character-class.posix.glob.shell + 2: punctuation.definition.character-class.end.glob.shell + pop: 1 + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + pattern-only-groups: + # included in contexts, Zsh doesn't support bare glob qualifiers in + - include: pattern-groups + + pattern-groups: + # included in contexts, Zsh supports bare glob qualifiers in + - match: '[?*+@!](?=\()' + scope: keyword.operator.quantifier.glob.shell + push: pattern-group + + pattern-group: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.glob.shell + set: pattern-group-body + + pattern-group-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: meta.group.glob.shell string.unquoted.shell + - include: pattern-group-end + - include: pattern-group-content + + pattern-group-end: + - match: \) + scope: punctuation.section.group.end.glob.shell + pop: 1 + - include: line-continuations + + pattern-group-content: + - include: string-unquoted-content + - include: pattern-only-groups + - include: pattern-group-charsets + - include: pattern-group-operators + - include: pattern-common + + pattern-group-charsets: + - match: (?=\[) + branch_point: pattern-group-charset + branch: + - pattern-group-charset + - pattern-charset-fallback + + pattern-group-charset: + - match: (\[)([!^]?) + captures: + 1: punctuation.definition.character-class.begin.glob.shell + 2: keyword.operator.logical.glob.shell + set: + - pattern-group-charset-body + - pattern-charset-begin + + pattern-group-charset-body: + - meta_scope: meta.character-class.glob.shell + - match: (?=\)) + fail: pattern-group-charset + - include: pattern-charset-end + - include: pattern-charset-content + + pattern-group-operators: + - match: \| + scope: keyword.operator.alternation.glob.shell + + pattern-common: + - match: \* + scope: constant.other.wildcard.asterisk.shell + - match: \? + scope: constant.other.wildcard.questionmark.shell + +###[ POSIX EXTENDED REGULAR EXPRESSIONS ]###################################### + + eregexp-main-content: + - include: eregexp-quantifiers + - include: string-unquoted-content + - include: eregexp-charsets + - include: eregexp-groups + - include: eregexp-anchors + - include: eregexp-operators + - include: eregexp-literals + + eregexp-groups: + - match: \( + scope: punctuation.section.group.begin.regexp.shell + push: [eregexp-group-body, eregexp-unexpected-quantifier] + + eregexp-group-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: meta.group.regexp.shell string.unquoted.shell + - match: \) + scope: punctuation.section.group.end.regexp.shell + pop: 1 + - include: line-continuations + - include: eregexp-group-content + + eregexp-group-content: + - include: eregexp-quantifiers + - include: string-unquoted-content + - include: eregexp-group-charsets + - include: eregexp-groups + - include: eregexp-anchors + - include: eregexp-operators + - include: eregexp-literals + + eregexp-charsets: + - match: (?=\[) + branch_point: eregexp-charset + branch: + - eregexp-charset + - pattern-charset-fallback + + eregexp-charset: + - meta_include_prototype: false + - match: (\[)(\^?) + captures: + 1: punctuation.definition.character-class.begin.regexp.shell + 2: keyword.operator.logical.regexp.shell + set: + - eregexp-charset-body + - eregexp-charset-begin + + eregexp-charset-body: + - meta_include_prototype: false + - meta_scope: meta.character-class.regexp.shell + - match: (?!\S) # also fail at eof + fail: eregexp-charset + - include: eregexp-charset-end + - include: eregexp-charset-content + + eregexp-group-charsets: + - match: (?=\[) + branch_point: eregexp-group-charset + branch: + - eregexp-group-charset + - pattern-charset-fallback + + eregexp-group-charset: + - match: (\[)(\^?) + captures: + 1: punctuation.definition.character-class.begin.regexp.shell + 2: keyword.operator.logical.regexp.shell + set: + - eregexp-group-charset-body + - eregexp-charset-begin + + eregexp-group-charset-body: + - meta_include_prototype: false + - meta_scope: meta.character-class.regexp.shell + - match: (?=\)) + fail: eregexp-group-charset + - include: eregexp-charset-end + - include: eregexp-charset-content + + eregexp-charset-begin: + - meta_include_prototype: false + # a range may start with `]` at the beginning of a set + - match: (?:(\\.)|.)(-)(?:(\\.)|[^\]$]|(?!\])) + scope: constant.other.range.regexp.shell + captures: + 1: constant.character.escape.regexp.shell + 2: punctuation.separator.sequence.regexp.shell + 3: constant.character.escape.regexp.shell + pop: 1 + # the following are treated literal at the beginning of a set + - match: '[]-]' + pop: 1 + - include: immediately-pop + + eregexp-charset-end: + - match: \] + scope: punctuation.definition.character-class.end.regexp.shell + pop: 1 + + eregexp-charset-fallback: + - meta_include_prototype: false + - match: \[ + pop: 1 + + eregexp-charset-content: + - match: \[\.(?=\S*\.\]) + scope: punctuation.definition.character-class.begin.regexp.shell + push: eregexp-charset-collate-body + - match: \[=(?=\S*=\]) + scope: punctuation.definition.character-class.begin.regexp.shell + push: eregexp-charset-equivalence-body + - match: \[:(?=(?:{{posix_classes}}|\$+(?:\{.*?\}|\w+)):\]) + scope: punctuation.definition.character-class.begin.regexp.shell + push: eregexp-charset-posix-body + - match: (?:(\\.)|[^\\\]])?(-)(?:(\\.)|[^\]$]|(?!\])) + scope: constant.other.range.regexp.shell + captures: + 1: constant.character.escape.regexp.shell + 2: punctuation.separator.sequence.regexp.shell + 3: constant.character.escape.regexp.shell + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + eregexp-charset-collate-body: + - meta_scope: meta.character-class.regexp.shell + - meta_content_scope: constant.other.character-class.collate.regexp.shell + - match: \.\] + scope: punctuation.definition.character-class.end.regexp.shell + pop: 1 + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + eregexp-charset-equivalence-body: + - meta_scope: meta.character-class.regexp.shell + - meta_content_scope: constant.other.character-class.equivalence.regexp.shell + - match: =\] + scope: punctuation.definition.character-class.end.regexp.shell + pop: 1 + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + eregexp-charset-posix-body: + - meta_scope: meta.character-class.regexp.shell + - meta_content_scope: constant.other.character-class.posix.regexp.shell + - match: ({{posix_classes}}?)(:\]) + captures: + 1: constant.other.character-class.posix.regexp.shell + 2: punctuation.definition.character-class.end.regexp.shell + pop: 1 + - include: any-escapes + - include: variable-expansions + - include: eol-pop + + eregexp-anchors: + - match: '[$^]' + scope: keyword.control.anchor.regexp.shell + push: eregexp-unexpected-quantifier + + eregexp-operators: + - match: \| + scope: keyword.operator.alternation.regexp.shell + push: eregexp-unexpected-quantifier + + eregexp-quantifiers: + - match: '{{ranged_quantifier}}{{lazy_or_possessive}}' + scope: keyword.operator.quantifier.regexp.shell + push: eregexp-unexpected-quantifier + - match: '{{character_quantifier}}{{lazy_or_possessive}}' + scope: keyword.operator.quantifier.regexp.shell + push: eregexp-unexpected-quantifier + + eregexp-unexpected-quantifier: + - meta_include_prototype: false + - match: '{{ranged_quantifier}}{{lazy_or_possessive}}' + scope: invalid.illegal.unexpected-quantifier.regexp.shell + - match: '{{character_quantifier}}{{lazy_or_possessive}}' + scope: invalid.illegal.unexpected-quantifier.regexp.shell + - include: immediately-pop + + eregexp-literals: + - match: \. + scope: keyword.other.any.regexp.shell + +###[ EXPANSIONS ]############################################################## + + variable-expansions: + - include: arithmetic-expansions + - include: command-expansions + - include: parameter-expansions + +###[ ARITHMETIC EXPANSIONS ]################################################### + + arithmetic-expansions: + - match: (?=\$\(\() + branch_point: arithmetic-expansion + branch: + - arithmetic-expansion + - command-expansion + - match: (\$)(\[) + captures: + 1: punctuation.definition.variable.shell.shell + 2: punctuation.section.interpolation.begin.shell.shell + push: arithmetic-expansion-bracket-body + + arithmetic-expansion: + - match: (\$)(\(\() + captures: + 1: punctuation.definition.variable.shell + 2: punctuation.section.interpolation.begin.shell + set: arithmetic-expansion-parens-body + + arithmetic-expansion-parens-body: + - meta_scope: meta.interpolation.arithmetic.shell + - match: \)\) + scope: punctuation.section.interpolation.end.shell + pop: 1 + - match: (?=\)) + fail: arithmetic-expansion + - include: expression-content + - include: expression-illegals + + arithmetic-expansion-bracket-body: + - meta_scope: meta.interpolation.arithmetic.shell.shell + - match: \] + scope: punctuation.section.interpolation.end.shell.shell + pop: 1 + - include: expression-content + - include: expression-illegals + +###[ BRACE EXPANSIONS ]######################################################## + + brace-interpolations: + # use branching as valid brace expansions must not exceed word boundaries + - match: (?={) + branch_point: brace-interpolation + branch: + - brace-interpolation-sequence + - brace-interpolation-series + - brace-interpolation-fallback + + brace-interpolation-sequence: + # sequence expression + - clear_scopes: 1 + - meta_include_prototype: false + - match: \{ + scope: + meta.interpolation.brace.shell + punctuation.section.interpolation.begin.shell + push: + - brace-interpolation-sequence-body + - brace-interpolation-sequence-begin + + brace-interpolation-sequence-begin: + - match: \.\. + scope: keyword.operator.range.shell + pop: 1 + - include: line-continuations + - include: brace-interpolation-sequence-content + + brace-interpolation-sequence-body: + - meta_content_scope: meta.interpolation.brace.shell + - match: \.\. + scope: keyword.operator.range.shell + - include: brace-interpolation-end + - include: brace-interpolation-sequence-content + + brace-interpolation-sequence-content: + - include: variable-expansions + - match: ([-+]?)(\d+) + scope: meta.number.integer.decimal.shell + captures: + 1: keyword.operator.arithmetic.shell + 2: constant.numeric.value.shell + - match: '[[:alpha:]]' + scope: constant.character.shell + - match: '' + fail: brace-interpolation + + brace-interpolation-series: + # series of comma-separated strings + - clear_scopes: 1 + - meta_include_prototype: false + - match: \{ + scope: + meta.interpolation.brace.shell + punctuation.section.interpolation.begin.shell + push: brace-interpolation-series-begin + + brace-interpolation-series-begin: + - meta_include_prototype: false + - meta_content_scope: + meta.interpolation.brace.shell + meta.string.shell string.unquoted.shell + - match: (?=\}) + fail: brace-interpolation + - include: line-continuations + - include: brace-interpolation-series-content + + brace-interpolation-series-body: + - meta_include_prototype: false + - meta_content_scope: + meta.interpolation.brace.shell + meta.string.shell string.unquoted.shell + - include: brace-interpolation-end + - include: brace-interpolation-series-content + + brace-interpolation-series-content: + - match: \, + scope: + meta.interpolation.brace.shell + punctuation.separator.sequence.shell + set: brace-interpolation-series-body + - include: line-continuations + - include: pattern-main-content + - match: '{{word_break}}' + fail: brace-interpolation + + brace-interpolation-end: + - match: \} + scope: + meta.interpolation.brace.shell + punctuation.section.interpolation.end.shell + pop: 2 + - include: line-continuations + + brace-interpolation-fallback: + - meta_include_prototype: false + - match: \{ + pop: 1 + +###[ COMMAND EXPANSIONS ]###################################################### + + command-expansions: + - match: (\$)(\() + captures: + 1: punctuation.definition.variable.shell + 2: punctuation.section.interpolation.begin.shell + push: command-expansion-body + # scope backtick command expansion containing only line comment + # `comment` to enable toggle_comment command + - match: (`)(#)(?=.*`) # No newlines + captures: + 1: punctuation.section.interpolation.begin.shell + 2: punctuation.definition.comment.shell + push: command-expansion-comment-body + # normal backtick command expansion + - match: \` + scope: + meta.interpolation.command.shell + punctuation.section.interpolation.begin.shell + embed: statements + embed_scope: meta.interpolation.command.shell + escape: '{{no_escape_behind}}\`' + escape_captures: + 0: meta.interpolation.command.shell + punctuation.section.interpolation.end.shell + + command-expansion-comment-body: + - meta_scope: meta.interpolation.command.shell comment.block.number-sign.shell + - match: \` + scope: punctuation.section.interpolation.end.shell + pop: 1 + + command-expansion: + - match: (\$)(\() + captures: + 1: punctuation.definition.variable.shell + 2: punctuation.section.interpolation.begin.shell + set: command-expansion-body + + command-expansion-body: + - meta_scope: meta.interpolation.command.shell + - match: \s*(\)) + captures: + 1: punctuation.section.interpolation.end.shell + pop: 1 + - include: statements + +###[ JOB EXPANSIONS ]########################################################## + + job-expansions: + # There are a number of ways to refer to a job in the shell. + # The symbols β%%β and β%+β refer to the shellβs notion of the current job, + # which is the last job stopped while it was in the foreground or started in + # the background. The previous job may be referenced using β%-β. + # Job number n may be referred to as β%nβ. + - match: (%)([-+%]|\d+) + scope: + meta.interpolation.job.shell + variable.language.job.shell + captures: + 1: punctuation.definition.variable.shell + # A job may also be referred to using a prefix of the name used to start it, + # or using a substring that appears in its command line. For example, β%ceβ + # refers to a stopped ce job. Using β%?ceβ, on the other hand, refers to any + # job containing the string βceβ in its command line. If the prefix or + # substring matches more than one job, Bash reports an error. + # A single β%β (with no accompanying job specification) also refers to the + # current job. + - match: (%)(?:(\??)\w+)? + scope: + meta.interpolation.job.shell + variable.other.readwrite.shell + captures: + 1: punctuation.definition.variable.shell + 2: keyword.operator.match.shell + +###[ PARAMETER EXPANSIONS ]#################################################### + + parameter-expansions: + - match: (\$)(\{) + captures: + 1: punctuation.definition.variable.shell + 2: punctuation.section.interpolation.begin.shell + push: + - parameter-expansion-meta + - parameter-expansion-modifier + - subscript + - parameter-expansion-name + - parameter-expansion-operator + - match: (?=\${{word_char}}) + push: simple-parmeter-expansion + + simple-parmeter-expansion: + - meta_include_prototype: false + - meta_scope: meta.interpolation.parameter.shell + # https://www.gnu.org/software/bash/manual/bash.html#Positional-Parameters + - match: (\$)\d + scope: variable.language.positional.shell + captures: + 1: punctuation.definition.variable.shell + pop: 1 + # https://www.gnu.org/software/bash/manual/bash.html#Shell-Variables + - match: (\$){{builtin_variables}} + scope: variable.language.builtin.shell + captures: + 1: punctuation.definition.variable.shell + pop: 1 + # https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters + - match: (\$){{special_variables}} + scope: variable.language.special.shell + captures: + 1: punctuation.definition.variable.shell + pop: 1 + - match: (\$){{identifier}} + scope: variable.other.readwrite.shell + captures: + 1: punctuation.definition.variable.shell + pop: 1 + - include: immediately-pop + + parameter-expansion-meta: + - meta_include_prototype: false + - meta_scope: meta.interpolation.parameter.shell + - include: immediately-pop + + parameter-expansion-operator: + # Both ! and # are operators and special parameters at the same time. + # First char is operator only if not followed by } or operator + # Note: Matches may be wrong if line continuation follows, but it seems + # unlikely enough to accept it, instead of overcomplicating with branching. + - meta_include_prototype: false + # Expansion result is used as new parameter name to expand + # Adds a level of indirection to name resolution + - match: \!(?![/%,~:=^}]|[-+?@][^}]) + scope: keyword.operator.expansion.indirection.shell + pop: 1 + # Length of var in words (array) or bytes + - match: \#(?![/%,~:=^}]|[-+?@#][^}]) + scope: keyword.operator.expansion.length.shell + pop: 1 + - include: line-continuations + - include: immediately-pop + + parameter-expansion-name: + - meta_include_prototype: false + - match: \d+ + scope: variable.language.positional.shell + pop: 1 + - match: '{{builtin_variables}}(?=[-+*/%?,~:=#^@}\[])' + scope: variable.language.builtin.shell + pop: 1 + - match: '{{special_variables}}(?=[-+*/%?,~:=#^@}\[])' + scope: variable.language.special.shell + pop: 1 + - match: '' + set: parameter-expansion-name-chars + + parameter-expansion-name-chars: + - meta_content_scope: variable.other.readwrite.shell + # note: no quoted name parts allowed within parameter expansions + - match: '[@*](?!\w)' + scope: variable.language.special.shell + pop: 1 + - include: variable-name-chars + + parameter-expansion-modifier: + # ${parameter@operator} + - match: (?:(@)({{parameter_switch}}))?(}) + captures: + 1: keyword.operator.expansion.shell + 2: variable.parameter.switch.shell + 3: punctuation.section.interpolation.end.shell + pop: 1 + # ${parameter:=word} + - match: :?[-+=?] + scope: keyword.operator.assignment.shell + set: + - parameter-expansion-pattern + - maybe-tilde-interpolation + # ${parameter:offset:length} + - match: ':' + scope: keyword.operator.substring.begin.shell + set: parameter-expansion-substr-start + # ${parameter/pattern/word} + - match: /[/#%]? + scope: keyword.operator.substitution.shell + set: + - parameter-expansion-substitution-pattern + - maybe-tilde-interpolation + # ${parameter#pattern} + # ${parameter##pattern} + # ${parameter%pattern} + # ${parameter%%pattern} + - match: (?:##?|%%?) + scope: keyword.operator.expansion.shell + set: + - parameter-expansion-pattern + - maybe-tilde-interpolation + # ${parameter^pattern} + # ${parameter^^pattern} + # ${parameter,pattern} + # ${parameter,,pattern} + # ${parameter~pattern} + # ${parameter~~pattern} + - match: (?:\^\^?|,,?|~~?) + scope: keyword.operator.expansion.shell + set: parameter-expansion-pattern + + parameter-expansion-substr-start: + - meta_content_scope: meta.arithmetic.shell + - match: ':' + scope: keyword.operator.substring.end.shell + set: parameter-expansion-expression + - include: parameter-expansion-expression + + parameter-expansion-expression: + - meta_content_scope: meta.arithmetic.shell + - include: parameter-expansion-end + - include: expression-content + - include: expression-illegals + + parameter-expansion-substitution-pattern: + # [3.5.8.1] Pattern Matching in parameter expansions' substitutions + - meta_include_prototype: false + - meta_content_scope: meta.string.glob.shell string.unquoted.shell + - match: / + scope: keyword.operator.substitution.shell + set: parameter-expansion-string + - include: parameter-expansion-pattern + + parameter-expansion-pattern: + # [3.5.8.1] Pattern Matching in parameter expansions + - meta_include_prototype: false + - meta_content_scope: meta.string.glob.shell string.unquoted.shell + - include: parameter-expansion-end + - include: string-unquoted-content + - include: parameter-expansion-pattern-charsets + - include: parameter-expansion-pattern-groups + - include: pattern-common + + parameter-expansion-pattern-charsets: + - match: (?=\[) + branch_point: parameter-expansion-pattern-charset + branch: + - parameter-expansion-pattern-charset + - pattern-charset-fallback + + parameter-expansion-pattern-charset: + - match: (\[)([!^]?) + captures: + 1: punctuation.definition.character-class.begin.glob.shell + 2: keyword.operator.logical.glob.shell + set: + - parameter-expansion-pattern-charset-body + - pattern-charset-begin + + parameter-expansion-pattern-charset-body: + - meta_scope: meta.character-class.glob.shell + - match: $|(?=\}) # bailout at end parameter + fail: parameter-expansion-pattern-charset + - include: pattern-charset-end + - include: pattern-charset-content + + parameter-expansion-pattern-groups: + - match: '[?*+@!]?(?=\()' + scope: keyword.operator.quantifier.glob.shell + push: parameter-expansion-pattern-group + + parameter-expansion-pattern-group: + - meta_include_prototype: false + - match: \( + scope: punctuation.section.group.begin.glob.shell + set: parameter-expansion-pattern-group-body + + parameter-expansion-pattern-group-body: + - clear_scopes: 1 # clear `string.unquoted` + - meta_include_prototype: false + - meta_scope: meta.group.glob.shell string.unquoted.shell + - include: pattern-group-end + - include: parameter-expansion-pattern-group-content + - include: brace-pop + + parameter-expansion-pattern-group-content: + - include: string-unquoted-content + - include: parameter-expansion-pattern-groups + - include: parameter-expansion-pattern-group-charsets + - include: pattern-group-operators + - include: pattern-common + + parameter-expansion-pattern-group-charsets: + - match: (?=\[) + branch_point: parameter-expansion-pattern-group-charset + branch: + - parameter-expansion-pattern-group-charset + - pattern-charset-fallback + + parameter-expansion-pattern-group-charset: + - match: (\[)([!^]?) + captures: + 1: punctuation.definition.character-class.begin.glob.shell + 2: keyword.operator.logical.glob.shell + set: + - parameter-expansion-pattern-group-charset-body + - pattern-charset-begin + + parameter-expansion-pattern-group-charset-body: + - meta_scope: meta.character-class.glob.shell + - match: $|(?=[)}]) # bailout at end of group or parameter + fail: parameter-expansion-pattern-group-charset + - include: pattern-charset-end + - include: pattern-charset-content + + parameter-expansion-string: + - meta_include_prototype: false + - meta_content_scope: meta.string.shell string.unquoted.shell + - include: parameter-expansion-end + - include: string-unquoted-content + + parameter-expansion-end: + - match: \} + scope: punctuation.section.interpolation.end.shell + pop: 1 + - include: line-continuations + +###[ TILDE EXPANSIONS ]######################################################## + + maybe-tilde-interpolation: + - meta_include_prototype: false + # https://www.gnu.org/software/bash/manual/bash.html#Tilde-Expansion + - include: tilde-interpolation + - include: line-continuations + - include: immediately-pop + + tilde-interpolation: + - match: \~ + scope: variable.language.tilde.shell + set: tilde-modifier + + tilde-modifier: + - clear_scopes: 1 + - meta_include_prototype: false + - meta_scope: meta.interpolation.tilde.shell + - match: (?:[-+]?\d+|[-+](?=\\?/|{{metachar}})) + scope: variable.language.tilde.shell + pop: 1 + - match: '' + set: tilde-modifier-username + + tilde-modifier-username: + - clear_scopes: 1 + - meta_include_prototype: false + - meta_content_scope: meta.interpolation.tilde.shell constant.other.username.shell + - include: line-continuations + - include: string-interpolations + - match: (?=\\?/|[]}{{metachar}}]) + pop: 1 + +###[ ILLEGALS ]################################################################ + + illegal-options: + - match: (--|[-+]){{identifier}} + scope: invalid.illegal.parameter.shell + + illegal-stray: + - match: '[)}\]]' + scope: invalid.illegal.stray.shell + + illegal-words: + - match: '{{word_begin}}' + push: illegal-word-chars + + illegal-word-chars: + - meta_include_prototype: false + - meta_scope: invalid.illegal.unexpected-token.shell + - include: literal-unquoted-content + - include: word-end + +###[ PROTOTYPES ]############################################################## + + brace-pop: + - match: (?=\}) + pop: 1 + + else-pop: + - match: (?=\S) + pop: 1 + + eoc-pop: + - match: (?=\s*(?:[)}|;]|&(?!>))) + pop: 1 + - include: eol-pop + + eol-pop: + - match: $|(?={{wspace}}[#\n]) + pop: 1 + - include: line-continuations + + immediately-pop: + - match: '' + pop: 1 + + pipesep-pop: + - match: (?=[{{pipe_seps}}]) + pop: 1 + + word-end: + - match: '{{word_break}}' + pop: 1 + - include: line-continuations + +###[ VARIABLES ]############################################################### + +variables: + # Language identifier in shebang + shebang_language: \b(?:bash|sh|tcsh|ash|dash)\b + + # Commands literals are command names without interpolation or quotation. + cmd_literal: '{{cmd_literal_char}}+{{cmd_break}}' + cmd_literal_char: '[^{{metachar}}%$\\"''`]' + + # Command names are non-posix identifiers, which may include assignment operators. + cmd_begin: (?={{cmd_char}}) + cmd_break: (?!{{cmd_char}}) + cmd_char: '[^{{metachar}}]' + + # Command options are identifiers, which may start with interpolation. + opt_punctuation: (--|[-+])(?={{word_char}}) + opt_break: (?!{{opt_char}}) + opt_char: '[^={{metachar}}]' + + # HEREDOC tag names + heredoc: '{{heredoc_first_char}}{{heredoc_char}}*' + heredoc_first_char: '[[:alpha:]_]' + heredoc_char: '[[:alnum:]_.-]' + heredoc_break: (?!{{heredoc_char}}) + + # Variable names + variable_begin: (?={{variable_first_char}}) + variable_first_char: '[{{identifier_first_char}}''"%${\\]' + + # POSIX identifiers (alpha-numeric) + identifier: '{{identifier_first_char}}{{identifier_char}}*' + identifier_first_char: '[[:alpha:]_]' + identifier_char: '[[:alnum:]_]' + identifier_break: (?!{{identifier_char}}) + + # Generic identifiers (shell words) + word_begin: (?=\S) + word_break: (?!{{word_char}}) + word_char: '[^{{metachar}}]' + + # A character that, when unquoted, separates words. A metacharacter is a + # space, tab, newline, or one of the following characters: β|β, β&β, β;β, + # β(β, β)β, β<β, or β>β. + metachar: '[\s(){{pipe_seps}}]' + pipe_seps: '\|&<>;' + wspace: (?:\s+|^) + + # Indentation and whitespace patterns + no_indent: ^ + tab_indent: ^\t* + + # A lookbehind used in embed..escape patterns, to check for unescaped characters + # in embed...escape statements. + no_escape_behind: (?<![^\\]\\)(?<![\\]{3}) + + case_clause_end: ;;&?|;& + + # Parameter expansions + is_interpolation: (?=\$[({\[{{identifier_char}}{{special_variables}}]|`) + parameter_switch: '[AEKLPQUaku]' + + # Filename expansions + pathlist_separator: :(?=\$|(?:~|\.?\.)?/(?!/)) + + illegal_group_separators: '[({{pipe_seps}}]' + + # POSIX extended regexp quantifiers + character_quantifier: '[?*+]' + lazy_or_possessive: '[?+]?' + ranged_quantifier: \{\d+(?:,\d*)?\} + + posix_classes: |- + (?x: ascii | alnum | alpha | blank | cntrl | digit | graph + | lower | print | punct | space | upper | word | xdigit ) + + # Numbers + dec_break: '{{word_break}}' + dec_digit: \d + hex_digit: \h + oct_digit: '[0-7]' + varassign: '[-+]?=' + + # 12 Test Expressions + arithmetic_comparison_operators: -(?:eq|ne|lt|le|gt|ge){{opt_break}} + file_comparison_operators: -(?:ef|nt|ot){{opt_break}} + test_options: ([-+])[bcdefghknprstuvwxzGLNORS]{{opt_break}}(?!\s*(=~|!=|==?)) + + # 3.3 Shell Functions + # Implicit function definition without `function` keyword + is_bare_function_definition: (?={{cmd_literal}}\s*\(\s*\)) + + # 4.2 Shell Built-in Commands + # https://www.gnu.org/software/bash/manual/bash.html#Bash-Builtins + # Note: Contains items which are not present as dedicated contexts + builtin_cmds: |- + (?x: \. | \: | bg | bind | caller | cd | compgen | complete | compopt + | dirs | disown | enable | eval | fc | fg | getopts | hash | help + | history | jobs | kill | logout | popd | printf | pushd | pwd | set + | shift | shopt | source | su | suspend | times | type | ulimit | umask + | wait ){{cmd_break}} + + modifier_cmds: |- + (?x: builtin ){{cmd_break}} + + # 5 Shell Variables + # https://www.gnu.org/software/bash/manual/bash.html#Shell-Variables + builtin_variables: |- + (?x: + _ + | BASH + | BASH_ALIASES + | BASH_ARGC + | BASH_ARGV + | BASH_ARGV0 + | BASH_CMDS + | BASH_COMMAND + | BASH_COMPAT + | BASH_ENV + | BASH_EXECUTION_STRING + | BASH_LINENO + | BASH_LOADABLES_PATH + | BASH_REMATCH + | BASH_SOURCE + | BASH_SUBSHELL + | BASH_VERSINFO + | BASH_VERSION + | BASH_XTRACEFD + | BASHOPTS + | BASHPID + | CDPATH + | CHILD_MAX + | COLUMNS + | COMP_CWORD + | COMP_KEY + | COMP_LINE + | COMP_POINT + | COMP_TYPE + | COMP_WORDBREAKS + | COMP_WORDS + | COMPREPLY + | COPROC + | DIRSTACK + | EMACS + | ENV + | EPOCHREALTIME + | EPOCHSECONDS + | EUID + | EXECIGNORE + | FCEDIT + | FIGNORE + | FUNCNAME + | FUNCNEST + | GLOBIGNORE + | GROUPS + | histchars + | HISTCMD + | HISTCONTROL + | HISTFILE + | HISTFILESIZE + | HISTIGNORE + | HISTSIZE + | HISTTIMEFORMAT + | HOME + | HOSTFILE + | HOSTNAME + | HOSTTYPE + | IFS + | IGNOREEOF + | INPUTRC + | INSIDE_EMACS + | LANG + | LC_ALL + | LC_COLLATE + | LC_CTYPE + | LC_MESSAGES + | LC_NUMERIC + | LC_TIME + | LINENO + | LINES + | MACHTYPE + | MAIL + | MAILCHECK + | MAILPATH + | MAPFILE + | OLDPWD + | OPTARG + | OPTERR + | OPTIND + | OSTYPE + | PATH + | PIPESTATUS + | POSIXLY_CORRECT + | PPID + | PROMPT_COMMAND + | PROMPT_DIRTRIM + | PS0 + | PS1 + | PS2 + | PS3 + | PS4 + | PWD + | RANDOM + | READLINE_ARGUMENT + | READLINE_LINE + | READLINE_MARK + | READLINE_POINT + | REPLY + | SECONDS + | SHELL + | SHELLOPTS + | SHLVL + | SRANDOM + | TIMEFORMAT + | TMOUT + | TMPDIR + | UID + ){{identifier_break}} + + # 3.4.2 Special Parameters + # https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters + special_variables: '[$#@!*?-]' + + signal_names: |- + (?x: EXIT | DEBUG | SIG {{signal_subnames}} ){{word_break}} + + signal_subnames: |- + (?x: + | ABRT + | ALRM + | BUS + | CHLD + | CONT + | FPE + | HUP + | ILL + | INT + | IO + | KILL + | LWP + | PIPE + | PROF + | PWR + | QUIT + | RTMAX(?:-(?:1[0-4]|\d))? + | RTMIN(?:\+(?:1[0-5]|\d))? + | SEGV + | STKFLT + | STOP + | SYS + | TERM + | TRAP + | TSTP + | TTIN + | TTOU + | URG + | USR1 + | USR2 + | VTALRM + | WAITING + | WINCH + | XCPU + | XFSZ + )